package com.doumee.service.business.impl; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.model.LoginUserInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Constants; import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.Utils; import com.doumee.dao.business.YwStocktakingMapper; import com.doumee.dao.business.YwStocktakingRecordMapper; import com.doumee.dao.business.model.*; import com.doumee.dao.system.model.SystemUser; import com.doumee.service.business.YwStocktakingRecordService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.List; import java.util.Objects; /** * 运维盘点明细记录表Service实现 * @author 江蹄蹄 * @date 2025/01/06 11:05 */ @Service public class YwStocktakingRecordServiceImpl implements YwStocktakingRecordService { @Autowired private YwStocktakingRecordMapper ywStocktakingRecordMapper; @Autowired private YwStocktakingMapper ywStocktakingMapper; @Override public Integer create(YwStocktakingRecord ywStocktakingRecord) { ywStocktakingRecordMapper.insert(ywStocktakingRecord); return ywStocktakingRecord.getId(); } @Override public void deleteById(Integer id) { ywStocktakingRecordMapper.deleteById(id); } @Override public void delete(YwStocktakingRecord ywStocktakingRecord) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(ywStocktakingRecord); ywStocktakingRecordMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } ywStocktakingRecordMapper.deleteBatchIds(ids); } @Override public void updateById(YwStocktakingRecord ywStocktakingRecord) { ywStocktakingRecordMapper.updateById(ywStocktakingRecord); } @Override public void updateByIdInBatch(List ywStocktakingRecords) { if (CollectionUtils.isEmpty(ywStocktakingRecords)) { return; } for (YwStocktakingRecord ywStocktakingRecord: ywStocktakingRecords) { this.updateById(ywStocktakingRecord); } } @Override public YwStocktakingRecord findById(Integer id) { return ywStocktakingRecordMapper.selectById(id); } @Override public YwStocktakingRecord getDetail(Integer id) { MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper<>(); queryWrapper.selectAll(YwStocktakingRecord.class) .selectAs(YwWarehouse::getName, YwStocktakingRecord::getWarehouseName) .selectAs(YwMaterial::getCode,YwStocktakingRecord::getMaterialCode) .selectAs(YwMaterial::getName,YwStocktakingRecord::getMaterialName) .selectAs(YwMaterial::getQrcode,YwStocktakingRecord::getMaterialQrcode) .selectAs(YwMaterial::getBrand,YwStocktakingRecord::getMaterialBrand) .selectAs(YwMaterial::getUnitName,YwStocktakingRecord::getMaterialUnitName) .selectAs(YwMaterial::getAttr,YwStocktakingRecord::getMaterialAttr) .selectAs(Company::getName,YwStocktakingRecord::getCompanyName) .selectAs(SystemUser::getRealname,YwStocktakingRecord::getUserName) .leftJoin(YwStocktaking.class,YwStocktaking::getId,YwStocktakingRecord::getStocktakingId) .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwStocktaking::getWarehouseId) .leftJoin(YwMaterial.class,YwMaterial::getId,YwStocktakingRecord::getMaterialId) .leftJoin(SystemUser.class,SystemUser::getId,YwStocktakingRecord::getUserId) .leftJoin(Company.class,Company::getId,SystemUser::getCompanyId) .eq(YwStocktakingRecord::getId,id) .last(" limit 1 "); ; return ywStocktakingRecordMapper.selectOne(queryWrapper); } @Override public YwStocktakingRecord findOne(YwStocktakingRecord ywStocktakingRecord) { QueryWrapper wrapper = new QueryWrapper<>(ywStocktakingRecord); return ywStocktakingRecordMapper.selectOne(wrapper); } @Override public List findList(YwStocktakingRecord ywStocktakingRecord) { QueryWrapper wrapper = new QueryWrapper<>(ywStocktakingRecord); return ywStocktakingRecordMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper<>(); Utils.MP.blankToNull(pageWrap.getModel()); YwStocktakingRecord model = pageWrap.getModel() ; queryWrapper.selectAll(YwStocktakingRecord.class) .selectAs(YwWarehouse::getName, YwStocktakingRecord::getWarehouseName) .selectAs(YwMaterial::getCode,YwStocktakingRecord::getMaterialCode) .selectAs(YwMaterial::getName,YwStocktakingRecord::getMaterialName) .selectAs(YwMaterial::getQrcode,YwStocktakingRecord::getMaterialQrcode) .selectAs(YwMaterial::getBrand,YwStocktakingRecord::getMaterialBrand) .selectAs(YwMaterial::getUnitName,YwStocktakingRecord::getMaterialUnitName) .selectAs(YwMaterial::getAttr,YwStocktakingRecord::getMaterialAttr) .leftJoin(YwStocktaking.class,YwStocktaking::getId,YwStocktakingRecord::getStocktakingId) .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwStocktaking::getWarehouseId) .leftJoin(YwMaterial.class,YwMaterial::getId,YwStocktakingRecord::getMaterialId) .eq(Objects.nonNull(model.getStocktakingId()),YwStocktakingRecord::getStocktakingId,model.getStocktakingId()) .and(StringUtils.isNotBlank(model.getMaterialCode()),i->i.like(YwMaterial::getCode,model.getMaterialCode()).or().like(YwMaterial::getName,model.getMaterialCode())) .eq(Objects.nonNull(model.getType()),YwStocktakingRecord::getType,model.getType()) .eq(Objects.nonNull(model.getStatus()),YwStocktakingRecord::getStatus,model.getStatus()) .eq(Objects.nonNull(model.getMaterialQrcode()),YwMaterial::getQrcode,model.getMaterialQrcode()); IPage iPage = ywStocktakingRecordMapper.selectJoinPage(page, YwStocktakingRecord.class,queryWrapper); return PageData.from(iPage); } @Override public long count(YwStocktakingRecord ywStocktakingRecord) { QueryWrapper wrapper = new QueryWrapper<>(ywStocktakingRecord); return ywStocktakingRecordMapper.selectCount(wrapper); } @Override @Transactional(rollbackFor = {Exception.class,BusinessException.class}) public void takingData(YwStocktakingRecord ywStocktakingRecord) { if(Objects.isNull(ywStocktakingRecord) || Objects.isNull(ywStocktakingRecord.getId()) || Objects.isNull(ywStocktakingRecord.getActStock()) || ywStocktakingRecord.getActStock().compareTo(BigDecimal.ZERO) < 0 ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } LoginUserInfo loginUserInfo = ywStocktakingRecord.getLoginUserInfo(); YwStocktakingRecord model = ywStocktakingRecordMapper.selectById(ywStocktakingRecord.getId()); if(Objects.isNull(model)){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } YwStocktaking ywStocktaking = ywStocktakingMapper.selectById(ywStocktakingRecord.getStocktakingId()); if(Objects.isNull(ywStocktaking)){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } if(!Constants.equalsInteger(loginUserInfo.getId(),ywStocktaking.getUserId())){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非您的盘点单无法进行操作"); } if(!Constants.equalsInteger(ywStocktaking.getStatus(),Constants.ONE)){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"盘点订状态已流转,无法进行该操作"); } if(ywStocktakingRecord.getActStock().compareTo(model.getStock())==Constants.ZERO){ ywStocktakingRecord.setType(Constants.ZERO); }else if(ywStocktakingRecord.getActStock().compareTo(model.getStock())>Constants.ZERO){ ywStocktakingRecord.setType(Constants.TWO); }else{ ywStocktakingRecord.setType(Constants.ONE); } ywStocktakingRecordMapper.update(new UpdateWrapper().lambda() .set(YwStocktakingRecord::getStatus,Constants.ONE) .set(YwStocktakingRecord::getType,ywStocktakingRecord.getType()) .set(YwStocktakingRecord::getActStock,ywStocktakingRecord.getActStock()) .set(YwStocktakingRecord::getUserId,loginUserInfo.getId()) .set(YwStocktakingRecord::getPlanDate, DateUtil.getCurrDateTime()) .set(StringUtils.isNotBlank(ywStocktakingRecord.getRemark()),YwStocktakingRecord::getRemark, ywStocktakingRecord.getRemark()) .eq(YwStocktakingRecord::getId,ywStocktakingRecord.getId()) ); } }