无关风月
2024-09-03 56dfe0d4bf81262622a1919cceb2b039fd356209
ruoyi-modules/ruoyi-management/src/main/java/com/ruoyi/management/service/impl/InventoriesSuppliesInfoServiceImpl.java
@@ -3,21 +3,24 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.management.domain.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.management.domain.dto.ADDPdDTO;
import com.ruoyi.management.domain.dto.InventoriesSuppliesInfoDTO;
import com.ruoyi.management.domain.dto.InventoriesSuppliesInfoQuery;
import com.ruoyi.management.domain.vo.InventoriesSuppliesInfoVO;
import com.ruoyi.management.domain.vo.InventoriesSuppliesVO;
import com.ruoyi.management.mapper.*;
import com.ruoyi.management.service.InventoriesSuppliesInfoService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.ListResourceBundle;
import java.util.Set;
import java.security.Security;
import java.util.*;
/**
 * <p>
@@ -42,14 +45,14 @@
    @Resource
    private SlGoodsShelfMapper slGoodsShelfMapper;
    @Autowired
    private InventoriesSuppliesServiceImpl inventoriesSuppliesService;
    @Override
    public PageDTO<InventoriesSuppliesInfoVO> inventoriesSuppliesInfoService(InventoriesSuppliesInfoQuery inventoriesSuppliesInfoQuery) {
        Page<InventoriesSuppliesInfo> page = new Page<>(inventoriesSuppliesInfoQuery.getPageCurr(), inventoriesSuppliesInfoQuery.getPageSize());
        LambdaQueryWrapper< InventoriesSuppliesInfo> wrapper1= Wrappers.lambdaQuery();
        wrapper1.eq(InventoriesSuppliesInfo::getSuppliesId, inventoriesSuppliesInfoQuery.getSuppliesId());
        wrapper1.eq( InventoriesSuppliesInfo::getDelFlag,0);
        wrapper1.orderByDesc(InventoriesSuppliesInfo::getCreateTime);
        wrapper1.orderByDesc(InventoriesSuppliesInfo::getType);
        Page<InventoriesSuppliesInfo> page2 = this.page(page, wrapper1);
        PageDTO<InventoriesSuppliesInfoVO> slGoodsMaterialsVO = PageDTO.of(page2, InventoriesSuppliesInfoVO.class);
@@ -71,20 +74,21 @@
    }
    @Override
    public void addInventoriesSuppliesInfo(InventoriesSuppliesInfoDTO inventoriesSuppliesInfoDTO) {
        if (inventoriesSuppliesInfoDTO.getId()==null){
    public void addInventoriesSuppliesInfo(List<InventoriesSuppliesInfoDTO> inventoriesSuppliesInfoDTO) {
        for (InventoriesSuppliesInfoDTO m:inventoriesSuppliesInfoDTO)
        if (m.getId()==null){
            InventoriesSuppliesInfo inventoriesSuppliesInf=new InventoriesSuppliesInfo();
            inventoriesSuppliesInf.setSuppliesId(inventoriesSuppliesInfoDTO.getSuppliesId());
            inventoriesSuppliesInf.setRkId(inventoriesSuppliesInfoDTO.getRkId());
            SlVolumeProductionRk slVolumeProductionRk = slVolumeProductionRkMapper.selectById(inventoriesSuppliesInfoDTO.getRkId());
            inventoriesSuppliesInf.setSuppliesId(m.getSuppliesId());
            inventoriesSuppliesInf.setRkId(m.getRkId());
            inventoriesSuppliesInf.setCreateTime(new Date());
            SlVolumeProductionRk slVolumeProductionRk = slVolumeProductionRkMapper.selectById(m.getRkId());
            inventoriesSuppliesInf.setZkNum(slVolumeProductionRk.getRepertoryZhai());
            inventoriesSuppliesInf.setSuppliesNum(inventoriesSuppliesInfoDTO.getSuppliesNum());
            inventoriesSuppliesInf.setSuppliesNum(m.getSuppliesNum());
            this.save(inventoriesSuppliesInf);
        }else{
            InventoriesSuppliesInfo byId = this.getById(inventoriesSuppliesInfoDTO.getId());
            byId.setSuppliesNum(inventoriesSuppliesInfoDTO.getSuppliesNum());
            InventoriesSuppliesInfo byId = this.getById(m.getId());
            byId.setSuppliesNum(m.getSuppliesNum());
            this.updateById(byId);
        }
    }
@@ -99,41 +103,78 @@
    }
    @Override
    public void submitInventoriesSuppliesInfo(InventoriesSuppliesInfoDTO inventoriesSuppliesInfoDTO) {
        LambdaQueryWrapper< InventoriesSuppliesInfo> wrapper1= Wrappers.lambdaQuery();
        wrapper1.eq(InventoriesSuppliesInfo::getSuppliesId, inventoriesSuppliesInfoDTO.getSuppliesId());
        wrapper1.eq( InventoriesSuppliesInfo::getDelFlag,0);
        List<InventoriesSuppliesInfo> page2 = this.list(wrapper1);
        for (InventoriesSuppliesInfo page:page2){
            if (page.getZkNum()!=page.getSuppliesNum()){
                page.setType(2);
    public String submitInventoriesSuppliesInfo(ADDPdDTO dto) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        // 添加主表
        InventoriesSupplies inventoriesSupplies = new InventoriesSupplies();
        inventoriesSupplies.setMaterialsId(dto.getManagementId());
        inventoriesSupplies.setPdrId(loginUser.getUserid());
        inventoriesSupplies.setPdTime(new Date());
        inventoriesSupplies.setPdrName(loginUser.getUsername());
        inventoriesSupplies.setCreateTime(new Date());
        inventoriesSupplies.setDelFlag("2");
        inventoriesSuppliesService.save(inventoriesSupplies);
        for (InventoriesSuppliesInfoDTO temp : dto.getList()) {
            InventoriesSuppliesInfo res = new InventoriesSuppliesInfo();
            res.setRkId(temp.getRkId());
            res.setSuppliesId(inventoriesSupplies.getId());
            res.setSuppliesNum(temp.getSuppliesNum());
            res.setZkNum(temp.getZkNum());
            res.setCreateTime(new Date());
            if (!Objects.equals(temp.getZkNum(), temp.getSuppliesNum())){
                res.setType(2);
            }else{
                res.setType(1);
            }
            this.updateById(page);
            this.save(res);
        }
        return inventoriesSupplies.getId().toString();
    }
    @Override
    public void accomplishInventoriesSuppliesInfo(InventoriesSuppliesInfoDTO inventoriesSuppliesInfoDTO) {
        InventoriesSupplies byId = inventoriesSuppliesService.getById1(inventoriesSuppliesInfoDTO.getSuppliesId());
        byId.setDelFlag("0");
        inventoriesSuppliesService.updateById(byId);
        LambdaQueryWrapper< InventoriesSuppliesInfo> wrapper1= Wrappers.lambdaQuery();
        wrapper1.eq(InventoriesSuppliesInfo::getSuppliesId, inventoriesSuppliesInfoDTO.getSuppliesId());
        wrapper1.eq(InventoriesSuppliesInfo::getType, 2);
        wrapper1.eq( InventoriesSuppliesInfo::getDelFlag,0);
        wrapper1.eq( InventoriesSuppliesInfo::getDelFlag,"0");
        wrapper1.orderByDesc(InventoriesSuppliesInfo::getType);
        List<InventoriesSuppliesInfo> page2 = this.list(wrapper1);
        for (InventoriesSuppliesInfo page:page2){
            SlVolumeProductionRk slVolumeProductionRk = slVolumeProductionRkMapper.selectById(page.getRkId());
            slVolumeProductionRk.setRepertoryZhai(page.getSuppliesNum());
            slVolumeProductionRkMapper.updateById(slVolumeProductionRk);
            LambdaQueryWrapper<ManagementGoodsMaterials> wrapper2 = Wrappers.lambdaQuery();
            wrapper2.eq(ManagementGoodsMaterials::getGoodsMaterialsId,slVolumeProductionRk.getMaterialsId());
            wrapper2.eq(ManagementGoodsMaterials::getManagementId,slVolumeProductionRk.getManagementId());
            wrapper2.eq(ManagementGoodsMaterials::getDelFlag, 0);
            ManagementGoodsMaterials managementGoodsMaterials = managementGoodsMaterialsMapper.selectOne(wrapper2);
            if (managementGoodsMaterials!=null){
                managementGoodsMaterials.setRepertoryZhai(page.getSuppliesNum());
                managementGoodsMaterialsMapper.updateById(managementGoodsMaterials);
                SlGoodsMaterials slGoodsMaterials = slGoodsMaterialsMapper.selectById(managementGoodsMaterials.getGoodsMaterialsId());
                if (slGoodsMaterials.getIsConsume() == 1){
                    // 非消耗品
                    long l = page.getZkNum() - page.getSuppliesNum();
                    if (l>0){
                        managementGoodsMaterials.setRepertoryZhai(page.getSuppliesNum());
                        Integer repertoryYishi = managementGoodsMaterials.getRepertoryYishi();
                        if (repertoryYishi!=null&& repertoryYishi!=0){
                            managementGoodsMaterials.setRepertoryYishi(repertoryYishi+(Integer.valueOf(String.valueOf(l))));
                        }else{
                            managementGoodsMaterials.setRepertoryYishi(Integer.valueOf(String.valueOf(l)));
                        }
                    }else if (l<0){
                        // 盘点数量大于在库数量 清零遗失数量
                        managementGoodsMaterials.setRepertoryZhai(page.getSuppliesNum());
                        managementGoodsMaterials.setRepertoryYishi(0);
                    }
                    managementGoodsMaterials.setCheckNum(Integer.valueOf(String.valueOf(page.getSuppliesNum())));
                    managementGoodsMaterialsMapper.updateById(managementGoodsMaterials);
                }else{
                    // 消耗品不计算遗失 更新在库数量即可
                    managementGoodsMaterials.setRepertoryZhai(page.getSuppliesNum());
                }
            }
        }