Ver código fonte

修改民生栏目后端代码的不规范性

hyx 2 anos atrás
pai
commit
213a6bc6c1

+ 2 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/MailDao.java

@@ -167,6 +167,8 @@ public interface MailDao {
     String  findDeptName(@Param("name") String name);
 
 
+    List<Map<TypeCasting, Object>> findWebNew(Map<String, Object> param);
 
+    List<Map<String, Object>> findDeptNew(Map<String, Object> param);
 }
 

+ 67 - 45
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/MailServiceImpl.java

@@ -30,6 +30,7 @@ public class MailServiceImpl implements MailService {
     private MailDao mailDao;
     @Resource
     private ArticleDao articleDao;
+
     /**
      * 通过ID查询单条数据
      *
@@ -90,7 +91,7 @@ public class MailServiceImpl implements MailService {
 
     /**
      * 通过主键删除数据
-     *message: "
+     * message: "
      * ↵### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'nazw.mail.emailTime' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
      * ↵### The error may exist in class path resource [mapper/MailDao.xml]
      * ↵### The error may involve defaultParameterMap
@@ -98,24 +99,25 @@ public class MailServiceImpl implements MailService {
      * ↵### SQL: SELECT             COUNT(*) count,             DATE_FORMAT(emailTime,'%Y-%m') monthToNOwyear         FROM             mail         WHERE emailTime > ?         GROUP BY DATE_FORMAT(emailTime,'%Y-%m')         ORDER BY emailTime ASC
      * ↵### Cause: java.sql.SQLSyntaxErrorException: Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'nazw.mail.emailTime' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by↵; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'nazw.mail.emailTime' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by"
      * path: "/mail/queryMonthStatus"
+     *
      * @return 是否成功
      */
     @Override
     public Map<String, Object> queryMonthStatus() {
-        String today= DateUtil.today();
+        String today = DateUtil.today();
         String[] split = today.split("-");
         StringBuffer append = new StringBuffer().append(split[0]).append("-01-01 00:00:00");
         DateTime parse = DateUtil.parse(append);
 
         List<Mail> byYearDate = mailDao.findByYearDate(parse.toSqlDate());
         List<Map<String, Object>> quantityPerMonth = mailDao.findQuantityPerMonth(parse.toSqlDate());
-        if (ObjectUtil.hasEmpty(byYearDate,quantityPerMonth)){
+        if (ObjectUtil.hasEmpty(byYearDate, quantityPerMonth)) {
             return SendUtil.send();
         }
         int startSub = 0;
         List<List<Mail>> mails = new ArrayList<>();
-        for (Map<String, Object> month: quantityPerMonth) {
-            int nowstart = startSub+Convert.toInt(month.get("count"));
+        for (Map<String, Object> month : quantityPerMonth) {
+            int nowstart = startSub + Convert.toInt(month.get("count"));
             List<Mail> sub = ListUtil.sub(byYearDate, startSub, nowstart);
             mails.add(sub);
             startSub = nowstart;
@@ -123,28 +125,28 @@ public class MailServiceImpl implements MailService {
         Map<String, Object> requstData = new HashMap<>();
         List<Integer> numberOfTransactions = new ArrayList<>();
         List<Integer> numberOfAcceptances = new ArrayList<>();
-        for (List<Mail> mail: mails) {
+        for (List<Mail> mail : mails) {
             int thisFour = 0;
             for (int i = 0; i < mail.size(); i++) {
-                if (mail.get(i).getPrograma()==4){
+                if (mail.get(i).getPrograma() == 4) {
                     thisFour++;
                 }
             }
             numberOfTransactions.add(thisFour);
-            if (mail.size()>0){
+            if (mail.size() > 0) {
                 numberOfAcceptances.add(mail.size());
-            }else {
+            } else {
                 numberOfAcceptances.add(0);
             }
         }
         requstData.put("accept", numberOfAcceptances);
         requstData.put("handle", numberOfTransactions);
-        return SendUtil.send(true,"",requstData);
+        return SendUtil.send(true, "", requstData);
     }
 
     @Override
     public Map<String, Object> queryLeaveAMessage() {
-        String today= DateUtil.today();
+        String today = DateUtil.today();
         Date date = DateUtil.parse(today);
         DateTime dateStart = DateUtil.offsetDay(date, -30);
         java.sql.Date date1 = dateStart.toSqlDate();
@@ -152,8 +154,8 @@ public class MailServiceImpl implements MailService {
         List<Mail> dayData = mailDao.find30DayData(dateStart.toSqlDate());
         int thisFour = 0;
         int notFour = 0;
-        for (int i = 0; i <dayData.size(); i++) {
-            if (dayData.get(i).getPrograma()==4){
+        for (int i = 0; i < dayData.size(); i++) {
+            if (dayData.get(i).getPrograma() == 4) {
                 thisFour++;
                 continue;
             }
@@ -162,8 +164,8 @@ public class MailServiceImpl implements MailService {
         Map<String, Object> requstData = new HashMap<>();
         requstData.put("accepting", notFour);
         requstData.put("finished", thisFour);
-        requstData.put("handle",dayData.size());
-        return SendUtil.send(true,"",requstData);
+        requstData.put("handle", dayData.size());
+        return SendUtil.send(true, "", requstData);
     }
 
     @Override
@@ -196,7 +198,7 @@ public class MailServiceImpl implements MailService {
             map.put("finished", notFour);
             map.put("count", mails.get(j).size());
             map.put("month", allMonth.get(j).get("monthToNOwyear"));
-            if (ObjectUtil.isNull(map.get("其他"))){
+            if (ObjectUtil.isNull(map.get("其他"))) {
                 map.put("其他", 0);
             }
             requstData.add(map);
@@ -204,18 +206,18 @@ public class MailServiceImpl implements MailService {
         if (requstData.size() < 1) {
             return SendUtil.layuiTable(0, null);
         }
-        List<Map<String, Object>> sub = ListUtil.sub(requstData, start, start+limit);
+        List<Map<String, Object>> sub = ListUtil.sub(requstData, start, start + limit);
         return SendUtil.layuiTable(requstData.size(), sub);
     }
 
     @Override
     public Map<String, Object> queryToType(String type) {
-        String today= DateUtil.today();
+        String today = DateUtil.today();
         Date date = DateUtil.parse(today);
         DateTime dateStart = DateUtil.offsetDay(date, -90);
         List<Mail> dayData = mailDao.find90DayData(dateStart.toSqlDate());
         List<MapVo> mapVos = null;
-        switch (type){
+        switch (type) {
             case "1":
                 mapVos = getType1(dayData);
                 break;
@@ -233,11 +235,11 @@ public class MailServiceImpl implements MailService {
         Map<String, Object> result = new HashMap<>();
         List resultList = new ArrayList();
         List resultSize = new ArrayList();
-        List<String> publicNum = mailDao.findPublicNum(type,urlId);
+        List<String> publicNum = mailDao.findPublicNum(type, urlId);
         if (publicNum.size() != 0) {
             for (int i = 0; i < publicNum.size(); i++) {
                 resultList.add(publicNum.get(i));
-                System.err.println("====>"+publicNum.get(i));
+                System.err.println("====>" + publicNum.get(i));
                 resultSize.add(mailDao.findUpdateStatus(publicNum.get(i)));
             }
             result.put("field", resultList);
@@ -255,7 +257,7 @@ public class MailServiceImpl implements MailService {
         List listColumn = new ArrayList();
         for (int i = 0; i < typeName.size(); i++) {
             List<String> dept = mailDao.findDept(typeName.get(i));
-            if (dept!=null) {
+            if (dept != null) {
                 listDept.add(dept);
             }
             listColumn.add(articleDao.queryPublicStreetInfoByName(typeName.get(i)));
@@ -278,23 +280,43 @@ public class MailServiceImpl implements MailService {
         param.put("type", type);
         param.put("Id", Id);
         //查询网站
-        List<Map<TypeCasting, Object>> web = mailDao.findWeb(param);
-        if (web.size() != 0) {
+//        List<Map<TypeCasting, Object>> web = mailDao.findWeb(param);
+//        if (web.size() != 0) {
+//            for (int i = 0; i < web.size(); i++) {
+//                Object releaseDate = web.get(i).get("releaseDate");
+//                Object columnFirstName = web.get(i).get("columnFirstName");
+//
+//                int webUpdateCount = mailDao.findWebUpdateCount(columnFirstName, releaseDate);
+//                typeName.add(columnFirstName);
+//                listDate.add(releaseDate);
+//                listCount.add(webUpdateCount);
+//            }
+//            for (int i = 0; i <typeName.size() ; i++) {
+//                List<String> dept = mailDao.findDept(String.valueOf(typeName.get(i)));
+//                listDept.add(dept);
+//
+//            }
+//        }
+        List<Map<TypeCasting, Object>> web = mailDao.findWebNew(param);
+        List<Map<String, Object>> deptList = mailDao.findDeptNew(param);
+        if (web != null && web.size() > 0) {
             for (int i = 0; i < web.size(); i++) {
-                Object releaseDate = web.get(i).get("releaseDate");
-                Object columnFirstName = web.get(i).get("columnFirstName");
-
-                int webUpdateCount = mailDao.findWebUpdateCount(columnFirstName, releaseDate);
-                typeName.add(columnFirstName);
-                listDate.add(releaseDate);
-                listCount.add(webUpdateCount);
-            }
-            for (int i = 0; i <typeName.size() ; i++) {
-                List<String> dept = mailDao.findDept(String.valueOf(typeName.get(i)));
-                listDept.add(dept);
-
+                typeName.add(web.get(i).get("columnFirstName"));
+                listDate.add(web.get(i).get("releaseDate"));
+                listCount.add(web.get(i).get("count"));
+                if (deptList != null && deptList.size() > 0) {
+                    List<String> dept=new ArrayList<>();
+                    for (int j = 0; j < deptList.size(); j++) {
+                        if(web.get(i).get("columnFirstName").equals(deptList.get(j).get("columnFirstName"))){
+                            dept.add(deptList.get(j).get("deptname").toString());
+                        }
+                    }
+                    listDept.add(dept);
+                    dept=new ArrayList<>();
+                }
             }
         }
+
         result.put("ColumnName", typeName);
         result.put("count", listCount);
         result.put("releaseDate", listDate);
@@ -307,11 +329,11 @@ public class MailServiceImpl implements MailService {
 
     @Override
     public Map<String, Object> NanAnTop(String type) {
-      Map<String,Object> result=new HashMap<>();
+        Map<String, Object> result = new HashMap<>();
         List<Map<String, Object>> nanAnTop = mailDao.findNanAnTop(type);
-        if (!Blank.isEmpty(nanAnTop)){
-            result.put("listTop",nanAnTop);
-            result.put("length",nanAnTop.size());
+        if (!Blank.isEmpty(nanAnTop)) {
+            result.put("listTop", nanAnTop);
+            result.put("length", nanAnTop.size());
             return result;
         }
         return null;
@@ -340,7 +362,7 @@ public class MailServiceImpl implements MailService {
                 maps.add(mapVo);
             }
         }
-        return  maps;
+        return maps;
     }
 
     private List<MapVo> getType1(List<Mail> dayData) {
@@ -361,16 +383,16 @@ public class MailServiceImpl implements MailService {
                 maps.add(mapVo);
             }
         }
-        return  maps;
+        return maps;
     }
 
-//    private void hasAndAddMap2(MapVo vo, String text){
+    //    private void hasAndAddMap2(MapVo vo, String text){
 //
 //    }
     private void hasAndAddMap(Map<String, Object> map, String text) {
-        if (ObjectUtil.isNull(map.get(text))){
+        if (ObjectUtil.isNull(map.get(text))) {
             map.put(text, 1);
-        }else {
+        } else {
             int integer = Convert.toInt(map.get(text));
             integer++;
             map.put(text, integer);

+ 40 - 0
nngkxxdp/src/main/resources/mapper/MailDao.xml

@@ -217,6 +217,22 @@
         ORDER BY releaseDate asc
     </select>
 
+    <select id="findWebNew" resultType="java.util.Map">
+        SELECT
+            a.columnFirstName,
+            count( * ) AS count,
+            MAX( a.releaseDate ) AS releaseDate
+        FROM
+            article AS a
+        WHERE
+            a.type = #{type}
+          AND a.urlId = #{Id}
+        GROUP BY
+            a.columnFirstName
+        ORDER BY
+            releaseDate ASC
+    </select>
+
     <select id="findWebUpdateCount" resultType="java.lang.Integer">
         SELECT COUNT(*)
         FROM article as a
@@ -248,6 +264,30 @@
         WHERE d.`column`=#{name}
     </select>
 
+    <select id="findDeptNew" resultType="java.util.Map">
+        SELECT
+            b.columnFirstName,
+            d.deptname
+        FROM
+            (
+                SELECT
+                    a.columnFirstName,
+                    MAX( a.releaseDate ) AS releaseDate
+                FROM
+                    article AS a
+                WHERE
+                    a.type = #{type}
+                  AND a.urlId = #{Id}
+                GROUP BY
+                    a.columnFirstName
+                ORDER BY
+                    releaseDate ASC
+            ) b
+                RIGHT JOIN dept d ON d.`column` = b.columnFirstName
+        WHERE
+            b.columnFirstName IS NOT NULL;
+    </select>
+
 
 
     <select id="findDeptName" resultType="java.lang.String">