Commit 153973f9 authored by 田涛's avatar 田涛

数字预案增删改查/启停用接口

parent e1d5bb1b
......@@ -10,11 +10,11 @@ import java.util.Map;
*/
public enum ContingencyPlanStatusEnum {
DRAFT("草稿","1"),
AVAILABLE("可用","2"),
NOAVAILABLE("不可用", "3"),
SIMULATION_START("模拟启动", "4"),
ONGOING("进行中", "5");
DRAFT("草稿",1),
AVAILABLE("可用",2),
NOAVAILABLE("不可用", 3),
SIMULATION_START("模拟启动", 4),
ONGOING("进行中", 5);
/**
* 名称,描述
*/
......@@ -22,14 +22,14 @@ public enum ContingencyPlanStatusEnum {
/**
* 编码
*/
private String code;
private Integer code;
private ContingencyPlanStatusEnum(String name, String code){
private ContingencyPlanStatusEnum(String name, Integer code){
this.name = name;
this.code = code;
}
public static ContingencyPlanStatusEnum getEnum(String code) {
public static ContingencyPlanStatusEnum getEnum(Integer code) {
ContingencyPlanStatusEnum checkStatusEnum = null;
for(ContingencyPlanStatusEnum type: ContingencyPlanStatusEnum.values()) {
if (type.getCode().equals(code)) {
......@@ -37,21 +37,9 @@ public enum ContingencyPlanStatusEnum {
break;
}
}
return checkStatusEnum;
}
public static List<Map<String,String>> getEnumList() {
List<Map<String,String>> nameList = new ArrayList<>();
for (ContingencyPlanStatusEnum c: ContingencyPlanStatusEnum.values()) {
Map<String, String> map = new HashMap<String, String>();
map.put("name", c.getName());
map.put("code", c.getCode());
nameList.add(map);
}
return nameList;
}
public String getName() {
return name;
}
......@@ -60,11 +48,11 @@ public enum ContingencyPlanStatusEnum {
this.name = name;
}
public String getCode() {
public Integer getCode() {
return code;
}
public void setCode(String code) {
public void setCode(Integer code) {
this.code = code;
}
......
package com.yeejoin.amos.fas.business.controller;
import com.yeejoin.amos.fas.business.service.intfc.ContingencyPlanService;
import com.yeejoin.amos.fas.business.vo.PlanDetailVo;
import com.yeejoin.amos.fas.config.Permission;
import com.yeejoin.amos.fas.core.util.CommonResponse;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/api/contingencyPlan")
@Api("预案api")
public class ContingencyPlanController extends BaseController {
@Autowired
private ContingencyPlanService contingencyPlanService;
/**
* 创建数字预案
*/
@Permission
@ApiOperation(value = "创建数字预案", notes = "创建数字预案")
@PostMapping(value = "", produces = "application/json;charset=UTF-8")
public CommonResponse createPlan(@RequestBody PlanDetailVo planDetail) {
if (null == planDetail) {
return CommonResponseUtil.failure("参数有误");
}
AgencyUserModel curUser = getUserInfo();
planDetail.setCreator(curUser.getUserId());
planDetail.setOrgCode(getOrgCode(getSelectedOrgInfo()));
return CommonResponseUtil.success(contingencyPlanService.createPlan(planDetail));
}
/**
* 修改数字预案
*/
@Permission
@ApiOperation(value = "修改数字预案", notes = "修改数字预案")
@PutMapping(value = "", produces = "application/json;charset=UTF-8")
public CommonResponse editPlan(@RequestBody PlanDetailVo planDetail) {
if (null == planDetail) {
return CommonResponseUtil.failure("参数有误");
}
AgencyUserModel curUser = getUserInfo();
planDetail.setReviser(curUser.getUserId());
planDetail.setUpdateTime(new Date());
return CommonResponseUtil.success(contingencyPlanService.editPlan(planDetail));
}
/**
* 查看数字预案详情
*/
@Permission
@ApiOperation(value = "查看数字预案详情", notes = "查看数字预案详情")
@GetMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
public CommonResponse createPlan(@PathVariable(value = "id") Long id) {
if (null == id) {
return CommonResponseUtil.failure("参数有误");
}
return CommonResponseUtil.success(contingencyPlanService.detail(id));
}
/**
* 启用预案
*/
@Permission
@ApiOperation(value = "启用预案", notes = "启用预案")
@PutMapping(value = "/activate", produces = "application/json;charset=UTF-8")
public CommonResponse activatePlan(@RequestBody List<Long> idList) {
if (null == idList || idList.isEmpty()) {
return CommonResponseUtil.failure("参数有误");
}
return CommonResponseUtil.success(contingencyPlanService.activatePlan(idList));
}
/**
* 停用预案
*/
@Permission
@ApiOperation(value = "停用预案", notes = "停用预案")
@PutMapping(value = "/deactivate", produces = "application/json;charset=UTF-8")
public CommonResponse deactivatePlan(@RequestBody List<Long> idList) {
if (null == idList || idList.isEmpty()) {
return CommonResponseUtil.failure("参数有误");
}
return CommonResponseUtil.success(contingencyPlanService.deactivatePlan(idList));
}
/**
* 删除预案
*/
@Permission
@ApiOperation(value = "停用预案", notes = "停用预案")
@DeleteMapping(value = "/{ids}", produces = "application/json;charset=UTF-8")
public CommonResponse deactivatePlan(@PathVariable(value = "ids") String idStr) {
if (StringUtils.isBlank(idStr)) {
return CommonResponseUtil.failure("参数有误");
}
String[] idArr = idStr.split(",");
List<Long> idList = new ArrayList();
for (String id : idArr) {
if (id.trim().length() > 0 && StringUtils.isNumeric(id.trim())) {
idList.add(Long.valueOf(id.trim()));
}
}
return CommonResponseUtil.success(contingencyPlanService.delete(idList));
}
}
package com.yeejoin.amos.fas.business.dao.mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <h1><h1>
*
......@@ -10,4 +13,8 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface PlanDetailMapper {
int updatePlanStatusByIdList(@Param("idList") List<Long> idList, @Param("status") Integer status);
int updateIsDeleteByIdList(@Param("idList") List<Long> idList, @Param("isDelete") Boolean isDelete);
}
......@@ -6,7 +6,7 @@ import org.springframework.stereotype.Repository;
import java.util.List;
@Repository("IPlanClassifyTreeDao")
@Repository
public interface IPlanClassifyTreeDao extends BaseDao<PlanClassifyTree, Long> {
......
......@@ -3,6 +3,8 @@ package com.yeejoin.amos.fas.business.dao.repository;
import com.yeejoin.amos.fas.dao.entity.PlanDetail;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <h1><h1>
*
......@@ -12,4 +14,5 @@ import org.springframework.stereotype.Repository;
@Repository
public interface IPlanDetailDao extends BaseDao<PlanDetail, Long> {
List<PlanDetail> getPlanDetailsByIdInAndIsDelete(List<Long> idList, Boolean isDelete);
}
......@@ -3,6 +3,8 @@ package com.yeejoin.amos.fas.business.dao.repository;
import com.yeejoin.amos.fas.dao.entity.PlanDoc;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <h1><h1>
*
......@@ -11,4 +13,8 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface IPlanDocDao extends BaseDao<PlanDoc, Long> {
void deleteByPlanId(Long planId);
List<PlanDoc> getPlanDocsByPlanId(Long planId);
}
......@@ -3,6 +3,8 @@ package com.yeejoin.amos.fas.business.dao.repository;
import com.yeejoin.amos.fas.dao.entity.PlanEquipment;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <h1><h1>
*
......@@ -11,4 +13,8 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface IPlanEquipmentDao extends BaseDao<PlanEquipment, Long> {
void deleteByPlanId(long planId);
List<PlanEquipment> getPlanDocsByPlanId(Long planId);
}
......@@ -3,6 +3,8 @@ package com.yeejoin.amos.fas.business.dao.repository;
import com.yeejoin.amos.fas.dao.entity.PlanRule;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <h1><h1>
*
......@@ -11,4 +13,8 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface IPlanRuleDao extends BaseDao<PlanRule, Long>{
void deleteByPlanId(long planId);
List<PlanRule> getPlanDocsByPlanId(Long planId);
}
package com.yeejoin.amos.fas.business.service.impl;
import com.yeejoin.amos.fas.business.dao.mapper.PlanDetailMapper;
import com.yeejoin.amos.fas.business.dao.repository.*;
import com.yeejoin.amos.fas.business.service.intfc.ContingencyPlanService;
import com.yeejoin.amos.fas.business.vo.PlanDetailVo;
import com.yeejoin.amos.fas.common.enums.ContingencyPlanStatusEnum;
import com.yeejoin.amos.fas.dao.entity.*;
import com.yeejoin.amos.fas.exception.YeeException;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
*@program: YeeAmosFireAutoSysRoot
*@description: 预案实现类
*@author: wujunkai
*@create: 2021-01-14 14:59
* @program: YeeAmosFireAutoSysRoot
* @description: 预案实现类
* @author: wujunkai
* @create: 2021-01-14 14:59
*/
@Service("ContingencyPlanService")
@Service
public class ContingencyPlanServiceImpl implements ContingencyPlanService {
private final IPlanDetailDao planDetailDao;
private final IPlanDocDao planDocDao;
private final IPlanEquipmentDao planEquipmentDao;
private final IPlanRuleDao planRuleDao;
private final IPlanClassifyTreeDao classifyTreeDao;
private final PlanDetailMapper planDetailMapper;
@Autowired
public ContingencyPlanServiceImpl(IPlanDetailDao planDetailDao, IPlanDocDao planDocDao, IPlanEquipmentDao planEquipmentDao,
IPlanRuleDao planRuleDao, IPlanClassifyTreeDao classifyTreeDao, PlanDetailMapper planDetailMapper) {
this.planDetailDao = planDetailDao;
this.planDocDao = planDocDao;
this.planEquipmentDao = planEquipmentDao;
this.planRuleDao = planRuleDao;
this.classifyTreeDao = classifyTreeDao;
this.planDetailMapper = planDetailMapper;
}
@Override
@Transactional(rollbackFor = {YeeException.class, Exception.class})
public PlanDetailVo createPlan(PlanDetailVo planDetail) {
PlanDoc planDoc = planDetail.getPlanDoc();
PlanRule planRule = planDetail.getPlanRule();
List<PlanEquipment> planEquipment = planDetail.getPlanEquipment();
if (StringUtils.isBlank(planDetail.getPlanName()) || null == planDetail.getClassifyId()
|| null == planDoc || null == planDoc.getDocId()
|| null == planRule || null == planRule.getRuleId()
|| null == planEquipment || planEquipment.isEmpty()) {
throw new YeeException("参数错误");
}
planEquipment.forEach(equipment -> {
if (null == equipment || null == equipment.getFireEquipmentId()) {
throw new YeeException("参数错误");
}
});
// 状态为草稿
planDetail.setStatus(ContingencyPlanStatusEnum.DRAFT.getCode());
long planId = planDetailDao.save(planDetail).getId();
planDetail.setId(planId);
planDoc.setPlanId(planId);
planDocDao.save(planDoc);
planRule.setPlanId(planId);
planRuleDao.save(planRule);
planEquipment.forEach(equipment -> equipment.setPlanId(planId));
planEquipmentDao.saveAll(planEquipment);
return planDetail;
}
@Override
public PlanDetailVo editPlan(PlanDetailVo planDetail) {
PlanDoc planDoc = planDetail.getPlanDoc();
PlanRule planRule = planDetail.getPlanRule();
List<PlanEquipment> planEquipment = planDetail.getPlanEquipment();
if (StringUtils.isBlank(planDetail.getPlanName()) || null == planDetail.getClassifyId()
|| null == planDoc || null == planDoc.getDocId()
|| null == planRule || null == planRule.getRuleId()
|| null == planEquipment || planEquipment.isEmpty()) {
throw new YeeException("参数错误");
}
planEquipment.forEach(equipment -> {
if (null == equipment || null == equipment.getFireEquipmentId()) {
throw new YeeException("参数错误");
}
});
long planId = planDetail.getId();
PlanDetail oldPlan = planDetailDao.getOne(planId);
if (null == oldPlan) {
throw new YeeException("数据不存在");
}
if (ContingencyPlanStatusEnum.getEnum(oldPlan.getStatus()) == ContingencyPlanStatusEnum.DRAFT
|| ContingencyPlanStatusEnum.getEnum(oldPlan.getStatus()) == ContingencyPlanStatusEnum.NOAVAILABLE) {
// 状态设置为草稿
planDetail.setStatus(ContingencyPlanStatusEnum.DRAFT.getCode());
} else {
throw new YeeException("不可编辑的状态");
}
planDoc.setPlanId(planId);
planDocDao.deleteByPlanId(planId);
planDocDao.save(planDoc);
planRule.setPlanId(planId);
planRuleDao.deleteByPlanId(planId);
planRuleDao.save(planRule);
planEquipment.forEach(equipment -> equipment.setPlanId(planId));
planEquipmentDao.deleteByPlanId(planId);
planEquipmentDao.saveAll(planEquipment);
return planDetail;
}
@Override
public PlanDetailVo detail(Long id) {
PlanDetail detail = planDetailDao.getOne(id);
if (null == detail) {
throw new YeeException("数据不存在");
}
PlanDetailVo detailVo = (PlanDetailVo) detail;
List<PlanDoc> docs = planDocDao.getPlanDocsByPlanId(id);
if (!docs.isEmpty()) {
detailVo.setPlanDoc(docs.get(0));
}
List<PlanRule> rules = planRuleDao.getPlanDocsByPlanId(id);
if (!rules.isEmpty()) {
detailVo.setPlanRule(rules.get(0));
}
List<PlanEquipment> equipments = planEquipmentDao.getPlanDocsByPlanId(id);
detailVo.setPlanEquipment(equipments);
//TODO-设置执行次数
detailVo.setExecutionTimes(0);
PlanClassifyTree classifyTree = classifyTreeDao.getOne(detailVo.getClassifyId());
if (null != classifyTree) {
detailVo.setClassifyName(classifyTree.getClassifyName());
}
return detailVo;
}
@Override
public List<PlanDetail> activatePlan(List<Long> idList) {
List<PlanDetail> planDetailList = planDetailDao.getPlanDetailsByIdInAndIsDelete(idList, false);
if (!planDetailList.isEmpty()) {
planDetailList.forEach(plan -> {
if (ContingencyPlanStatusEnum.getEnum(plan.getStatus()) != ContingencyPlanStatusEnum.DRAFT
&& ContingencyPlanStatusEnum.getEnum(plan.getStatus()) != ContingencyPlanStatusEnum.AVAILABLE
&& ContingencyPlanStatusEnum.getEnum(plan.getStatus()) != ContingencyPlanStatusEnum.NOAVAILABLE) {
throw new YeeException("包含不可启用的状态");
}
plan.setStatus(ContingencyPlanStatusEnum.AVAILABLE.getCode());
});
planDetailMapper.updatePlanStatusByIdList(idList, ContingencyPlanStatusEnum.AVAILABLE.getCode());
}
return planDetailList;
}
@Override
public List<PlanDetail> deactivatePlan(List<Long> idList) {
List<PlanDetail> planDetailList = planDetailDao.getPlanDetailsByIdInAndIsDelete(idList, false);
if (!planDetailList.isEmpty()) {
planDetailList.forEach(plan -> {
if (ContingencyPlanStatusEnum.getEnum(plan.getStatus()) != ContingencyPlanStatusEnum.AVAILABLE
&& ContingencyPlanStatusEnum.getEnum(plan.getStatus()) != ContingencyPlanStatusEnum.NOAVAILABLE) {
throw new YeeException("包含不可禁用的状态");
}
plan.setStatus(ContingencyPlanStatusEnum.NOAVAILABLE.getCode());
});
planDetailMapper.updatePlanStatusByIdList(idList, ContingencyPlanStatusEnum.NOAVAILABLE.getCode());
}
return planDetailList;
}
@Override
public Boolean delete(List<Long> idList) {
planDetailMapper.updateIsDeleteByIdList(idList, true);
return true;
}
}
\ No newline at end of file
package com.yeejoin.amos.fas.business.service.intfc;
import com.yeejoin.amos.fas.business.vo.PlanDetailVo;
import com.yeejoin.amos.fas.dao.entity.PlanDetail;
import java.util.List;
/**
* @author wjk
* @date 2021-01-14
......@@ -7,4 +12,45 @@ package com.yeejoin.amos.fas.business.service.intfc;
*/
public interface ContingencyPlanService {
/**
* 创建
* @param planDetail
* @return
*/
PlanDetailVo createPlan(PlanDetailVo planDetail);
/**
* 编辑
* @param planDetail
* @return
*/
PlanDetailVo editPlan(PlanDetailVo planDetail);
/**
* 单个详情
* @param id
* @return
*/
PlanDetailVo detail(Long id);
/**
* 启用
* @param idList
* @return
*/
List<PlanDetail> activatePlan(List<Long> idList);
/**
* 停用
* @param idList
* @return
*/
List<PlanDetail> deactivatePlan(List<Long> idList);
/**
* 删除
* @param idList
* @return
*/
Boolean delete(List<Long> idList);
}
package com.yeejoin.amos.fas.business.vo;
import com.yeejoin.amos.fas.dao.entity.*;
import lombok.Data;
import java.util.List;
/**
* <h1><h1>
*
* @author tiantao
* @date 2021/1/15 11:18
*/
@Data
public class PlanDetailVo extends PlanDetail {
/**
* 预案所属分类名称
*/
private String classifyName;
/**
* 绑定规则
*/
private PlanRule planRule;
/**
* 绑定文档
*/
private PlanDoc planDoc;
/**
* 绑定装备
*/
private List<PlanEquipment> planEquipment;
/**
* 执行次数
*/
private int executionTimes;
}
......@@ -2,4 +2,18 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.fas.business.dao.mapper.PlanDetailMapper">
<update id="updatePlanStatusByIdList" parameterType="list">
UPDATE c_plan_detail SET status = #{status} WHERE id IN
<foreach collection="idList" separator="," item="id" open="(" close=")">
#{id}
</foreach>
</update>
<update id="updateIsDeleteByIdList" parameterType="list">
UPDATE c_plan_detail SET is_delete = #{isDelete} WHERE id IN
<foreach collection="idList" separator="," item="id" open="(" close=")">
#{id}
</foreach>
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment