Prechádzať zdrojové kódy

借阅图表接口,填充日,月,年字段

yangsijie 2 rokov pred
rodič
commit
6b91b3adae

+ 3 - 14
src/main/java/com/chy/borrow/controller/BorrowApplyController.java

@@ -223,23 +223,12 @@ public class BorrowApplyController extends BaseController {
         return borrowApplyService.getCountList();
     }
 
-    @RequestMapping(value = "/listYearCount")
+    @RequestMapping(value = "/listYMDCount")
     @ResponseBody
-    public String getYearCountList() {
-        return borrowApplyService.getApplyTimeCountList(0,0);
+    public String getYearCountList(Integer start,Integer num) {
+        return borrowApplyService.getApplyTimeCountList(start,num);
     }
 
-    @RequestMapping(value = "/listMonthCount")
-    @ResponseBody
-    public String getMonthCountList() {
-        return borrowApplyService.getApplyTimeCountList(3,3);
-    }
-
-    @RequestMapping(value = "/listDayCount")
-    @ResponseBody
-    public String getDayCountList() {
-        return borrowApplyService.getApplyTimeCountList(6,6);
-    }
 
     @RequestMapping(value = "/listPeriodCount")
     @ResponseBody

+ 3 - 15
src/main/java/com/chy/borrow/controller/BorrowApplyZjl0754Controller.java

@@ -148,22 +148,10 @@ public class BorrowApplyZjl0754Controller extends BaseController {
         return borrowApplyZjl0754Service.getCountListzj();
     }
 
-    @RequestMapping(value = "/listYearCount")
+    @RequestMapping(value = "/listYMDCount")
     @ResponseBody
-    public String getYearCountList() {
-        return borrowApplyZjl0754Service.getApplyTimeCountList(0,0);
-    }
-
-    @RequestMapping(value = "/listMonthCount")
-    @ResponseBody
-    public String getMonthCountList() {
-        return borrowApplyZjl0754Service.getApplyTimeCountList(3,3);
-    }
-
-    @RequestMapping(value = "/listDayCount")
-    @ResponseBody
-    public String getDayCountList() {
-        return borrowApplyZjl0754Service.getApplyTimeCountList(6,6);
+    public String getYearCountList(Integer start,Integer num) {
+        return borrowApplyZjl0754Service.getApplyTimeCountList(start,num);
     }
 
     @RequestMapping(value = "/listPeriodCount")

+ 72 - 25
src/main/java/com/chy/borrow/service/impl/BorrowApplyServiceImpl.java

@@ -29,11 +29,13 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author 沈晔浩
@@ -52,10 +54,10 @@ public class BorrowApplyServiceImpl extends ServiceImpl<BorrowApplyMapper, Borro
             Integer pageSize = Integer.valueOf(map.get("pageSize").toString());
             PageHelper.startPage(current, pageSize);
             Page<Map> list = borrowApplyMapper.getList(map);
-            if (list!=null) {
+            if (list != null) {
                 return new ResultMsg<>(ResultState.SUCCESS, null, JSONObject.toJSONString(list), list.getPageNum(), list.getTotal(), list.getPageSize(), list.getPages()).toPageJSON();
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             return new ResultMsg<String>().setCode(ResultState.ERROR).setMsg("服务器出错").toJSON();
         }
         return new ResultMsg<String>().setCode(ResultState.SUCCESS).setMsg("无数据").toJSON();
@@ -66,13 +68,13 @@ public class BorrowApplyServiceImpl extends ServiceImpl<BorrowApplyMapper, Borro
         try {
             Integer current = Integer.valueOf(map.get("current").toString());
             Integer pageSize = Integer.valueOf(map.get("pageSize").toString());
-            map.put("borrowStatus","");
+            map.put("borrowStatus", "");
             PageHelper.startPage(current, pageSize);
             Page<Map> list = borrowApplyMapper.getListForRange(map);
-            if (list!=null) {
+            if (list != null) {
                 return new ResultMsg<>(ResultState.SUCCESS, null, JSONObject.toJSONString(list), list.getPageNum(), list.getTotal(), list.getPageSize(), list.getPages()).toPageJSON();
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             return new ResultMsg<String>().setCode(ResultState.ERROR).setMsg("服务器出错").toJSON();
         }
         return new ResultMsg<String>().setCode(ResultState.SUCCESS).setMsg("无数据").toJSON();
@@ -82,13 +84,13 @@ public class BorrowApplyServiceImpl extends ServiceImpl<BorrowApplyMapper, Borro
     public String getInfoById(BorrowApply borrowApply) {
         Map map1 = borrowApplyMapper.getInfoById(borrowApply.getBorrowApplyId());
         Map data = TestData.getProjectInfo(map1.get("projectCode").toString());
-        if (data!=null) {
+        if (data != null) {
             for (Object obj : data.keySet()) {
                 map1.put(obj, data.get(obj));
             }
         }
         List result = new ArrayList();
-        if (map1!=null) {
+        if (map1 != null) {
             result.add(map1);
         }
         return new ResultMsg<>().setCode(ResultState.SUCCESS).setData(result).toJSON();
@@ -96,24 +98,25 @@ public class BorrowApplyServiceImpl extends ServiceImpl<BorrowApplyMapper, Borro
 
     @Override
     public String saveFile(BorrowApply borrowApply) {
-        String fileName = "常规申请"+(new Date().getTime())+".csv";
+        String fileName = "常规申请" + (new Date().getTime()) + ".csv";
         List<Map> list = new ArrayList<>();
         Map map = new HashMap();
-        map.put("项目编号",borrowApply.getTmpCode()==null?borrowApply.getProjectCode():borrowApply.getTmpCode());
-        map.put("数据范围",borrowApply.getDataRange());
-        map.put("申请理由",borrowApply.getApplyReason());
-        map.put("期限说明材料",borrowApply.getDeadlineMaterials());
-        map.put("借阅期限",borrowApply.getBorrowDeadline());
-        map.put("借阅数据",borrowApply.getBorrowData());
+        map.put("项目编号", borrowApply.getTmpCode() == null ? borrowApply.getProjectCode() : borrowApply.getTmpCode());
+        map.put("数据范围", borrowApply.getDataRange());
+        map.put("申请理由", borrowApply.getApplyReason());
+        map.put("期限说明材料", borrowApply.getDeadlineMaterials());
+        map.put("借阅期限", borrowApply.getBorrowDeadline());
+        map.put("借阅数据", borrowApply.getBorrowData());
         list.add(map);
-        CSVUtil.writeFileForMap("D:\\file\\"+fileName,list);
-        String url = "http://47.101.207.123:8080/file/"+fileName;
+        CSVUtil.writeFileForMap("D:\\file\\" + fileName, list);
+        String url = "http://47.101.207.123:8080/file/" + fileName;
         List result = new ArrayList();
         Map map1 = new HashMap();
-        map1.put("url",url);
+        map1.put("url", url);
         result.add(map1);
         return new ResultMsg<>().setCode(ResultState.SUCCESS).setData(result).toJSON();
     }
+
     //借阅量(常规)
     @Override
     public String getCountList() {
@@ -133,7 +136,7 @@ public class BorrowApplyServiceImpl extends ServiceImpl<BorrowApplyMapper, Borro
 
         for (Map data : unitCountList) {
 
-            BigDecimal borrowCount = new BigDecimal((Long)data.get("borrowCount"));
+            BigDecimal borrowCount = new BigDecimal((Long) data.get("borrowCount"));
 
             total = total.add(borrowCount);
 
@@ -152,9 +155,9 @@ public class BorrowApplyServiceImpl extends ServiceImpl<BorrowApplyMapper, Borro
                 data.put("percentage", subtract);
 
             } else {
-                BigDecimal count = new BigDecimal((Long)data.get("borrowCount"));
+                BigDecimal count = new BigDecimal((Long) data.get("borrowCount"));
 
-                BigDecimal percentage =  count.divide(total, 4, RoundingMode.CEILING);
+                BigDecimal percentage = count.divide(total, 4, RoundingMode.CEILING);
 
                 temp = temp.add(percentage);
 
@@ -167,14 +170,58 @@ public class BorrowApplyServiceImpl extends ServiceImpl<BorrowApplyMapper, Borro
     }
 
     @Override
-    public String getApplyTimeCountList(Integer start,Integer num) {
-        List<Map> TimeCountList = borrowApplyMapper.getApplyTimeCountList(start,num);
-        return new ResultMsg<>().setCode(ResultState.SUCCESS).setData(TimeCountList).toJSON();
+    public String getApplyTimeCountList(Integer start, Integer num) {
+        List<Map> timeCountList = borrowApplyMapper.getApplyTimeCountList(start, num);
+        List<Map> result = new ArrayList<>();
+        LocalDate date = LocalDate.now();
+        LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
+        System.out.println(lastDay.getDayOfMonth());
+        int MonthDay=lastDay.getDayOfMonth();
+        //年填充字段
+        if (start == 0 && num == 0) {
+            for (int i = 1; i <= 12; i++) {
+                Map<String,Integer> temp = new HashMap();
+                        temp.put("applyTime", i);
+                        temp.put("borrowCount", 0);
+                        result.add(temp);
+
+            }
+        }
+        //日填充字段
+        else if(start == 6 && num == 6){
+            for (int i = 1; i <= 24; i++) {
+                Map<String,Integer> temp = new HashMap();
+                temp.put("applyTime", i);
+                temp.put("borrowCount", 0);
+                result.add(temp);
+            }
+        }
+        //月填充字段
+        else if(start == 3 && num == 3){
+            for (int i = 1; i <=MonthDay ; i++) {
+                Map<String,Integer> temp = new HashMap();
+                temp.put("applyTime", i);
+                temp.put("borrowCount", 0);
+                result.add(temp);
+            }
+        }
+        for (Map<String,String> data : timeCountList){
+
+            Integer idx=Integer.valueOf(data.get("applyTime"));
+
+            if (Integer.valueOf(data.get("applyTime")) == idx) {
+                Map map = result.get(idx - 1);
+
+                map.put("borrowCount",data.get("borrowCount"));
+            }
+
+        }
+        return new ResultMsg<>().setCode(ResultState.SUCCESS).setData(result).toJSON();
     }
 
     @Override
     public String getApplyTimeByPeriod(Timestamp start, Timestamp end) {
-        List<Map> TimeByPeriodList = borrowApplyMapper.getApplyTimeByPeriod(start,end);
+        List<Map> TimeByPeriodList = borrowApplyMapper.getApplyTimeByPeriod(start, end);
         return new ResultMsg<>().setCode(ResultState.SUCCESS).setData(TimeByPeriodList).toJSON();
     }
 

+ 50 - 3
src/main/java/com/chy/borrow/service/impl/BorrowApplyZjl0754ServiceImpl.java

@@ -14,7 +14,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -68,9 +71,53 @@ public class BorrowApplyZjl0754ServiceImpl extends ServiceImpl<BorrowApplyZjl075
     }
 
     @Override
-    public String getApplyTimeCountList(Integer start,Integer num) {
-        List<Map> TimeCountList = borrowApplyZjl0754Mapper.getApplyTimeCountList(start,num);
-        return new ResultMsg<>().setCode(ResultState.SUCCESS).setData(TimeCountList).toJSON();
+    public String getApplyTimeCountList(Integer start, Integer num) {
+        List<Map> timeCountList = borrowApplyZjl0754Mapper.getApplyTimeCountList(start, num);
+        List<Map> result = new ArrayList<>();
+        LocalDate date = LocalDate.now();
+        LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
+        System.out.println(lastDay.getDayOfMonth());
+        int MonthDay=lastDay.getDayOfMonth();
+        //年填充字段
+        if (start == 0 && num == 0) {
+            for (int i = 1; i <= 12; i++) {
+                Map<String,Integer> temp = new HashMap();
+                temp.put("applyTime", i);
+                temp.put("borrowCount", 0);
+                result.add(temp);
+
+            }
+        }
+        //日填充字段
+        else if(start == 6 && num == 6){
+            for (int i = 1; i <= 24; i++) {
+                Map<String,Integer> temp = new HashMap();
+                temp.put("applyTime", i);
+                temp.put("borrowCount", 0);
+                result.add(temp);
+            }
+        }
+        //月填充字段
+        else if(start == 3 && num == 3){
+            for (int i = 1; i <=MonthDay ; i++) {
+                Map<String,Integer> temp = new HashMap();
+                temp.put("applyTime", i);
+                temp.put("borrowCount", 0);
+                result.add(temp);
+            }
+        }
+        for (Map<String,String> data : timeCountList){
+
+            Integer idx=Integer.valueOf(data.get("applyTime"));
+
+            if (Integer.valueOf(data.get("applyTime")) == idx) {
+                Map map = result.get(idx - 1);
+
+                map.put("borrowCount",data.get("borrowCount"));
+            }
+
+        }
+        return new ResultMsg<>().setCode(ResultState.SUCCESS).setData(result).toJSON();
     }
 
     @Override

+ 1 - 1
src/main/resources/mapper/BorrowApplyMapper.xml

@@ -208,7 +208,7 @@
     <select id="getApplyTimeByPeriod" resultType="java.util.Map">
         SELECT y.apply_time,COUNT(*) AS borrow_count
         FROM (
-                 SELECT substring(cast(apply_time as Varchar),9,2) AS apply_time
+                 SELECT substring(cast(apply_time as Varchar),6,5) AS apply_time
                  FROM jygl.borrow_apply
                  WHERE apply_time between #{start} and #{end}
              ) y

+ 1 - 1
src/main/resources/mapper/BorrowApplyZjl0754Mapper.xml

@@ -84,7 +84,7 @@
     <select id="getApplyTimeByPeriod" resultType="java.util.Map">
         SELECT y.apply_time,COUNT(*) AS borrow_count
         FROM (
-                 SELECT substring(cast(apply_time as Varchar),9,2) AS apply_time
+                 SELECT substring(cast(apply_time as Varchar),6,5) AS apply_time
                  FROM jygl.borrow_apply_zjl0754
                  WHERE apply_time between #{start} and #{end}
              ) y