drew 6 years ago
parent
commit
bf0fdde3e9
1 changed files with 56 additions and 49 deletions
  1. 56 49
      src/main/java/com/thmodel/dao/impl/ModelInfoDaoImpl.java

+ 56 - 49
src/main/java/com/thmodel/dao/impl/ModelInfoDaoImpl.java

@@ -47,11 +47,11 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
     @Override
     public Map<String, Object> getmodel(int memberpk, String area, int index, int size) {
         String whereSql = " m.nominate = 1 ";
-        if ("烟台".equals(area)) {
+        if (StringUtils.isNotBlank(area) && !"全国".equals(area)) {
             if (StringUtils.isNotEmpty(whereSql)) {
-                whereSql += " and b.Area=80 ";
+                whereSql += " and b.Area=(select PK from datatypeinfo where TypeName = '地区' and Name = '" + area + "') ";
             } else {
-                whereSql = " b.Area=80 ";
+                whereSql = " b.Area=(select PK from datatypeinfo where TypeName = '地区' and Name = '" + area + "') ";
             }
         }
         List<ModelInfo> list = modelInfoAndPhotoInfoList(memberpk, whereSql, true, index, size);
@@ -172,11 +172,13 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
                     modelinfo.setConstellation(rs.getString("constellation"));
                     modelinfo.setAge(rs.getString("Age"));
                     modelinfo.setTotalOrder(rs.getString("order_num"));
-                    modelinfo.setOrderRate(String.valueOf(rs.getInt("answer_num") * 100 / (Math.max(Integer.valueOf(modelinfo.getTotalOrder()), 1))));
+                    modelinfo.setOrderRate(String.valueOf(rs.getInt("answer_num") * 100 / (Math
+                            .max(Integer.valueOf(modelinfo.getTotalOrder()), 1))));
 
                     //拼接3个 技能标签名字
                     int skill_sum = 3;
-                    String skillnames = new DbConnection().queryOneString("select GROUP_CONCAT(name separator ' ') from (select name from datatypeinfo where pk in(select skillpk from ModelPrice where ModelPK =" + modelpk + " order by PDate desc ) order by ordid limit " + skill_sum + ")tt0_ ");
+                    String skillnames = new DbConnection()
+                            .queryOneString("select GROUP_CONCAT(name separator ' ') from (select name from datatypeinfo where pk in(select skillpk from ModelPrice where ModelPK =" + modelpk + " order by PDate desc ) order by ordid limit " + skill_sum + ")tt0_ ");
                     modelinfo.setSkillnames(skillnames);
 
                     modelinfo.setTel(rs.getString("tel"));//账号
@@ -525,7 +527,8 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
 
                     List<Integer> photoPkList = new ArrayList<Integer>();
                     List<String> photoList = new ArrayList<String>();
-                    sql = "select distinct modelpk, t.photo from(select * from modelphoto where modelpk in (select PK from modelinfo where brokepk = '" + rs.getString("pk") + "')ORDER BY modelpk,OrdId) t group by modelpk";
+                    sql = "select distinct modelpk, t.photo from(select * from modelphoto where modelpk in (select PK from modelinfo where brokepk = '" + rs
+                            .getString("pk") + "')ORDER BY modelpk,OrdId) t group by modelpk";
 
                     CachedRowSet rs2 = db.executeQuery(sql);
                     if (rs2 != null) {
@@ -587,11 +590,11 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
         if (likeName != null && !likeName.equals("")) {
             whereSql = " (b.pet like '%" + likeName + "%' or m.Stage like '%" + likeName + "%')";
         }
-        if ("烟台".equals(area)) {
+        if (StringUtils.isNotBlank(area) && !"全国".equals(area)) {
             if (StringUtils.isNotEmpty(whereSql)) {
-                whereSql += " and b.Area=80 ";
+                whereSql += " and b.Area=(select PK from datatypeinfo where TypeName = '地区' and Name = '" + area + "') ";
             } else {
-                whereSql = " b.Area=80 ";
+                whereSql = " b.Area=(select PK from datatypeinfo where TypeName = '地区' and Name = '" + area + "') ";
             }
         }
         List<ModelInfo> list = modelInfoAndPhotoInfoList(memberpk, whereSql, true, index, size);
@@ -924,11 +927,11 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
             Map<String, Object> resultMap = new HashMap<String, Object>();
             String whereSql = " m.pk in(select distinct modelpk from modelprice where skillpk in (" + pks + ")) ";
 
-            if ("烟台".equals(area)) {
+            if (StringUtils.isNotBlank(area) && !"全国".equals(area)) {
                 if (StringUtils.isNotEmpty(whereSql)) {
-                    whereSql += " and b.Area=80' ";
+                    whereSql += " and b.Area=(select PK from datatypeinfo where TypeName = '地区' and Name = '" + area + "') ";
                 } else {
-                    whereSql = " b.Area=80' ";
+                    whereSql = " b.Area=(select PK from datatypeinfo where TypeName = '地区' and Name = '" + area + "') ";
                 }
             }
 
@@ -1516,8 +1519,9 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
 
         String vprice = PropertyUtil.getProperty("default_vprice");
 
-        String sql = String.format("insert into modelinfo(memberpk, name, stage, BrokePK, BMemberPK, ratio_R, ratio_V, ratio_S, vprice)values('%s', '%s', '%s', '%s', '%s','%s','%s','%s', '%s')",
-                memberpk, name, name, BrokePK, BMemberPK, ratio_R, ratio_V, ratio_S, vprice);
+        String sql = String
+                .format("insert into modelinfo(memberpk, name, stage, BrokePK, BMemberPK, ratio_R, ratio_V, ratio_S, vprice)values('%s', '%s', '%s', '%s', '%s','%s','%s','%s', '%s')",
+                        memberpk, name, name, BrokePK, BMemberPK, ratio_R, ratio_V, ratio_S, vprice);
         DbConnection db = new DbConnection();
         int modelpk = db.executeUpdate(sql);
         return modelpk;
@@ -1758,7 +1762,8 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
         if (where != null && !where.equals("")) {
             sql += " and " + where;
         }
-        sql += String.format(" order by FIND_IN_SET(`is_a`, '%s,%s,%s'), sort DESC  ", Constants.IS_A_ONLINE, Constants.IS_A_BUSY, Constants.IS_A_OFFLINE);
+        sql += String
+                .format(" order by FIND_IN_SET(`is_a`, '%s,%s,%s'), sort DESC  ", Constants.IS_A_ONLINE, Constants.IS_A_BUSY, Constants.IS_A_OFFLINE);
         return sql;
     }
 
@@ -1873,17 +1878,17 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
 
         Result<Record4<Integer, String, String, Serializable>> result =
                 ctx.select(MEMBERINFO.PK.as("pk"), MEMBERINFO.PET.as("name"), MEMBERINFO.HPHOTO.as("avatar"), sumField)
-                   .from(MODELINFO)
-                   .innerJoin(MEMBERINFO)
-                   .on(MODELINFO.MEMBERPK.equal(MEMBERINFO.PK))
-                   .leftJoin(ACCOUNTRECORD)
-                   .on(ACCOUNTRECORD.MEMBERPK.equal(MEMBERINFO.PK))
-                   .and(ACCOUNTRECORD.ADATE.greaterOrEqual(Timestamp.valueOf(LocalDateTime.now().minusDays(day))))
-                   .and(ACCOUNTRECORD.ATYPE.in(AccountConstants.ACCOUNTRECORD_INCOME_TYPES))
-                   .groupBy(MEMBERINFO.PK)
-                   .orderBy(sumField.desc())
-                   .limit(20)
-                   .fetch();
+                        .from(MODELINFO)
+                        .innerJoin(MEMBERINFO)
+                        .on(MODELINFO.MEMBERPK.equal(MEMBERINFO.PK))
+                        .leftJoin(ACCOUNTRECORD)
+                        .on(ACCOUNTRECORD.MEMBERPK.equal(MEMBERINFO.PK))
+                        .and(ACCOUNTRECORD.ADATE.greaterOrEqual(Timestamp.valueOf(LocalDateTime.now().minusDays(day))))
+                        .and(ACCOUNTRECORD.ATYPE.in(AccountConstants.ACCOUNTRECORD_INCOME_TYPES))
+                        .groupBy(MEMBERINFO.PK)
+                        .orderBy(sumField.desc())
+                        .limit(20)
+                        .fetch();
         for (int i = 0; i < result.size(); i++) {
             JSONObject jsonObject = DBRecordsPack.Pack(result.get(i));
             jsonObject.put("rank", i + 1);
@@ -1893,18 +1898,19 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
 
         Field<Object> f =
                 ctx.select(ifnull(sum(ACCOUNTRECORD.COIN), 0))
-                   .from(ACCOUNTRECORD)
-                   .where(ACCOUNTRECORD.MEMBERPK.equal(MEMBERINFO.PK))
-                   .and((ACCOUNTRECORD.ADATE.greaterOrEqual(Timestamp.valueOf(LocalDateTime.now().minusDays(day)))))
-                   .and(ACCOUNTRECORD.ATYPE.in(AccountConstants.ACCOUNTRECORD_INCOME_TYPES))
-                   .asField("coin");
+                        .from(ACCOUNTRECORD)
+                        .where(ACCOUNTRECORD.MEMBERPK.equal(MEMBERINFO.PK))
+                        .and((ACCOUNTRECORD.ADATE
+                                .greaterOrEqual(Timestamp.valueOf(LocalDateTime.now().minusDays(day)))))
+                        .and(ACCOUNTRECORD.ATYPE.in(AccountConstants.ACCOUNTRECORD_INCOME_TYPES))
+                        .asField("coin");
         Record4<Integer, String, String, Object> record =
                 ctx.select(MEMBERINFO.PK.as("pk"), MEMBERINFO.PET.as("name"), MEMBERINFO.HPHOTO.as("avatar"), f)
-                   .from(MODELINFO)
-                   .innerJoin(MEMBERINFO)
-                   .on(MODELINFO.MEMBERPK.equal(MEMBERINFO.PK))
-                   .where(MODELINFO.MEMBERPK.equal(memberpk))
-                   .fetchOne();
+                        .from(MODELINFO)
+                        .innerJoin(MEMBERINFO)
+                        .on(MODELINFO.MEMBERPK.equal(MEMBERINFO.PK))
+                        .where(MODELINFO.MEMBERPK.equal(memberpk))
+                        .fetchOne();
         if (record != null) {
             map.put("myRank", DBRecordsPack.Pack(record));
         }
@@ -1916,9 +1922,9 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
     public boolean setOnline(int modelpk, int state) {
         DSLContext ctx = DSL.using(DbConnection.getPara("MySQLURL"));
         int num = ctx.update(MODELINFO)
-                     .set(MODELINFO.IS_A, state)
-                     .where(MODELINFO.PK.equal(modelpk))
-                     .execute();
+                .set(MODELINFO.IS_A, state)
+                .where(MODELINFO.PK.equal(modelpk))
+                .execute();
         ctx.close();
         return num > 0;
     }
@@ -1927,8 +1933,8 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
     public boolean applyRecommend(int modelpk) {
         DSLContext ctx = DSL.using(DbConnection.getPara("MySQLURL"));
         int num = ctx.insertInto(RECOMMEND_APPLY, RECOMMEND_APPLY.MODELPK)
-                     .values(modelpk)
-                     .execute();
+                .values(modelpk)
+                .execute();
         ctx.close();
         return num > 0;
     }
@@ -1936,7 +1942,8 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
     @Override
     public int findModelPKByMemberPK(int memberPK) {
         DSLContext ctx = DSL.using(DbConnection.getPara("MySQLURL"));
-        Integer modelPK = ctx.select(MODELINFO.PK).from(MODELINFO).where(MODELINFO.MEMBERPK.equal(memberPK)).fetchOne(MODELINFO.PK);
+        Integer modelPK = ctx.select(MODELINFO.PK).from(MODELINFO).where(MODELINFO.MEMBERPK.equal(memberPK))
+                .fetchOne(MODELINFO.PK);
         ctx.close();
         return modelPK == null ? 0 : modelPK;
     }
@@ -1945,13 +1952,13 @@ public class ModelInfoDaoImpl implements ModelInfoDao {
     public List<JSONObject> fans(int modelPK, int page, int size) {
         DSLContext ctx = DSL.using(DbConnection.getPara("MySQLURL"));
         List<JSONObject> list = DBRecordsPack.Pack(ctx.select(MEMBERINFO.fields())
-                                                      .from(MODELFAN)
-                                                      .join(MEMBERINFO)
-                                                      .on(MODELFAN.MEMBERPK.equal(MEMBERINFO.PK))
-                                                      .where(MODELFAN.MODELPK.equal(modelPK))
-                                                      .orderBy(MODELFAN.PK.desc())
-                                                      .limit((page - 1) * size, size)
-                                                      .fetch());
+                .from(MODELFAN)
+                .join(MEMBERINFO)
+                .on(MODELFAN.MEMBERPK.equal(MEMBERINFO.PK))
+                .where(MODELFAN.MODELPK.equal(modelPK))
+                .orderBy(MODELFAN.PK.desc())
+                .limit((page - 1) * size, size)
+                .fetch());
         ctx.close();
         return list;
     }