|
@@ -303,7 +303,6 @@ public class OpsAppApi {
|
|
|
@PostMapping("/recordSave")
|
|
|
public R<Boolean> recordSave(@RequestBody EquRecord equRecord) {
|
|
|
BaseContextHandler.setTenant("0000");
|
|
|
- System.out.println("小程序换料接口");
|
|
|
LambdaUpdateWrapper<EquBarrel> updateWrapper = new LambdaUpdateWrapper();
|
|
|
updateWrapper.set(EquBarrel::getMtrId, equRecord.getReplaceMaterial()).set(EquBarrel::getMtrName, equRecord.getMtName()).set(EquBarrel::getMtrResidue, equRecord.getSpecs())
|
|
|
.set(StringUtil.isNotEmpty(equRecord.getDate()), EquBarrel::getExprTime, equRecord.getDate()).eq(EquBarrel::getId, equRecord.getMaterialId());
|
|
@@ -312,67 +311,34 @@ public class OpsAppApi {
|
|
|
bool = equRecordService.save(equRecord);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- // 根据设备id查询商品
|
|
|
+ // 根据设备id查询商品
|
|
|
List<EquGoodsDto> equGoods = productionTenantResourceService.getEquGoods(equRecord.getEquId());
|
|
|
QueryWrap<EquBarrel> equBarrelQueryWrap = new QueryWrap<>();
|
|
|
- equBarrelQueryWrap.eq("equ_id", equRecord.getEquId());
|
|
|
-
|
|
|
- Page<EquBarrel> page = new Page<>(1L, 20);
|
|
|
- IPage<EquBarrel> equBarrelIPage = equBarrelService.pageList(page, equBarrelQueryWrap);
|
|
|
- List<EquBarrel> barrelList = equBarrelIPage.getRecords();
|
|
|
- List<Long> mtList = new ArrayList<>();
|
|
|
- if (null != barrelList && barrelList.size()>0) {
|
|
|
- mtList = barrelList.stream().map(EquBarrel::getMtrId).collect(toList());
|
|
|
- }
|
|
|
-
|
|
|
-// 遍历商品,查询配方列表
|
|
|
- if (equGoods != null && equGoods.size() > 0) {
|
|
|
- List<Long> finalMtList = mtList;
|
|
|
- equGoods.forEach(equGoodsDto -> {
|
|
|
- QueryWrap<Spe> speQueryWrap = new QueryWrap<>();
|
|
|
- speQueryWrap.eq("goods_id", equGoodsDto.getGoodsId());
|
|
|
- List<Spe> speList = speService.list(speQueryWrap);
|
|
|
- equGoodsDto.setSpeList(speList);
|
|
|
-// 查询每一个规格的配方列表
|
|
|
- if (speList != null && speList.size() > 0) {
|
|
|
- speList.forEach(spe -> {
|
|
|
- QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
|
|
|
- formulaQueryWrap.eq("formula_spe_id", spe.getId());
|
|
|
- List<Formula> formulaList = formulaService.list(formulaQueryWrap);
|
|
|
- if (formulaList != null && barrelList != null) {
|
|
|
- formulaList.forEach(formula -> {
|
|
|
- if (finalMtList.contains(formula.getFormulaMtId())) {
|
|
|
- System.out.println("料筒里有原料" + formula.getFormulaMtId());
|
|
|
- } else {
|
|
|
- System.out.println("料筒里没有原料" + formula.getFormulaMtId() + ",商品" + equGoodsDto.getGoodsName() + "缺料");
|
|
|
- equGoodsDto.setIsStarving("0");
|
|
|
- }
|
|
|
- barrelList.forEach(equBarrel -> {
|
|
|
- if (formula.getFormulaMtId().equals(equBarrel.getMtrId())) {
|
|
|
- System.out.println("小程序换料接口-->配方中的原料" + formula.getFormulaMtId() + "和料筒中的原料" + equBarrel.getMtrId() + "相同");
|
|
|
- LambdaUpdateWrapper<EquAndGoods> equGoodsDtoUpdateWrapper = new LambdaUpdateWrapper<EquAndGoods>();
|
|
|
-
|
|
|
- if (equBarrel.getMtrResidue().compareTo(equBarrel.getResidueWarn()) == 1) {
|
|
|
- equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "1").eq(EquAndGoods::getGoodsId, equGoodsDto.getGoodsId()).eq(EquAndGoods::getEquId, equRecord.getEquId());
|
|
|
- equGoodsDto.setIsStarving("1");
|
|
|
- } else {
|
|
|
- equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "0");
|
|
|
- equGoodsDto.setIsStarving("0");
|
|
|
- }
|
|
|
- equAndGoodsService.update(equGoodsDtoUpdateWrapper);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- ;
|
|
|
- });
|
|
|
+ equBarrelQueryWrap.eq("id", equRecord.getMaterialId());
|
|
|
+ Page<EquBarrel> page = new Page<>(1L, 1);
|
|
|
+ EquBarrel equBarrel = equBarrelService.pageList(page, equBarrelQueryWrap).getRecords().get(0);
|
|
|
+ QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
|
|
|
+ formulaQueryWrap.eq("formula_mt_id", equBarrel.getMtrId());
|
|
|
+ //获取关联配方数据
|
|
|
+ List<Formula> formulaList = formulaService.list(formulaQueryWrap);
|
|
|
+ //获取商品对应规格数据
|
|
|
+ List<Long> speIds = formulaList.stream().map(Formula::getFormulaSpeId).collect(toList());
|
|
|
+ //商品规格获取对应商品数据
|
|
|
+ QueryWrap<Spe> speQueryWrap = new QueryWrap<>();
|
|
|
+ speQueryWrap.in("id", speIds);
|
|
|
+ List<Long> goodsIds = speService.list(speQueryWrap).stream().map(Spe::getGoodsId).collect(toList());
|
|
|
+
|
|
|
+ equGoods.forEach(equGoodsDto -> {
|
|
|
+ if(CollectionUtil.contains(goodsIds, equGoodsDto.getGoodsId())){
|
|
|
+ LambdaUpdateWrapper<EquAndGoods> equGoodsDtoUpdateWrapper = new LambdaUpdateWrapper<EquAndGoods>();
|
|
|
+ if (equBarrel.getMtrResidue().compareTo(equBarrel.getResidueWarn()) == 1) {
|
|
|
+ equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "1").eq(EquAndGoods::getId, equGoodsDto.getId());
|
|
|
+ } else {
|
|
|
+ equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "0").eq(EquAndGoods::getId, equGoodsDto.getId());
|
|
|
}
|
|
|
- ;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ equAndGoodsService.update(null, equGoodsDtoUpdateWrapper);
|
|
|
+ }
|
|
|
+ });
|
|
|
return R.success(bool);
|
|
|
}
|
|
|
|
|
@@ -394,16 +360,34 @@ public class OpsAppApi {
|
|
|
bool = equRecordService.save(equRecord);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- ;
|
|
|
-
|
|
|
-
|
|
|
-// 遍历配方
|
|
|
-
|
|
|
-
|
|
|
-// 根据配方中原料用量和料筒余量对比 修改商品是否缺料状态
|
|
|
-
|
|
|
-
|
|
|
+ // 根据设备id查询商品
|
|
|
+ List<EquGoodsDto> equGoods = productionTenantResourceService.getEquGoods(equRecord.getEquId());
|
|
|
+ QueryWrap<EquBarrel> equBarrelQueryWrap = new QueryWrap<>();
|
|
|
+ equBarrelQueryWrap.eq("id", equRecord.getMaterialId());
|
|
|
+ Page<EquBarrel> page = new Page<>(1L, 1);
|
|
|
+ EquBarrel equBarrel = equBarrelService.pageList(page, equBarrelQueryWrap).getRecords().get(0);
|
|
|
+ QueryWrap<Formula> formulaQueryWrap = new QueryWrap<>();
|
|
|
+ formulaQueryWrap.eq("formula_mt_id", equBarrel.getMtrId());
|
|
|
+ //获取关联配方数据
|
|
|
+ List<Formula> formulaList = formulaService.list(formulaQueryWrap);
|
|
|
+ //获取商品对应规格数据
|
|
|
+ List<Long> speIds = formulaList.stream().map(Formula::getFormulaSpeId).collect(toList());
|
|
|
+ //商品规格获取对应商品数据
|
|
|
+ QueryWrap<Spe> speQueryWrap = new QueryWrap<>();
|
|
|
+ speQueryWrap.in("id", speIds);
|
|
|
+ List<Long> goodsIds = speService.list(speQueryWrap).stream().map(Spe::getGoodsId).collect(toList());
|
|
|
+
|
|
|
+ equGoods.forEach(equGoodsDto -> {
|
|
|
+ if(CollectionUtil.contains(goodsIds, equGoodsDto.getGoodsId())){
|
|
|
+ LambdaUpdateWrapper<EquAndGoods> equGoodsDtoUpdateWrapper = new LambdaUpdateWrapper<EquAndGoods>();
|
|
|
+ if (equBarrel.getMtrResidue().compareTo(equBarrel.getResidueWarn()) == 1) {
|
|
|
+ equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "1").eq(EquAndGoods::getId, equGoodsDto.getId());
|
|
|
+ } else {
|
|
|
+ equGoodsDtoUpdateWrapper.set(EquAndGoods::getIsStarving, "0").eq(EquAndGoods::getId, equGoodsDto.getId());
|
|
|
+ }
|
|
|
+ equAndGoodsService.update(null, equGoodsDtoUpdateWrapper);
|
|
|
+ }
|
|
|
+ });
|
|
|
return R.success(bool);
|
|
|
}
|
|
|
|