/* * Copyright (c) 2018-2025, ztt All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the pig4cloud.com developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: ztt */ package com.chinaztt.mes.warehouse.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.chinaztt.mes.common.numgen.NumberGenerator; import com.chinaztt.mes.warehouse.dto.CheckMainDTO; import com.chinaztt.mes.warehouse.entity.*; import com.chinaztt.mes.warehouse.mapper.*; import com.chinaztt.mes.warehouse.service.CheckMainService; import com.chinaztt.mes.warehouse.util.StockUtils; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; /** * 盘点主表 * * @author sunxl * @date 2020-12-01 11:06:00 */ @AllArgsConstructor @Service public class CheckMainServiceImpl extends ServiceImpl implements CheckMainService { private NumberGenerator numberGenerator; private WarehouseCheckLocationMapper warehouseCheckLocationMapper; private WarehouseCheckPartMapper warehouseCheckPartMapper; private CheckDetailMapper checkDetailMapper; private CheckDiffAdjDetailMapper checkDiffAdjDetailMapper; private StockMapper stockMapper; private StockUtils stockUtils; @Override public boolean fullSave(CheckMainDTO checkMainDTO) { checkMainDTO.setChkNo(numberGenerator.generateNumberWithPrefix(CheckMain.DIGIT, CheckMain.PREFIX, CheckMain::getChkNo)); baseMapper.insert(checkMainDTO); addWarehouseCheck(checkMainDTO); checkDetailMapper.getCheckDetail(checkMainDTO); return true; } @Override public IPage> getCheckMainPage(Page page, QueryWrapper gen) { return baseMapper.getCheckMainPage(page,gen); } @Override public CheckMainDTO getCheckMainPageById(Long id) { return baseMapper.getCheckMainPageById(id); } @Override public void fullDelete(Long id) { baseMapper.deleteCheckMainById(id); } @Override public boolean updateByCheckMainId(CheckMainDTO checkMainDTO) { baseMapper.deleteCheckMain(checkMainDTO.getId()); baseMapper.updateById(checkMainDTO); addWarehouseCheck(checkMainDTO); checkDetailMapper.getCheckDetail(checkMainDTO); return false; } @Override public boolean updateWarehouseCheck(List ids) { for (long id:ids){ CheckMain checkMain = baseMapper.selectById(id); if ("未下发".equals(checkMain.getChkStatus())) { checkMain.setChkStatus("已下发"); } else{ List checkDetailList = checkDetailMapper.selectList(Wrappers.lambdaQuery().eq(CheckDetail::getWarehouseCheckId,checkMain.getId())); for (CheckDetail checkDetail:checkDetailList){ if (checkDetail.getStatus().equals("待盘")){ throw new RuntimeException("有库存没有盘点"); } } checkMain.setChkStatus("盘点中"); } baseMapper.updateById(checkMain); } return false; } @Override public List getCheckMainPdaPage( QueryWrapper gen) { return baseMapper.getCheckMainPdaPage(gen); } @Override public boolean submitWarehouseCheck(Long id) { List checkDetailList = checkDetailMapper.selectList(Wrappers.lambdaQuery().eq(CheckDetail::getWarehouseCheckId,id)); for (CheckDetail checkDetail:checkDetailList) { CheckDiffAdjDetail checkDiffAdjDetail = checkDiffAdjDetailMapper.selectOne(Wrappers.lambdaQuery().eq(CheckDiffAdjDetail::getCheckDetailId, checkDetail.getId())); if (checkDiffAdjDetail==null){ continue; } Stock stock = stockMapper.selectOne(Wrappers.lambdaQuery().eq(Stock::getPartId,checkDetail.getPartId()).eq(Stock::getLocationId,checkDetail.getLocationId()).eq(Stock::getPartBatchNo,checkDetail.getPartBatchNo()).eq(Stock::getSystemNo,checkDetail.getSystemNo())); stockUtils.updateById(stock.getId(), checkDiffAdjDetail.getAdjQty(), BigDecimal.ZERO, BigDecimal.ZERO,BigDecimal.ZERO, checkDiffAdjDetail.getChkNo(), "CHECK"); } return false; } @Override public IPage> getCheckPage(Page page, QueryWrapper gen) { return baseMapper.getCheckPage(page,gen); } public void addWarehouseCheck(CheckMainDTO checkMainDTO){ if (checkMainDTO.getLocationIds().size()!=0){ for(Long locationId :checkMainDTO.getLocationIds()) { WarehouseCheckLocation warehouseCheckLocation = new WarehouseCheckLocation(); warehouseCheckLocation.setCheckMainId(checkMainDTO.getId()); warehouseCheckLocation.setLocationId(locationId); warehouseCheckLocationMapper.insert(warehouseCheckLocation); } } if (checkMainDTO.getPartIds().size()!=0){ for(Long partId :checkMainDTO.getPartIds()) { WarehouseCheckPart warehouseCheckPart= new WarehouseCheckPart(); warehouseCheckPart.setCheckMainId(checkMainDTO.getId()); warehouseCheckPart.setPartId(partId); warehouseCheckPartMapper.insert(warehouseCheckPart); } } } }