package com.gkhy.safePlatform.equipment.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.utils.StringUtils;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo;
|
import com.gkhy.safePlatform.equipment.excepiton.EquipmentException;
|
import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyAddReq;
|
import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyModReq;
|
import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyQuery;
|
import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyDto;
|
import com.gkhy.safePlatform.equipment.service.MaterialClassifyService;
|
import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialClassifyInfoService;
|
import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialInfoService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Service("MaterialClassifyService")
|
public class MaterialClassifyServiceImpl implements MaterialClassifyService {
|
@Autowired
|
private SafeMaterialClassifyInfoService safeMaterialClassifyInfoService;
|
@Autowired
|
private SafeMaterialInfoService safeMaterialInfoService;
|
|
@Override
|
public ResultVO<List<SafeMaterialClassifyDto>> list(SafeMaterialClassifyQuery query) {
|
List<SafeMaterialClassifyInfo> list = safeMaterialClassifyInfoService.listByCondition(query);
|
List<SafeMaterialClassifyDto> respList = new ArrayList<>();
|
if(!CollectionUtils.isEmpty(list)){
|
for(SafeMaterialClassifyInfo classifyInfo : list){
|
SafeMaterialClassifyDto respDTO = new SafeMaterialClassifyDto();
|
respDTO.setId(classifyInfo.getId());
|
respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
|
respList.add(respDTO);
|
}
|
}
|
return new ResultVO<>(ResultCodes.OK,respList);
|
}
|
|
@Override
|
public ResultVO save(ContextCacheUser currentUser, SafeMaterialClassifyAddReq req) {
|
ResultVO resultVO = null;
|
SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
|
classifyInfo.setMaterialClassifyName(req.getMaterialClassifyName());
|
boolean flag = safeMaterialClassifyInfoService.save(classifyInfo);
|
if (flag){
|
resultVO = new ResultVO(ResultCodes.OK);
|
}else {
|
resultVO = new ResultVO(ResultCodes.SERVER_ADD_ERROR);
|
}
|
return resultVO;
|
}
|
|
@Override
|
public ResultVO update(ContextCacheUser currentUser, SafeMaterialClassifyModReq req) {
|
ResultVO resultVO = null;
|
if(req.getId() == null){
|
throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
|
classifyInfo.setMaterialClassifyName(req.getMaterialClassifyName());
|
classifyInfo.setId(req.getId());
|
boolean flag = safeMaterialClassifyInfoService.updateById(classifyInfo);
|
if (flag){
|
resultVO = new ResultVO(ResultCodes.OK);
|
}else {
|
resultVO = new ResultVO(ResultCodes.SERVER_UPDATE_ERROR);
|
}
|
return resultVO;
|
}
|
|
@Override
|
public ResultVO delete(Long id) {
|
if(id == null){
|
throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
ResultVO resultVO = null;
|
//判断是否被绑定
|
int count = safeMaterialInfoService.getCountByClassify(id);
|
if(count > 0){
|
throw new EquipmentException(ResultCodes.SERVER_DEL_ERROR,"该类型已被绑定,不可删除!");
|
}else{
|
//如果没有被绑定,逻辑删除
|
SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
|
classifyInfo.setId(id);
|
classifyInfo.setDelFlag(1);
|
boolean flag = safeMaterialClassifyInfoService.updateById(classifyInfo);
|
if (flag){
|
resultVO = new ResultVO(ResultCodes.OK);
|
}else {
|
resultVO = new ResultVO(ResultCodes.SERVER_DEL_ERROR);
|
}
|
}
|
return resultVO;
|
}
|
|
@Override
|
public ResultVO<SafeMaterialClassifyDto> queryById(Long id) {
|
if(id == null){
|
throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(id);
|
SafeMaterialClassifyDto respDTO = new SafeMaterialClassifyDto();
|
respDTO.setId(classifyInfo.getId());
|
respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
|
return new ResultVO<>(ResultCodes.OK,respDTO);
|
}
|
}
|