Sfoglia il codice sorgente

Merge branch 'master' of http://47.100.37.243:10080/ZHOU/yunsu

# Conflicts:
#	target/classes/main/resources/mapper/MouldEquipmentMapper.xml
#	target/classes/main/resources/mapper/MouldMapper.xml
5 anni fa
parent
commit
75d1ea32b0

+ 7 - 5
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldEquipmentController.java

@@ -71,19 +71,21 @@ public class MouldEquipmentController {
     }
 
     /**
-     * 启用设备
-     * 传参 id 设备id ,isUse 启用传 1
-     * @return
+     * 云平台下行配置数据包接口
+     * lowPowerLimit 低电量报警限值:(1 字节,十六进制)如:1e=31
+     * hotAlarmLimit 热报警限值:(1 字节,十六进制)如:50=80
+     * isUse:0-停止,1-启动
+     * equipmentNo 设备编号(可能是多个或者一个)多个以“,”隔开传  如:"123456"(单个),"123456,456878,123589"(多个)
      */
     @ApiOperation("启用设备")
     @RequestMapping("/use")
     @ResponseBody
-    public HttpRespMsg use(MouldEquipment mouldEquipment,String token) {
+    public HttpRespMsg use(MouldEquipmentVO mouldEquipmentVO,String token) {
         HttpRespMsg msg = new HttpRespMsg();
         QueryWrapper<User> qw = new QueryWrapper<>();
         qw.eq("head_imgurl",token);
         User user = userService.getOne(qw);
-        msg = mouldEquipmentService.isUse(mouldEquipment,user);
+        msg = mouldEquipmentService.isUse(mouldEquipmentVO,user);
         return msg;
     }
 

+ 2 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/entity/vo/MouldEquipmentVO.java

@@ -21,6 +21,8 @@ public class MouldEquipmentVO extends MouldEquipment {
     private Integer mouldId;//模具id
     private String alarmBattery;//报警电量
     private String alarmDegree;//报警温度
+    private Integer lowPowerLimit;//最低电量
+    private Integer hotAlarmLimit;//最高温度
     /**
      * 模具编号
      */

+ 1 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/service/MouldEquipmentService.java

@@ -21,7 +21,7 @@ public interface MouldEquipmentService extends IService<MouldEquipment> {
 
     HttpRespMsg addAndUpdateMouldEquipment(MouldEquipment mouldEquipment, User user);
 
-    HttpRespMsg isUse(MouldEquipment mouldEquipment, User user);
+    HttpRespMsg isUse(MouldEquipmentVO mouldEquipment, User user);
 
     HttpRespMsg getList(User user,PageUtil page,Integer companyId,String keyName);
 

+ 54 - 13
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldEquipmentServiceImpl.java

@@ -61,9 +61,7 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
     @Resource
     ProjectApproveMapper projectApproveMapper;
     @Resource
-    CustomCompanyMapper customCompanyMapper;
-    @Resource
-    CompanyMapper companyMapper;
+    MouldDownPacketMapper mouldDownPacketMapper;
     @Resource
     ProjectUserMapper projectUserMapper;
 
@@ -97,21 +95,44 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
     }
 
     @Override
-    public HttpRespMsg isUse(MouldEquipment mouldEquipment, User user) {
+    public HttpRespMsg isUse(MouldEquipmentVO mouldEquipment, User user) {
         HttpRespMsg msg = new HttpRespMsg();
+        //16进制的转化
+        String lowPowerLimitStr = Integer.toHexString(mouldEquipment.getLowPowerLimit());
+        String hotAlarmLimitStr = Integer.toHexString(mouldEquipment.getHotAlarmLimit());
+        String isUseStr = "0"+Integer.toHexString(mouldEquipment.getIsUse());
         //判断是不是超级管理员,是才可操作
         if (user.getParentId() == 0) {
             //修改设备
-            MouldEquipment newMouldEquipment = mouldEquipmentMapper.selectById(mouldEquipment.getId());
-            if (null == newMouldEquipment.getBelongCompanyId()) {
-                msg.setError("该设备没有所属公司,请添加所属公司后再启用");
-                return msg;
+            String[] split = mouldEquipment.getEquipmentNo().split(",");
+            MouldDownPacket packet = null;
+            String setPacketMessage = "";
+            for (String str : split) {
+                packet = mouldDownPacketMapper.selectOne(new QueryWrapper<MouldDownPacket>().eq("equipment_no", str));
+                MouldEquipment equipment = new MouldEquipment();
+                equipment.setIsUse(mouldEquipment.getIsUse());
+                equipment.setEquipmentNo(mouldEquipment.getEquipmentNo());
+                equipment.setHillNumber(mouldEquipment.getLowPowerLimit()+"");
+                equipment.setTemperature(mouldEquipment.getHotAlarmLimit());
+                mouldEquipmentMapper.update(equipment,new QueryWrapper<MouldEquipment>().eq("equipment_no",str));
+                if(packet != null){
+                    //已经存在更新下发数据包
+                    MouldDownPacket mouldDownPacket = new MouldDownPacket();
+                    mouldDownPacket.setId(packet.getId());
+                    setPacketMessage = downProcessMsg(mouldEquipment.getLowPowerLimit()+"",mouldEquipment.getHotAlarmLimit()+"",isUseStr);
+                    mouldDownPacket.setPacketStr(setPacketMessage);
+                    mouldDownPacket.setPacketStr(setPacketMessage);
+                    mouldDownPacket.setIsUse(mouldEquipment.getIsUse());
+                    mouldDownPacketMapper.updateById(mouldDownPacket);
+                }else{
+                    MouldDownPacket mouldDownPacket = new MouldDownPacket();
+                    setPacketMessage = downProcessMsg(mouldEquipment.getLowPowerLimit()+"",mouldEquipment.getHotAlarmLimit()+"",isUseStr);
+                    mouldDownPacket.setPacketStr(setPacketMessage);
+                    mouldDownPacket.setPacketStr(setPacketMessage);
+                    mouldDownPacket.setIsUse(mouldEquipment.getIsUse());
+                    mouldDownPacketMapper.insert(mouldDownPacket);
+                }
             }
-            newMouldEquipment.setIsUse(mouldEquipment.getIsUse());
-            LocalDateTime now = LocalDateTime.now();
-            newMouldEquipment.setStartTime(now);
-            newMouldEquipment.setEndTime(now.plusYears(newMouldEquipment.getUseLife()));
-            mouldEquipmentMapper.updateById(newMouldEquipment);
         } else {
             msg.setError("对不起,您不是超级管理员,不具备启用设备的权限");
             return msg;
@@ -404,5 +425,25 @@ public class MouldEquipmentServiceImpl extends ServiceImpl<MouldEquipmentMapper,
         }
     }
 
+    // 下行配置数据包
+    private String downProcessMsg(String lowPowerLimit,String hotAlarmLimit,String isUse) {
+        //"23"不解析
+        if("23".equals(lowPowerLimit)){
+            lowPowerLimit="24";
+        }
+        if("23".equals(hotAlarmLimit)){
+            hotAlarmLimit="24";
+        }
+        if("23".equals(isUse)){
+            isUse="24";
+        }
+        String ret = "FA AF 00 07 "+isUse+" 1e 78 "+lowPowerLimit+" "+hotAlarmLimit+" 00 3C";
+        ret = ret.replaceAll(" ", "");
+        String crcCode = CRC16Util.getCRC(ret);
+        System.out.println("ret===>"+ret);
+        String lastPart = (ret + crcCode).replaceAll("23", "24").replaceAll(" ", "");
+        System.out.println("lastPart===>"+lastPart);
+        return lastPart;
+    }
 
 }

+ 73 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/util/CRC16Util.java

@@ -0,0 +1,73 @@
+package com.hssx.cloudmodel.util;
+public class CRC16Util {
+    /**
+     * 计算CRC16校验码
+     *
+     * @param data 需要校验的字符串
+     * @return 校验码
+     */
+    public static String getCRC(String data) {
+        data = data.replace(" ", "");
+        int len = data.length();
+        if (!(len % 2 == 0)) {
+            return "0000";
+        }
+        int num = len / 2;
+        byte[] para = new byte[num];
+        for (int i = 0; i < num; i++) {
+            int value = Integer.valueOf(data.substring(i * 2, 2 * (i + 1)), 16);
+            para[i] = (byte) value;
+        }
+        return getCRC(para);
+    }
+ 
+ 
+    /**
+     * 计算CRC16校验码
+     *
+     * @param bytes 字节数组
+     * @return {@link String} 校验码
+     * @since 1.0
+     */
+    public static String getCRC(byte[] bytes) {
+        //CRC寄存器全为1
+        int CRC = 0x0000ffff;
+        //多项式校验值
+        int POLYNOMIAL = 0x0000a001;
+        int i, j;
+        for (i = 0; i < bytes.length; i++) {
+            CRC ^= ((int) bytes[i] & 0x000000ff);
+            for (j = 0; j < 8; j++) {
+                if ((CRC & 0x00000001) != 0) {
+                    CRC >>= 1;
+                    CRC ^= POLYNOMIAL;
+                } else {
+                    CRC >>= 1;
+                }
+            }
+        }
+        System.out.println("CRC"+CRC);
+        //结果转换为16进制
+        String result = Integer.toHexString(CRC).toUpperCase();
+        System.out.println("result"+result);
+        if (result.length() != 4) {
+            StringBuffer sb = new StringBuffer("0000");
+            result = sb.replace(4 - result.length(), 4, result).toString();
+        }
+//        return result;
+//        交换高低位
+        return result.substring(2, 4) + result.substring(0, 2);//高位在前,低位在后
+    }
+ 
+ 
+    public static void main(String[] args) {
+        //01 03 20 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 8C 45
+        //01 03 00 00 00 08 44 0C
+        //01 03 10 00 8F 02 4E 00 91 02 44 00 92 02 5A 00 8B 02 47 40 D8
+//        System.out.println(getCRC("01 03 20 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF"));
+//        System.out.println(getCRC("01 03 00 00 00 08"));
+//        System.out.println(getCRC("01 03 10 00 8F 02 4E 00 91 02 44 00 92 02 5A 00 8B 02 47"));
+    	String crc = getCRC("FA AF 00 07 01 1e 78 1e 50 00 3C");
+        System.out.println(crc);
+    }
+}

+ 1 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/util/CodeGenerator.java

@@ -204,7 +204,7 @@ public class CodeGenerator {
         //若想要生成的实体类继承某个Controller,则可打开下面注释。写上需要继承的Controller的位置即可
 //        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
         //此处user是表名,多个英文逗号分割
-        strategy.setInclude("mould_history_time");
+        strategy.setInclude("mould_down_packet");
 //        strategy.setExclude();//数据库表全生成
 //        strategy.setInclude(scanner("user").split(","));//表名,多个英文逗号分割
         strategy.setControllerMappingHyphenStyle(true);

+ 2 - 2
cloud-model/src/test/java/com/hssx/cloudmodel/CloudModelApplicationTests.java

@@ -36,8 +36,8 @@ public class CloudModelApplicationTests {
 
         CustomCompany customCompany = new CustomCompany();
         customCompany.setCompanyId(66);
-        customCompany.setCompanyName("123456");
-        customCompanyMapper.update(customCompany,new QueryWrapper<CustomCompany>().eq("company_id",66));
+        customCompany.setCompanyName("123455");
+        customCompanyMapper.update(customCompany,new QueryWrapper<>(customCompany));
 
 //        User user = new User();
 //        user.setUsername("超级管理员");

+ 2 - 1
cloud-socket/src/com/js/kbt/controller/WeiXinUserInfoController.java

@@ -14,6 +14,7 @@ import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
@@ -263,7 +264,7 @@ public class WeiXinUserInfoController {
 	 * isUse:0-停止,1-启动
 	 * equipmentNo 设备编号(可能是多个或者一个)多个以“,”隔开传  如:"123456"(单个),"123456,456878,123589"(多个)
 	 */
-	@RequestMapping("/setPacket")
+	@RequestMapping(value = "/userInfo", method = {RequestMethod.POST,RequestMethod.GET})
 	public void bindAccount(HttpServletResponse response,Integer isUse,Integer lowPowerLimit,Integer hotAlarmLimit,String equipmentNo) {
 		HttpRespMsg msg = new HttpRespMsg();
 		//16进制的转化