测试用例
This commit is contained in:
parent
468d5a64c2
commit
7b85f36269
|
|
@ -0,0 +1,283 @@
|
|||
package com.dkl.large.controller;
|
||||
|
||||
import com.dkl.common.core.domain.AjaxResult;
|
||||
import com.dkl.common.core.page.TableDataInfo;
|
||||
import com.dkl.large.domain.DklSecurityPersonnel;
|
||||
import com.dkl.large.service.IDklSecurityPersonnelService;
|
||||
import com.koal.kms.sdk.ed.KmsSdkException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* 安保力量(人员)Controller单元测试
|
||||
* 风格与之前保持一致:JUnit 5 + Mockito,覆盖所有核心接口与关键逻辑
|
||||
*
|
||||
* @author Falling
|
||||
* @date 2025-06-16
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class DklSecurityPersonnelControllerTest {
|
||||
|
||||
// 待测试的Controller(自动注入Mock的Service依赖,解耦真实业务层)
|
||||
@InjectMocks
|
||||
private DklSecurityPersonnelController securityPersonnelController;
|
||||
|
||||
// 模拟Controller依赖的Service层(避免依赖真实数据库)
|
||||
@Mock
|
||||
private IDklSecurityPersonnelService securityPersonnelService;
|
||||
|
||||
// 模拟HTTP响应对象(用于导出/导入模板接口)
|
||||
private MockHttpServletResponse mockResponse;
|
||||
|
||||
// 测试核心实体数据(安保人员)
|
||||
private DklSecurityPersonnel testPersonnel;
|
||||
|
||||
// 测试实体列表数据
|
||||
private List<DklSecurityPersonnel> testPersonnelList;
|
||||
|
||||
/**
|
||||
* 每个测试方法执行前初始化数据(保证测试用例独立性,避免相互干扰)
|
||||
*/
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
// 1. 初始化模拟HTTP响应
|
||||
mockResponse = new MockHttpServletResponse();
|
||||
|
||||
// 2. 初始化单个安保人员实体
|
||||
testPersonnel = new DklSecurityPersonnel();
|
||||
testPersonnel.setId(1L);
|
||||
testPersonnel.setDelFlag("0");
|
||||
testPersonnel.setCreateTime(new Date());
|
||||
testPersonnel.setCreateBy("admin");
|
||||
testPersonnel.setDeptId(100L);
|
||||
testPersonnel.setUpdateTime(new Date());
|
||||
testPersonnel.setUpdateBy("admin");
|
||||
|
||||
// 3. 初始化安保人员列表
|
||||
testPersonnelList = new ArrayList<>();
|
||||
testPersonnelList.add(testPersonnel);
|
||||
|
||||
// 4. 模拟Security上下文(解决getUsername()/getDeptId()等权限方法依赖,避免测试报错)
|
||||
Authentication authentication = mock(Authentication.class);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
doReturn("admin").when(authentication).getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:查询安保人员列表(list接口)
|
||||
*/
|
||||
@Test
|
||||
void testList() throws KmsSdkException {
|
||||
// 步骤1:模拟Service层返回列表数据
|
||||
when(securityPersonnelService.selectDklSecurityPersonnelList(any(DklSecurityPersonnel.class)))
|
||||
.thenReturn(testPersonnelList);
|
||||
|
||||
// 步骤2:调用Controller接口执行测试
|
||||
TableDataInfo result = securityPersonnelController.list(testPersonnel);
|
||||
|
||||
// 步骤3:断言结果(验证返回数据有效性)
|
||||
assertNotNull(result, "返回的TableDataInfo不能为null");
|
||||
assertEquals(1, result.getRows().size(), "返回的列表数据条数应为1");
|
||||
assertEquals(testPersonnel.getId(), ((DklSecurityPersonnel) result.getRows().get(0)).getId(), "返回的实体ID应与测试数据一致");
|
||||
|
||||
// 步骤4:验证Service方法被正确调用(确保流程无遗漏)
|
||||
verify(securityPersonnelService, times(1)).selectDklSecurityPersonnelList(any(DklSecurityPersonnel.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:查询安保人员消息(listMessgae接口,注意Controller中方法名拼写)
|
||||
*/
|
||||
@Test
|
||||
void testListMessgae() throws KmsSdkException {
|
||||
// 步骤1:模拟Service层返回查询消息
|
||||
String mockSuccessMsg = "查询成功,共获取1条安保人员数据";
|
||||
when(securityPersonnelService.selectDklSecurityPersonnelListMessage(any(DklSecurityPersonnel.class)))
|
||||
.thenReturn(mockSuccessMsg);
|
||||
|
||||
// 步骤2:调用Controller接口执行测试
|
||||
AjaxResult result = securityPersonnelController.listMessgae(testPersonnel);
|
||||
|
||||
// 步骤3:断言结果
|
||||
assertNotNull(result, "返回的AjaxResult不能为null");
|
||||
assertTrue(result.isSuccess(), "接口应返回成功状态");
|
||||
assertEquals(mockSuccessMsg, result.getData(), "返回的消息应与模拟数据一致");
|
||||
|
||||
// 步骤4:验证Service方法调用
|
||||
verify(securityPersonnelService, times(1)).selectDklSecurityPersonnelListMessage(any(DklSecurityPersonnel.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:导出安保人员列表(export接口,无返回值,验证流程有效性)
|
||||
*/
|
||||
@Test
|
||||
void testExport() throws KmsSdkException {
|
||||
// 步骤1:模拟Service层返回列表数据
|
||||
when(securityPersonnelService.selectDklSecurityPersonnelList(any(DklSecurityPersonnel.class)))
|
||||
.thenReturn(testPersonnelList);
|
||||
|
||||
// 步骤2:调用导出接口(无返回值,验证无异常抛出即可)
|
||||
assertDoesNotThrow(() -> securityPersonnelController.export(mockResponse, testPersonnel),
|
||||
"导出接口执行过程中不应抛出异常");
|
||||
|
||||
// 步骤3:验证Service方法被调用,且HTTP响应状态正常
|
||||
verify(securityPersonnelService, times(1)).selectDklSecurityPersonnelList(any(DklSecurityPersonnel.class));
|
||||
assertEquals(200, mockResponse.getStatus(), "HTTP响应状态码应为200");
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:获取安保人员详细信息(getInfo接口)
|
||||
*/
|
||||
@Test
|
||||
void testGetInfo() throws KmsSdkException {
|
||||
// 步骤1:模拟Service层返回单个实体数据
|
||||
when(securityPersonnelService.selectDklSecurityPersonnelById(anyLong())).thenReturn(testPersonnel);
|
||||
|
||||
// 步骤2:调用Controller接口执行测试
|
||||
AjaxResult result = securityPersonnelController.getInfo(1L);
|
||||
|
||||
// 步骤3:断言结果
|
||||
assertNotNull(result, "返回的AjaxResult不能为null");
|
||||
assertTrue(result.isSuccess(), "接口应返回成功状态");
|
||||
assertEquals(testPersonnel.getId(), ((DklSecurityPersonnel) result.getData()).getId(), "返回的实体ID应与测试数据一致");
|
||||
|
||||
// 步骤4:验证Service方法调用
|
||||
verify(securityPersonnelService, times(1)).selectDklSecurityPersonnelById(1L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:新增安保人员(add接口)
|
||||
*/
|
||||
@Test
|
||||
void testAdd() throws KmsSdkException {
|
||||
// 步骤1:模拟Service层新增成功(返回1表示操作成功)
|
||||
when(securityPersonnelService.insertDklSecurityPersonnel(any(DklSecurityPersonnel.class))).thenReturn(1);
|
||||
|
||||
// 步骤2:调用Controller接口执行测试
|
||||
AjaxResult result = securityPersonnelController.add(testPersonnel);
|
||||
|
||||
// 步骤3:断言结果
|
||||
assertNotNull(result, "返回的AjaxResult不能为null");
|
||||
assertTrue(result.isSuccess(), "新增接口应返回成功状态");
|
||||
assertEquals(1, result.getData(), "新增操作应返回1表示成功");
|
||||
|
||||
// 步骤4:验证实体系统字段被正确设置(核心业务逻辑校验)
|
||||
verify(securityPersonnelService).insertDklSecurityPersonnel(argThat(personnel ->
|
||||
"0".equals(personnel.getDelFlag()) &&
|
||||
"admin".equals(personnel.getCreateBy()) &&
|
||||
100L.equals(personnel.getDeptId()) &&
|
||||
personnel.getCreateTime() != null &&
|
||||
personnel.getUpdateTime() != null
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:修改安保人员(edit接口)
|
||||
*/
|
||||
@Test
|
||||
void testEdit() throws KmsSdkException {
|
||||
// 步骤1:模拟Service层修改成功(返回1表示操作成功)
|
||||
when(securityPersonnelService.updateDklSecurityPersonnel(any(DklSecurityPersonnel.class))).thenReturn(1);
|
||||
|
||||
// 步骤2:调用Controller接口执行测试
|
||||
AjaxResult result = securityPersonnelController.edit(testPersonnel);
|
||||
|
||||
// 步骤3:断言结果
|
||||
assertNotNull(result, "返回的AjaxResult不能为null");
|
||||
assertTrue(result.isSuccess(), "修改接口应返回成功状态");
|
||||
assertEquals(1, result.getData(), "修改操作应返回1表示成功");
|
||||
|
||||
// 步骤4:验证实体更新字段被正确设置
|
||||
verify(securityPersonnelService).updateDklSecurityPersonnel(argThat(personnel ->
|
||||
"admin".equals(personnel.getUpdateBy()) &&
|
||||
personnel.getUpdateTime() != null
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:删除安保人员(remove接口,批量删除)
|
||||
*/
|
||||
@Test
|
||||
void testRemove() {
|
||||
// 步骤1:准备批量删除ID数组
|
||||
Long[] ids = {1L, 2L};
|
||||
|
||||
// 步骤2:模拟Service层删除成功(返回2表示删除2条数据)
|
||||
when(securityPersonnelService.deleteDklSecurityPersonnelByIds(any(Long[].class))).thenReturn(2);
|
||||
|
||||
// 步骤3:调用Controller接口执行测试
|
||||
AjaxResult result = securityPersonnelController.remove(ids);
|
||||
|
||||
// 步骤4:断言结果
|
||||
assertNotNull(result, "返回的AjaxResult不能为null");
|
||||
assertTrue(result.isSuccess(), "删除接口应返回成功状态");
|
||||
assertEquals(2, result.getData(), "删除操作应返回2表示成功删除2条数据");
|
||||
|
||||
// 步骤5:验证Service方法调用
|
||||
verify(securityPersonnelService, times(1)).deleteDklSecurityPersonnelByIds(any(Long[].class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:导入安保人员数据(importData接口)
|
||||
* @throws Exception 导入过程中的异常
|
||||
*/
|
||||
@Test
|
||||
void testImportData() throws Exception {
|
||||
// 步骤1:模拟Excel上传文件(空流,仅验证流程有效性)
|
||||
MockMultipartFile mockFile = new MockMultipartFile(
|
||||
"file",
|
||||
"security_personnel.xlsx",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
new ByteArrayInputStream(new byte[0])
|
||||
);
|
||||
|
||||
// 步骤2:模拟Service层返回导入成功消息
|
||||
String mockImportMsg = "导入成功,共导入0条有效数据";
|
||||
when(securityPersonnelService.importData(anyList(), anyBoolean(), anyString()))
|
||||
.thenReturn(mockImportMsg);
|
||||
|
||||
// 步骤3:调用Controller接口执行测试(updateSupport为true)
|
||||
AjaxResult result = securityPersonnelController.importData(mockFile, true);
|
||||
|
||||
// 步骤4:断言结果
|
||||
assertNotNull(result, "返回的AjaxResult不能为null");
|
||||
assertTrue(result.isSuccess(), "导入接口应返回成功状态");
|
||||
assertEquals(mockImportMsg, result.getData(), "导入消息应与模拟数据一致");
|
||||
|
||||
// 步骤5:验证Service方法调用
|
||||
verify(securityPersonnelService, times(1)).importData(anyList(), eq(true), eq("admin"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试:下载安保人员导入模板(importTemplate接口)
|
||||
*/
|
||||
@Test
|
||||
void testImportTemplate() {
|
||||
// 步骤1:调用导入模板接口(无返回值,验证无异常抛出)
|
||||
assertDoesNotThrow(() -> securityPersonnelController.importTemplate(mockResponse),
|
||||
"下载导入模板接口不应抛出异常");
|
||||
|
||||
// 步骤2:验证响应状态与格式(确保模板下载流程有效)
|
||||
assertEquals(200, mockResponse.getStatus(), "HTTP响应状态码应为200");
|
||||
assertTrue(mockResponse.getContentType().contains("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
|
||||
"响应内容应为Excel格式");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package com.dkl.large.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
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_security_personnel
|
||||
*
|
||||
* @author Falling
|
||||
* @date 2025-06-16
|
||||
*/
|
||||
@Data
|
||||
public class DklSecurityPersonnel extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** $column.columnComment */
|
||||
private Long id;
|
||||
|
||||
/** 姓名 */
|
||||
@Excel(name = "姓名")
|
||||
private String name;
|
||||
|
||||
/** 身份证号 */
|
||||
@Excel(name = "身份证号")
|
||||
private String code;
|
||||
|
||||
/** 联系方式 */
|
||||
@Excel(name = "联系方式")
|
||||
private String phone;
|
||||
|
||||
/** 入职日期 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "入职日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date entryTime;
|
||||
|
||||
/** 岗位 */
|
||||
@Excel(name = "岗位")
|
||||
private String post;
|
||||
|
||||
/** 证书名称 */
|
||||
@Excel(name = "证书名称")
|
||||
private String certificate;
|
||||
|
||||
/** 证书编号 */
|
||||
@Excel(name = "证书编号")
|
||||
private String certificateCode;
|
||||
|
||||
/** 监控点信息ID */
|
||||
|
||||
private Long monitoringPointsId;
|
||||
|
||||
/** '删除标志(0代表存在 2代表删除) */
|
||||
private String delFlag;
|
||||
|
||||
/** 部门id */
|
||||
private Long deptId;
|
||||
|
||||
/** 名称 */
|
||||
@Excel(name = "监控点信息名称")
|
||||
private String pointName;
|
||||
/** 地址 */
|
||||
private String pointAddress;
|
||||
/** 经度 */
|
||||
private String lng;
|
||||
/** 纬度 */
|
||||
private String lat;
|
||||
private String sigenCode;
|
||||
/** 开始时间 */
|
||||
@TableField(exist = false)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date startTime;
|
||||
|
||||
/** 结束时间 */
|
||||
@TableField(exist = false)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date endTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package com.dkl.large.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.dkl.large.domain.DklSecurityPersonnel;
|
||||
|
||||
/**
|
||||
* 安保力量(人员)Mapper接口
|
||||
*
|
||||
* @author Falling
|
||||
* @date 2025-06-16
|
||||
*/
|
||||
public interface DklSecurityPersonnelMapper
|
||||
{
|
||||
/**
|
||||
* 查询安保力量(人员)
|
||||
*
|
||||
* @param id 安保力量(人员)主键
|
||||
* @return 安保力量(人员)
|
||||
*/
|
||||
public DklSecurityPersonnel selectDklSecurityPersonnelById(Long id);
|
||||
|
||||
/**
|
||||
* 查询安保力量(人员)列表
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 安保力量(人员)集合
|
||||
*/
|
||||
public List<DklSecurityPersonnel> selectDklSecurityPersonnelList(DklSecurityPersonnel dklSecurityPersonnel);
|
||||
|
||||
/**
|
||||
* 新增安保力量(人员)
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDklSecurityPersonnel(DklSecurityPersonnel dklSecurityPersonnel);
|
||||
|
||||
/**
|
||||
* 修改安保力量(人员)
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDklSecurityPersonnel(DklSecurityPersonnel dklSecurityPersonnel);
|
||||
|
||||
/**
|
||||
* 删除安保力量(人员)
|
||||
*
|
||||
* @param id 安保力量(人员)主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDklSecurityPersonnelById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除安保力量(人员)
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDklSecurityPersonnelByIds(Long[] ids);
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package com.dkl.large.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.koal.kms.sdk.ed.KmsSdkException;
|
||||
import com.dkl.large.domain.DklSecurityEquipment;
|
||||
import com.dkl.large.domain.DklSecurityPersonnel;
|
||||
|
||||
/**
|
||||
* 安保力量(人员)Service接口
|
||||
*
|
||||
* @author Falling
|
||||
* @date 2025-06-16
|
||||
*/
|
||||
public interface IDklSecurityPersonnelService
|
||||
{
|
||||
/**
|
||||
* 查询安保力量(人员)
|
||||
*
|
||||
* @param id 安保力量(人员)主键
|
||||
* @return 安保力量(人员)
|
||||
*/
|
||||
public DklSecurityPersonnel selectDklSecurityPersonnelById(Long id) throws KmsSdkException;
|
||||
|
||||
/**
|
||||
* 查询安保力量(人员)列表
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 安保力量(人员)集合
|
||||
*/
|
||||
public List<DklSecurityPersonnel> selectDklSecurityPersonnelList(DklSecurityPersonnel dklSecurityPersonnel) throws KmsSdkException;
|
||||
public String selectDklSecurityPersonnelListMessage(DklSecurityPersonnel dklSecurityPersonnel) throws KmsSdkException;
|
||||
/**
|
||||
* 新增安保力量(人员)
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDklSecurityPersonnel(DklSecurityPersonnel dklSecurityPersonnel) throws KmsSdkException;
|
||||
|
||||
/**
|
||||
* 修改安保力量(人员)
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDklSecurityPersonnel(DklSecurityPersonnel dklSecurityPersonnel) throws KmsSdkException;
|
||||
|
||||
/**
|
||||
* 批量删除安保力量(人员)
|
||||
*
|
||||
* @param ids 需要删除的安保力量(人员)主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDklSecurityPersonnelByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除安保力量(人员)信息
|
||||
*
|
||||
* @param id 安保力量(人员)主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDklSecurityPersonnelById(Long id);
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param list 数据列表
|
||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||
* @param operName 操作用户
|
||||
* @return 结果
|
||||
*/
|
||||
public String importData(List<DklSecurityPersonnel> list, Boolean isUpdateSupport, String operName) throws KmsSdkException;
|
||||
}
|
||||
|
|
@ -0,0 +1,309 @@
|
|||
package com.dkl.large.service.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.koal.kms.sdk.ed.KmsSdkException;
|
||||
import com.dkl.common.exception.ServiceException;
|
||||
import com.dkl.common.utils.DateUtils;
|
||||
import com.dkl.common.utils.StringUtils;
|
||||
import com.dkl.large.domain.DklMonitoringPoints;
|
||||
import com.dkl.large.domain.DklSecurityEquipment;
|
||||
import com.dkl.large.mapper.DklMonitoringPointsMapper;
|
||||
import com.dkl.large.utli.EnciphermentUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.dkl.large.mapper.DklSecurityPersonnelMapper;
|
||||
import com.dkl.large.domain.DklSecurityPersonnel;
|
||||
import com.dkl.large.service.IDklSecurityPersonnelService;
|
||||
|
||||
import static com.dkl.common.utils.SecurityUtils.getDeptId;
|
||||
import static com.dkl.common.utils.SecurityUtils.getUsername;
|
||||
import static org.springframework.util.SerializationUtils.serialize;
|
||||
|
||||
/**
|
||||
* 安保力量(人员)Service业务层处理
|
||||
*
|
||||
* @author Falling
|
||||
* @date 2025-06-16
|
||||
*/
|
||||
@Service
|
||||
public class DklSecurityPersonnelServiceImpl implements IDklSecurityPersonnelService
|
||||
{
|
||||
@Autowired
|
||||
private DklSecurityPersonnelMapper dklSecurityPersonnelMapper;
|
||||
|
||||
@Autowired
|
||||
private DklMonitoringPointsMapper dklMonitoringPointsMapper;
|
||||
|
||||
|
||||
//身份证号码正则
|
||||
private static final String CODE_REGEX = "^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
|
||||
|
||||
/**
|
||||
* 查询安保力量(人员)
|
||||
*
|
||||
* @param id 安保力量(人员)主键
|
||||
* @return 安保力量(人员)
|
||||
*/
|
||||
@Override
|
||||
public DklSecurityPersonnel selectDklSecurityPersonnelById(Long id) throws KmsSdkException {
|
||||
|
||||
DklSecurityPersonnel dklSecurityPersonnelInfo= dklSecurityPersonnelMapper.selectDklSecurityPersonnelById(id);
|
||||
|
||||
String code = dklSecurityPersonnelInfo.getCode();
|
||||
String phone = dklSecurityPersonnelInfo.getPhone();
|
||||
dklSecurityPersonnelInfo.setCode(EnciphermentUtil.kmsDencrypt(code));
|
||||
dklSecurityPersonnelInfo.setPhone(EnciphermentUtil.kmsDencrypt(phone));
|
||||
return dklSecurityPersonnelInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询安保力量(人员)列表
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 安保力量(人员)
|
||||
*/
|
||||
@Override
|
||||
public List<DklSecurityPersonnel> selectDklSecurityPersonnelList(DklSecurityPersonnel dklSecurityPersonnel) throws KmsSdkException {
|
||||
List<DklSecurityPersonnel> list = dklSecurityPersonnelMapper.selectDklSecurityPersonnelList(dklSecurityPersonnel);
|
||||
for (DklSecurityPersonnel dklSecurityPersonnelInfo : list) {
|
||||
String code = dklSecurityPersonnelInfo.getCode();
|
||||
String phone = dklSecurityPersonnelInfo.getPhone();
|
||||
dklSecurityPersonnelInfo.setCode(EnciphermentUtil.kmsDencrypt(code));
|
||||
dklSecurityPersonnelInfo.setPhone(EnciphermentUtil.kmsDencrypt(phone));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String selectDklSecurityPersonnelListMessage(DklSecurityPersonnel dklSecurityPersonnel) throws KmsSdkException {
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
List<DklSecurityPersonnel> list = dklSecurityPersonnelMapper.selectDklSecurityPersonnelList(dklSecurityPersonnel);
|
||||
for (DklSecurityPersonnel dklSecurityPersonnelInfo : list) {
|
||||
String code = dklSecurityPersonnelInfo.getCode();
|
||||
String phone = dklSecurityPersonnelInfo.getPhone();
|
||||
dklSecurityPersonnelInfo.setCode(EnciphermentUtil.kmsDencrypt(code));
|
||||
dklSecurityPersonnelInfo.setPhone(EnciphermentUtil.kmsDencrypt(phone));
|
||||
byte[] bytes = serialize(dklSecurityPersonnelInfo.getName()+","+dklSecurityPersonnelInfo.getCode()+","+dklSecurityPersonnelInfo.getPhone());
|
||||
String isor = EnciphermentUtil.kmsSign(bytes);
|
||||
if (!isor.equals(dklSecurityPersonnelInfo.getSigenCode())) {
|
||||
successMsg.append("名称为"+dklSecurityPersonnelInfo.getName()+"的数据被篡改");
|
||||
}
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增安保力量(人员)
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertDklSecurityPersonnel(DklSecurityPersonnel dklSecurityPersonnel) throws KmsSdkException {
|
||||
dklSecurityPersonnel.setCreateTime(DateUtils.getNowDate());
|
||||
|
||||
String code = dklSecurityPersonnel.getCode();
|
||||
String phone = dklSecurityPersonnel.getPhone();
|
||||
dklSecurityPersonnel.setCode(EnciphermentUtil.kmsEncrypt(code));
|
||||
dklSecurityPersonnel.setPhone(EnciphermentUtil.kmsEncrypt(phone));
|
||||
// (序列化)
|
||||
byte[] bytes = serialize(code+","+phone);
|
||||
String sigenCode = EnciphermentUtil.kmsSign(bytes);
|
||||
dklSecurityPersonnel.setSigenCode(sigenCode);
|
||||
return dklSecurityPersonnelMapper.insertDklSecurityPersonnel(dklSecurityPersonnel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改安保力量(人员)
|
||||
*
|
||||
* @param dklSecurityPersonnel 安保力量(人员)
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateDklSecurityPersonnel(DklSecurityPersonnel dklSecurityPersonnel) throws KmsSdkException {
|
||||
dklSecurityPersonnel.setUpdateTime(DateUtils.getNowDate());
|
||||
String code = dklSecurityPersonnel.getCode();
|
||||
String phone = dklSecurityPersonnel.getPhone();
|
||||
dklSecurityPersonnel.setCode(EnciphermentUtil.kmsEncrypt(code));
|
||||
dklSecurityPersonnel.setPhone(EnciphermentUtil.kmsEncrypt(phone));
|
||||
// (序列化)
|
||||
byte[] bytes = serialize(code+","+phone);
|
||||
String sigenCode = EnciphermentUtil.kmsSign(bytes);
|
||||
dklSecurityPersonnel.setSigenCode(sigenCode);
|
||||
return dklSecurityPersonnelMapper.updateDklSecurityPersonnel(dklSecurityPersonnel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除安保力量(人员)
|
||||
*
|
||||
* @param ids 需要删除的安保力量(人员)主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDklSecurityPersonnelByIds(Long[] ids)
|
||||
{
|
||||
return dklSecurityPersonnelMapper.deleteDklSecurityPersonnelByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除安保力量(人员)信息
|
||||
*
|
||||
* @param id 安保力量(人员)主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDklSecurityPersonnelById(Long id)
|
||||
{
|
||||
return dklSecurityPersonnelMapper.deleteDklSecurityPersonnelById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param list 数据列表
|
||||
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
||||
* @param operName 操作用户
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String importData(List<DklSecurityPersonnel> list, Boolean isUpdateSupport, String operName) throws KmsSdkException {
|
||||
DklMonitoringPoints points = new DklMonitoringPoints();
|
||||
List<DklMonitoringPoints> pointsList = dklMonitoringPointsMapper.selectDklMonitoringPointsList(points);
|
||||
|
||||
if (StringUtils.isNull(list) || list.size() == 0) {
|
||||
throw new ServiceException("导入数据不能为空!");
|
||||
}
|
||||
int successNum = 0;
|
||||
int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
try
|
||||
{
|
||||
//姓名
|
||||
if (StringUtils.isEmpty(list.get(i).getName())){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据姓名为空");
|
||||
}else{
|
||||
if (list.get(i).getName().length()>=100){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据姓名长度过长");
|
||||
}
|
||||
}
|
||||
|
||||
//身份证号码
|
||||
if (StringUtils.isEmpty(list.get(i).getCode())){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据身份证号码为空");
|
||||
}else{
|
||||
if (list.get(i).getCode().length()>=30){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据身份证号码长度过长");
|
||||
}else if (!Pattern.matches(CODE_REGEX, list.get(i).getCode())){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据身份证号码有误");
|
||||
}
|
||||
}
|
||||
|
||||
//联系方式
|
||||
if (StringUtils.isEmpty(list.get(i).getPhone())){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据联系方式为空");
|
||||
}else{
|
||||
if (list.get(i).getPhone().length()>=30){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据联系方式长度过长");
|
||||
}
|
||||
}
|
||||
|
||||
//入职日期
|
||||
if (StringUtils.isEmpty(list.get(i).getEntryTime().toString())){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据入职日期为空,时间应该为yyyy-MM-dd");
|
||||
}else if (list.get(i).getEntryTime() == null || list.get(i).getEntryTime().getTime() == 0) {
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据入职日期无效,时间应该为yyyy-MM-dd");
|
||||
}
|
||||
|
||||
|
||||
//岗位
|
||||
if (StringUtils.isEmpty(list.get(i).getPost())){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1)+ "条数据岗位为空");
|
||||
}else{
|
||||
if (list.get(i).getPost().length()>=10){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1) + "条数据岗位长度过长");
|
||||
}
|
||||
}
|
||||
|
||||
//证书名称
|
||||
if (StringUtils.isNotEmpty(list.get(i).getCertificate()) && list.get(i).getCertificate().length()>=30 ){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1)+ "条数据证书名称长度过长");
|
||||
}
|
||||
|
||||
//证书编号
|
||||
if (StringUtils.isNotEmpty(list.get(i).getCertificateCode()) && list.get(i).getCertificateCode().length()>=50 ){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1)+ "条数据证书名称长度过长");
|
||||
}
|
||||
|
||||
//监控点
|
||||
if (StringUtils.isNotEmpty(list.get(i).getPointName())){
|
||||
for (DklMonitoringPoints monitoringPoints: pointsList){
|
||||
if (monitoringPoints.getPointName().equals(list.get(i).getPointName())){
|
||||
list.get(i).setMonitoringPointsId((long) monitoringPoints.getId());
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNull(String.valueOf(list.get(i).getMonitoringPointsId()))){
|
||||
failureNum++;
|
||||
failureMsg.append("<br/> 第" + (i+1)+ "条数据监控点名称找不到");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "导入失败请检查数据类型:";
|
||||
failureMsg.append(msg + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (failureNum > 0)
|
||||
{
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
for (DklSecurityPersonnel personnel :list){
|
||||
//添加系统信息
|
||||
personnel.setDelFlag("0");
|
||||
personnel.setCreateTime(new Date());
|
||||
personnel.setCreateBy(getUsername());
|
||||
personnel.setDeptId(getDeptId());
|
||||
personnel.setUpdateTime(new Date());
|
||||
personnel.setUpdateBy(getUsername());
|
||||
String name = personnel.getName();
|
||||
String code = personnel.getCode();
|
||||
String phone = personnel.getPhone();
|
||||
personnel.setCode(EnciphermentUtil.kmsEncrypt(code));
|
||||
personnel.setPhone(EnciphermentUtil.kmsEncrypt(phone));
|
||||
// (序列化)
|
||||
byte[] bytes = serialize(code+","+phone);
|
||||
String sigenCode = EnciphermentUtil.kmsSign(bytes);
|
||||
personnel.setSigenCode(sigenCode);
|
||||
dklSecurityPersonnelMapper.insertDklSecurityPersonnel(personnel);
|
||||
}
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!");
|
||||
}
|
||||
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dkl.large.mapper.DklSecurityPersonnelMapper">
|
||||
|
||||
<resultMap type="DklSecurityPersonnel" id="DklSecurityPersonnelResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="code" column="code" />
|
||||
<result property="phone" column="phone" />
|
||||
<result property="entryTime" column="entry_time" />
|
||||
<result property="post" column="post" />
|
||||
<result property="certificate" column="certificate" />
|
||||
<result property="certificateCode" column="certificate_code" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="monitoringPointsId" column="monitoring_points_id" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
<result property="deptId" column="dept_id" />
|
||||
<result property="sigenCode" column="sigen_code" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDklSecurityPersonnelVo">
|
||||
select dsp.id, dsp.name,dsp.sigen_code, dsp.code, dsp.phone, dsp.entry_time, dsp.post, dsp.certificate, dsp.certificate_code, dsp.remark,
|
||||
dsp.monitoring_points_id, dsp.create_by, dsp.create_time, dsp.update_by, dsp.update_time, dsp.del_flag, dsp.dept_id,
|
||||
dmp.lng, dmp.lat, dmp.point_name AS pointName,dmp.point_address
|
||||
from dkl_security_personnel dsp
|
||||
left join sys_dept d on dsp.dept_id = d.dept_id
|
||||
Left Join dkl_monitoring_points dmp on dmp.id = dsp.monitoring_points_id
|
||||
</sql>
|
||||
|
||||
<select id="selectDklSecurityPersonnelList" parameterType="DklSecurityPersonnel" resultMap="DklSecurityPersonnelResult">
|
||||
<include refid="selectDklSecurityPersonnelVo"/>
|
||||
<where>
|
||||
<if test="name != null and name != ''"> and dsp.name like concat('%', #{name}, '%')</if>
|
||||
<if test="code != null and code != ''"> and dsp.code = #{code}</if>
|
||||
<if test="phone != null and phone != ''"> and dsp.phone = #{phone}</if>
|
||||
<if test="entryTime != null "> and dsp.entry_time = #{entryTime}</if>
|
||||
<if test="post != null and post != ''"> and dsp.post = #{post}</if>
|
||||
<if test="certificate != null and certificate != ''"> and dsp.certificate = #{certificate}</if>
|
||||
<if test="certificateCode != null and certificateCode != ''"> and dsp.certificate_code = #{certificateCode}</if>
|
||||
<if test="monitoringPointsId != null "> and dsp.monitoring_points_id = #{monitoringPointsId}</if>
|
||||
<if test="delFlag != null and delFlag != ''"> and dsp.del_flag = #{delFlag}</if>
|
||||
<if test="startTime != null and endTime != null ">
|
||||
AND dsp.create_time BETWEEN #{startTime} and #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
${params.dataScope}
|
||||
order by dsp.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectDklSecurityPersonnelById" parameterType="Long" resultMap="DklSecurityPersonnelResult">
|
||||
<include refid="selectDklSecurityPersonnelVo"/>
|
||||
where dsp.id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertDklSecurityPersonnel" parameterType="DklSecurityPersonnel">
|
||||
insert into dkl_security_personnel
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="code != null">code,</if>
|
||||
<if test="phone != null">phone,</if>
|
||||
<if test="entryTime != null">entry_time,</if>
|
||||
<if test="post != null">post,</if>
|
||||
<if test="certificate != null">certificate,</if>
|
||||
<if test="certificateCode != null">certificate_code,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="monitoringPointsId != null">monitoring_points_id,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="delFlag != null">del_flag,</if>
|
||||
<if test="deptId != null">dept_id,</if>
|
||||
<if test="sigenCode != null">sigen_code,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="code != null">#{code},</if>
|
||||
<if test="phone != null">#{phone},</if>
|
||||
<if test="entryTime != null">#{entryTime},</if>
|
||||
<if test="post != null">#{post},</if>
|
||||
<if test="certificate != null">#{certificate},</if>
|
||||
<if test="certificateCode != null">#{certificateCode},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="monitoringPointsId != null">#{monitoringPointsId},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="delFlag != null">#{delFlag},</if>
|
||||
<if test="deptId != null">#{deptId},</if>
|
||||
<if test="sigenCode != null">#{sigenCode},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateDklSecurityPersonnel" parameterType="DklSecurityPersonnel">
|
||||
update dkl_security_personnel
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="code != null">code = #{code},</if>
|
||||
<if test="phone != null">phone = #{phone},</if>
|
||||
<if test="entryTime != null">entry_time = #{entryTime},</if>
|
||||
<if test="post != null">post = #{post},</if>
|
||||
<if test="certificate != null">certificate = #{certificate},</if>
|
||||
<if test="certificateCode != null">certificate_code = #{certificateCode},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="monitoringPointsId != null">monitoring_points_id = #{monitoringPointsId},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
||||
<if test="deptId != null">dept_id = #{deptId},</if>
|
||||
<if test="sigenCode != null">sigen_code = #{sigenCode},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteDklSecurityPersonnelById" parameterType="Long">
|
||||
delete from dkl_security_personnel where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteDklSecurityPersonnelByIds" parameterType="String">
|
||||
delete from dkl_security_personnel where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue