|  |  |  | 
|---|
|  |  |  | 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.YwStocktakingRecord; | 
|---|
|  |  |  | 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实现 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwStocktakingRecordMapper ywStocktakingRecordMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwStocktakingMapper ywStocktakingMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer create(YwStocktakingRecord ywStocktakingRecord) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return ywStocktakingRecordMapper.selectById(id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public YwStocktakingRecord getDetail(Integer id) { | 
|---|
|  |  |  | MPJLambdaWrapper<YwStocktakingRecord> 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<YwStocktakingRecord> wrapper = new QueryWrapper<>(ywStocktakingRecord); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public PageData<YwStocktakingRecord> findPage(PageWrap<YwStocktakingRecord> pageWrap) { | 
|---|
|  |  |  | IPage<YwStocktakingRecord> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | QueryWrapper<YwStocktakingRecord> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | MPJLambdaWrapper<YwStocktakingRecord> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | Utils.MP.blankToNull(pageWrap.getModel()); | 
|---|
|  |  |  | if (pageWrap.getModel().getId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreator() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getCreator, pageWrap.getModel().getCreator()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreateDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(YwStocktakingRecord::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(YwStocktakingRecord::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEditor() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getEditor, pageWrap.getModel().getEditor()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEditDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(YwStocktakingRecord::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(YwStocktakingRecord::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getIsdeleted() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getRemark() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getRemark, pageWrap.getModel().getRemark()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getStatus() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getStatus, pageWrap.getModel().getStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getUserId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getUserId, pageWrap.getModel().getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getPlanDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(YwStocktakingRecord::getPlanDate, Utils.Date.getStart(pageWrap.getModel().getPlanDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(YwStocktakingRecord::getPlanDate, Utils.Date.getEnd(pageWrap.getModel().getPlanDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCode() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getCode, pageWrap.getModel().getCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getMaterialId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getMaterialId, pageWrap.getModel().getMaterialId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getStock() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getStock, pageWrap.getModel().getStock()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getActStock() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getActStock, pageWrap.getModel().getActStock()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getType() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getType, pageWrap.getModel().getType()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getStocktakingId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwStocktakingRecord::getStocktakingId, pageWrap.getModel().getStocktakingId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|---|
|  |  |  | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|---|
|  |  |  | queryWrapper.orderByDesc(sortData.getProperty()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.orderByAsc(sortData.getProperty()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return PageData.from(ywStocktakingRecordMapper.selectPage(page, queryWrapper)); | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | IPage iPage = ywStocktakingRecordMapper.selectJoinPage(page, YwStocktakingRecord.class,queryWrapper); | 
|---|
|  |  |  | return PageData.from(iPage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<YwStocktakingRecord> 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.nonNull(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<YwStocktakingRecord>().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()) | 
|---|
|  |  |  | .eq(YwStocktakingRecord::getId,ywStocktakingRecord.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|