package com.gk.hotwork.Service.ServiceImpl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gk.hotwork.Domain.EmergencyPlanFile;
|
import com.gk.hotwork.Domain.SafetyInspectionItem;
|
import com.gk.hotwork.Domain.Exception.BusinessException;
|
import com.gk.hotwork.Domain.SafetyInspectionItemDeduction;
|
import com.gk.hotwork.Domain.UserInfo;
|
import com.gk.hotwork.Domain.Utils.StringUtils;
|
import com.gk.hotwork.Mapper.SafetyInspectionItemDeductionMapper;
|
import com.gk.hotwork.Mapper.SafetyInspectionItemMapper;
|
import com.gk.hotwork.Service.SafetyInspectionItemService;
|
import org.apache.commons.collections4.CollectionUtils;
|
import org.checkerframework.checker.units.qual.C;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service("SafetyInspectionItemService")
|
@Transactional
|
public class SafetyInspectionItemImpl extends ServiceImpl<SafetyInspectionItemMapper,SafetyInspectionItem> implements SafetyInspectionItemService {
|
|
@Autowired
|
private SafetyInspectionItemMapper safetyInspectionItemMapper;
|
@Autowired
|
private SafetyInspectionItemDeductionMapper safetyInspectionItemDeductionMapper;
|
|
/**
|
* @Description: 分页
|
*/
|
@Override
|
public IPage<SafetyInspectionItem> selectPage(Page<SafetyInspectionItem> page, Map<String, Object> filter, UserInfo user) {
|
IPage<SafetyInspectionItem> res = safetyInspectionItemMapper.selectPages(page,filter);
|
if (CollectionUtils.isNotEmpty(res.getRecords())){
|
for (int i = 0 ; i < res.getRecords().size(); i++){
|
List<SafetyInspectionItemDeduction> fileList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(res.getRecords().get(i).getId());
|
res.getRecords().get(i).setDeductionList(fileList);
|
}
|
}
|
return res;
|
}
|
|
|
/**
|
* @Description: 新增
|
*/
|
@Override
|
public void addOne(SafetyInspectionItem param, UserInfo user) {
|
requiredVerification(param);
|
|
Date date = new Date();
|
String username = user.getRealname();
|
param.setValidFlag(Boolean.TRUE);
|
param.setUpdateBy(username);
|
param.setCreateBy(username);
|
param.setUpdateTime(date);
|
param.setCreateTime(date);
|
this.save(param);
|
|
if (CollectionUtils.isNotEmpty(param.getDeductionList())){
|
for (SafetyInspectionItemDeduction safetyInspectionItemDeduction : param.getDeductionList()){
|
safetyInspectionItemDeduction.setValidFlag(Boolean.TRUE);
|
safetyInspectionItemDeduction.setUpdateBy(username);
|
safetyInspectionItemDeduction.setCreateBy(username);
|
safetyInspectionItemDeduction.setUpdateTime(date);
|
safetyInspectionItemDeduction.setCreateTime(date);
|
safetyInspectionItemDeduction.setSafetyInspectionItemId(param.getId());
|
safetyInspectionItemDeductionMapper.insert(safetyInspectionItemDeduction);
|
}
|
}
|
}
|
|
|
/**
|
* @Description: 修改
|
*/
|
@Override
|
public void modOne(SafetyInspectionItem param, UserInfo user) {
|
selectVerification(param.getId());
|
requiredVerification(param);
|
//更新主表
|
Date date = new Date();
|
String username = user.getRealname();
|
param.setUpdateTime(date);
|
param.setUpdateBy(username);
|
this.updateById(param);
|
//更新扣分项表
|
|
List<SafetyInspectionItemDeduction> oldList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(param.getId());
|
List<SafetyInspectionItemDeduction> newList = param.getDeductionList();
|
|
List<Long> oldIdList = new ArrayList<>();
|
List<Long> newIdList = new ArrayList<>();
|
|
|
for (SafetyInspectionItemDeduction oldSafetyInspectionItemDeduction :oldList ){
|
oldIdList.add(oldSafetyInspectionItemDeduction.getId());
|
}
|
for (SafetyInspectionItemDeduction newSafetyInspectionItemDeduction :newList ){
|
if (newSafetyInspectionItemDeduction.getId()==null){
|
//1.添加新增的元素
|
newSafetyInspectionItemDeduction.setValidFlag(Boolean.TRUE);
|
newSafetyInspectionItemDeduction.setUpdateBy(username);
|
newSafetyInspectionItemDeduction.setCreateBy(username);
|
newSafetyInspectionItemDeduction.setUpdateTime(date);
|
newSafetyInspectionItemDeduction.setCreateTime(date);
|
newSafetyInspectionItemDeduction.setSafetyInspectionItemId(param.getId());
|
safetyInspectionItemDeductionMapper.insert(newSafetyInspectionItemDeduction);
|
}else{
|
newIdList.add(newSafetyInspectionItemDeduction.getId());
|
//2.修改id一致 的元素
|
for (int i =0;i<oldList.size();i++){
|
if (oldList.get(i).getId().equals(newSafetyInspectionItemDeduction.getId())){
|
newSafetyInspectionItemDeduction.setUpdateBy(username);
|
newSafetyInspectionItemDeduction.setUpdateTime(date);
|
safetyInspectionItemDeductionMapper.updateById(newSafetyInspectionItemDeduction);
|
}
|
}
|
}
|
}
|
//2.删除不存在的元素
|
List<Long> diffList = getDif(oldIdList,newIdList);
|
if (CollectionUtils.isNotEmpty(diffList)){
|
for (Long id : diffList){
|
safetyInspectionItemDeductionMapper.deleteById(id,username,date);
|
}
|
}
|
}
|
|
public List<Long> getDif(List<Long> oldIdList , List<Long> newIdList ){
|
ArrayList<Long> dif = new ArrayList<>();
|
//查找出oldIdList表中不包含newIdList的元素
|
for (Long id : oldIdList) {
|
if (!(newIdList.contains(id))) {
|
dif.add(id);
|
}
|
}
|
return dif;
|
}
|
|
/**
|
* @Description: 删除
|
*/
|
@Override
|
public void delOne(Long id, UserInfo user) {
|
selectVerification(id);
|
// deleteVerification(SafetyInspectionItem);
|
|
SafetyInspectionItem delOne = new SafetyInspectionItem();
|
delOne.setId(id);
|
delOne.setUpdateTime(new Date());
|
delOne.setUpdateBy(user.getRealname());
|
delOne.setValidFlag(Boolean.FALSE);
|
this.updateById(delOne);
|
}
|
|
@Override
|
public List<SafetyInspectionItem> infoElementA(Long id, UserInfo user) {
|
List<SafetyInspectionItem> list = safetyInspectionItemMapper.infoElementA(id);
|
if (CollectionUtils.isNotEmpty(list)){
|
for (SafetyInspectionItem safetyInspectionItem : list){
|
List<SafetyInspectionItemDeduction> deductionList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(safetyInspectionItem.getId());
|
if (CollectionUtils.isNotEmpty(deductionList)){
|
safetyInspectionItem.setDeductionList(deductionList);
|
}else{
|
safetyInspectionItem.setDeductionList(new ArrayList<>());
|
}
|
}
|
}
|
return list;
|
}
|
|
@Override
|
public SafetyInspectionItem info(Long id, UserInfo user) {
|
SafetyInspectionItem safetyInspectionItem = safetyInspectionItemMapper.getById(id);
|
List<SafetyInspectionItemDeduction> list = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(id);
|
if (CollectionUtils.isNotEmpty(list)){
|
safetyInspectionItem.setDeductionList(list);
|
}else{
|
safetyInspectionItem.setDeductionList(new ArrayList<>());
|
}
|
return safetyInspectionItem;
|
}
|
|
|
/**
|
* 查询验证
|
* 验证对象存在
|
*/
|
public void selectVerification(Long id){
|
if (id == null) throw new BusinessException("id传参不能为空");
|
SafetyInspectionItem SafetyInspectionItem = this.getById(id);
|
if (SafetyInspectionItem == null) throw new BusinessException("找不到对应实体");
|
}
|
|
/**
|
* 操作验证
|
* 验证必填项
|
*
|
*/
|
public void requiredVerification(SafetyInspectionItem param){
|
if (param.getElementA() == null) throw new BusinessException("请选择A级要素");
|
if (param.getElementB() == null) throw new BusinessException("请选择B级要素");
|
if(StringUtils.isBlank(param.getStandardizationRequirements())) throw new BusinessException("请填写标准化要求");
|
if(StringUtils.isBlank(param.getEnterpriseStandard())) throw new BusinessException("请填写企业达标标准");
|
if(StringUtils.isBlank(param.getReviewMethod())) throw new BusinessException("请填写评审方法");
|
if (CollectionUtils.isEmpty(param.getDeductionList())){
|
throw new BusinessException("请填写扣分项列表");
|
}
|
}
|
|
/**
|
* 操作验证
|
* 删除已被B级要素绑定的A级要素
|
*
|
*/
|
// public void deleteVerification(SafetyInspectionItem param){
|
// if (param.getType()==0){
|
// int count = this.count(new LambdaQueryWrapper<SafetyInspectionItem>()
|
// .eq(SafetyInspectionItem::getParentId, param.getId())
|
// .eq(SafetyInspectionItem::getType , 1)
|
// .eq(SafetyInspectionItem::getValidFlag, Boolean.TRUE));
|
// if (count > 0) throw new BusinessException("当前A级要素仍然有已绑定的B级要素,无法删除");
|
// }
|
// }
|
}
|