ICSITEMLotService.java 3.25 KB
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.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
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;

@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.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("物料不存在");
            }
            Material material = materialService.getMaterialByCode(icsitemLot.getItemCode());
            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("物料条码列表插入成功");
    }




}