Yansen 2 år sedan
förälder
incheckning
5cc89fbdea

+ 6
- 0
src/main/java/com/yunzhi/inte/common/DateUtils.java Visa fil

@@ -39,6 +39,12 @@ public class DateUtils {
39 39
         return d.format(formatter);
40 40
     }
41 41
 
42
+    public static LocalDateTime fromString(String str, String formatter) {
43
+        DateTimeFormatter df = DateTimeFormatter.ofPattern(formatter);
44
+
45
+        return LocalDateTime.parse(str, df);
46
+    }
47
+
42 48
     public static LocalDateTime day2LocalDateime(String day) {
43 49
         DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
44 50
         return LocalDateTime.parse(day + " 00:00:00", df);

+ 6
- 1
src/main/java/com/yunzhi/inte/controller/PostsController.java Visa fil

@@ -10,6 +10,7 @@ import com.yunzhi.inte.common.ResponseBean;
10 10
 import java.time.LocalDateTime;
11 11
 import java.util.List;
12 12
 
13
+import com.yunzhi.inte.common.StringUtils;
13 14
 import com.yunzhi.inte.entity.PostsFiles;
14 15
 import com.yunzhi.inte.service.PostsFilesService;
15 16
 import io.swagger.annotations.Api;
@@ -67,10 +68,14 @@ public class PostsController extends BaseController {
67 68
     @ApiOperation("分页查询")
68 69
     @GetMapping("/posts")
69 70
     public ResponseBean list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
70
-                             @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {
71
+                             @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
72
+                             @ApiParam("标题") @RequestParam(value = "title", required = false) String title,
73
+                             @ApiParam("状态") @RequestParam(value = "status", required = false) Integer status) throws Exception {
71 74
 
72 75
         IPage<Posts> pg = new Page<>(pageNum, pageSize);
73 76
         QueryWrapper<Posts> queryWrapper = new QueryWrapper<>();
77
+        queryWrapper.like(!StringUtils.isEmpty(title), "title", title);
78
+        queryWrapper.eq(null != status, "status", status);
74 79
         queryWrapper.gt("status", Constants.STATUS_DELETE);
75 80
 
76 81
         queryWrapper.orderByDesc("create_date");

+ 30
- 24
src/main/java/com/yunzhi/inte/controller/PostsFilesController.java Visa fil

@@ -5,7 +5,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.inte.common.BaseController;
7 7
 import com.yunzhi.inte.common.ResponseBean;
8
+
8 9
 import java.util.List;
10
+
11
+import com.yunzhi.inte.common.StringUtils;
9 12
 import io.swagger.annotations.Api;
10 13
 import io.swagger.annotations.ApiOperation;
11 14
 import io.swagger.annotations.ApiParam;
@@ -14,8 +17,9 @@ import org.springframework.web.bind.annotation.*;
14 17
 import com.yunzhi.inte.entity.PostsFiles;
15 18
 import com.yunzhi.inte.service.PostsFilesService;
16 19
 
17
- /**
20
+/**
18 21
  * 关联文件;(posts_files)表控制层
22
+ *
19 23
  * @author : http://njyunzhi.com
20 24
  * @date : 2022-10-13
21 25
  */
@@ -23,12 +27,12 @@ import com.yunzhi.inte.service.PostsFilesService;
23 27
 @RestController
24 28
 @RequestMapping("/")
25 29
 public class PostsFilesController extends BaseController {
26
-    
30
+
27 31
     @Autowired
28 32
     private PostsFilesService postsFilesService;
29
-    
30
-    /** 
31
-     * 通过ID查询单条数据 
33
+
34
+    /**
35
+     * 通过ID查询单条数据
32 36
      *
33 37
      * @param id 主键
34 38
      * @return 实例对象
@@ -38,28 +42,30 @@ public class PostsFilesController extends BaseController {
38 42
     public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
39 43
         return ResponseBean.success(postsFilesService.getById(id));
40 44
     }
41
-    
42
-    /** 
45
+
46
+    /**
43 47
      * 分页查询
44 48
      *
45
-     * @param pageNum 当前页码
49
+     * @param pageNum  当前页码
46 50
      * @param pageSize 每页条数
47 51
      * @return 查询结果
48 52
      */
49 53
     @ApiOperation("分页查询")
50 54
     @GetMapping("/postsFiles")
51
-    public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-                            @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
53
-        
55
+    public ResponseBean list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
56
+                             @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
57
+                             @ApiParam("文件名称") @RequestParam(value = "fileName", required = false) String fileName) throws Exception {
58
+
54 59
         IPage<PostsFiles> pg = new Page<>(pageNum, pageSize);
55
-        // QueryWrapper<PostsFiles> queryWrapper = new QueryWrapper<>();
56
-        // queryWrapper.orderByDesc("create_date");
57
-        IPage<PostsFiles> result = postsFilesService.page(pg);
58
-        
60
+        QueryWrapper<PostsFiles> queryWrapper = new QueryWrapper<>();
61
+        queryWrapper.like(!StringUtils.isEmpty(fileName), "file_name", fileName);
62
+        queryWrapper.orderByDesc("id");
63
+        IPage<PostsFiles> result = postsFilesService.page(pg, queryWrapper);
64
+
59 65
         return ResponseBean.success(result);
60 66
     }
61
-    
62
-    /** 
67
+
68
+    /**
63 69
      * 新增数据
64 70
      *
65 71
      * @param postsFiles 实例对象
@@ -71,8 +77,8 @@ public class PostsFilesController extends BaseController {
71 77
         postsFilesService.save(postsFiles);
72 78
         return ResponseBean.success(postsFiles);
73 79
     }
74
-    
75
-    /** 
80
+
81
+    /**
76 82
      * 更新数据
77 83
      *
78 84
      * @param postsFiles 实例对象
@@ -81,12 +87,12 @@ public class PostsFilesController extends BaseController {
81 87
     @ApiOperation("更新数据")
82 88
     @PutMapping("/postsFiles/{id}")
83 89
     public ResponseBean edit(@ApiParam("对象实体") @RequestBody PostsFiles postsFiles,
84
-                            @ApiParam("对象ID") @PathVariable Integer id ) throws Exception {
90
+                             @ApiParam("对象ID") @PathVariable Integer id) throws Exception {
85 91
         postsFilesService.updateById(postsFiles);
86 92
         return ResponseBean.success(postsFiles);
87 93
     }
88
-    
89
-    /** 
94
+
95
+    /**
90 96
      * 通过主键删除数据
91 97
      *
92 98
      * @param id 主键
@@ -94,8 +100,8 @@ public class PostsFilesController extends BaseController {
94 100
      */
95 101
     @ApiOperation("通过主键删除数据")
96 102
     @DeleteMapping("/postsFiles/{id}")
97
-    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
98
-        postsFilesService.removeLogicById(id);
103
+    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id) {
104
+        postsFilesService.removeById(id);
99 105
         return ResponseBean.success("success");
100 106
     }
101 107
 }

+ 65
- 3
src/main/java/com/yunzhi/inte/controller/StatisController.java Visa fil

@@ -1,13 +1,75 @@
1 1
 package com.yunzhi.inte.controller;
2 2
 
3 3
 import com.yunzhi.inte.common.BaseController;
4
+import com.yunzhi.inte.common.DateUtils;
5
+import com.yunzhi.inte.common.ResponseBean;
6
+import com.yunzhi.inte.service.GuaranteeTaskService;
7
+import com.yunzhi.inte.service.StoreService;
4 8
 import io.swagger.annotations.Api;
5
-import org.springframework.web.bind.annotation.RequestMapping;
6
-import org.springframework.web.bind.annotation.RestController;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.web.bind.annotation.*;
13
+
14
+import java.time.Duration;
15
+import java.time.LocalDateTime;
16
+import java.time.temporal.ChronoUnit;
17
+import java.util.ArrayList;
18
+import java.util.HashMap;
19
+import java.util.List;
20
+import java.util.Map;
7 21
 
8 22
 @Api(tags = "统计功能接口")
9 23
 @RestController
10
-@RequestMapping("/")
24
+@RequestMapping("/statis")
11 25
 public class StatisController extends BaseController {
12 26
 
27
+    @Autowired
28
+    GuaranteeTaskService guaranteeTaskService;
29
+
30
+    @Autowired
31
+    StoreService storeService;
32
+
33
+    @ApiOperation("汇总统计")
34
+    @GetMapping("/summary")
35
+    public ResponseBean getSummary() {
36
+
37
+        // 任务总数
38
+        Integer taskCount = guaranteeTaskService.total();
39
+        // 接待军人总数
40
+        Integer personNum = guaranteeTaskService.sumPerson();
41
+        // 总体评价
42
+        String evaValue = "良";
43
+        // 设备数量
44
+        Integer deviceNum = storeService.countDevice();
45
+
46
+        return ResponseBean.success(new HashMap<String, Object>(){{
47
+            put("taskCount", taskCount);
48
+            put("personNum", personNum);
49
+            put("evaValue", evaValue);
50
+            put("deviceNum", deviceNum);
51
+        }});
52
+    }
53
+
54
+
55
+    @ApiOperation("任务汇总")
56
+    @GetMapping("/taskInfo")
57
+    public ResponseBean getTaskInfo(@ApiParam("起始日期") @RequestParam(value ="startDate") String startDate,
58
+                                    @ApiParam("起始日期") @RequestParam(value ="endDate") String endDate) {
59
+
60
+        LocalDateTime dt1 = DateUtils.day2LocalDateime(startDate);
61
+        LocalDateTime dt2 = DateUtils.day2LocalDateime(endDate);
62
+
63
+        Long days = ChronoUnit.DAYS.between(dt1, dt2) + 1;
64
+
65
+        List<Map<String, Object>> result;
66
+        if (days < 180) {
67
+            result = guaranteeTaskService.countByDays(startDate, endDate, days);
68
+        } else {
69
+            long months = ChronoUnit.MONTHS.between(dt1, dt2) + 1;
70
+            result = guaranteeTaskService.countByMonths(startDate, endDate, months);
71
+        }
72
+
73
+        return ResponseBean.success(result);
74
+    }
13 75
 }

+ 8
- 0
src/main/java/com/yunzhi/inte/mapper/GuaranteeTaskMapper.java Visa fil

@@ -5,6 +5,9 @@ import org.apache.ibatis.annotations.Mapper;
5 5
 import org.apache.ibatis.annotations.Param;
6 6
 import com.yunzhi.inte.entity.GuaranteeTask;
7 7
 
8
+import java.util.List;
9
+import java.util.Map;
10
+
8 11
 /**
9 12
  * 供给保障;(guarantee_task)表数据库访问层
10 13
  * @author : http://njyunzhi.com
@@ -13,4 +16,9 @@ import com.yunzhi.inte.entity.GuaranteeTask;
13 16
 @Mapper
14 17
 public interface GuaranteeTaskMapper  extends BaseMapper<GuaranteeTask>{
15 18
 
19
+    int sumPerson(@Param("status") int status);
20
+
21
+    List<Map<String, Object>> countByDays(@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("days") Long days);
22
+
23
+    List<Map<String, Object>> countByMonths(@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("months") Long months);
16 24
 }

+ 10
- 0
src/main/java/com/yunzhi/inte/service/GuaranteeTaskService.java Visa fil

@@ -3,6 +3,9 @@ package com.yunzhi.inte.service;
3 3
 import com.baomidou.mybatisplus.extension.service.IService;
4 4
 import com.yunzhi.inte.entity.GuaranteeTask;
5 5
 
6
+import java.util.List;
7
+import java.util.Map;
8
+
6 9
 /**
7 10
  * 供给保障;(guarantee_task)表服务接口
8 11
  * @author : http://njyunzhi.com
@@ -10,4 +13,11 @@ import com.yunzhi.inte.entity.GuaranteeTask;
10 13
  */
11 14
 public interface GuaranteeTaskService extends IBaseService<GuaranteeTask> {
12 15
 
16
+    Integer total();
17
+
18
+    Integer sumPerson();
19
+
20
+    List<Map<String, Object>> countByDays(String startDate, String endDate, Long days);
21
+
22
+    List<Map<String, Object>> countByMonths(String startDate, String endDate, Long months);
13 23
 }

+ 2
- 0
src/main/java/com/yunzhi/inte/service/StoreService.java Visa fil

@@ -15,4 +15,6 @@ public interface StoreService extends IBaseService<Store> {
15 15
     IPage<Store> getPageBy(IPage<Store> pg, Integer id, String name, String typeId, Integer isDish);
16 16
 
17 17
     List<Store> getListBy(String name, String typeId, Integer isDish);
18
+
19
+    Integer countDevice();
18 20
 }

+ 2
- 1
src/main/java/com/yunzhi/inte/service/UsersService.java Visa fil

@@ -6,12 +6,13 @@ import com.yunzhi.inte.vo.LoginParm;
6 6
 
7 7
 /**
8 8
  * 用户表;(users)表服务接口
9
+ *
9 10
  * @author : http://njyunzhi.com
10 11
  * @date : 2022-10-12
11 12
  */
12 13
 public interface UsersService extends IBaseService<Users> {
13 14
 
14
-     Users login(LoginParm loginParm) throws Exception;
15
+    Users login(LoginParm loginParm) throws Exception;
15 16
 
16 17
     boolean mergeData(Users users) throws Exception;
17 18
 }

+ 28
- 0
src/main/java/com/yunzhi/inte/service/impl/GuaranteeTaskServiceImpl.java Visa fil

@@ -1,10 +1,16 @@
1 1
 package com.yunzhi.inte.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.inte.common.Constants;
3 5
 import org.springframework.beans.factory.annotation.Autowired;
4 6
 import org.springframework.stereotype.Service;
5 7
 import com.yunzhi.inte.entity.GuaranteeTask;
6 8
 import com.yunzhi.inte.mapper.GuaranteeTaskMapper;
7 9
 import com.yunzhi.inte.service.GuaranteeTaskService;
10
+
11
+import java.util.List;
12
+import java.util.Map;
13
+
8 14
 /**
9 15
  * 供给保障;(guarantee_task)表服务实现类
10 16
  * @author : http://www.chiner.pro
@@ -13,4 +19,26 @@ import com.yunzhi.inte.service.GuaranteeTaskService;
13 19
 @Service
14 20
 public class GuaranteeTaskServiceImpl extends BaseServiceImpl<GuaranteeTaskMapper, GuaranteeTask> implements GuaranteeTaskService {
15 21
 
22
+    @Override
23
+    public Integer total() {
24
+        QueryWrapper<GuaranteeTask> queryWrapper = new QueryWrapper<>();
25
+        queryWrapper.eq("status", Constants.STATUS_NORMAL);
26
+
27
+        return count(queryWrapper);
28
+    }
29
+
30
+    @Override
31
+    public Integer sumPerson() {
32
+        return baseMapper.sumPerson(Constants.STATUS_NORMAL);
33
+    }
34
+
35
+    @Override
36
+    public List<Map<String, Object>> countByDays(String startDate, String endDate, Long days) {
37
+        return baseMapper.countByDays(startDate, endDate, days);
38
+    }
39
+
40
+    @Override
41
+    public List<Map<String, Object>> countByMonths(String startDate, String endDate, Long months) {
42
+        return baseMapper.countByMonths(startDate, endDate, months);
43
+    }
16 44
 }

+ 11
- 0
src/main/java/com/yunzhi/inte/service/impl/StoreServiceImpl.java Visa fil

@@ -1,6 +1,8 @@
1 1
 package com.yunzhi.inte.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.yunzhi.inte.common.Constants;
4 6
 import com.yunzhi.inte.common.StringUtils;
5 7
 import org.springframework.stereotype.Service;
6 8
 import com.yunzhi.inte.entity.Store;
@@ -38,4 +40,13 @@ public class StoreServiceImpl extends BaseServiceImpl<StoreMapper, Store> implem
38 40
 
39 41
         return baseMapper.getListBy(name, typeId, isDish);
40 42
     }
43
+
44
+    @Override
45
+    public Integer countDevice() {
46
+        QueryWrapper<Store> queryWrapper = new QueryWrapper<>();
47
+        queryWrapper.eq("is_device", 1);
48
+        queryWrapper.eq("status", Constants.STATUS_NORMAL);
49
+
50
+        return count(queryWrapper);
51
+    }
41 52
 }

+ 52
- 0
src/main/resources/mapper/GuaranteeTaskMapper.xml Visa fil

@@ -3,4 +3,56 @@
3 3
 
4 4
 <mapper namespace="com.yunzhi.inte.mapper.GuaranteeTaskMapper">
5 5
 
6
+    <select id="sumPerson" resultType="java.lang.Integer">
7
+        SELECT
8
+            sum( t.total_person_num )
9
+        FROM
10
+            guarantee_task t
11
+        WHERE
12
+            t.`status` = #{status}
13
+    </select>
14
+    <select id="countByDays" resultType="java.util.Map">
15
+        SELECT
16
+            ADDDATE( #{startDate}, INTERVAL t.rownum DAY ) AS dt,
17
+            IFNULL( s.cnt, 0 ) AS cnt
18
+        FROM
19
+            sequence t
20
+            LEFT JOIN (
21
+                SELECT
22
+                    DATE( a.start_date ) AS dt,
23
+                    COUNT( * ) AS cnt
24
+                FROM
25
+                    guarantee_task a
26
+                WHERE
27
+                    a.`status` = 1
28
+                    AND DATE( a.start_date ) &gt;= #{startDate}
29
+                    AND DATE( a.start_date ) &lt;= #{endDate}
30
+                GROUP BY
31
+                    DATE( a.start_date )
32
+            ) s ON s.dt = ADDDATE(#{startDate}, INTERVAL t.rownum DAY )
33
+        WHERE
34
+            t.rownum &lt; #{days}
35
+    </select>
36
+    <select id="countByMonths" resultType="java.util.Map">
37
+        SELECT
38
+            DATE_FORMAT(ADDDATE(#{startDate}, INTERVAL rownum MONTH), '%Y-%m') AS dt,
39
+            IFNULL( s.cnt, 0 ) AS cnt
40
+        FROM
41
+            sequence t
42
+            LEFT JOIN (
43
+                SELECT
44
+                    DATE_FORMAT( a.start_date, '%Y-%m') AS dt,
45
+                    count( * ) AS cnt
46
+                FROM
47
+                    guarantee_task a
48
+                WHERE
49
+                    a.`status` = 1
50
+                    AND DATE( a.start_date ) &gt;= #{startDate}
51
+                    AND DATE( a.start_date ) &lt;= #{endDate}
52
+                    GROUP BY
53
+                        DATE_FORMAT( a.start_date, '%Y-%m')
54
+            ) s ON s.dt = DATE_FORMAT(ADDDATE(#{startDate}, INTERVAL rownum MONTH), '%Y-%m')
55
+        WHERE
56
+            t.rownum &lt; #{months}
57
+    </select>
6 58
 </mapper>