张延森 2 年之前
父節點
當前提交
404b0315dd

+ 112
- 0
src/main/java/com/yunzhi/nanyang/controller/ScreenDataController.java 查看文件

@@ -0,0 +1,112 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.nanyang.common.BaseController;
5
+import com.yunzhi.nanyang.common.Constants;
6
+import com.yunzhi.nanyang.common.ResponseBean;
7
+import com.yunzhi.nanyang.entity.TaMachinery;
8
+import com.yunzhi.nanyang.entity.TaOrg;
9
+import com.yunzhi.nanyang.entity.TdMachineryType;
10
+import com.yunzhi.nanyang.service.ITaMachineryService;
11
+import com.yunzhi.nanyang.service.ITaOrderService;
12
+import com.yunzhi.nanyang.service.ITaOrgService;
13
+import com.yunzhi.nanyang.service.ITdMachineryTypeService;
14
+import com.yunzhi.nanyang.vo.ChartParam;
15
+import io.swagger.annotations.Api;
16
+import io.swagger.annotations.ApiOperation;
17
+import io.swagger.annotations.ApiParam;
18
+import org.springframework.beans.factory.annotation.Autowired;
19
+import org.springframework.web.bind.annotation.GetMapping;
20
+import org.springframework.web.bind.annotation.RequestMapping;
21
+import org.springframework.web.bind.annotation.RequestParam;
22
+import org.springframework.web.bind.annotation.RestController;
23
+
24
+import java.util.ArrayList;
25
+import java.util.List;
26
+
27
+
28
+@Api(tags = "数据大屏")
29
+@RestController
30
+@RequestMapping("/admin/screen-data")
31
+public class ScreenDataController extends BaseController {
32
+
33
+    @Autowired
34
+    ITaMachineryService iTaMachineryService;
35
+
36
+    @Autowired
37
+    ITaOrderService iTaOrderService;
38
+
39
+    @Autowired
40
+    ITdMachineryTypeService iTdMachineryTypeService;
41
+
42
+    @Autowired
43
+    ITaOrgService iTaOrgService;
44
+
45
+
46
+    @GetMapping("/basic")
47
+    @ApiOperation(value="基本数据统计", notes = "基本数据统计", httpMethod = "GET", response = ResponseBean.class)
48
+    public ResponseBean getBasicStatis() throws Exception {
49
+        // 农机总数
50
+        int totalMachineryNum = iTaMachineryService.countBy("1", 1, true);
51
+        // 农机使用数
52
+        int totalMachineryUsed = 0;
53
+        // 总预约数 == 订单数
54
+        int totalOrderNum = iTaOrderService.countBy("1", 1, true);
55
+        // 总服务数
56
+        int totalServiceNum = 0;
57
+
58
+        List<ChartParam> result = new ArrayList<>();
59
+        result.add(new ChartParam("totalMachineryNum", totalMachineryNum));
60
+        result.add(new ChartParam("totalMachineryUsed", totalMachineryUsed));
61
+        result.add(new ChartParam("totalOrderNum", totalOrderNum));
62
+        result.add(new ChartParam("totalServiceNum", totalServiceNum));
63
+
64
+        return ResponseBean.success(result);
65
+    }
66
+
67
+    @GetMapping("/machinery-type")
68
+    @ApiOperation(value="所有农机类型", notes = "所有农机类型", httpMethod = "GET", response = ResponseBean.class)
69
+    public ResponseBean getMachineryType() throws Exception {
70
+        List<TdMachineryType> result = iTdMachineryTypeService.getTypesOfScreen();
71
+        return ResponseBean.success(result);
72
+    }
73
+
74
+    @GetMapping("/machinery-type/machinery")
75
+    @ApiOperation(value="农机类型统计", notes = "农机类型统计", httpMethod = "GET", response = ResponseBean.class)
76
+    public ResponseBean getMachineryTypeStatis() throws Exception {
77
+        List<ChartParam> result = iTdMachineryTypeService.statisMachineryNum();
78
+        return ResponseBean.success(result);
79
+    }
80
+
81
+    @GetMapping("/machinery-type/work-job")
82
+    @ApiOperation(value="农机作业数统计", notes = "农机作业数统计", httpMethod = "GET", response = ResponseBean.class)
83
+    public ResponseBean getMachineryTypeWorkJobs() throws Exception {
84
+        List<ChartParam> result = iTdMachineryTypeService.statisWorkJobNum();
85
+        return ResponseBean.success(result);
86
+    }
87
+
88
+
89
+    @GetMapping("/machinery-type/area")
90
+    @ApiOperation(value="农机作业面积统计", notes = "农机作业面积统计", httpMethod = "GET", response = ResponseBean.class)
91
+    public ResponseBean getMachineryTypeArea() throws Exception {
92
+        List<ChartParam> result = iTdMachineryTypeService.statisArea();
93
+        return ResponseBean.success(result);
94
+    }
95
+
96
+    @GetMapping("/org")
97
+    @ApiOperation(value="所有合作社", notes = "所有合作社", httpMethod = "GET", response = ResponseBean.class)
98
+    public ResponseBean getAllOrgs() throws Exception {
99
+        QueryWrapper<TaOrg> queryWrapper = new QueryWrapper<TaOrg>()
100
+                .gt("status", Constants.STATUS_DELETE);
101
+        List<TaOrg> result = iTaOrgService.list(queryWrapper);
102
+        return ResponseBean.success(result);
103
+    }
104
+
105
+
106
+    @GetMapping("/machinery/all")
107
+    @ApiOperation(value="依据类型查询农机", notes = "依据类型查询农机", httpMethod = "GET", response = ResponseBean.class)
108
+    public ResponseBean getMachineryOfType(@ApiParam("农机类型") @RequestParam("typeId") String typeId) throws Exception {
109
+        List<TaMachinery> result = iTaMachineryService.listByTypeWithLoc(typeId);
110
+        return ResponseBean.success(result);
111
+    }
112
+}

+ 6
- 0
src/main/java/com/yunzhi/nanyang/controller/SysUserController.java 查看文件

@@ -7,6 +7,7 @@ import com.yunzhi.nanyang.common.*;
7 7
 import com.yunzhi.nanyang.entity.SysLogin;
8 8
 import com.yunzhi.nanyang.service.ISysLoginService;
9 9
 import com.yunzhi.nanyang.service.ISysUserDataScopeService;
10
+import com.yunzhi.nanyang.service.ITaOrgService;
10 11
 import io.swagger.annotations.Api;
11 12
 import io.swagger.annotations.ApiOperation;
12 13
 import io.swagger.annotations.ApiParam;
@@ -49,6 +50,9 @@ public class SysUserController extends BaseController {
49 50
     @Autowired
50 51
     public ISysUserDataScopeService iSysUserDataScopeService;
51 52
 
53
+    @Autowired
54
+    public ITaOrgService iTaOrgService;
55
+
52 56
     @Value("${yz.default.password}")
53 57
     public String defaultPassword;
54 58
 
@@ -117,6 +121,7 @@ public class SysUserController extends BaseController {
117 121
         }
118 122
 
119 123
         if (iSysUserService.save(sysUser)){
124
+            iTaOrgService.updateNum(sysUser.getOrgId(), "worker_num", 1);
120 125
             iSysUserDataScopeService.addNew(sysUser.getOrgId(), sysUser.getUserId());
121 126
 
122 127
             if (!StringUtils.isEmpty(sysUser.getLoginName())) {
@@ -148,6 +153,7 @@ public class SysUserController extends BaseController {
148 153
         }
149 154
 
150 155
         if(iSysUserService.removeLogicById(id)){
156
+            iTaOrgService.updateNum(sysUser.getOrgId(), "worker_num", -1);
151 157
             iSysLoginService.removeLogicByUser(id);
152 158
 
153 159
             return ResponseBean.success("success");

+ 5
- 0
src/main/java/com/yunzhi/nanyang/controller/TaMachineryController.java 查看文件

@@ -50,6 +50,9 @@ public class TaMachineryController extends BaseController {
50 50
     @Autowired
51 51
     public ISysUserService iSysUserService;
52 52
 
53
+    @Autowired
54
+    public ITaOrgService iTaOrgService;
55
+
53 56
     @Autowired
54 57
     public ITaOrderService iTaOrderService;
55 58
 
@@ -146,6 +149,7 @@ public class TaMachineryController extends BaseController {
146 149
         taMachinery.setCreateUser(sysUser.getUserId());
147 150
 
148 151
         if (iTaMachineryService.saveAll(taMachinery)){
152
+            iTaOrgService.updateNum(taMachinery.getOrgId(), "machinery_num", 1);
149 153
             return ResponseBean.success(taMachinery);
150 154
         }else {
151 155
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -168,6 +172,7 @@ public class TaMachineryController extends BaseController {
168 172
         checkOrgAccess(taMachinery.getOrgId());
169 173
 
170 174
         if(iTaMachineryService.removeLogicById(id)){
175
+            iTaOrgService.updateNum(taMachinery.getOrgId(), "machinery_num", -1);
171 176
             return ResponseBean.success("success");
172 177
         }else {
173 178
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);

+ 4
- 3
src/main/java/com/yunzhi/nanyang/controller/TaWorkJobController.java 查看文件

@@ -191,9 +191,6 @@ public class TaWorkJobController extends BaseController {
191 191
         origin.setArea(taWorkJob.getArea());
192 192
         origin.setEndDate(LocalDateTime.now());
193 193
 
194
-//        iTaOrderService.updateStatus(taWorkJob.getOrderId(), "work_status", Constants.WORK_DONE);
195
-        iTaMachineryService.updateStatus(taWorkJob.getMachineryId(), "job_status", Constants.WORK_DONE);
196
-
197 194
         // 更新订单
198 195
         TaOrder taOrder = iTaOrderService.getExistBy("order_id", origin.getOrderId(), false, true);
199 196
         if (null == taOrder) {
@@ -206,6 +203,10 @@ public class TaWorkJobController extends BaseController {
206 203
         taOrder.setCharges(charges);
207 204
         taOrder.setWorkStatus(Constants.WORK_DONE);
208 205
         iTaOrderService.updateById(taOrder);
206
+        iTaOrgService.updateNum(taOrder.getOrgId(), "order_num", 1);
207
+
208
+//        iTaOrderService.updateStatus(taWorkJob.getOrderId(), "work_status", Constants.WORK_DONE);
209
+        iTaMachineryService.updateStatus(taWorkJob.getMachineryId(), "job_status", Constants.WORK_DONE);
209 210
 
210 211
         if (iTaWorkJobService.updateById(origin)){
211 212
             return ResponseBean.success(origin);

+ 4
- 0
src/main/java/com/yunzhi/nanyang/mapper/TaOrgMapper.java 查看文件

@@ -7,6 +7,7 @@ import com.yunzhi.nanyang.vo.ChartParam;
7 7
 import org.apache.ibatis.annotations.Mapper;
8 8
 import org.apache.ibatis.annotations.Param;
9 9
 import org.apache.ibatis.annotations.Select;
10
+import org.apache.ibatis.annotations.Update;
10 11
 
11 12
 /**
12 13
  * <p>
@@ -23,4 +24,7 @@ public interface TaOrgMapper extends BaseMapper<TaOrg> {
23 24
 
24 25
     @Select("SELECT 'org' as `name`, count(*) as `value`  FROM ta_org t WHERE t.`status` > -1")
25 26
     ChartParam statisTotal();
27
+
28
+    @Update("UPDATE ta_org SET ${fieldName} = ${fieldName} + #{increment} WHERE org_id = #{orgId} ")
29
+    int updateNum(@Param("orgId") String orgId, @Param("fieldName") String fieldName, @Param("increment") int increment);
26 30
 }

+ 10
- 0
src/main/java/com/yunzhi/nanyang/mapper/TdMachineryTypeMapper.java 查看文件

@@ -2,8 +2,11 @@ package com.yunzhi.nanyang.mapper;
2 2
 
3 3
 import com.yunzhi.nanyang.entity.TdMachineryType;
4 4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import com.yunzhi.nanyang.vo.ChartParam;
5 6
 import org.apache.ibatis.annotations.Mapper;
6 7
 
8
+import java.util.List;
9
+
7 10
 /**
8 11
  * <p>
9 12
  * 农机类型表 Mapper 接口
@@ -15,4 +18,11 @@ import org.apache.ibatis.annotations.Mapper;
15 18
 @Mapper
16 19
 public interface TdMachineryTypeMapper extends BaseMapper<TdMachineryType> {
17 20
 
21
+    List<ChartParam> statisMachineryNum();
22
+
23
+    List<ChartParam> statisWorkJobNum();
24
+
25
+    List<ChartParam> statisArea();
26
+
27
+    List<TdMachineryType> getTypesOfScreen();
18 28
 }

+ 4
- 0
src/main/java/com/yunzhi/nanyang/service/ITaMachineryService.java 查看文件

@@ -5,6 +5,8 @@ import com.yunzhi.nanyang.entity.TaMachinery;
5 5
 import com.yunzhi.nanyang.vo.ChartParam;
6 6
 import com.yunzhi.nanyang.vo.MachineSummary;
7 7
 
8
+import java.util.List;
9
+
8 10
 /**
9 11
  * <p>
10 12
  * 农机表 服务类
@@ -34,4 +36,6 @@ public interface ITaMachineryService extends IBaseService<TaMachinery> {
34 36
     IPage<TaMachinery> getPageBy(IPage<TaMachinery> pg, String name, String typeId, String orgId, Integer status);
35 37
 
36 38
     ChartParam statisTotal();
39
+
40
+    List<TaMachinery> listByTypeWithLoc(String typeId);
37 41
 }

+ 6
- 0
src/main/java/com/yunzhi/nanyang/service/ITaOrgService.java 查看文件

@@ -2,9 +2,12 @@ package com.yunzhi.nanyang.service;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.yunzhi.nanyang.entity.SysUser;
5
+import com.yunzhi.nanyang.entity.TaMachinery;
5 6
 import com.yunzhi.nanyang.entity.TaOrg;
6 7
 import com.yunzhi.nanyang.vo.ChartParam;
7 8
 
9
+import java.util.List;
10
+
8 11
 /**
9 12
  * <p>
10 13
  * 机构管理 服务类
@@ -20,4 +23,7 @@ public interface ITaOrgService extends IBaseService<TaOrg> {
20 23
     boolean saveWithDataScope(TaOrg taOrg) throws Exception;
21 24
 
22 25
     ChartParam statisTotal();
26
+
27
+    int updateNum(String orgId, String fieldName, int increment);
28
+
23 29
 }

+ 10
- 0
src/main/java/com/yunzhi/nanyang/service/ITdMachineryTypeService.java 查看文件

@@ -2,6 +2,9 @@ package com.yunzhi.nanyang.service;
2 2
 
3 3
 import com.yunzhi.nanyang.entity.TdMachineryType;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.yunzhi.nanyang.vo.ChartParam;
6
+
7
+import java.util.List;
5 8
 
6 9
 /**
7 10
  * <p>
@@ -13,4 +16,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 16
  */
14 17
 public interface ITdMachineryTypeService extends IBaseService<TdMachineryType> {
15 18
 
19
+    List<ChartParam> statisMachineryNum();
20
+
21
+    List<ChartParam> statisWorkJobNum();
22
+
23
+    List<ChartParam> statisArea();
24
+
25
+    List<TdMachineryType> getTypesOfScreen();
16 26
 }

+ 12
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TaMachineryServiceImpl.java 查看文件

@@ -1,5 +1,6 @@
1 1
 package com.yunzhi.nanyang.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 4
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
4 5
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 6
 import com.yunzhi.nanyang.common.Constants;
@@ -144,6 +145,17 @@ public class TaMachineryServiceImpl extends BaseServiceImpl<TaMachineryMapper, T
144 145
         return baseMapper.statisTotal();
145 146
     }
146 147
 
148
+    @Override
149
+    public List<TaMachinery> listByTypeWithLoc(String typeId) {
150
+        QueryWrapper<TaMachinery> queryWrapper = new QueryWrapper<>();
151
+        queryWrapper.eq("type_id", typeId);
152
+//        queryWrapper.eq("online_status", 1);
153
+        queryWrapper.isNotNull("location");
154
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
155
+
156
+        return list(queryWrapper);
157
+    }
158
+
147 159
     private void saveImages(TaMachinery taMachinery) {
148 160
         String machineryId = taMachinery.getMachineryId();
149 161
         // 先删除所有

+ 5
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TaOrgServiceImpl.java 查看文件

@@ -58,4 +58,9 @@ public class TaOrgServiceImpl extends BaseServiceImpl<TaOrgMapper, TaOrg> implem
58 58
     public ChartParam statisTotal() {
59 59
         return baseMapper.statisTotal();
60 60
     }
61
+
62
+    @Override
63
+    public int updateNum(String orgId, String fieldName, int increment) {
64
+        return baseMapper.updateNum(orgId, fieldName, increment);
65
+    }
61 66
 }

+ 22
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TdMachineryTypeServiceImpl.java 查看文件

@@ -4,8 +4,11 @@ import com.yunzhi.nanyang.entity.TdMachineryType;
4 4
 import com.yunzhi.nanyang.mapper.TdMachineryTypeMapper;
5 5
 import com.yunzhi.nanyang.service.ITdMachineryTypeService;
6 6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import com.yunzhi.nanyang.vo.ChartParam;
7 8
 import org.springframework.stereotype.Service;
8 9
 
10
+import java.util.List;
11
+
9 12
 /**
10 13
  * <p>
11 14
  * 农机类型表 服务实现类
@@ -17,4 +20,23 @@ import org.springframework.stereotype.Service;
17 20
 @Service
18 21
 public class TdMachineryTypeServiceImpl extends BaseServiceImpl<TdMachineryTypeMapper, TdMachineryType> implements ITdMachineryTypeService {
19 22
 
23
+    @Override
24
+    public List<ChartParam> statisMachineryNum() {
25
+        return baseMapper.statisMachineryNum();
26
+    }
27
+
28
+    @Override
29
+    public List<ChartParam> statisWorkJobNum() {
30
+        return baseMapper.statisWorkJobNum();
31
+    }
32
+
33
+    @Override
34
+    public List<ChartParam> statisArea() {
35
+        return baseMapper.statisArea();
36
+    }
37
+
38
+    @Override
39
+    public List<TdMachineryType> getTypesOfScreen() {
40
+        return baseMapper.getTypesOfScreen();
41
+    }
20 42
 }

+ 2
- 0
src/main/java/com/yunzhi/nanyang/vo/ChartParam.java 查看文件

@@ -2,10 +2,12 @@ package com.yunzhi.nanyang.vo;
2 2
 
3 3
 import io.swagger.annotations.ApiModel;
4 4
 import io.swagger.annotations.ApiModelProperty;
5
+import lombok.AllArgsConstructor;
5 6
 import lombok.Data;
6 7
 
7 8
 @ApiModel("二位图标")
8 9
 @Data
10
+@AllArgsConstructor
9 11
 public class ChartParam {
10 12
 
11 13
     @ApiModelProperty("维度")

+ 84
- 0
src/main/resources/mapper/TdMachineryTypeMapper.xml 查看文件

@@ -2,4 +2,88 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.yunzhi.nanyang.mapper.TdMachineryTypeMapper">
4 4
 
5
+    <select id="statisMachineryNum" resultType="com.yunzhi.nanyang.vo.ChartParam">
6
+        SELECT
7
+            t.`name`,
8
+            ifnull( s.num, 0 ) AS `value`
9
+        FROM
10
+            `td_machinery_type` t
11
+                LEFT JOIN (
12
+                SELECT
13
+                    a.type_id,
14
+                    count( 1 ) AS num
15
+                FROM
16
+                    ta_machinery a
17
+                WHERE
18
+                    a.`status` &gt; -1
19
+                GROUP BY
20
+                    a.type_id
21
+            ) s ON t.type_id = s.type_id
22
+        WHERE
23
+            t.screen_statis = 1
24
+          AND t.`status` &gt; -1
25
+        ORDER BY
26
+            t.`name`
27
+    </select>
28
+    <select id="statisWorkJobNum" resultType="com.yunzhi.nanyang.vo.ChartParam">
29
+        SELECT
30
+            t.`name`,
31
+            ifnull( s.num, 0 ) AS `value`
32
+        FROM
33
+            `td_machinery_type` t
34
+                LEFT JOIN (
35
+                SELECT
36
+                    a.type_id,
37
+                    count( 1 ) AS num
38
+                FROM
39
+                    ta_machinery a
40
+                        INNER JOIN ta_work_job b ON a.machinery_id = b.machinery_id
41
+                WHERE
42
+                    a.`status` &gt; -1
43
+                  AND b.`status` &gt; -1
44
+                GROUP BY
45
+                    a.type_id
46
+            ) s ON t.type_id = s.type_id
47
+        WHERE
48
+            t.screen_statis = 1
49
+          AND t.`status` &gt; -1
50
+        ORDER BY
51
+            t.`name`
52
+    </select>
53
+    <select id="statisArea" resultType="com.yunzhi.nanyang.vo.ChartParam">
54
+        SELECT
55
+            t.`name`,
56
+            ifnull( s.num, 0 ) AS `value`
57
+        FROM
58
+            `td_machinery_type` t
59
+                LEFT JOIN (
60
+                SELECT
61
+                    a.type_id,
62
+                    SUM( b.area ) AS num
63
+                FROM
64
+                    ta_machinery a
65
+                        INNER JOIN ta_work_job b ON a.machinery_id = b.machinery_id
66
+                WHERE
67
+                    a.`status` &gt; -1
68
+                  AND b.`status` &gt; -1
69
+                GROUP BY
70
+                    a.type_id
71
+            ) s ON t.type_id = s.type_id
72
+        WHERE
73
+            t.screen_statis = 1
74
+          AND t.`status` &gt; -1
75
+        ORDER BY
76
+            t.`name`
77
+    </select>
78
+    <select id="getTypesOfScreen" resultType="com.yunzhi.nanyang.entity.TdMachineryType">
79
+        SELECT
80
+            t.*
81
+        FROM
82
+            `td_machinery_type` t
83
+        WHERE
84
+            t.screen_statis = 1
85
+          AND t.`status` &gt; -1
86
+        ORDER BY
87
+            t.`name`
88
+    </select>
5 89
 </mapper>