|  |  |  | 
|---|
|  |  |  | package com.doumee.service.business.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.core.model.LoginUserModel; | 
|---|
|  |  |  | import com.doumee.core.model.PageData; | 
|---|
|  |  |  | import com.doumee.core.model.PageWrap; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.Utils; | 
|---|
|  |  |  | import com.doumee.dao.business.YwMaterialMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.YwMaterial; | 
|---|
|  |  |  | import com.doumee.dao.business.YwOutinboundMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.YwOutinboundRecordMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.*; | 
|---|
|  |  |  | import com.doumee.dao.system.MultifileMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.model.Multifile; | 
|---|
|  |  |  | import com.doumee.service.business.YwMaterialService; | 
|---|
|  |  |  | 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.base.MPJBaseMapper; | 
|---|
|  |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
|---|
|  |  |  | import org.apache.commons.lang.StringUtils; | 
|---|
|  |  |  | import org.checkerframework.checker.units.qual.A; | 
|---|
|  |  |  | 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.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 运维资产信息表Service实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwMaterialMapper ywMaterialMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MultifileMapper multifileMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwOutinboundRecordMapper ywOutinboundRecordMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemDictDataBiz systemDictDataBiz; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | public Integer create(YwMaterial ywMaterial) { | 
|---|
|  |  |  | //TODO rk 所属项目/房间需求问题 | 
|---|
|  |  |  | if(Objects.isNull(ywMaterial) | 
|---|
|  |  |  | || StringUtils.isBlank(ywMaterial.getName()) | 
|---|
|  |  |  | || StringUtils.isBlank(ywMaterial.getQrcode()) | 
|---|
|  |  |  | || Objects.isNull(ywMaterial.getCateId()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ywMaterial.setId(null); | 
|---|
|  |  |  | if(StringUtils.isBlank(ywMaterial.getCode())){ | 
|---|
|  |  |  | //自动生成 TODO 存在问题 | 
|---|
|  |  |  | Long countCode = ywMaterialMapper.selectCount(new QueryWrapper<YwMaterial>().lambda().eq(YwMaterial::getAutoCode, Constants.ONE)); | 
|---|
|  |  |  | String nextCode = StringUtils.leftPad(Long.toString(countCode + 1),4,"0"); | 
|---|
|  |  |  | ywMaterial.setCode("P"+nextCode); | 
|---|
|  |  |  | ywMaterial.setAutoCode(Constants.ONE); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //验证code是否存在 | 
|---|
|  |  |  | if(ywMaterialMapper.selectCount(new QueryWrapper<YwMaterial>().lambda().eq(YwMaterial::getCode, ywMaterial.getCode()))>0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前编码已存在"); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | ywMaterial.setAutoCode(Constants.ZERO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = ywMaterial.getLoginUserInfo(); | 
|---|
|  |  |  | ywMaterial.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | ywMaterial.setCreateDate(new Date()); | 
|---|
|  |  |  | ywMaterial.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | ywMaterial.setStatus(Constants.ZERO); | 
|---|
|  |  |  | ywMaterialMapper.insert(ywMaterial); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Objects.nonNull(ywMaterial.getMultifile())){ | 
|---|
|  |  |  | if(org.apache.commons.lang3.StringUtils.isBlank(ywMaterial.getMultifile().getFileurl()) | 
|---|
|  |  |  | || org.apache.commons.lang3.StringUtils.isBlank(ywMaterial.getMultifile().getName())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"附件信息错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ywMaterial.getMultifile().setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | ywMaterial.getMultifile().setCreateDate(new Date()); | 
|---|
|  |  |  | ywMaterial.getMultifile().setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | ywMaterial.getMultifile().setObjType(Constants.MultiFile.MATERIAL_FILE.getKey()); | 
|---|
|  |  |  | ywMaterial.getMultifile().setObjId(ywMaterial.getId()); | 
|---|
|  |  |  | multifileMapper.insert(ywMaterial.getMultifile()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ywMaterial.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void deleteById(Integer id) { | 
|---|
|  |  |  | ywMaterialMapper.deleteById(id); | 
|---|
|  |  |  | if(ywOutinboundRecordMapper.selectCount(new QueryWrapper<YwOutinboundRecord>().lambda().eq(YwOutinboundRecord::getMaterialId,id))>Constants.ZERO){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前资产已有出入库记录,不可删除"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ywMaterialMapper.update(new UpdateWrapper<YwMaterial>().lambda().set(YwMaterial::getIsdeleted,Constants.ONE).eq(YwMaterial::getId,id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | public void updateById(YwMaterial ywMaterial) { | 
|---|
|  |  |  | //TODO rk 所属项目/房间需求问题 | 
|---|
|  |  |  | if(Objects.isNull(ywMaterial) | 
|---|
|  |  |  | || StringUtils.isBlank(ywMaterial.getName()) | 
|---|
|  |  |  | || StringUtils.isBlank(ywMaterial.getCode()) | 
|---|
|  |  |  | || StringUtils.isBlank(ywMaterial.getQrcode()) | 
|---|
|  |  |  | || Objects.isNull(ywMaterial.getCateId()) | 
|---|
|  |  |  | || Objects.isNull(ywMaterial.getId()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ywMaterial.setCode(null); | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = ywMaterial.getLoginUserInfo(); | 
|---|
|  |  |  | ywMaterial.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | ywMaterial.setEditDate(new Date()); | 
|---|
|  |  |  | ywMaterialMapper.updateById(ywMaterial); | 
|---|
|  |  |  | multifileMapper.delete(new QueryWrapper<Multifile>().lambda().eq(Multifile::getObjType,Constants.MultiFile.MATERIAL_FILE.getKey()).eq(Multifile::getObjId,ywMaterial.getId())); | 
|---|
|  |  |  | if(Objects.nonNull(ywMaterial.getMultifile())){ | 
|---|
|  |  |  | if(org.apache.commons.lang3.StringUtils.isBlank(ywMaterial.getMultifile().getFileurl()) | 
|---|
|  |  |  | || org.apache.commons.lang3.StringUtils.isBlank(ywMaterial.getMultifile().getName())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"附件信息错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ywMaterial.getMultifile().setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | ywMaterial.getMultifile().setCreateDate(new Date()); | 
|---|
|  |  |  | ywMaterial.getMultifile().setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | ywMaterial.getMultifile().setObjType(Constants.MultiFile.MATERIAL_FILE.getKey()); | 
|---|
|  |  |  | ywMaterial.getMultifile().setObjId(ywMaterial.getId()); | 
|---|
|  |  |  | multifileMapper.insert(ywMaterial.getMultifile()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateStatus(YwMaterial ywMaterials) { | 
|---|
|  |  |  | if(Objects.isNull(ywMaterials) | 
|---|
|  |  |  | || Objects.isNull(ywMaterials.getId()) | 
|---|
|  |  |  | || Objects.isNull(ywMaterials.getStatus())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ywMaterialMapper.update(new UpdateWrapper<YwMaterial>().lambda().eq(YwMaterial::getId,ywMaterials.getId()).set(YwMaterial::getStatus,ywMaterials.getStatus())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public YwMaterial findById(Integer id) { | 
|---|
|  |  |  | return ywMaterialMapper.selectById(id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public YwMaterial getDetail(Integer id) { | 
|---|
|  |  |  | YwMaterial ywMaterial = ywMaterialMapper.selectById(id); | 
|---|
|  |  |  | if(Objects.isNull(ywMaterial)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Multifile multifile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.MATERIAL_FILE.getKey())); | 
|---|
|  |  |  | if(Objects.nonNull(multifile)){ | 
|---|
|  |  |  | String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() | 
|---|
|  |  |  | +systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_MATERIAL).getCode(); | 
|---|
|  |  |  | multifile.setFileurlFull(path + multifile.getFileurl()); | 
|---|
|  |  |  | ywMaterial.setMultifile(multifile); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ywMaterial; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public PageData<YwMaterial> findPage(PageWrap<YwMaterial> pageWrap) { | 
|---|
|  |  |  | IPage<YwMaterial> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | QueryWrapper<YwMaterial> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | MPJLambdaWrapper<YwMaterial> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | Utils.MP.blankToNull(pageWrap.getModel()); | 
|---|
|  |  |  | if (pageWrap.getModel().getId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreator() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getCreator, pageWrap.getModel().getCreator()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreateDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(YwMaterial::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(YwMaterial::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEditor() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getEditor, pageWrap.getModel().getEditor()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEditDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(YwMaterial::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(YwMaterial::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getIsdeleted() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getRemark() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getRemark, pageWrap.getModel().getRemark()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getName() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(YwMaterial::getName, Utils.Date.getStart(pageWrap.getModel().getName())); | 
|---|
|  |  |  | queryWrapper.lambda().le(YwMaterial::getName, Utils.Date.getEnd(pageWrap.getModel().getName())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getStatus() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getStatus, pageWrap.getModel().getStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCode() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getCode, pageWrap.getModel().getCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getParentCateId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getParentCateId, pageWrap.getModel().getParentCateId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCateId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getCateId, pageWrap.getModel().getCateId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getQrcode() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getQrcode, pageWrap.getModel().getQrcode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getSortnum() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getSortnum, pageWrap.getModel().getSortnum()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getBrand() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getBrand, pageWrap.getModel().getBrand()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getAttr() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getAttr, pageWrap.getModel().getAttr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getMinStock() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getMinStock, pageWrap.getModel().getMinStock()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getMaxStock() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getMaxStock, pageWrap.getModel().getMaxStock()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getUnitName() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getUnitName, pageWrap.getModel().getUnitName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getRoomId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwMaterial::getRoomId, pageWrap.getModel().getRoomId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|---|
|  |  |  | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|---|
|  |  |  | queryWrapper.orderByDesc(sortData.getProperty()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.orderByAsc(sortData.getProperty()); | 
|---|
|  |  |  | YwMaterial model = pageWrap.getModel(); | 
|---|
|  |  |  | queryWrapper.selectAll(YwMaterial.class) | 
|---|
|  |  |  | .leftJoin(YwRoom.class,YwRoom::getId,YwMaterial::getRoomId) | 
|---|
|  |  |  | .and(StringUtils.isNotBlank(model.getCode()),i->i.like(YwMaterial::getCode,model.getCode()).or().like(YwMaterial::getName,model.getCode())) | 
|---|
|  |  |  | .like(StringUtils.isNotBlank(model.getAttr()),YwMaterial::getAttr,model.getAttr()) | 
|---|
|  |  |  | .eq(Objects.nonNull(model.getProjectId()),YwRoom::getProjectId,model.getProjectId()) | 
|---|
|  |  |  | .eq(Objects.nonNull(model.getRoomId()),YwMaterial::getRoomId,model.getRoomId()) | 
|---|
|  |  |  | .eq(Objects.nonNull(model.getFloorId()),YwRoom::getFloor,model.getFloorId()) | 
|---|
|  |  |  | .eq(Objects.nonNull(model.getBuildingId()),YwRoom::getBuildingId,model.getBuildingId()) | 
|---|
|  |  |  | .eq(YwMaterial::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .orderByAsc(YwMaterial::getCode) | 
|---|
|  |  |  | ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | IPage<YwMaterial> iPage = ywMaterialMapper.selectJoinPage(page,YwMaterial.class,queryWrapper); | 
|---|
|  |  |  | String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() | 
|---|
|  |  |  | +systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_MATERIAL).getCode(); | 
|---|
|  |  |  | for (YwMaterial ywMaterial:iPage.getRecords()) { | 
|---|
|  |  |  | Multifile multifile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getObjId,ywMaterial.getId()).eq(Multifile::getObjType,Constants.MultiFile.MATERIAL_FILE.getKey())); | 
|---|
|  |  |  | if(Objects.nonNull(multifile)){ | 
|---|
|  |  |  | multifile.setFileurlFull(path + multifile.getFileurl()); | 
|---|
|  |  |  | ywMaterial.setMultifile(multifile); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return PageData.from(ywMaterialMapper.selectPage(page, queryWrapper)); | 
|---|
|  |  |  | return PageData.from(iPage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|