package com.huaheng.pc.srm.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huaheng.api.srm.domain.SRMResult; import com.huaheng.common.exception.RunFailException; import com.huaheng.common.utils.StringUtils; import com.huaheng.common.utils.Wrappers; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.pc.config.material.domain.Material; import com.huaheng.pc.config.material.service.MaterialService; import com.huaheng.pc.srm.domain.ICSASN; import com.huaheng.pc.srm.domain.ICSITEMLot; import com.huaheng.pc.srm.mapper.ICSITEMlotMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; import java.util.stream.Collectors; @Service public class ICSITEMLotService extends ServiceImpl<ICSITEMlotMapper, ICSITEMLot> { @Resource RunFailException runFailException; @Resource private MaterialService materialService; public List<ICSITEMLot> selectList(ICSITEMLot icsitemLot){ LambdaQueryWrapper<ICSITEMLot> queryWrapper = Wrappers.lambdaQuery(); queryWrapper.eq(StringUtils.isNotEmpty(icsitemLot.getLotNO()),ICSITEMLot::getLotNO,icsitemLot.getLotNO()); return this.list(queryWrapper); } public ICSITEMLot selectFirstModel(ICSITEMLot icsitemLot){ LambdaQueryWrapper<ICSITEMLot> queryWrapper = Wrappers.lambdaQuery(); queryWrapper.eq(StringUtils.isNotEmpty(icsitemLot.getLotNO()),ICSITEMLot::getLotNO,icsitemLot.getLotNO()); queryWrapper.eq(StringUtils.isNotEmpty(icsitemLot.getWarehouseCode()),ICSITEMLot::getWarehouseCode,icsitemLot.getWarehouseCode()); queryWrapper.last("limit 1"); return this.getOne(queryWrapper); } /** * 获取物料条码 * * @param icsitemLotList * @return */ @Transactional(rollbackFor = Exception.class) public SRMResult saveICSItemLotList(List<ICSITEMLot> icsitemLotList) { SRMResult srmResult = new SRMResult(); ICSITEMLot queryIcsitemLot = new ICSITEMLot(); for (ICSITEMLot icsitemLot : icsitemLotList) { if(StringUtils.isEmpty(icsitemLot.getItemCode())){ return srmResult.error("物料不存在"); } if(StringUtils.isEmpty(icsitemLot.getWarehouseCode())){ return srmResult.error("仓库code不存在"); } Material material = materialService.getMaterialByCode(icsitemLot.getItemCode(),icsitemLot.getWarehouseCode()); if(material == null){ runFailException.sendException("ID为:"+icsitemLot.getID()+"的物料条码在wms不存在"); return srmResult.error("ID为:"+icsitemLot.getID()+"的物料条码在wms不存在"); } queryIcsitemLot.setLotNO(icsitemLot.getLotNO()); if (this.selectList(queryIcsitemLot).size()!=0){ if(!this.updateById(icsitemLot)){ runFailException.sendException("ID为:"+icsitemLot.getID()+"的物料条码更新失败"); return srmResult.error("ID为:"+icsitemLot.getID()+"的物料条码更新失败"); } }else { if (!this.save(icsitemLot)){ runFailException.sendException("ID为:"+icsitemLot.getID()+"的物料条码插入失败"); return srmResult.error("ID为:"+icsitemLot.getID()+"的物料条码插入失败"); } } } return srmResult.success("物料条码列表插入成功"); } public SRMResult delICSItemLotList(List<ICSITEMLot> icsitemLotList) { SRMResult srmResult = new SRMResult(); if (icsitemLotList.isEmpty()){ return srmResult.error("请勿提交空数据!"); } if (icsitemLotList.size() == 0){ return srmResult.error("条码数据不能为空!"); } List<String> warehouseCodes = icsitemLotList.stream().map(ICSITEMLot::getWarehouseCode).collect(Collectors.toList()); if (warehouseCodes.size() == 0){ return srmResult.error("仓库code不能为空值!"); } try { deleteByLOTNOs(icsitemLotList.stream().map(ICSITEMLot::getLotNO).collect(Collectors.toList())); }catch (Exception e){ return srmResult.error(e.getMessage()); } return srmResult.success("条码删除成功!"); } public void deleteByLOTNOs(List<String> list) { if(list!=null&&list.size()>0){ String[] split=list.toArray(new String[0]); LambdaQueryWrapper<ICSITEMLot> queryWrapper = Wrappers.lambdaQuery(); queryWrapper.in(ICSITEMLot::getLotNO,split); this.remove(queryWrapper); } } }