fix:修复已知bug-03-10

liutao_branch
HuangHuiKang 2 weeks ago
parent 89e8024282
commit 8d816aefa0

@ -78,6 +78,10 @@ public class ErpStockOutRespVO {
@ExcelProperty("产品信息")
private String productNames;
@Schema(description = "计划单Code", example = "随便")
private String planCode;
@Data
public static class Item {

@ -39,6 +39,10 @@ public class ErpStockOutSaveReqVO {
@Valid
private List<Item> items;
@Schema(description = "计划单Code", example = "随便")
private String planCode;
@Data
public static class Item {

@ -74,4 +74,9 @@ public class ErpStockOutDO extends BaseDO {
* URL
*/
private String fileUrl;
/**
* Code
*/
private String planCode;
}

@ -63,6 +63,11 @@ public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
default int updateCountIncrement(Long id, BigDecimal count, boolean negativeEnable) {
LambdaUpdateWrapper<ErpStockDO> updateWrapper = new LambdaUpdateWrapper<ErpStockDO>()
.eq(ErpStockDO::getId, id);
if (count == null || count.compareTo(BigDecimal.ZERO) == 0) {
return 0;
}
if (count.compareTo(BigDecimal.ZERO) > 0) {
updateWrapper.setSql("count = count + " + count);
} else if (count.compareTo(BigDecimal.ZERO) < 0) {
@ -86,7 +91,7 @@ public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
return BigDecimal.valueOf(MapUtil.getDouble(result.get(0), "sumCount", 0D));
}
int updateStockCount(@Param("productId") Long productId,
void updateStockCount(@Param("productId") Long productId,
@Param("warehouseId") Long warehouseId,
@Param("num") BigDecimal num);

@ -22,6 +22,7 @@ import cn.iocoder.yudao.module.erp.service.mold.MoldService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -88,7 +89,10 @@ public class ErpStockInServiceImpl implements ErpStockInService {
.setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)));
stockInMapper.insert(stockIn);
// 2.2 插入入库单项
stockInItems.forEach(o -> o.setInId(stockIn.getId()));
stockInItems.forEach(o -> {
o.setInId(stockIn.getId());
// o.setCount(o.getCount());
});
stockInItemMapper.insertBatch(stockInItems);
// for (ErpStockInItemDO item : stockInItems) {
// MoldDO moldDO = moldService.getMold(item.getProductId());
@ -118,6 +122,8 @@ public class ErpStockInServiceImpl implements ErpStockInService {
stockInMapper.updateById(updateObj);
// 2.2 更新入库单项
updateStockInItemList(updateReqVO.getId(), stockInItems);
}
@Override
@ -160,8 +166,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
ErpStockRecordBizTypeEnum.getTypeByName(stockIn.getInType(),status), stockInItem.getInId(), stockInItem.getId(), stockIn.getNo(), stockIn.getInTime()));
//更新库存
// erpStockMapper.updateStockCount(productDO.getId(), stockInItem.getWarehouseId(), BigDecimal.ONE);
//
// erpStockMapper.updateStockCount(productDO.getId(), stockInItem.getWarehouseId(), stockInItem.getCount());
// ErpStockDO stock = erpStockMapper.selectByProductIdAndWarehouseId(productDO.getId(), stockInItem.getWarehouseId());
// stock.setCount(stock.getCount() + 1);
// erpStockMapper.updateById(stock);

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageR
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -74,18 +75,18 @@ public class ErpStockServiceImpl implements ErpStockService {
stockMapper.insert(stock);
}
// 1.2 校验库存是否充足
// if (!NEGATIVE_STOCK_COUNT_ENABLE && stock.getCount().add(count).compareTo(BigDecimal.ZERO) < 0) {
// throw exception(STOCK_COUNT_NEGATIVE, productService.getProduct(productId).getName(),
// warehouseService.getWarehouse(warehouseId).getName(), stock.getCount(), count);
// }
if (!NEGATIVE_STOCK_COUNT_ENABLE && stock.getCount().add(count).compareTo(BigDecimal.ZERO) < 0) {
throw exception(STOCK_COUNT_NEGATIVE, productService.getProduct(productId).getName(),
warehouseService.getWarehouse(warehouseId).getName(), stock.getCount(), count);
}
// 2. 库存变更
// int updateCount = stockMapper.updateCountIncrement(stock.getId(), count, NEGATIVE_STOCK_COUNT_ENABLE);
// if (updateCount == 0) {
// // 此时不好去查询最新库存,所以直接抛出该提示,不提供具体库存数字
// throw exception(STOCK_COUNT_NEGATIVE2, productService.getProduct(productId).getName(),
// warehouseService.getWarehouse(warehouseId).getName());
// }
int updateCount = stockMapper.updateCountIncrement(stock.getId(), count, NEGATIVE_STOCK_COUNT_ENABLE);
if (updateCount == 0) {
// 此时不好去查询最新库存,所以直接抛出该提示,不提供具体库存数字
throw exception(STOCK_COUNT_NEGATIVE2, productService.getProduct(productId).getName(),
warehouseService.getWarehouse(warehouseId).getName());
}
// 3. 返回最新库存
return stock.getCount().add(count);

@ -14,6 +14,5 @@
SET count = count + #{num}
WHERE product_id = #{productId}
AND warehouse_id = #{warehouseId}
AND count + #{num} >= 0
</update>
</mapper>

@ -96,10 +96,9 @@ public class RecipePointRecordController {
@Operation(summary = "批量创建IoT配方点位记录")
@PreAuthorize("@ss.hasPermission('iot:recipe-point-record:create')")
public CommonResult<Boolean> createRecipePointRecordBatch(@Valid @RequestBody List<RecipePointRecordSaveReqVO> createReqVOList) {
for (RecipePointRecordSaveReqVO createReqVO : createReqVOList) {
createReqVO.setId(null);
recipePointRecordService.createRecipePointRecord(createReqVO);
}
recipePointRecordService.createBatchRecipePointRecord(createReqVOList);
return success(true);
}

@ -52,4 +52,7 @@ public interface RecipePointRecordService {
*/
PageResult<RecipePointRecordDO> getRecipePointRecordPage(RecipePointRecordPageReqVO pageReqVO);
void createBatchRecipePointRecord(@Valid List<RecipePointRecordSaveReqVO> createReqVOList);
}

@ -32,10 +32,6 @@ public class RecipePointRecordServiceImpl implements RecipePointRecordService {
@Override
public Long createRecipePointRecord(RecipePointRecordSaveReqVO createReqVO) {
List<RecipePointRecordDO> recipePointRecordDOS = recipePointRecordMapper.selectList(Wrappers.<RecipePointRecordDO>lambdaQuery().eq(RecipePointRecordDO::getRecipeId, createReqVO.getRecipeId()));
if (!recipePointRecordDOS.isEmpty()){
recipePointRecordMapper.deleteByIds(recipePointRecordDOS);
}
// 插入
RecipePointRecordDO recipePointRecord = BeanUtils.toBean(createReqVO, RecipePointRecordDO.class);
@ -77,4 +73,30 @@ public class RecipePointRecordServiceImpl implements RecipePointRecordService {
return recipePointRecordMapper.selectPage(pageReqVO);
}
@Override
public void createBatchRecipePointRecord(List<RecipePointRecordSaveReqVO> reqList) {
if (reqList == null || reqList.isEmpty()) {
return;
}
Long recipeId = reqList.get(0).getRecipeId();
// 1 删除旧数据
recipePointRecordMapper.delete(
Wrappers.<RecipePointRecordDO>lambdaQuery()
.eq(RecipePointRecordDO::getRecipeId, recipeId)
);
// 2 VO -> DO
List<RecipePointRecordDO> recordList =
BeanUtils.toBean(reqList, RecipePointRecordDO.class);
recordList.forEach(o -> o.setId(null));
// 3 批量插入
recipePointRecordMapper.insertBatch(recordList);
}
}

@ -209,6 +209,7 @@ public class FeedingRecordController {
planItemListMap, planItemMap);
//更新计划对应的领料单投料时间
Map<Long, Long> map = new HashMap<>();
if (recordPlanDOMap!=null && !recordPlanDOMap.isEmpty()) {
for (String key : recordPlanDOMap.keySet()) {
FeedingRecordPlanDO item = recordPlanDOMap.get(key);
if (!map.containsKey(item.getPlanId())) {
@ -221,6 +222,7 @@ public class FeedingRecordController {
}
}
}
}
} else {
}
@ -235,6 +237,7 @@ public class FeedingRecordController {
// );
// feedingRecordDetailMapper.insertBatch(list);
// }
recordDO.setRecordStatus(status);
feedingRecordMapper.updateById(recordDO);
return success(true);
} else return CommonResult.error(500, "无法获取操作用户!请检查!");

@ -9,15 +9,26 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockOutService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
import cn.iocoder.yudao.module.iot.framework.mqtt.utils.DateUtils;
import cn.iocoder.yudao.module.mes.controller.admin.itemrequisition.vo.ItemRequisitionSaveReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.*;
import cn.iocoder.yudao.module.mes.controller.admin.zjproductrecord.vo.ZjProductRecordSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDetailDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.zjproduct.ZjProductDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.zjproductrecord.ZjProductRecordDO;
import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomDetailMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.plan.PlanMapper;
import cn.iocoder.yudao.module.mes.service.bom.BomService;
import cn.iocoder.yudao.module.mes.service.itemrequisition.ItemAnalysisService;
import cn.iocoder.yudao.module.mes.service.itemrequisition.entity.ItemRequisitionAndStock;
import cn.iocoder.yudao.module.mes.service.organization.OrganizationService;
@ -25,6 +36,7 @@ import cn.iocoder.yudao.module.mes.service.plan.PlanService;
import cn.iocoder.yudao.module.mes.service.zjproduct.ZjProductService;
import cn.iocoder.yudao.module.mes.service.zjproductrecord.ZjProductRecordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -42,6 +54,7 @@ import java.math.RoundingMode;
import java.time.*;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
@ -68,6 +81,16 @@ public class PlanController {
@Resource
private ZjProductRecordService zjProductRecordService;
@Resource
private ErpStockOutService erpStockOutService;
@Resource
private BomMapper bomMapper;
@Resource
private BomDetailMapper bomDetailMapper;
@PostMapping("/create")
@Operation(summary = "创建生产计划")
@ -91,6 +114,68 @@ public class PlanController {
zjProductRecordService.createZjProductRecord(BeanUtils.toBean(zjProductRecordDO, ZjProductRecordSaveReqVO.class));
}
}
// // 生成领料出库单据
// List<ErpStockOutSaveReqVO.Item> itemList;
//
// // 1 查询最新 BOM
// BomDO bomDO = bomMapper.selectOne(
// Wrappers.<BomDO>lambdaQuery()
// .eq(BomDO::getProductId, createReqVO.getProductId())
// .orderByDesc(BomDO::getCreateTime)
// .last("limit 1")
// );
//
// if (bomDO == null) {
// return success(false);
// }
//
// // 2 查询 BOM 明细
// List<BomDetailDO> bomDetails = bomDetailMapper.selectList(
// Wrappers.<BomDetailDO>lambdaQuery()
// .eq(BomDetailDO::getBomId, bomDO.getId())
// );
//
// if (bomDetails.isEmpty()) {
// return success(false);
// }
//
// // 3 查询仓库
// ErpWarehouseDO warehouse = erpWarehouseMapper.selectOne(
// Wrappers.<ErpWarehouseDO>lambdaQuery()
// .orderByDesc(ErpWarehouseDO::getCreateTime)
// .last("limit 1")
// );
//
// if (warehouse == null) {
// return success(false);
// }
//
// // 4 计算领料数量
// Long planNumber = Optional.ofNullable(createReqVO.getPlanNumber()).orElse(0L);
//
// itemList = bomDetails.stream().map(detail -> {
//
// BigDecimal usageNumber = Optional.ofNullable(detail.getUsageNumber()).orElse(BigDecimal.ZERO);
//
// BigDecimal count = usageNumber.multiply(BigDecimal.valueOf(planNumber));
//
// ErpStockOutSaveReqVO.Item item = new ErpStockOutSaveReqVO.Item();
// item.setProductId(detail.getProductId());
// item.setWarehouseId(warehouse.getId());
// item.setCount(count);
//
// return item;
//
// }).collect(Collectors.toList());
//
// // 5 构造出库单
// ErpStockOutSaveReqVO stockOut = new ErpStockOutSaveReqVO();
// stockOut.setOutType("领料出库");
// stockOut.setOutTime(LocalDateTime.now());
// stockOut.setItems(itemList);
//
// // 6 创建出库单
// erpStockOutService.createStockOut(stockOut);
return success(true);
}

@ -68,12 +68,12 @@ public class ItemAnalysisServiceImpl implements ItemAnalysisService {
//算物料需求
for (TaskDetailDO detail : detailDOList) {
//这里要求销售的单位和物料单位一致等于内置单位
BomDO bomDO = bomService.selectByProductId(detail.getProductId());
if (!bomDO.getUnitId().equals(ProductUnitEnum.Each.getUnitId())
|| !detail.getUnitId().equals(ProductUnitEnum.Each.getUnitId())) {
log.error(UNIT_ERROR);
throw exception(new ErrorCode(500, UNIT_ERROR));
}
// BomDO bomDO = bomService.selectByProductId(detail.getProductId());
// if (!bomDO.getUnitId().equals(ProductUnitEnum.Each.getUnitId())
// || !detail.getUnitId().equals(ProductUnitEnum.Each.getUnitId())) {
// log.error(UNIT_ERROR);
// throw exception(new ErrorCode(500, UNIT_ERROR));
// }
//每个taskDetail计算一次物料需求汇总到map里面
List<BomDetailDO> bomDetailDOList =

@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProduc
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockOutService;
@ -35,6 +37,7 @@ import cn.iocoder.yudao.module.mes.service.paigongrecord.PaigongRecordService;
import cn.iocoder.yudao.module.mes.service.task.TaskService;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -89,19 +92,25 @@ public class PlanServiceImpl implements PlanService {
@Resource
private OrganizationService organizationService;
@Resource
private ErpWarehouseMapper erpWarehouseMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createPlan(PlanSaveReqVO createReqVO) {
// 插入
PlanDO plan = BeanUtils.toBean(createReqVO, PlanDO.class);
String code = "";
if (StringUtils.isEmpty(plan.getCode())) {
code = autoCodeUtil.genSerialCode("PLAN_CODE", null);
// 1.4 生成订单号,并校验唯一性
// String no = noRedisDAO.generate3(MesNoRedisDAO.PLAN_NO_PREFIX);
// if (planMapper.selectByNo(no) != null) {
// throw exception(PLAN_NOT_EXISTS);
// }
// plan.setCode(no);
plan.setCode(autoCodeUtil.genSerialCode("PLAN_CODE",null));
plan.setCode(code);
} else {
if (planMapper.selectByNo(plan.getCode()) != null) {
throw exception(PLAN_CODE_EXISTS);
@ -156,15 +165,21 @@ public class PlanServiceImpl implements PlanService {
List<ErpStockOutSaveReqVO.Item> itemList = new ArrayList<>();
stockOut.setOutTime(LocalDateTime.now());
stockOut.setOutType("领料出库");
ErpWarehouseDO warehouse = erpWarehouseMapper.selectOne(
Wrappers.<ErpWarehouseDO>lambdaQuery()
.orderByDesc(ErpWarehouseDO::getCreateTime)
.last("limit 1")
);
for (ItemRequisitionAndStock requisition : list) {
ErpStockOutSaveReqVO.Item item = new ErpStockOutSaveReqVO.Item();
// todo 修改仓库
item.setWarehouseId(3L);
item.setWarehouseId(warehouse.getId());
item.setProductId(requisition.getItemId());
item.setCount(requisition.getNumber());
itemList.add(item);
}
stockOut.setItems(itemList);
stockOut.setPlanCode(StringUtils.isEmpty(plan.getCode()) ? code : plan.getCode());
stockOutService.createStockOut(stockOut);
return plan.getId();
}

Loading…
Cancel
Save