162 lines
5.1 KiB
Java
162 lines
5.1 KiB
Java
package com.rzyc.controller;
|
|
|
|
import com.common.utils.StringUtils;
|
|
import com.common.utils.model.SingleResult;
|
|
import com.rzyc.bean.risk.SourcesAddDto;
|
|
import com.rzyc.bean.risk.SourcesDelDto;
|
|
import com.rzyc.enums.DelState;
|
|
import com.rzyc.enums.ResourceRiskLevel;
|
|
import com.rzyc.model.RkSources;
|
|
import com.rzyc.model.ent.SysEnterprise;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.validation.Valid;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @author dong
|
|
* @date 2022-09-20 17:40
|
|
* @Version V1.0
|
|
*/
|
|
@Api(tags = "重大危险源")
|
|
@CrossOrigin("*")
|
|
@RequestMapping("risk")
|
|
@RestController
|
|
@Validated
|
|
public class RiskController extends BaseController {
|
|
|
|
|
|
/**
|
|
* 企业重大危险源新增修改
|
|
*
|
|
* @version v1.0
|
|
* @author dong
|
|
* @date 2022/8/2 9:34
|
|
*/
|
|
@ApiOperation(value = "重大危险源新增修改", notes = "企业重大危险源新增修改")
|
|
@PostMapping("/sourcesAdd")
|
|
public SingleResult<String> sourcesAdd(@Valid SourcesAddDto sourcesAddDto) throws Exception {
|
|
SingleResult<String> result = new SingleResult<>();
|
|
|
|
String userId = getUserId();
|
|
RkSources sources = new RkSources();
|
|
BeanUtils.copyProperties(sources, sourcesAddDto);
|
|
|
|
sources.setModified(userId);
|
|
sources.setModifyTime(new Date());
|
|
|
|
SysEnterprise enterprise = sysEnterpriseMapper.selectByPrimaryKey(sourcesAddDto.getEnterpriseId());
|
|
if (null != enterprise) {
|
|
sources.setEntName(enterprise.getEntname());
|
|
sources.setOrgcode(enterprise.getOrgcode());
|
|
sources.setStreetCode(enterprise.getStreetCode());
|
|
sources.setCommunityCode(enterprise.getCommunityCode());
|
|
//最新工作单元行业id
|
|
sources.setBaseInclassId(enterprise.getWorkClassId());
|
|
}
|
|
|
|
//计算风险等级
|
|
Integer riskGrade = getRiskLevel(sources.getPossibility(), sources.getSeriousness());
|
|
sources.setRiskGrade(riskGrade);
|
|
|
|
RkSources rkSources = rkSourcesMapper.selectById(sources.getSourceId());
|
|
if (null != rkSources) {
|
|
rkSourcesMapper.updateById(sources);
|
|
} else {
|
|
|
|
sources.setXindex("");
|
|
sources.setYindex("");
|
|
sources.setDelState(DelState.NOT_DEL.getState());
|
|
|
|
sources.setCreated(userId);
|
|
sources.setCreateTime(new Date());
|
|
rkSourcesMapper.insert(sources);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param possibility 可能性
|
|
* @param seriousness 后果严重性
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public Integer getRiskLevel(Integer possibility, Integer seriousness) throws Exception {
|
|
Integer riskLevel = ResourceRiskLevel.BLUE.getLevel();
|
|
|
|
//风险等级
|
|
Map<String, Integer> riskLevelMap = new HashMap<>();
|
|
|
|
riskLevelMap.put("1-1", 1);
|
|
riskLevelMap.put("1-2", 1);
|
|
riskLevelMap.put("1-3", 1);
|
|
riskLevelMap.put("1-4", 2);
|
|
riskLevelMap.put("1-5", 3);
|
|
|
|
riskLevelMap.put("2-1", 1);
|
|
riskLevelMap.put("2-2", 1);
|
|
riskLevelMap.put("2-3", 2);
|
|
riskLevelMap.put("2-4", 3);
|
|
riskLevelMap.put("2-5", 4);
|
|
|
|
riskLevelMap.put("3-1", 1);
|
|
riskLevelMap.put("3-2", 1);
|
|
riskLevelMap.put("3-3", 2);
|
|
riskLevelMap.put("3-4", 3);
|
|
riskLevelMap.put("3-5", 4);
|
|
|
|
riskLevelMap.put("4-1", 2);
|
|
riskLevelMap.put("4-2", 2);
|
|
riskLevelMap.put("4-3", 3);
|
|
riskLevelMap.put("4-4", 4);
|
|
riskLevelMap.put("4-5", 4);
|
|
|
|
riskLevelMap.put("5-1", 2);
|
|
riskLevelMap.put("5-2", 3);
|
|
riskLevelMap.put("5-3", 4);
|
|
riskLevelMap.put("5-4", 4);
|
|
riskLevelMap.put("5-5", 4);
|
|
|
|
//风险等级
|
|
String key = possibility + "-" + seriousness;
|
|
if (null != riskLevelMap.get(key)) {
|
|
riskLevel = riskLevelMap.get(key);
|
|
}
|
|
return riskLevel;
|
|
}
|
|
|
|
/**
|
|
* 删除危险源
|
|
*
|
|
* @version v1.0
|
|
* @author dong
|
|
* @date 2022/8/2 13:33
|
|
*/
|
|
@ApiOperation(value = "删除危险源", notes = "删除危险源")
|
|
@PostMapping("/sourcesDel")
|
|
public SingleResult<String> sourcesDel(@Valid SourcesDelDto sourcesDelDto) throws Exception {
|
|
SingleResult<String> result = new SingleResult<>();
|
|
if (StringUtils.isNotBlank(sourcesDelDto.getSourceIds())) {
|
|
String[] stts = sourcesDelDto.getSourceIds().split(",");
|
|
for (String str : stts) {
|
|
RkSources sources = new RkSources();
|
|
sources.setSourceId(str);
|
|
sources.setDelState(DelState.DELETE.getState());
|
|
rkSourcesMapper.updateById(sources);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|