Bladeren bron

修改更新标签冠字号范围方法

hill.liu 8 maanden geleden
bovenliggende
commit
795ce54901
1 gewijzigde bestanden met toevoegingen van 78 en 0 verwijderingen
  1. 78 0
      src/main/java/com/sy/coinage/workshop/service/impl/BaseInfoServiceImpl.java

+ 78 - 0
src/main/java/com/sy/coinage/workshop/service/impl/BaseInfoServiceImpl.java

@@ -14,6 +14,7 @@ import com.sy.coinage.app.req.HalfBindReq;
 import com.sy.coinage.config.PrinterConfig;
 import com.sy.coinage.core.constants.BusinessEnum;
 import com.sy.coinage.core.exception.RetException;
+import com.sy.coinage.core.util.CommonUtil;
 import com.sy.coinage.core.util.DateUtils;
 import com.sy.coinage.core.vo.CacheUserVO;
 import com.sy.coinage.core.vo.OptVO;
@@ -553,6 +554,83 @@ public class BaseInfoServiceImpl extends ServiceImpl<BaseInfoDao, BaseInfo> impl
         return data.getRecords().get(0);
     }
 
+    @Override
+    public void updateRfidInfo(BaseInfoReq req) {
+
+        //首先判断是不是一个号段
+        String start = req.getCrownFrom();
+        String end = req.getCrownTo();
+        String[] startArray = start.split("-");
+        String[] endArray = end.split("-");
+        //起始号段 ,起始序号
+        String startCode = startArray[0];
+        String startSeq = startArray[1];
+
+        String endCode = endArray[0];
+        String endSeq = endArray[1];
+
+        //
+        String crownPrefix = req.getCrownPrefix();
+
+        //startCode == endCode ,则只更新当前数据,不涉及子表
+        if(startCode.equalsIgnoreCase(endCode)){
+
+            BaseInfo model = this.getById(req.getId());
+            BeanUtils.copyProperties(req, model);
+            model.setCrownBetween(model.getCrownPrefix() +"-"+ model.getCrownFrom() + " 至 "
+                    + model.getCrownPrefix() +"-"+ model.getCrownTo());
+            // model.setUpdateBy(user.getName());
+            this.updateById(model);
+            //判断子表中是否存在,如果子表存在,则需要删除子表里的数据
+            BaseInfoSub subInfo = this.getSubInfo(model.getId());
+            if(subInfo!=null){
+                baseInfoSubService.removeById(subInfo.getId());
+            }
+
+
+        }else {
+            //当不相等,则需要更新主表,及子表
+            BaseInfo model = this.getById(req.getId());
+            BeanUtils.copyProperties(req, model);
+            //注意更新crownBetween,crownFrom,crownTo字段
+            String crownFromFirst = startCode.concat("-").concat(startSeq) ;
+            String crownToFirst =  startCode.concat("-").concat( "5000");
+            String crownFromSecond = endCode.concat( "-").concat( "0001");
+            String crownToSecond =  endCode.concat("-").concat(endSeq);
+            StringBuffer crownBetweenSb = new StringBuffer();
+            crownBetweenSb.append(crownPrefix).append("-").append(crownFromFirst).append(" 至 ").append(crownPrefix).append("-").append(crownToFirst).append(",");
+            crownBetweenSb.append(crownPrefix).append("-").append(crownFromSecond).append(" 至 ").append(crownPrefix).append("-").append(crownToSecond);
+            model.setCrownBetween(crownBetweenSb.toString());
+            model.setCrownFrom(crownFromFirst);
+            model.setCrownTo(crownToFirst);
+            this.updateById(model);
+            log.info(" update rfid_base_info, baseInfo is :{}",JSONObject.toJSONString(model));
+            // 判断子表,如果存在,则更新,如果不存在,则插入
+            BaseInfoSub subInfo = this.getSubInfo(model.getId());
+            if(subInfo!=null){
+                subInfo.setCrownFrom(crownFromSecond);
+                subInfo.setCrownTo(crownToSecond);
+                subInfo.setCrownPrefix(crownPrefix);
+                baseInfoSubService.updateById(subInfo);
+            }else{
+                subInfo = new BaseInfoSub();
+                subInfo.setBaseInfoId(model.getId());
+                subInfo.setSerialNumber(model.getSerialNumber());
+                subInfo.setCrownPrefix(model.getCrownPrefix());
+                subInfo.setCrownFrom(crownFromSecond);
+                subInfo.setCrownTo(crownToSecond);
+                baseInfoSubService.save(subInfo);
+
+            }
+          log.info("operate baseInfoSub :{}",JSONObject.toJSONString(subInfo));
+
+        }
+
+
+
+
+    }
+
     /**
      * 校验baseInfo:
      * 当数据crown_prefix字段为空时,就返回false