package doumeemes.service.business.impl; import com.alibaba.druid.util.StringUtils; 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 doumeemes.core.model.ApiResponse; import doumeemes.core.model.LoginUserInfo; import doumeemes.core.model.PageData; import doumeemes.core.model.PageWrap; import doumeemes.core.utils.Constants; import doumeemes.core.utils.Utils; import doumeemes.dao.business.DepartmentMapper; import doumeemes.dao.business.MaterialDistributeMapper; import doumeemes.dao.business.MaterialMapper; import doumeemes.dao.business.model.Department; import doumeemes.dao.business.model.Material; import doumeemes.dao.business.model.MaterialDistribute; import doumeemes.service.business.MaterialDistributeService; import org.apache.shiro.SecurityUtils; 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.ArrayList; import java.util.Date; import java.util.List; /** * 物料分配信息表Service实现 * @author 江蹄蹄 * @date 2022/04/20 09:34 */ @Service public class MaterialDistributeServiceImpl implements MaterialDistributeService { @Autowired private MaterialDistributeMapper materialDistributeMapper; @Autowired private MaterialMapper materialMapper; @Autowired private DepartmentMapper departmentMapper; @Override public Integer create(MaterialDistribute materialDistribute) { materialDistributeMapper.insert(materialDistribute); return materialDistribute.getId(); } @Override public void deleteById(Integer id) { materialDistributeMapper.deleteById(id); } @Override public void delete(MaterialDistribute materialDistribute) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(materialDistribute); materialDistributeMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } materialDistributeMapper.deleteBatchIds(ids); } @Override public void updateById(MaterialDistribute materialDistribute) { materialDistributeMapper.updateById(materialDistribute); } @Override public void updateByIdInBatch(List materialDistributes) { if (CollectionUtils.isEmpty(materialDistributes)) { return; } for (MaterialDistribute materialDistribute: materialDistributes) { this.updateById(materialDistribute); } } @Override public MaterialDistribute findById(Integer id) { return materialDistributeMapper.selectById(id); } @Override public MaterialDistribute findOne(MaterialDistribute materialDistribute) { QueryWrapper wrapper = new QueryWrapper<>(materialDistribute); return materialDistributeMapper.selectOne(wrapper); } @Override public List findList(MaterialDistribute materialDistribute) { QueryWrapper wrapper = new QueryWrapper<>(materialDistribute); return materialDistributeMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); QueryWrapper queryWrapper = new QueryWrapper<>(); Utils.MP.blankToNull(pageWrap.getModel()); if (pageWrap.getModel().getId() != null) { queryWrapper.lambda().eq(MaterialDistribute::getId, pageWrap.getModel().getId()); } if (pageWrap.getModel().getDeleted() != null) { queryWrapper.lambda().eq(MaterialDistribute::getDeleted, pageWrap.getModel().getDeleted()); } if (pageWrap.getModel().getCreateUser() != null) { queryWrapper.lambda().eq(MaterialDistribute::getCreateUser, pageWrap.getModel().getCreateUser()); } if (pageWrap.getModel().getCreateTime() != null) { queryWrapper.lambda().ge(MaterialDistribute::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime())); queryWrapper.lambda().le(MaterialDistribute::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime())); } if (pageWrap.getModel().getUpdateUser() != null) { queryWrapper.lambda().eq(MaterialDistribute::getUpdateUser, pageWrap.getModel().getUpdateUser()); } if (pageWrap.getModel().getUpdateTime() != null) { queryWrapper.lambda().ge(MaterialDistribute::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime())); queryWrapper.lambda().le(MaterialDistribute::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime())); } if (pageWrap.getModel().getRemark() != null) { queryWrapper.lambda().eq(MaterialDistribute::getRemark, pageWrap.getModel().getRemark()); } if (pageWrap.getModel().getRootDepartId() != null) { queryWrapper.lambda().eq(MaterialDistribute::getRootDepartId, pageWrap.getModel().getRootDepartId()); } if (pageWrap.getModel().getDepartId() != null) { queryWrapper.lambda().eq(MaterialDistribute::getDepartId, pageWrap.getModel().getDepartId()); } if (pageWrap.getModel().getMaterialId() != null) { queryWrapper.lambda().eq(MaterialDistribute::getMaterialId, pageWrap.getModel().getMaterialId()); } if (pageWrap.getModel().getAttr() != null) { queryWrapper.lambda().eq(MaterialDistribute::getAttr, pageWrap.getModel().getAttr()); } if (pageWrap.getModel().getUnionName() != null) { queryWrapper.lambda().eq(MaterialDistribute::getUnionName, pageWrap.getModel().getUnionName()); } if (pageWrap.getModel().getUnitId() != null) { queryWrapper.lambda().eq(MaterialDistribute::getUnitId, pageWrap.getModel().getUnitId()); } if (pageWrap.getModel().getCateUnionId() != null) { queryWrapper.lambda().eq(MaterialDistribute::getCateUnionId, pageWrap.getModel().getCateUnionId()); } if (pageWrap.getModel().getFormation() != null) { queryWrapper.lambda().eq(MaterialDistribute::getFormation, pageWrap.getModel().getFormation()); } if (pageWrap.getModel().getStatus() != null) { queryWrapper.lambda().eq(MaterialDistribute::getStatus, pageWrap.getModel().getStatus()); } if (pageWrap.getModel().getValidTime() != null) { queryWrapper.lambda().ge(MaterialDistribute::getValidTime, Utils.Date.getStart(pageWrap.getModel().getValidTime())); queryWrapper.lambda().le(MaterialDistribute::getValidTime, Utils.Date.getEnd(pageWrap.getModel().getValidTime())); } if (pageWrap.getModel().getInvalidTime() != null) { queryWrapper.lambda().ge(MaterialDistribute::getInvalidTime, Utils.Date.getStart(pageWrap.getModel().getInvalidTime())); queryWrapper.lambda().le(MaterialDistribute::getInvalidTime, Utils.Date.getEnd(pageWrap.getModel().getInvalidTime())); } for(PageWrap.SortData sortData: pageWrap.getSorts()) { if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { queryWrapper.orderByDesc(sortData.getProperty()); } else { queryWrapper.orderByAsc(sortData.getProperty()); } } return PageData.from(materialDistributeMapper.selectPage(page, queryWrapper)); } @Override public long count(MaterialDistribute materialDistribute) { QueryWrapper wrapper = new QueryWrapper<>(materialDistribute); return materialDistributeMapper.selectCount(wrapper); } @Override @Transactional public ApiResponse insert(String materialIds, String departIds) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); MaterialDistribute materialDistribute=new MaterialDistribute(); materialDistribute.setDeleted(Constants.ZERO); materialDistribute.setRootDepartId(user.getRootDepartment().getId()); materialDistribute.setCreateTime(new Date()); materialDistribute.setCreateUser(user.getId()); String[] arraymater=materialIds.split(",") ; String[] arraydepart=departIds.split(",") ; if(arraymater.length>0){ for(String materid:arraymater){ //获取物料信息 Material material= materialMapper.selectById(Integer.valueOf(materid)); if(arraydepart.length>0){ for(String departid:arraydepart){ //分配信息插入 materialDistribute.setDepartId(Integer.valueOf(departid)); materialDistribute.setMaterialId(Integer.valueOf(materid)); materialDistribute.setAttr(material.getAttr()); materialDistribute.setUnionName(material.getUnionName()); materialDistribute.setUnitId(material.getUnitId()); materialDistribute.setCateUnionId(material.getCateUnionId()); materialDistribute.setFormation(material.getFormation()); materialDistribute.setStatus(material.getStatus()); materialDistribute.setValidTime(material.getValidTime()); //判断同一组织内物料编码不能重复 MaterialDistribute findmd=new MaterialDistribute(); findmd.setDeleted(Constants.ZERO); findmd.setRootDepartId(user.getRootDepartment().getId()); findmd.setDepartId(Integer.valueOf(departid)); findmd.setMaterialId(Integer.valueOf(materid)); List findList= this.findList(findmd); if(findList.size()>0){ Department department= departmentMapper.selectById(Integer.valueOf(departid)); return ApiResponse.failed(department.getName()+"下物料编码"+material.getCode()+"已存在,不允许添加"); } materialDistributeMapper.insert(materialDistribute); } } } } return ApiResponse.success(null); } @Override @Transactional public ApiResponse updateStatusById(String ids, String status) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); String [] str=ids.split(","); List idList = new ArrayList<>(); if(str.length>0){ for(String id:str){ MaterialDistribute md=new MaterialDistribute(); if(StringUtils.equals(status,"0")){ //失效 md.setStatus(Constants.ZERO); md.setInvalidTime(new Date()); } if(StringUtils.equals(status,"1")){ //有效 md.setStatus(Constants.ONE); md.setValidTime(new Date()); } md.setId(Integer.valueOf(id)); idList.add(md); } } this.updateByIdInBatch(idList); return ApiResponse.success(null); } }