/* * 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.basic.entity.Location; import com.chinaztt.mes.basic.entity.Part; import com.chinaztt.mes.basic.mapper.LocationMapper; import com.chinaztt.mes.basic.mapper.PartMapper; import com.chinaztt.mes.warehouse.dto.CheckDetailDTO; import com.chinaztt.mes.warehouse.entity.CheckDetail; import com.chinaztt.mes.warehouse.entity.CheckDiffAdjDetail; import com.chinaztt.mes.warehouse.entity.CheckMain; import com.chinaztt.mes.warehouse.mapper.CheckDetailMapper; import com.chinaztt.mes.warehouse.mapper.CheckDiffAdjDetailMapper; import com.chinaztt.mes.warehouse.mapper.CheckMainMapper; import com.chinaztt.mes.warehouse.service.CheckDetailService; import com.chinaztt.ztt.common.core.util.R; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; /** * 盘点明细表 * * @author sunxl * @date 2020-12-01 13:42:14 */ @AllArgsConstructor @Service public class CheckDetailServiceImpl extends ServiceImpl implements CheckDetailService { private CheckDiffAdjDetailMapper checkDiffAdjDetailMapper; private CheckMainMapper checkMainMapper; private PartMapper partMapper; private LocationMapper locationMapper; @Override public IPage> getCheckDetailPage(Page page, QueryWrapper gen) { return baseMapper.getCheckDetailPage(page,gen); } @Override public CheckDetailDTO getCheckDetailById(Long id) { return baseMapper.getCheckDetailById(id); } @Override public R findCheckDetailByNo(CheckDetailDTO checkDetailDTO) { if (checkDetailDTO.getChkNo()==null){ return R.failed("盘点编号为空,请选择盘点编号"); } if (checkDetailDTO.getPartNo()==null){ return R.failed("盘点编号为空,请选择盘点编号"); } if (checkDetailDTO.getLocNo()==null){ return R.failed("盘点库位号为空,请选择盘点库位号"); } if (checkDetailDTO.getPartBatchNo()==null){ return R.failed("盘点零件批次号为空,请选择盘点零件批次号"); } CheckDetailDTO checkDetail = baseMapper.getCheckDetailByNo(checkDetailDTO); if (checkDetail == null){ return R.failed("查询的盘点零件不存在"); } return R.ok(checkDetail); } @Override public R pdaCheckDetailSave(CheckDetailDTO checkDetailDTO) { CheckDetailDTO newCheckDetailDTO = baseMapper.getCheckDetailByNo(checkDetailDTO); if (newCheckDetailDTO == null) { return R.failed("找不到对应的库存明细,请重新选择"); } newCheckDetailDTO.setChkQty(checkDetailDTO.getChkQty()); newCheckDetailDTO.setChkDiffQty(checkDetailDTO.getChkQty().subtract(newCheckDetailDTO.getLocQty())); if (newCheckDetailDTO.getLocQty().subtract(checkDetailDTO.getChkQty()).compareTo(BigDecimal.ZERO) == 0) { newCheckDetailDTO.setStatus("一致"); } if (newCheckDetailDTO.getLocQty().subtract(checkDetailDTO.getChkQty()).compareTo(BigDecimal.ZERO) == 1) { newCheckDetailDTO.setStatus("盘亏"); } if (newCheckDetailDTO.getLocQty().subtract(checkDetailDTO.getChkQty()).compareTo(BigDecimal.ZERO) == -1) { newCheckDetailDTO.setStatus("盘盈"); } return R.ok(baseMapper.updateById(newCheckDetailDTO)); } @Override public IPage> getCheckDetailByPage(Page page, QueryWrapper gen) { return baseMapper.getCheckDetailByPage(page,gen); } @Override public boolean fullSave(CheckDiffAdjDetail checkDiffAdjDetail) { CheckDiffAdjDetail checkDiffAdjDetail1 = checkDiffAdjDetailMapper.selectOne(Wrappers.lambdaQuery().eq(CheckDiffAdjDetail::getCheckDetailId,checkDiffAdjDetail.getCheckDetailId())); if (checkDiffAdjDetail1!=null){ throw new RuntimeException("请不要重复保存"); } CheckDetail checkDetail =baseMapper.selectOne(Wrappers.lambdaQuery().eq(CheckDetail::getId,checkDiffAdjDetail.getCheckDetailId())); CheckMain checkMain = checkMainMapper.selectOne(Wrappers.lambdaQuery().eq(CheckMain::getId,checkDetail.getWarehouseCheckId())); if (checkDetail.getChkDiffQty().compareTo(checkDiffAdjDetail.getAdjQty())!=0){ throw new RuntimeException("请重新确认调整数量,与差异数量不匹配"); } checkDiffAdjDetail.setChkNo(checkMain.getChkNo()); checkDiffAdjDetail.setAdjTime(LocalDateTime.now()); checkDiffAdjDetailMapper.insert(checkDiffAdjDetail); return false; } @Override public IPage> getCheckDiffAdjDetailPage(Page page, QueryWrapper gen, Long id) { return checkDiffAdjDetailMapper.getCheckDiffAdjDetailPage(page,gen,id); } }