package org.jeecg.modules.lsw.service.impl;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.exception.JeecgBootException;
|
import org.jeecg.modules.lsw.entity.LswMaterial;
|
import org.jeecg.modules.lsw.mapper.LswMaterialMapper;
|
import org.jeecg.modules.lsw.service.ILswMaterialService;
|
import org.jeecg.modules.mes.entity.MesProductionOrder;
|
import org.jeecg.modules.sap.dto.OrderBomDTO;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Collection;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Description: 线边库物料信息
|
* @Author: jeecg-boot
|
* @Date: 2025-06-30
|
* @Version: V1.0
|
*/
|
@Service
|
public class LswMaterialServiceImpl extends ServiceImpl<LswMaterialMapper, LswMaterial> implements ILswMaterialService {
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean editMaterial(LswMaterial lswMaterial) {
|
LswMaterial entity = this.getBaseMapper().selectById(lswMaterial.getId());
|
if (entity == null) {
|
throw new JeecgBootException("要编辑的数据不存在!");
|
}
|
entity.setMaterialCategory(lswMaterial.getMaterialCategory());
|
this.updateById(entity);
|
return true;
|
}
|
|
@Override
|
public LswMaterial queryByMaterialNumber(String materialNumber) {
|
LambdaQueryWrapper<LswMaterial> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(LswMaterial::getMaterialNumber, materialNumber);
|
queryWrapper.eq(LswMaterial::getDelFlag, CommonConstant.DEL_FLAG_0);
|
List<LswMaterial> list = this.getBaseMapper().selectList(queryWrapper);
|
if (CollectionUtil.isEmpty(list)) {
|
return null;
|
}
|
return list.get(0);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean saveOrUpdateMaterial(Map<String, MesProductionOrder> orderMap, List<OrderBomDTO> orderBomDTOList) {
|
Map<String, LswMaterial> addMap = new HashMap<>();
|
for (Map.Entry<String, MesProductionOrder> entry : orderMap.entrySet()) {
|
MesProductionOrder order = entry.getValue();
|
LswMaterial material = queryByMaterialNumber(order.getMaterialNumber());
|
if (material == null) {
|
//新增物料
|
material = new LswMaterial();
|
material.setMaterialStatus(CommonConstant.STATUS_1);
|
material.setMaterialNumber(order.getMaterialNumber());
|
material.setMaterialName(order.getMaterialName());
|
material.setMaterialUnit(order.getProductionUnit());
|
material.setDelFlag(CommonConstant.DEL_FLAG_0);
|
addMap.put(material.getMaterialNumber(), material);
|
}
|
}
|
for (OrderBomDTO bomDTO : orderBomDTOList) {
|
LswMaterial material = queryByMaterialNumber(bomDTO.getMATNR());
|
if (material == null) {
|
//新增物料
|
material = new LswMaterial();
|
material.setMaterialStatus(CommonConstant.STATUS_1);
|
material.setMaterialNumber(bomDTO.getMATNR());
|
material.setMaterialName(bomDTO.getMAKTX());
|
material.setMaterialUnit(bomDTO.getMEINS());
|
material.setDelFlag(CommonConstant.DEL_FLAG_0);
|
addMap.put(material.getMaterialNumber(), material);
|
}
|
}
|
if (CollectionUtil.isNotEmpty(addMap)) {
|
Collection<LswMaterial> addList = addMap.values();
|
super.saveBatch(addList);
|
}
|
return true;
|
}
|
|
}
|