瀏覽代碼

保温灯,保温板单独配置

523096025 2 年之前
父節點
當前提交
2238a2a464

+ 20 - 14
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/service/impl/LampTempServiceImpl.java

@@ -18,6 +18,7 @@ import javax.xml.ws.ServiceMode;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.Date;
+import java.util.Optional;
 
 /**
  * @Project : huimv-env-platform
@@ -53,22 +54,27 @@ public class LampTempServiceImpl implements ILampTempService {
     private LampConfigEntityRepo lampConfigEntityRepo;
     @Override
     public int saveLampTemp(String deviceId, String temp, Date addTime) {
-        LampConfigEntity LampConfigEntity = new LampConfigEntity();
-        LampConfigEntity.setDeviceId(deviceId);
-        Example<LampConfigEntity> example = Example.of(LampConfigEntity);
-        LampConfigEntity one = lampConfigEntityRepo.findOne(example).get();
-        if (ObjectUtil.isEmpty(one)){
-            System.out.println("保温灯不存在");
-            return -1;
+        try {
+            LampConfigEntity LampConfigEntity = new LampConfigEntity();
+            LampConfigEntity.setDeviceId(deviceId);
+            Example<LampConfigEntity> example = Example.of(LampConfigEntity);
+            if (!lampConfigEntityRepo.findOne(example).isPresent()){
+                System.out.println("保温灯不存在");
+                return -1;
+            }
+            LampConfigEntity one =lampConfigEntityRepo.findOne(example).get();
+            LampTempEntity lampTempEntity = new LampTempEntity();
+            lampTempEntity.setDeviceId(deviceId);
+            lampTempEntity.setTemp(temp);
+            lampTempEntity.setFarmCode(one.getFarmCode());
+            lampTempEntity.setAddTime(new Timestamp(addTime.getTime()));
+            lampTempEntityRepo.saveAndFlush(lampTempEntity);
+            return 0;
+        }catch (Exception e){
+            System.out.println("保温灯报错--->"+e);
+            return 1;
         }
 
-        LampTempEntity lampTempEntity = new LampTempEntity();
-        lampTempEntity.setDeviceId(deviceId);
-        lampTempEntity.setTemp(temp);
-        lampTempEntity.setFarmCode(one.getFarmCode());
-        lampTempEntity.setAddTime(new Timestamp(addTime.getTime()));
-        lampTempEntityRepo.saveAndFlush(lampTempEntity);
-        return 0;
     }
 }
 

+ 2 - 0
huimv-env-platform/huimv-env-common/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

@@ -42,6 +42,7 @@ com\huimv\env\common\utils\MathUtil.class
 com\huimv\env\common\dao\repo\EnvDeviceEqipmentRepo.class
 com\huimv\env\common\entity\BaseThreshold.class
 com\huimv\env\common\service\EnvElectricityMonthService.class
+com\huimv\env\common\mapper\LampTempMapper.class
 com\huimv\env\common\dao\entity\EnvTempEntity.class
 com\huimv\env\common\dao\entity\BasePigpenEntity.class
 com\huimv\env\common\dao\repo\EnvAmmoniaEntityRepo.class
@@ -75,6 +76,7 @@ com\huimv\env\common\service\ILampTempService.class
 com\huimv\env\common\service\impl\SprayConfigServiceImpl.class
 com\huimv\env\common\service\IEnvPushMessageService.class
 com\huimv\env\common\dao\entity\LampConfig.class
+com\huimv\env\common\entity\LampTemp.class
 com\huimv\env\common\utils\DateUtil.class
 com\huimv\env\common\service\impl\LampTempServiceImpl.class
 com\huimv\env\common\service\ISprayStatusService.class

+ 6 - 3
huimv-env-platform/huimv-env-lamp/src/main/java/com/huimv/env/lamp/server/LampInputServer.java

@@ -19,7 +19,7 @@ import org.springframework.stereotype.Component;
  * @Create : 2020-12-25
  **/
 @Component
-public class LampInputServer {
+public class LampInputServer extends Thread{
     @Autowired
     private LampInputServerHandler serverHandler;
     //监听端口
@@ -43,7 +43,8 @@ public class LampInputServer {
     /**
      * 启动流程
      */
-    public void run() throws InterruptedException {
+    @Override
+    synchronized  public void run()  {
         //配置服务端线程组
         EventLoopGroup bossGroup=new NioEventLoopGroup();
         EventLoopGroup workGroup=new NioEventLoopGroup();
@@ -65,7 +66,9 @@ public class LampInputServer {
             ChannelFuture cf = serverBootstrap.bind(port).sync();
             // 等待服务端监听端口关闭
             cf.channel().closeFuture().sync();
-        }finally {
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } finally {
             //优雅的退出
             bossGroup.shutdownGracefully();
             workGroup.shutdownGracefully();

+ 5 - 4
huimv-env-platform/huimv-env-lamp/src/main/java/com/huimv/env/lamp/service/impl/LampInputHandleServiceImpl.java

@@ -47,7 +47,10 @@ public class LampInputHandleServiceImpl implements LampInputHandleService {
 
     @Override
     public void getLampTemp(String askText, String idCode, ChannelHandlerContext ctx) throws ParseException {
-
+        System.out.println(idCode);
+        String answerText = "hm+"+idCode+"+2+0+7+end";
+        answerCmd(answerText, ctx);
+        log.info(">>上传温度请求-应答数据>>" + answerText);
         System.out.println("上传温度");
         String[] dataArray = askText.split("\\+");
         String tempText = dataArray[4];
@@ -56,9 +59,7 @@ public class LampInputHandleServiceImpl implements LampInputHandleService {
         String eartemp = new BigDecimal(temp).setScale(1, BigDecimal.ROUND_HALF_UP).toString();
         DateUtil dateUtil = new DateUtil();
         lampTempService.saveLampTemp(idCode,eartemp,dateUtil.getTodayDatetime());
-        String answerText = "hm+"+idCode+"+2+0+7+end";
-        log.info(">>上传温度请求-应答数据>>" + answerText);
-        answerCmd(answerText, ctx);
+
     }
 
     @Override

+ 1 - 1
huimv-env-platform/huimv-env-manage/src/main/java/com/huimv/env/manage/saas/service/ILampConfigService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.huimv.env.manage.utils.Result;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -39,5 +40,4 @@ public interface ILampConfigService extends IService<LampConfig> {
 
     Result listByLampId(Map<String, String> map, HttpServletRequest request);
 
-
 }

+ 9 - 9
huimv-env-platform/huimv-env-manage/src/main/java/com/huimv/env/manage/saas/service/impl/LampConfigServiceImpl.java

@@ -73,7 +73,8 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
     @Override
     public Result lsitAllLamp(Map<String, String> map, HttpServletRequest request) {
         String farmCode = map.get("farmCode");
-        List<LampConfig> lampConfigs = lampConfigMapper.selectList(new QueryWrapper<LampConfig>().eq("farm_code", farmCode));
+        List<LampConfig> lampConfigs = lampConfigMapper.selectList(new QueryWrapper<LampConfig>().eq("farm_code", farmCode)
+                .last(" ORDER BY unit_id, CAST( REPLACE(location,\"号产床\",\"\")AS SIGNED)"));
         List endList = new ArrayList();
         for (LampConfig lampConfig : lampConfigs) {
             Map endMap = new HashMap();
@@ -135,10 +136,11 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
     public String updateTemp(String ageList, Integer dayAge) {
 
         String[] split = ageList.split(";");
+        // 5,32;10,36;12,39;40,39; 5->32
         String temp = split[split.length-1].split(",")[1];
         for (int i = 0; i < split.length; i++) {
             String  lamp1 = split[i];
-            if (dayAge>=Integer.parseInt(lamp1.split(",")[0])){
+            if (dayAge<=Integer.parseInt(lamp1.split(",")[0])){
                 temp = lamp1.split(",")[1];
                 String tempStr = (Double.parseDouble(temp) * 10) + "";
                 return  tempStr.substring(0,tempStr.lastIndexOf("."));
@@ -154,14 +156,10 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
         try {
             Integer initDayAge =  (Integer) map.get("initDayAge");
             List<String> dayAgeList =  (List<String> )map.get("dayAgeList");
-            //
-//            Integer boardGear =(Integer) map.get("boardGear");
             String unitId =(String) map.get("unitId");
             String id = (String)map.get("id");
-
             LampConfig lampConfig = new LampConfig();
             lampConfig.setInitAge(initDayAge);
-//            lampConfig.setBoardGear(boardGear);
             StringBuilder dayAgeListStr = new StringBuilder();
             for (String s : dayAgeList) {
                 dayAgeListStr.append(s).append(";");
@@ -172,17 +170,17 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
             lampConfig.setAgeList(dayAgeListStr.toString());
             lampConfig.setDayAge(initDayAge);
             UpdateWrapper<LampConfig> wrapper = new UpdateWrapper<>();
+            //栋舍配置
             if (StringUtils.isBlank(id)){
                 LampConfigAll lampConfigAll = new LampConfigAll();
-//                lampConfigAll.setBoardGear(boardGear);
                 lampConfigAll.setInitDayage((initDayAge));
                 lampConfigAll.setListDayage((dayAgeListStr.toString()));
-
                 lampConfigAllMapper.update(lampConfigAll,new UpdateWrapper<LampConfigAll>().eq("unit_id",unitId));
                 wrapper.eq("unit_id",unitId);
                 lampConfigMapper.update(lampConfig,wrapper);
                 return new Result(10000,"全局配置成功",true);
             }else {
+                //单个配置
                 wrapper.eq("id",id);
                 lampConfigMapper.update(lampConfig,wrapper);
                 return new Result(10000,"配置成功",true);
@@ -228,7 +226,7 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
     public Result listByUnit(Map<String, String> map, HttpServletRequest request) {
         String unitId = map.get("unitId");
         QueryWrapper<LampConfig> wrapper = new QueryWrapper<>();
-        wrapper.eq("unit_id",unitId);
+        wrapper.eq("unit_id",unitId).last("ORDER BY CAST( REPLACE(location,\"号产床\",\"\")AS SIGNED) ");
         List<LampConfig> lampConfigs = lampConfigMapper.selectList(wrapper);
         for (LampConfig lampConfig : lampConfigs) {
             String deviceId = lampConfig.getDeviceId();
@@ -320,4 +318,6 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
         endMap.put("pigpenName",basePigpen.getPigpenName());
         return new Result(ResultCode.SUCCESS,endMap);
     }
+
+
 }

+ 4 - 2
huimv-env-platform/huimv-env-manage/src/main/java/com/huimv/env/manage/time/Timer.java

@@ -8,6 +8,7 @@ import com.huimv.env.manage.saas.service.ILampConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -20,9 +21,10 @@ public class Timer {
     //更新日龄,温度
     @Scheduled(cron = "0 59 23 * * ?")
 //    @Scheduled(cron = "0 * * * * ?")
-    private void updateAge(){
+    @Transactional
+    public void updateAge(){
         System.out.println("更新日龄");
-        List<LampConfig> lampConfigs = lampConfigService.list(new QueryWrapper<>());
+        List<LampConfig> lampConfigs = lampConfigService.list(null);
         System.out.println(lampConfigs);
         for (LampConfig lampConfig : lampConfigs) {
             Integer dayAge = lampConfig.getDayAge()+1;

+ 2 - 2
huimv-env-platform/huimv-env-manage/src/main/resources/application.properties

@@ -1,6 +1,6 @@
 #spring.profiles.active=dev
-#spring.profiles.active=prod
-spring.profiles.active=qingshan
+spring.profiles.active=prod
+#spring.profiles.active=qingshan
 
 # mysql:/cache:
 device.online.access_mode=mysql