diff --git a/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/controller/DklWarningInformationHandleControllerTest.java b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/controller/DklWarningInformationHandleControllerTest.java new file mode 100644 index 0000000..edf1bdb --- /dev/null +++ b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/controller/DklWarningInformationHandleControllerTest.java @@ -0,0 +1,194 @@ +package com.dkl.large.controller; + +import com.dkl.large.domain.DklWarningInformationHandle; +import com.dkl.large.service.IDklWarningInformationHandleService; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 预警信息处置控制器测试类 + * + * @author Dkl + * @date 2025-06-16 + */ +@WebMvcTest(DklWarningInformationHandleController.class) +public class DklWarningInformationHandleControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private IDklWarningInformationHandleService warningInformationHandleService; + + @Autowired + private ObjectMapper objectMapper; + + private DklWarningInformationHandle testHandle; + + /** + * 初始化测试数据 + */ + @BeforeEach + void setUp() { + testHandle = new DklWarningInformationHandle(); + testHandle.setId(1L); + testHandle.setDelFlag("0"); + testHandle.setCreateTime(new Date()); + testHandle.setCreateBy("testUser"); + testHandle.setUpdateTime(new Date()); + testHandle.setUpdateBy("testUser"); + } + + /** + * 测试查询预警信息处置列表接口 + */ + @Test + @WithMockUser(authorities = "large:handle:list") + void testList() throws Exception { + // 构造测试数据 + List handleList = new ArrayList<>(); + handleList.add(testHandle); + + // mock 服务层方法 + Mockito.when(warningInformationHandleService.selectDklWarningInformationHandleList(Mockito.any(DklWarningInformationHandle.class))) + .thenReturn(handleList); + + // 执行请求并断言结果 + mockMvc.perform(MockMvcRequestBuilders.get("/large/handle/list") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.rows").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$.rows[0].id").value(1L)); + } + + /** + * 测试查询所有预警信息处置列表接口 + */ + @Test + void testListAll() throws Exception { + // 构造测试数据 + List handleList = new ArrayList<>(); + handleList.add(testHandle); + + // mock 服务层方法 + Mockito.when(warningInformationHandleService.selectDklWarningInformationHandleList(Mockito.any(DklWarningInformationHandle.class))) + .thenReturn(handleList); + + // 执行请求并断言结果 + mockMvc.perform(MockMvcRequestBuilders.get("/large/handle/listAll") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.rows").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$.rows[0].delFlag").value("0")); + } + + /** + * 测试导出预警信息处置列表接口 + */ + @Test + @WithMockUser + void testExport() throws Exception { + // 构造测试数据 + List handleList = new ArrayList<>(); + handleList.add(testHandle); + + // mock 服务层方法 + Mockito.when(warningInformationHandleService.selectDklWarningInformationHandleList(Mockito.any(DklWarningInformationHandle.class))) + .thenReturn(handleList); + + // 执行请求并断言结果 + mockMvc.perform(MockMvcRequestBuilders.post("/large/handle/export") + .contentType(MediaType.APPLICATION_JSON) + .param("id", "1")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.header().exists("Content-Disposition")); + } + + /** + * 测试获取预警信息处置详细信息接口 + */ + @Test + @WithMockUser + void testGetInfo() throws Exception { + // mock 服务层方法 + Mockito.when(warningInformationHandleService.selectDklWarningInformationHandleById(1L)) + .thenReturn(testHandle); + + // 执行请求并断言结果 + mockMvc.perform(MockMvcRequestBuilders.get("/large/handle/1") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value(200)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data.id").value(1L)); + } + + /** + * 测试新增预警信息处置接口 + */ + @Test + @WithMockUser + void testAdd() throws Exception { + // mock 服务层方法 + Mockito.when(warningInformationHandleService.insertDklWarningInformationHandle(Mockito.any(DklWarningInformationHandle.class))) + .thenReturn(1); + + // 执行请求并断言结果 + mockMvc.perform(MockMvcRequestBuilders.post("/large/handle") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(testHandle))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value(200)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").value(1)); + } + + /** + * 测试修改预警信息处置接口 + */ + @Test + @WithMockUser + void testEdit() throws Exception { + // mock 服务层方法 + Mockito.when(warningInformationHandleService.updateDklWarningInformationHandle(Mockito.any(DklWarningInformationHandle.class))) + .thenReturn(1); + + // 执行请求并断言结果 + mockMvc.perform(MockMvcRequestBuilders.put("/large/handle") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(testHandle))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value(200)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").value(1)); + } + + /** + * 测试删除预警信息处置接口 + */ + @Test + @WithMockUser + void testRemove() throws Exception { + // mock 服务层方法 + Mockito.when(warningInformationHandleService.deleteDklWarningInformationHandleByIds(Mockito.any(Long[].class))) + .thenReturn(1); + + // 执行请求并断言结果 + mockMvc.perform(MockMvcRequestBuilders.delete("/large/handle/1") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").value(200)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").value(1)); + } +} \ No newline at end of file diff --git a/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/domain/DklWarningInformationHandle.java b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/domain/DklWarningInformationHandle.java new file mode 100644 index 0000000..8096ade --- /dev/null +++ b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/domain/DklWarningInformationHandle.java @@ -0,0 +1,76 @@ +package com.dkl.large.domain; + +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.dkl.common.annotation.Excel; +import com.dkl.common.core.domain.BaseEntity; + +/** + * 预警信息处置对象 dkl_warning_information_handle + * + * @author Dkl + * @date 2025-06-16 + */ +@Data +public class DklWarningInformationHandle extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** id */ + @TableId(type = IdType.AUTO) + private Long id; + + /** 预警唯一标识符 */ + @Excel(name = "预警唯一标识符") + private String warningSigns; + + /** 委派人 */ + @Excel(name = "委派人") + private Long delegatePersonnel; + + /** 委派时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "委派时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date delegationTime; + + /** 委派部门 */ + @Excel(name = "委派部门") + private Long delegationDept; + + /** 处置措施 */ + @Excel(name = "处置措施") + private String disposalMeasures; + + /** 处置结果 */ + @Excel(name = "处置结果") + private String disposalResults; + + /** 处理状态 */ + @Excel(name = "处理状态") + private String disposalStatus; + + /** 删除标志(0代表存在 2代表删除) */ + private String delFlag; + + /** 规则名称 */ + @TableField(exist = false) + private int rulesId; + + /** 预警id */ + private int warningId; + + /** 用户名称 */ + @TableField(exist = false) + private String nickName; + + /** 部门名称 */ + @TableField(exist = false) + private String deptName; +} diff --git a/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/mapper/DklWarningInformationHandleMapper.java b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/mapper/DklWarningInformationHandleMapper.java new file mode 100644 index 0000000..07c6e27 --- /dev/null +++ b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/mapper/DklWarningInformationHandleMapper.java @@ -0,0 +1,61 @@ +package com.dkl.large.mapper; + +import java.util.List; +import com.dkl.large.domain.DklWarningInformationHandle; + +/** + * 预警信息处置Mapper接口 + * + * @author Dkl + * @date 2025-06-16 + */ +public interface DklWarningInformationHandleMapper +{ + /** + * 查询预警信息处置 + * + * @param id 预警信息处置主键 + * @return 预警信息处置 + */ + public DklWarningInformationHandle selectDklWarningInformationHandleById(Long id); + + /** + * 查询预警信息处置列表 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 预警信息处置集合 + */ + public List selectDklWarningInformationHandleList(DklWarningInformationHandle dklWarningInformationHandle); + + /** + * 新增预警信息处置 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 结果 + */ + public int insertDklWarningInformationHandle(DklWarningInformationHandle dklWarningInformationHandle); + + /** + * 修改预警信息处置 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 结果 + */ + public int updateDklWarningInformationHandle(DklWarningInformationHandle dklWarningInformationHandle); + + /** + * 删除预警信息处置 + * + * @param id 预警信息处置主键 + * @return 结果 + */ + public int deleteDklWarningInformationHandleById(Long id); + + /** + * 批量删除预警信息处置 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteDklWarningInformationHandleByIds(Long[] ids); +} diff --git a/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/service/IDklWarningInformationHandleService.java b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/service/IDklWarningInformationHandleService.java new file mode 100644 index 0000000..4488464 --- /dev/null +++ b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/service/IDklWarningInformationHandleService.java @@ -0,0 +1,61 @@ +package com.dkl.large.service; + +import java.util.List; +import com.dkl.large.domain.DklWarningInformationHandle; + +/** + * 预警信息处置Service接口 + * + * @author Dkl + * @date 2025-06-16 + */ +public interface IDklWarningInformationHandleService +{ + /** + * 查询预警信息处置 + * + * @param id 预警信息处置主键 + * @return 预警信息处置 + */ + public DklWarningInformationHandle selectDklWarningInformationHandleById(Long id); + + /** + * 查询预警信息处置列表 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 预警信息处置集合 + */ + public List selectDklWarningInformationHandleList(DklWarningInformationHandle dklWarningInformationHandle); + + /** + * 新增预警信息处置 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 结果 + */ + public int insertDklWarningInformationHandle(DklWarningInformationHandle dklWarningInformationHandle); + + /** + * 修改预警信息处置 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 结果 + */ + public int updateDklWarningInformationHandle(DklWarningInformationHandle dklWarningInformationHandle); + + /** + * 批量删除预警信息处置 + * + * @param ids 需要删除的预警信息处置主键集合 + * @return 结果 + */ + public int deleteDklWarningInformationHandleByIds(Long[] ids); + + /** + * 删除预警信息处置信息 + * + * @param id 预警信息处置主键 + * @return 结果 + */ + public int deleteDklWarningInformationHandleById(Long id); +} diff --git a/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/service/impl/DklWarningInformationHandleServiceImpl.java b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/service/impl/DklWarningInformationHandleServiceImpl.java new file mode 100644 index 0000000..2fe9eb7 --- /dev/null +++ b/Dkl-Vue-master/dkl-large/src/test/java/com/dkl/large/service/impl/DklWarningInformationHandleServiceImpl.java @@ -0,0 +1,156 @@ +package com.dkl.large.service.impl; + +import java.util.Date; +import java.util.List; +import com.dkl.common.utils.DateUtils; +import com.dkl.common.utils.bean.BeanUtils; +import com.dkl.large.domain.DklWarningInformation; +import com.dkl.large.domain.DklWarningInformationProcess; +import com.dkl.large.mapper.DklWarningInformationMapper; +import com.dkl.large.mapper.DklWarningInformationProcessMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dkl.large.mapper.DklWarningInformationHandleMapper; +import com.dkl.large.domain.DklWarningInformationHandle; +import com.dkl.large.service.IDklWarningInformationHandleService; +import org.springframework.transaction.annotation.Transactional; + +/** + * 预警信息处置Service业务层处理 + * + * @author Dkl + * @date 2025-06-16 + */ +@Service +public class DklWarningInformationHandleServiceImpl implements IDklWarningInformationHandleService +{ + @Autowired + private DklWarningInformationHandleMapper dklWarningInformationHandleMapper; + @Autowired + private DklWarningInformationMapper dklWarningInformationMapper; + + @Autowired + private DklWarningInformationProcessMapper dklWarningInformationProcessMapper; + /** + * 查询预警信息处置 + * + * @param id 预警信息处置主键 + * @return 预警信息处置 + */ + @Override + public DklWarningInformationHandle selectDklWarningInformationHandleById(Long id) + { + return dklWarningInformationHandleMapper.selectDklWarningInformationHandleById(id); + } + + /** + * 查询预警信息处置列表 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 预警信息处置 + */ + @Override + public List selectDklWarningInformationHandleList(DklWarningInformationHandle dklWarningInformationHandle) + { + return dklWarningInformationHandleMapper.selectDklWarningInformationHandleList(dklWarningInformationHandle); + } + + /** + * 新增预警信息处置 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 结果 + */ + @Override + @Transactional + public int insertDklWarningInformationHandle(DklWarningInformationHandle dklWarningInformationHandle) + { + //下发 即在处置表中添加数据 + //修改主表的处置规则 + DklWarningInformation dklWarningInformation = dklWarningInformationMapper.selectDklWarningInformationById((long) dklWarningInformationHandle.getWarningId()); + dklWarningInformation.setRulesId(dklWarningInformationHandle.getRulesId()); + dklWarningInformation.setEventStatus("1"); + dklWarningInformationMapper.updateDklWarningInformation(dklWarningInformation); + //添加流程数据 + DklWarningInformationProcess dklWarningInformationProcess = new DklWarningInformationProcess(); + BeanUtils.copyProperties( dklWarningInformationHandle,dklWarningInformationProcess); + dklWarningInformationHandle.setDisposalStatus("0"); + dklWarningInformationHandle.setDelFlag("0"); + dklWarningInformationHandle.setCreateTime(new Date()); + dklWarningInformationHandle.setCreateBy(dklWarningInformationHandle.getCreateBy()); + dklWarningInformationHandle.setUpdateTime(new Date()); + dklWarningInformationHandle.setUpdateBy(dklWarningInformationHandle.getCreateBy()); + dklWarningInformationHandleMapper.insertDklWarningInformationHandle(dklWarningInformationHandle); + dklWarningInformationProcess.setHandleId(dklWarningInformationHandle.getId()); + dklWarningInformationProcess.setDisposalStatus("0"); + return dklWarningInformationProcessMapper.insertDklWarningInformationProcess(dklWarningInformationProcess); + } + + /** + * 修改预警信息处置 + * + * @param dklWarningInformationHandle 预警信息处置 + * @return 结果 + */ + @Override + @Transactional + public int updateDklWarningInformationHandle(DklWarningInformationHandle dklWarningInformationHandle) + { + DklWarningInformationProcess dklWarningInformationProcess = new DklWarningInformationProcess(); + BeanUtils.copyProperties( dklWarningInformationHandle,dklWarningInformationProcess); + dklWarningInformationHandle.setDelFlag("0"); + dklWarningInformationHandle.setCreateTime(new Date()); + dklWarningInformationHandle.setCreateBy(dklWarningInformationHandle.getCreateBy()); + dklWarningInformationHandle.setUpdateTime(new Date()); + dklWarningInformationHandle.setUpdateBy(dklWarningInformationHandle.getCreateBy()); + //预警信息处置流程是1 即受理 + if (("1").equals(dklWarningInformationHandle.getDisposalStatus())){ + dklWarningInformationProcess.setHandleId(dklWarningInformationHandle.getId()); + dklWarningInformationProcess.setDisposalStatus(dklWarningInformationHandle.getDisposalStatus()); + dklWarningInformationProcessMapper.insertDklWarningInformationProcess(dklWarningInformationProcess); + //修改主表的处置规则 处理中 + DklWarningInformation dklWarningInformation = dklWarningInformationMapper.selectDklWarningInformationById((long) dklWarningInformationHandle.getId()); +// dklWarningInformation.setRulesId(dklWarningInformationHandle.getRulesId()); + dklWarningInformation.setWarningStatus("2"); + dklWarningInformationMapper.updateDklWarningInformation(dklWarningInformation); + }else if(("2").equals(dklWarningInformationHandle.getDisposalStatus())){ + dklWarningInformationProcess.setHandleId(dklWarningInformationHandle.getId()); + dklWarningInformationProcess.setDisposalStatus(dklWarningInformationHandle.getDisposalStatus()); + dklWarningInformationProcess.setDisposalMeasures(dklWarningInformationHandle.getDisposalMeasures()); +// dklWarningInformationProcess.setDisposalResults(dklWarningInformationHandle.getDisposalResults()); + dklWarningInformationProcessMapper.insertDklWarningInformationProcess(dklWarningInformationProcess); + //修改主表的处置规则 已完成 + DklWarningInformation dklWarningInformation = dklWarningInformationMapper.selectDklWarningInformationById((long) dklWarningInformationHandle.getId()); + dklWarningInformation.setRulesId(dklWarningInformationHandle.getRulesId()); + dklWarningInformation.setWarningStatus("3"); + dklWarningInformationMapper.updateDklWarningInformation(dklWarningInformation); + } + + + return 1; + } + + /** + * 批量删除预警信息处置 + * + * @param ids 需要删除的预警信息处置主键 + * @return 结果 + */ + @Override + public int deleteDklWarningInformationHandleByIds(Long[] ids) + { + return dklWarningInformationHandleMapper.deleteDklWarningInformationHandleByIds(ids); + } + + /** + * 删除预警信息处置信息 + * + * @param id 预警信息处置主键 + * @return 结果 + */ + @Override + public int deleteDklWarningInformationHandleById(Long id) + { + return dklWarningInformationHandleMapper.deleteDklWarningInformationHandleById(id); + } +} diff --git a/Dkl-Vue-master/dkl-large/src/test/resources/mapper/large/DklWarningInformationHandleMapper.xml b/Dkl-Vue-master/dkl-large/src/test/resources/mapper/large/DklWarningInformationHandleMapper.xml new file mode 100644 index 0000000..1aa8bde --- /dev/null +++ b/Dkl-Vue-master/dkl-large/src/test/resources/mapper/large/DklWarningInformationHandleMapper.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + select dwih.id, dwih.warning_signs, dwih.delegate_personnel, dwih.delegation_time, dwih.delegation_dept, + dwih.disposal_measures, dwih.disposal_results, dwih.disposal_status, dwih.create_by, dwih.create_time,dwih.warning_id, + dwih.update_by, dwih.update_time, dwih.del_flag,d.dept_name AS deptName,u.nick_name AS nickName from dkl_warning_information_handle AS dwih + left join sys_dept d on dwih.delegation_dept = d.dept_id + left join sys_user u on dwih.delegate_personnel = u.user_id + + + + + + + + insert into dkl_warning_information_handle + + warning_signs, + delegate_personnel, + delegation_time, + delegation_dept, + disposal_measures, + disposal_results, + disposal_status, + create_by, + create_time, + update_by, + update_time, + del_flag, + warning_id, + + + #{warningSigns}, + #{delegatePersonnel}, + #{delegationTime}, + #{delegationDept}, + #{disposalMeasures}, + #{disposalResults}, + #{disposalStatus}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{delFlag}, + #{warningId}, + + + SELECT CURRVAL('dkl_warning_information_handle_id_seq') + + + + + update dkl_warning_information_handle + + warning_signs = #{warningSigns}, + delegate_personnel = #{delegatePersonnel}, + delegation_time = #{delegationTime}, + delegation_dept = #{delegationDept}, + disposal_measures = #{disposalMeasures}, + disposal_results = #{disposalResults}, + disposal_status = #{disposalStatus}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + warning_id = #{warningId}, + + where id = #{id} + + + + update dkl_warning_information_handle set del_flag = 2 where id = #{id} + + + + update dkl_warning_information_handle set del_flag = 2 where id in + + #{id} + + +