Browse Source

事前事后标记添加公司 工厂编码

zjs 1 week ago
parent
commit
e9d9a1a446

+ 15 - 4
src/main/java/com/cn/esermis/controller/DataAcquisitionInstrumentController.java

@@ -15,6 +15,8 @@ import com.cn.esermis.dpld.model.OutletAndFactorVo;
15 15
 import com.cn.esermis.dpld.service.IAnalyticalInstrumentsService;
16 16
 import com.cn.esermis.dpld.service.IDataAcquisitionInstrumentService;
17 17
 import com.cn.esermis.dpld.service.IDetectMonitoringFactorService;
18
+import com.cn.esermis.model.BaseUser;
19
+import com.cn.esermis.utils.TokenUtils;
18 20
 import org.springframework.beans.BeanUtils;
19 21
 import org.springframework.beans.factory.annotation.Autowired;
20 22
 import org.springframework.data.redis.core.RedisTemplate;
@@ -23,10 +25,13 @@ import org.springframework.validation.annotation.Validated;
23 25
 import org.springframework.web.bind.annotation.*;
24 26
 
25 27
 import javax.annotation.Resource;
28
+import javax.servlet.http.HttpServletRequest;
26 29
 
27 30
 import java.util.*;
28 31
 
32
+import static com.cn.esermis.dpld.model.AjaxResult.error;
29 33
 import static com.cn.esermis.dpld.model.AjaxResult.success;
34
+import static com.cn.esermis.utils.TokenUtils.extractToken;
30 35
 
31 36
 @RestController
32 37
 @RequestMapping("/data_Acquisition")
@@ -43,10 +48,12 @@ public class DataAcquisitionInstrumentController {
43 48
      * 获取数采仪信息表
44 49
      */
45 50
     @GetMapping("/list")
46
-    public AjaxResult list(DataAcquisitionInstrumentVo vo)
51
+    public AjaxResult list(DataAcquisitionInstrumentVo vo, HttpServletRequest request)
47 52
     {
48 53
         IPage<DataAcquisitionInstrument> page = new Page<>(vo.getPageNum(), vo.getPageSize());
49 54
         QueryWrapper<DataAcquisitionInstrument> wrapper = new QueryWrapper<>();
55
+        BaseUser userInfo = TokenUtils.getUserInfo(extractToken(request));
56
+//        wrapper.eq("company_code",userInfo.getCompanyId());
50 57
         wrapper.orderByDesc("department_code");
51 58
         IPage<DataAcquisitionInstrument> pageList = dataAcquisitionInstrumentService.page(page, wrapper);
52 59
         IPage<DataAcquisitionInstrumentVo> volits = new Page<>();
@@ -231,11 +238,15 @@ public class DataAcquisitionInstrumentController {
231 238
      * 获取数采仪信息表
232 239
      */
233 240
     @GetMapping("/listByCode")
234
-    public AjaxResult listByCode(DataAcquisitionInstrumentVo vo)
241
+    public AjaxResult listByCode(HttpServletRequest  request)
235 242
     {
236 243
         QueryWrapper<DataAcquisitionInstrument> wrapper = new QueryWrapper<>();
237
-        wrapper.eq(vo.getDepartmentCode()!=null,"department_code", vo.getDepartmentCode());
238
-//        wrapper.eq(vo.getCompanyCode()!=null,"company_code", vo.getCompanyCode());
244
+        BaseUser userInfo = TokenUtils.getUserInfo(extractToken(request));
245
+        if (userInfo==null){
246
+            return error("无数据");
247
+        }
248
+        wrapper.eq(userInfo.getCompanyId()!=null,"department_code", userInfo.getCompanyId());
249
+        wrapper.eq(userInfo.getFactoryId()!=null,"company_code", userInfo.getFactoryId());
239 250
 //        List<DataAcquisitionInstrument> dataAcquisitionInstruments = dataAcquisitionInstrumentService.listByCode(vo);
240 251
         List<DataAcquisitionInstrument> dataAcquisitionInstruments = dataAcquisitionInstrumentService.list(wrapper);
241 252
         return success(dataAcquisitionInstruments);

+ 16 - 2
src/main/java/com/cn/esermis/controller/PreMarkingController.java

@@ -4,17 +4,23 @@ import com.alibaba.fastjson2.JSON;
4 4
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 5
 import com.baomidou.mybatisplus.core.metadata.IPage;
6 6
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7
+import com.cn.esermis.dpld.entity.DataAcquisitionInstrument;
7 8
 import com.cn.esermis.dpld.entity.PreMarking;
8 9
 import com.cn.esermis.dpld.model.AjaxResult;
9 10
 import com.cn.esermis.dpld.model.PreMarkingVo;
10 11
 import com.cn.esermis.dpld.service.IPreMarkingService;
12
+import com.cn.esermis.model.BaseUser;
13
+import com.cn.esermis.utils.TokenUtils;
11 14
 import org.springframework.beans.factory.annotation.Autowired;
12 15
 import org.springframework.data.redis.core.RedisTemplate;
13 16
 import org.springframework.web.bind.annotation.*;
14 17
 
15 18
 import javax.annotation.Resource;
19
+import javax.servlet.http.HttpServletRequest;
16 20
 import java.util.List;
17 21
 
22
+import static com.cn.esermis.utils.TokenUtils.extractToken;
23
+
18 24
 @RestController
19 25
 @RequestMapping("/pre_marking")
20 26
 public class PreMarkingController {
@@ -26,7 +32,11 @@ public class PreMarkingController {
26 32
     private IPreMarkingService preMarkingService;
27 33
 
28 34
     @PostMapping("/add")
29
-    public Object add(@RequestBody PreMarking preMarking) {
35
+    public Object add(@RequestBody PreMarking preMarking, HttpServletRequest request) {
36
+        BaseUser userInfo = TokenUtils.getUserInfo(extractToken(request));
37
+        assert userInfo != null;
38
+        preMarking.setCompanyCode(userInfo.getCompanyId());
39
+        preMarking.setDepartmentCode(userInfo.getFactoryId());
30 40
         preMarkingService.save(preMarking);
31 41
         sendMessage();
32 42
         return AjaxResult.success("success");
@@ -40,7 +50,11 @@ public class PreMarkingController {
40 50
     }
41 51
 
42 52
     @PostMapping("/edit")
43
-    public Object edit(@RequestBody PreMarking preMarking) {
53
+    public Object edit(@RequestBody PreMarking preMarking, HttpServletRequest request) {
54
+        BaseUser userInfo = TokenUtils.getUserInfo(extractToken(request));
55
+        assert userInfo != null;
56
+        preMarking.setCompanyCode(userInfo.getCompanyId());
57
+        preMarking.setDepartmentCode(userInfo.getFactoryId());
44 58
         preMarkingService.updateById(preMarking);
45 59
         sendMessage();
46 60
         return AjaxResult.success("success");

+ 3 - 0
src/main/java/com/cn/esermis/dpld/business/MonitorBusiness.java

@@ -493,6 +493,9 @@ public class MonitorBusiness {
493 493
             postMarking.setOutletName(first.get().getOutletName());
494 494
             postMarking.setOutletNumber(first.get().getOutletCode());
495 495
             postMarking.setManagementNumber(String.valueOf(UuidUtil.getTimeBasedUuid()));
496
+            postMarking.setMnCode(first.get().getMnCode());
497
+            postMarking.setCompanyCode(first.get().getCompanyCode());
498
+            postMarking.setDepartmentCode(first.get().getDepartmentCode());
496 499
             switch (dataType){
497 500
                 case "1":
498 501
                     //判断是否为负值数据

+ 9 - 0
src/main/java/com/cn/esermis/dpld/entity/PostMarking.java

@@ -70,5 +70,14 @@ public class PostMarking {
70 70
      */
71 71
     @TableField(value = "management_reasons")
72 72
     private String managementReasons;
73
+    /**
74
+     * mn好
75
+     */
76
+    @TableField(value = "mn_code")
77
+    private String mnCode;
78
+    @TableField(value = "company_code")
79
+    private String companyCode;
80
+    @TableField(value = "department_code")
81
+    private String departmentCode;
73 82
 
74 83
 }

+ 6 - 0
src/main/java/com/cn/esermis/dpld/entity/PreMarking.java

@@ -80,4 +80,10 @@ public class PreMarking {
80 80
     private Date createTime;
81 81
 
82 82
 
83
+
84
+    @TableField(value = "company_code")
85
+    private String companyCode;
86
+    @TableField(value = "department_code")
87
+    private String departmentCode;
88
+
83 89
 }

+ 5 - 0
src/main/java/com/cn/esermis/dpld/model/OutletAndFactorVo.java

@@ -19,6 +19,11 @@ public class OutletAndFactorVo {
19 19
 
20 20
 
21 21
     private String factor;
22
+    private String mnCode;
23
+    private String companyCode;
24
+    private String departmentCode;
25
+
26
+
22 27
 
23 28
 
24 29
 }

+ 14 - 0
src/main/java/com/cn/esermis/utils/TokenUtils.java

@@ -5,8 +5,13 @@ import com.auth0.jwt.exceptions.JWTDecodeException;
5 5
 import com.auth0.jwt.interfaces.DecodedJWT;
6 6
 import com.cn.esermis.model.BaseUser;
7 7
 
8
+import javax.servlet.http.HttpServletRequest;
9
+
8 10
 public class TokenUtils {
9 11
 
12
+    private static final String AUTH_HEADER = "Authorization";
13
+    private static final String TOKEN_PREFIX = "Bearer ";
14
+
10 15
     public static BaseUser getUserInfo(String token) {
11 16
         try {
12 17
             DecodedJWT jwt = JWT.decode(token);
@@ -20,6 +25,15 @@ public class TokenUtils {
20 25
         }
21 26
     }
22 27
 
28
+
29
+    public static String extractToken(HttpServletRequest request) {
30
+        String bearerToken = request.getHeader(AUTH_HEADER);
31
+        if (bearerToken != null && bearerToken.startsWith(TOKEN_PREFIX)) {
32
+            return bearerToken.substring(TOKEN_PREFIX.length());
33
+        }
34
+        return null;
35
+    }
36
+
23 37
     public static void main(String[] args) {
24 38
         System.out.println(getUserInfo("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb21wYW55SWQiOiIxMDAwMDAwMDEiLCJpc3MiOiJhdXRoMCIsImV4cCI6MTcyODYxMTk5NywidXNlcklkIjoiMTEwMDAwMTk3MTAxMDEwMDAwIn0.ZlKMmrDKQiU1PTxseg0qCu5Bb2LwZryBr72C9XxWpHs"));
25 39
     }

+ 6 - 1
src/main/resources/static/mybatis/DataAcquisitionInstrumentMapper.xml

@@ -5,7 +5,12 @@
5 5
 <mapper namespace="com.cn.esermis.dpld.mapper.DataAcquisitionInstrumentMapper">
6 6
 
7 7
     <select id="selectListAll" resultType="com.cn.esermis.dpld.model.OutletAndFactorVo">
8
-        select a.outlet_name `outletName`,a.outlet_code outletCode,c.factor factor
8
+        select a.outlet_name `outletName`,
9
+               a.outlet_code outletCode,
10
+               c.factor `factor`,
11
+               a.mn_code `mnCode`,
12
+               a.company_code `companyCode`,
13
+               a.department_code `departmentCode`
9 14
         from data_acquisition_instrument a
10 15
                  left join analytical_instruments b on a.id = b.data_acquisition_instrument_id
11 16
                  left join monitoring_factor c on b.id = c.analytical_instrument_id