package com.thhy.materials.modules.biz.concret.controller; import com.thhy.materials.modules.biz.concret.entity.SysSteel; import com.thhy.materials.modules.biz.concret.entity.dto.DicetName; import com.thhy.materials.modules.biz.concret.entity.dto.TMinxingPlant; import com.thhy.materials.modules.biz.concret.entity.dto.WeighDto; import com.thhy.materials.modules.biz.weigh.entity.TWeighbridge; import com.thhy.materials.modules.biz.weigh.mapper.WeighMapper; import com.thhy.materials.modules.biz.weigh.service.WeighService; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.concurrent.TimeUnit; @Component public class MixingPlantNewScheduled { @Resource private WeighService weighService; @Resource private WeighMapper weighMapper; @Resource private RedissonClient redissonclient; @Scheduled(fixedRate = 2000000) // 每隔3秒执行一次任务 public void task() { //查询搅拌 所有类型 List dictList = weighService.dictList(); System.out.println("-------"+dictList); Integer byId = weighService.mixingPlantIdNew(); for (DicetName values : dictList){ if(byId!=null){ List weighVos =weighService.findAlltaskNew(byId,values.getDictName()); for (WeighDto weighVo : weighVos){ HashMap hashMap = new HashMap<>(); hashMap.put("byId",weighVo.getById()); hashMap.put("carName",weighVo.getCarNumber()); //*****************改为净重********************* hashMap.put("changeStock",weighVo.getNetWeight()/1000); hashMap.put("dictId",values.getDictId()); hashMap.put("createTime",weighVo.getUpdateTime()); String forwardingUnit = weighVo.getForwardingUnit(); String id = weighService.forwardingUnitSelectBy(forwardingUnit); hashMap.put("supplierId",id); hashMap.put("companyId","02d2fc8b7ea0eff7ec70c649"); //***********数据消耗(毛重 改为净重) *********** double v = (weighVo.getNetWeight() / 1000); //字典表id String dictId = values.getDictId(); //查询当前库存 Double materialValue = weighMapper.selectMaterialValueNew(dictId); //**********判断净重是否入库( 净重>0 ) 增加库存 ********** if(weighVo.getNetWeight()>0){ hashMap.put("isIn",2); //入库记录添加 HashMap hashMap1 = new HashMap<>(); hashMap1.put("createDate",new Date()); hashMap1.put("materialName",dictId); hashMap1.put("type",1); hashMap1.put("opType",1); hashMap1.put("materialValue",v); BigDecimal b1 = new BigDecimal(v); BigDecimal b2 = new BigDecimal(materialValue); hashMap1.put("beforeStock",materialValue); hashMap1.put("afterStock",b1.add(b2).doubleValue()); hashMap1.put("companyId","02d2fc8b7ea0eff7ec70c649"); RLock lock = redissonclient.getLock("materlock"); System.out.println(hashMap1); if(!lock.isLocked()) { lock.lock(10, TimeUnit.SECONDS); //插入记录表 weighMapper.materialStockRecordInNew(hashMap1); //更改记录值 weighMapper.materialStockRecordUpNew(dictId,b1.add(b2).doubleValue()); lock.unlock(); } }else { hashMap.put("isIn",1); } weighMapper.minxingInNew(hashMap); } }else { List weighVos =weighService.findAlltaskAllNew(values.getDictName()); for (WeighDto weighVo : weighVos){ HashMap hashMap = new HashMap<>(); hashMap.put("byId",weighVo.getById()); hashMap.put("carName",weighVo.getCarNumber()); //*****************改为净重********************* hashMap.put("changeStock",weighVo.getNetWeight()/1000); hashMap.put("dictId",values.getDictId()); hashMap.put("createTime",weighVo.getUpdateTime()); //供应商 String forwardingUnit = weighVo.getForwardingUnit(); String id = weighService.forwardingUnitSelectBy(forwardingUnit); hashMap.put("supplierId",id); hashMap.put("companyId","02d2fc8b7ea0eff7ec70c649"); System.out.println("----------"+hashMap); //数据消耗 double v = (weighVo.getGrossWeight() / 1000); //字典表id String dictId = values.getDictId(); //查询当前库存 Double materialValue = weighMapper.selectMaterialValueNew(dictId); if(weighVo.getNetWeight()>0){ hashMap.put("isIn",2); //入库记录添加 HashMap hashMap1 = new HashMap<>(); hashMap1.put("createDate",new Date()); hashMap1.put("materialName",dictId); hashMap1.put("type",1); hashMap1.put("opType",1); hashMap1.put("materialValue",v); BigDecimal b1 = new BigDecimal(v); BigDecimal b2 = new BigDecimal(materialValue); hashMap1.put("beforeStock",materialValue); double v1 = b1.add(b2).doubleValue(); System.out.println("---------====-=--="+v1); System.out.println("---------====-=--="+v1); hashMap1.put("afterStock",v1); hashMap1.put("companyId","02d2fc8b7ea0eff7ec70c649"); RLock lock = redissonclient.getLock("materlock"); if(!lock.isLocked()) { lock.lock(10, TimeUnit.SECONDS); //插入记录表 weighMapper.materialStockRecordInNew(hashMap1); //更改记录值 weighMapper.materialStockRecordUpNew(dictId,b1.add(b2).doubleValue()); lock.unlock(); } }else { hashMap.put("isIn",1); } weighMapper.minxingInNew(hashMap); } } // 定时执行的任务内容 } } @Scheduled(fixedRate = 2400000) // 每隔3秒执行一次任务 public void taskUpdate() { List minxingPlants = weighMapper.mixingPlantIsIn(); for (TMinxingPlant minxingPlant : minxingPlants){ Integer byId = minxingPlant.getById(); //原料值 Integer netWeight = weighMapper.netWeighNew(byId); if(netWeight!=null && netWeight>0){ //数据消耗 double v = (netWeight/ 1000); HashMap hashMap1 = new HashMap<>(); hashMap1.put("createDate",new Date()); hashMap1.put("materialName",minxingPlant.getDictId()); hashMap1.put("type",1); hashMap1.put("opType",1); hashMap1.put("materialValue",v); //查询当前库存 Double materialValue = weighMapper.selectMaterialValueNew(minxingPlant.getDictId()); BigDecimal b1 = new BigDecimal(v); BigDecimal b2 = new BigDecimal(materialValue); hashMap1.put("beforeStock",materialValue); double v1 = b1.add(b2).doubleValue(); System.out.println("---------====-=--="+v1); System.out.println("---------====-=--="+v1); hashMap1.put("afterStock",v1); hashMap1.put("companyId","02d2fc8b7ea0eff7ec70c649"); RLock lock = redissonclient.getLock("materlock"); if(!lock.isLocked()) { lock.lock(10, TimeUnit.SECONDS); //插入记录表 weighMapper.materialStockRecordInNew(hashMap1); //更改记录值 weighMapper.materialStockRecordUpNew(minxingPlant.getDictId(),b1.add(b2).doubleValue()); lock.unlock(); } weighMapper.netWeighUpdateNew(byId,v); }else { System.out.println("********未二次称重********"); } } } //苏州项目------- 地磅入库 记录,及库存修改 @Scheduled(fixedRate = 2000000) // 每隔3秒执行一次任务 public void weighbridge() { //查询搅拌 所有类型 List dictList = weighService.dictList(); List tWeighbridges = weighMapper.weighbridgeListType(); for (DicetName dicetName : dictList){ for (TWeighbridge weighbridge :tWeighbridges){ if(dicetName.getDictName().equals(weighbridge.getMatname())){ //开始的库存 Double materialValue = weighMapper.materialStockValue(dicetName.getDictId()); //净重 String jweight = weighbridge.getJweight(); HashMap hashMap = new HashMap<>(); hashMap.put("id",""); hashMap.put("type",1); hashMap.put("opType",1); hashMap.put("materialName",dicetName.getDictId()); hashMap.put("materialValue",Double.valueOf(jweight)); hashMap.put("beforeStock",materialValue); BigDecimal b1 = new BigDecimal(jweight); BigDecimal b2 = new BigDecimal(materialValue); double v1 = b1.add(b2).doubleValue(); hashMap.put("afterStock",v1); hashMap.put("companyId","031e3dd577e8ed28e96aa69b"); RLock lock = redissonclient.getLock("materlock"); if(!lock.isLocked()) { lock.lock(10, TimeUnit.SECONDS); //插入记录表//苏州项目(入库计入增加) weighMapper.materialStockRecordIns(hashMap); //更改记录值 weighMapper.materialStockRecordUp(dicetName.getDictId(),b1.add(b2).doubleValue()); lock.unlock(); } weighMapper.weighbridgeUpdateType(weighbridge.getWeighbridgeId()); } } } } //苏州项目------- 地磅入库 记录,及库存修改 钢筋 @Scheduled(fixedRate = 2000000) // 每隔3秒执行一次任务 public void weighbridgeSteel() { //查询搅拌 所有类型 List steels = weighService.steelType(); List tWeighbridges = weighMapper.weighbridgeListType(); for (SysSteel steel : steels){ for (TWeighbridge weighbridge :tWeighbridges){ if(steel.getSteelName().equals(weighbridge.getMatname())&&steel.getSteelModel().equals(weighbridge.getMatmodel())){ //净重 String jweight = weighbridge.getJweight(); HashMap hashMap = new HashMap<>(); hashMap.put("id",""); hashMap.put("steelId",steel.getSteelId()); hashMap.put("stockType",1); hashMap.put("changeStock",jweight); hashMap.put("companyId","031e3dd577e8ed28e96aa69b"); BigDecimal b1 = new BigDecimal(jweight); BigDecimal b2 = new BigDecimal(steel.getStock()); RLock lock = redissonclient.getLock("materlock"); if(!lock.isLocked()) { lock.lock(10, TimeUnit.SECONDS); //插入记录表//苏州项目(入库计入增加) weighMapper.steelRecordIn(hashMap); //更改记录值 weighMapper.steelUp(steel.getSteelId(),b1.add(b2).doubleValue()); lock.unlock(); } weighMapper.weighbridgeUpdateType(weighbridge.getWeighbridgeId()); } } } } }