From 80ed3eae1f54121af1784b3ccf01026469e466f4 Mon Sep 17 00:00:00 2001 From: liulu Date: Mon, 28 Oct 2024 14:08:32 +0800 Subject: [PATCH] init web --- chsm-web-manage/pom.xml | 2 +- .../com/sunyard/chsm/dto/KeyTemplateDTO.java | 9 +- .../com/sunyard/config/MyBatisConfig.java | 26 ++ .../ssp/modules/common/CaptchaController.java | 60 ++++ .../sunyard/ssp/modules/jna/CipherJna.java | 319 ++++++++++++++++++ .../controller/TransactionController.java | 35 ++ .../entity/StatisticalConstant.java | 28 ++ .../transaction/entity/StatisticalParam.java | 40 +++ .../transaction/entity/StatisticalResult.java | 13 + .../transaction/mapper/StatisticalMapper.java | 71 ++++ .../service/TransactionService.java | 14 + .../serviceImpl/StatisticalServiceImpl.java | 90 +++++ .../controller/ScCipherMachineController.java | 230 +++++++++++++ .../controller/StatusController.java | 48 +++ .../cipherunit/entity/ScCipherMachine.java | 134 ++++++++ .../cipherunit/entity/ScCipherMachineVo.java | 30 ++ .../sysconf/cipherunit/enums/ConfigEnum.java | 29 ++ .../sysconf/cipherunit/enums/LibEnum.java | 28 ++ .../sysconf/cipherunit/enums/RetEnum.java | 35 ++ .../mapper/ScCipherMachineMapper.java | 18 + .../service/ScCipherMachineService.java | 38 +++ .../impl/ScCipherMachineServiceImpl.java | 78 +++++ .../cipherunit/utils/IniFileUpdater.java | 62 ++++ .../dict/controller/ScDictController.java | 140 ++++++++ .../dict/controller/ScDictDataController.java | 171 ++++++++++ .../modules/sysconf/dict/entity/ScDict.java | 75 ++++ .../sysconf/dict/entity/ScDictData.java | 78 +++++ .../sysconf/dict/mapper/ScDictDataMapper.java | 62 ++++ .../sysconf/dict/mapper/ScDictMapper.java | 25 ++ .../dict/service/IScDictDataService.java | 48 +++ .../sysconf/dict/service/IScDictService.java | 22 ++ .../serviceimpl/ScDictDataServiceImpl.java | 116 +++++++ .../dict/serviceimpl/ScDictServiceImpl.java | 76 +++++ .../paramconf/mapper/ParamConfMapper.java | 6 +- .../mapper/user/ScPermissionMapper.xml | 70 ++++ .../mapper/user/ScPositionMapper.xml | 20 ++ .../resources/mapper/user/ScUserMapper.xml | 128 +++++++ .../mapper/user/ScUserRoleMapper.xml | 31 ++ .../mapper/user/StatisticalMapper.xml | 217 ++++++++++++ 39 files changed, 2713 insertions(+), 9 deletions(-) create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/common/CaptchaController.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/jna/CipherJna.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/controller/TransactionController.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalConstant.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalParam.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalResult.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/mapper/StatisticalMapper.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/service/TransactionService.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/serviceImpl/StatisticalServiceImpl.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/controller/ScCipherMachineController.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/controller/StatusController.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/entity/ScCipherMachine.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/entity/ScCipherMachineVo.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/ConfigEnum.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/LibEnum.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/RetEnum.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/mapper/ScCipherMachineMapper.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/service/ScCipherMachineService.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/service/impl/ScCipherMachineServiceImpl.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/utils/IniFileUpdater.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/controller/ScDictController.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/controller/ScDictDataController.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/entity/ScDict.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/entity/ScDictData.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/mapper/ScDictDataMapper.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/mapper/ScDictMapper.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/service/IScDictDataService.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/service/IScDictService.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/serviceimpl/ScDictDataServiceImpl.java create mode 100644 chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/serviceimpl/ScDictServiceImpl.java create mode 100644 chsm-web-manage/src/main/resources/mapper/user/ScPermissionMapper.xml create mode 100644 chsm-web-manage/src/main/resources/mapper/user/ScPositionMapper.xml create mode 100644 chsm-web-manage/src/main/resources/mapper/user/ScUserMapper.xml create mode 100644 chsm-web-manage/src/main/resources/mapper/user/ScUserRoleMapper.xml create mode 100644 chsm-web-manage/src/main/resources/mapper/user/StatisticalMapper.xml diff --git a/chsm-web-manage/pom.xml b/chsm-web-manage/pom.xml index 9839df1..04984ec 100644 --- a/chsm-web-manage/pom.xml +++ b/chsm-web-manage/pom.xml @@ -92,7 +92,7 @@ net.java.dev.jna jna - 4.5.2 + 5.5.0 io.swagger diff --git a/chsm-web-manage/src/main/java/com/sunyard/chsm/dto/KeyTemplateDTO.java b/chsm-web-manage/src/main/java/com/sunyard/chsm/dto/KeyTemplateDTO.java index 02152b3..4a013d6 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/chsm/dto/KeyTemplateDTO.java +++ b/chsm-web-manage/src/main/java/com/sunyard/chsm/dto/KeyTemplateDTO.java @@ -21,7 +21,7 @@ public abstract class KeyTemplateDTO { public static class Query extends PageQuery { /** * 密钥类型 - * @see com.sunyard.ssp.web.enums.KeyCategory#getCode() + * @see com.sunyard.chsm.enums.KeyCategory#getCode() */ private String keyType; } @@ -63,24 +63,23 @@ public abstract class KeyTemplateDTO { private String name; /** * 密钥类型 - * @see com.sunyard.ssp.web.enums.KeyCategory#getCode() + * @see com.sunyard.chsm.enums.KeyCategory#getCode() */ @NotBlank(message = "密钥类型不能为空") private String keyType; /** * 密钥算法 - * @see com.sunyard.ssp.web.enums.KeyAlg#getCode() + * @see com.sunyard.chsm.enums.KeyAlg#getCode() */ @NotBlank(message = "密钥算法不能为空") private String keyAlg; /** * 密钥长度 */ - @NotNull(message = "密钥长度不能为空") private Integer keyLength; /** * 密钥用途 - * @see com.sunyard.ssp.web.enums.KeyUsage#getCode() + * @see com.sunyard.chsm.enums.KeyUsage#getCode() */ @NotEmpty(message = "密钥用途不能为空") private List keyUsages; diff --git a/chsm-web-manage/src/main/java/com/sunyard/config/MyBatisConfig.java b/chsm-web-manage/src/main/java/com/sunyard/config/MyBatisConfig.java index ee71d4f..962b3fd 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/config/MyBatisConfig.java +++ b/chsm-web-manage/src/main/java/com/sunyard/config/MyBatisConfig.java @@ -1,12 +1,18 @@ package com.sunyard.config; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.apache.ibatis.mapping.DatabaseIdProvider; +import org.apache.ibatis.mapping.VendorDatabaseIdProvider; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import javax.sql.DataSource; +import java.util.Properties; + /** * @author liulu * @since 2024/10/28 @@ -27,4 +33,24 @@ public class MyBatisConfig { return interceptor; } + @Bean + public DatabaseIdProvider databaseIdProvider() { + VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider(){ + @Override + public String getDatabaseId(DataSource dataSource) { + String databaseId = super.getDatabaseId(dataSource); + if (StrUtil.isBlank(databaseId)){ + throw new NullPointerException("多数据库标识为空,请检查数据库连接情况"); + } + return databaseId; + } + }; + Properties properties = new Properties(); + properties.put("Oracle","oracle"); + properties.put("MySQL","mysql"); + properties.put("DM","dm"); + databaseIdProvider.setProperties(properties); + return databaseIdProvider; + } + } diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/common/CaptchaController.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/common/CaptchaController.java new file mode 100644 index 0000000..c031f6e --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/common/CaptchaController.java @@ -0,0 +1,60 @@ +package com.sunyard.ssp.modules.common; + +import com.sunyard.ssp.common.Result; +import com.sunyard.ssp.common.vo.Captcha; +import com.sunyard.ssp.utils.CreateVerifyCode; +import com.sunyard.ssp.utils.ResultUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +/** + * @author Exrickx + */ +@Api(description = "验证码接口") +@RequestMapping("/common/captcha") +@RestController +@Transactional +@Slf4j +public class CaptchaController { + + @Autowired + private StringRedisTemplate redisTemplate; + + @RequestMapping(value = "/init",method = RequestMethod.GET) + @ApiOperation(value = "初始化验证码") + public Result initCaptcha() { + + String captchaId = UUID.randomUUID().toString().replace("-",""); + String code = new CreateVerifyCode().randomStr(4); + Captcha captcha = new Captcha(); + captcha.setCaptchaId(captchaId); + captcha.setCode(code); + //缓存验证码 + redisTemplate.opsForValue().set(captchaId,code,3L, TimeUnit.MINUTES); + return new ResultUtil().setData(captcha); + } + + @RequestMapping(value = "/draw/{captchaId}", method = RequestMethod.GET) + @ApiOperation(value = "根据验证码ID获取图片") + public void drawCaptcha(@PathVariable("captchaId") String captchaId, HttpServletResponse response) throws IOException { + + // 得到验证码 生成指定验证码 + String code=redisTemplate.opsForValue().get(captchaId); + CreateVerifyCode vCode = new CreateVerifyCode(116,36,4,10,code); + vCode.write(response.getOutputStream()); + } + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/jna/CipherJna.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/jna/CipherJna.java new file mode 100644 index 0000000..a65957f --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/jna/CipherJna.java @@ -0,0 +1,319 @@ +package com.sunyard.ssp.modules.jna; + +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.ptr.PointerByReference; +import com.sunyard.ssp.modules.sysconf.cipherunit.enums.LibEnum; + +/** + * @author sunyard + */ +public interface CipherJna extends Library { + + /** + * 加载动态库 + */ + CipherJna INSTANCE = Native.load(LibEnum.LIB_NAME.getValue(), CipherJna.class); + + + /** + * 打开设备 + * @param phDeviceHandle 设备句柄 + * @return int 响应码 + */ + int SDF_OpenDevice(PointerByReference phDeviceHandle); + + /** + * 关闭设备 + * @param hDeviceHandle 设备句柄 + * @return int 响应码 + */ + int SDF_CloseDevice(Pointer hDeviceHandle); + + /** + * 打开会话 + * @param hDeviceHandle 设备句柄 + * @param phSessionHandle 会话句柄 + * @return int 响应码 + */ + int SDF_OpenSession(Pointer hDeviceHandle, PointerByReference phSessionHandle); + + int SDF_ImportKey(Pointer hSessionHandle, byte[] pucKey, int uiKeyLen, PointerByReference phKeyhandle); + + /** + * 关闭会话 + * @param hSessionHandle 会话句柄 + * @return int 响应码 + */ + int SDF_CloseSession(Pointer hSessionHandle); + + /** + * 生成随机数 + * @param hSessionHandle 会话句柄 + * @param uiLength 生成随机数长度 + * @param pucRandom 存放随机数容器 + * @return int 响应码 + */ + int SDF_GenerateRandom(Pointer hSessionHandle, int uiLength, byte[] pucRandom); + + /** + * 对称加密 + * @param phSessionHandle 会话句柄 + * @param hKeyHandle 密钥句柄 + * @param uiAlgID 算法标识 + * @param pucIV IV数据 + * @param pucData 待加密数据 + * @param pucDataLength 待加密数据长度 + * @param pucEncData 存放密文容器 + * @param pucEncDataLength 密文长度 + * @return int 响应码 + */ + int SDF_Encrypt( + Pointer phSessionHandle, + Pointer hKeyHandle, + int uiAlgID, + byte[] pucIV, + byte[] pucData, + int pucDataLength, + byte[] pucEncData, + IntByReference pucEncDataLength + ); + + /** + * 对称解密 + * @param phSessionHandle 会话句柄 + * @param hKeyHandle 密钥句柄 + * @param uiAlgID 算法标识 + * @param pucIV IV数据 + * @param purEncData 指向密文数据的指针 + * @param encDataLength 密文数据长度 + * @param pucData 输出明文数据 + * @param pucDataLength 输出明文数据长度 + * @return int 响应码 + */ + int SDF_Decrypt( + Pointer phSessionHandle, + Pointer hKeyHandle, + int uiAlgID, + byte[] pucIV, + byte[] purEncData, + int encDataLength, + byte[] pucData, + IntByReference pucDataLength + ); + + + /** + * 生成ECC密钥对 + * @param phSessionHandle 会话句柄 + * @param uiAlgID 算法标识 + * @param uiKeyBits 密钥长度 + * @param pucPublicKey 输出的ECC公钥结构 + * @param pucPrivateKey 输出的ECC私钥结构 + * @return int 响应码 + */ + int SDF_GenerateKeyPair_ECC( + Pointer phSessionHandle, + int uiAlgID, + int uiKeyBits, + byte[] pucPublicKey, + byte[] pucPrivateKey + ); + + /** + * 生成会话密钥并用外部ECC公钥加密输出,输出密钥句柄 + * @param hSessionHandle 会话句柄 + * @param uiKeyBits 密钥长度 + * @param uiAlgID 算法标识 + * @param pucPublicKey ECC公钥结构 + * @param pucKey 密钥密文 + * @param phKeyHandle 密钥句柄 + * @return int 响应码 + */ + int SDF_GenerateKeyWithEPK_ECC( + Pointer hSessionHandle, + int uiKeyBits, + int uiAlgID, + byte[] pucPublicKey, + byte[] pucKey, + PointerByReference phKeyHandle + ); + + + /** + * 杂凑运算初始化 + * @param phSessionHandle 会话句柄 + * @param uiAlgID 算法标识 + * @param pucPublicKey ECC公钥结构 + * @param pucID 签名者的ID值 + * @param pucIDlength 签名者ID的长度 + * @return int 响应码 + */ + int SDF_HashInit(Pointer phSessionHandle, int uiAlgID, byte[] pucPublicKey, String pucID, int pucIDlength); + + /** + * 多包杂凑运算 + * @param phSessionHandle 会话句柄 + * @param pucData 输入的数据明文 + * @param uiDataLength 输入的数据明文长度 + * @return int 响应码 + */ + int SDF_HashUpdate( + Pointer phSessionHandle, // 使用IntByReference,因为SessionHandle可能是引用类型的 + byte[] pucData, // 输入的明文数据作为字节数组 + int uiDataLength // 明文数据长度 + ); + + /** + * MAC 计算 + * @param phSessionHandle 会话句柄 + * @param hKeyHadnle 密钥句柄 + * @param uiAlgID 算法标识 + * @param pucIV IV数据 + * @param purData 待计算MAC的数据 + * @param pucDatalength 待计算MAC的数据长度 + * @param pucMAC MAC值 + * @param pucMACLength MAC值长度 + * @return + */ + int SDF_CalculateMAC(Pointer phSessionHandle, + Pointer hKeyHadnle, + int uiAlgID, + byte[] pucIV, + byte[] purData, + int pucDatalength, + byte[] pucMAC, + IntByReference pucMACLength); + + /** + * 杂凑运算结束 + * @param phSessionHandle 会话句柄 + * @param pucHash 杂凑结果 + * @param pucHashLength 杂凑结果长度 + * @return int 响应码 + */ + int SDF_HashFinal(Pointer phSessionHandle, byte[] pucHash, IntByReference pucHashLength); + + /** + * 外部ECC签名 + * @param phSessionHandle 会话句柄 + * @param uiAlgID 算法标识 + * @param pucPublicKey ECC公钥结构 + * @param pucData 输入的数据明文 + * @param pucDataLength 输入的数据明文长度 + * @param pucECCSignature 输出的签名值数据 + * @return int 响应码 + */ + int SDF_ExternalSign_ECC( + Pointer phSessionHandle, + int uiAlgID, + byte[] pucPublicKey, + byte[] pucData, + int pucDataLength, + byte[] pucECCSignature + ); + + /** + * 外部ECC验签 + * @param phSessionHandle 会话句柄 + * @param uiAlgID 算法标识 + * @param pucPublicKey ECC公钥结构 + * @param pucData 输入的数据明文 + * @param pucDataLength 输入的数据明文长度 + * @param pucECCSignature 输入的签名值数据 + * @return int 响应码 + */ + int SDF_ExternalVerify_ECC(Pointer phSessionHandle, int uiAlgID, byte[] pucPublicKey, byte[] pucData, int pucDataLength, byte[] pucECCSignature); + + /** + * 密钥加密 + * @param phSessionHandle 会话句柄 + * @param uiAlgID 算法标识 + * @param pucPublicKey ECC公钥结构 + * @param pucData 输入的数据明文 + * @param pucDatalength 输入的数据明文长度 + * @param pucEncData 输出的密文数据 + * @return int 响应码 + */ + int SDF_ExternalEncrypt_ECC(Pointer phSessionHandle, int uiAlgID, byte[] pucPublicKey, byte[] pucData, int pucDatalength, byte[] pucEncData); + + /** + * 密钥解密 + * @param phSessionHandle 会话句柄 + * @param uiAlgID 算法标识 + * @param pucPrivateKey ECC私钥结构 + * @param pucEncData 输入的密文数据 + * @param pucDataOut 输出的数据明文 + * @param pucDatalength 输出的数据明文长度 + * @return int 响应码 + */ + int SDF_ExternalDecrypt_ECC(Pointer phSessionHandle, int uiAlgID, byte[] pucPrivateKey, byte[] pucEncData, byte[] pucDataOut, IntByReference pucDatalength); + + /** + * 生成密钥协商数据 + * @param phSessionHandle 会话句柄 + * @param uiISKIndex 密码设备存储私钥的索引值 + * @param uiKeyBits 要求协商的密钥长度 + * @param pucSponsorID 参与密钥协商的发起方ID值 + * @param uiSponsorIDLength 发起方ID长度 + * @param pucSponsorPublicKey 返回的发起方ECC公钥结构 + * @param pucSponsorTmpPublicKey 返回的发起方临时ECC公钥结构 + * @param phAgreementHandle 返回的协商对象,用于计算协商密钥 + * @return int 响应码 + */ + int SDF_GenerateAgreementDataWithECC(Pointer phSessionHandle, int uiISKIndex, int uiKeyBits, + String pucSponsorID, int uiSponsorIDLength, + byte[] pucSponsorPublicKey, byte[] pucSponsorTmpPublicKey, + PointerByReference phAgreementHandle); + + /** + * 生成密钥协商数据并计算密钥 + * @param phSessionHandle 会话句柄 + * @param uiISKIndex 密码设备存储私钥的索引值 + * @param uiKeyBits 要求协商的密钥长度 + * @param pucResponseID 参与密钥协商的响应方ID值 + * @param uiResponseIDLength 响应方ID长度 + * @param pucSponsorID 参与密钥协商的发起方ID值 + * @param uiSponsorIDLength 发起方ID长度 + * @param pucSponsorPublicKey 发起方ECC公钥结构 + * @param pucSponsorTmpPublicKey 发起方临时ECC公钥结构 + * @param pucResponsePublicKey 响应方ECC公钥结构 + * @param pucResponseTmpPublicKey 响应方临时ECC公钥结构 + * @param phKeyhandle 返回的密钥句柄 + * @return + */ + int SDF_GenerateAgreementDataAndKeyWithECC( + Pointer phSessionHandle, + int uiISKIndex, + int uiKeyBits, + String pucResponseID, + int uiResponseIDLength, + String pucSponsorID, + int uiSponsorIDLength, + byte[] pucSponsorPublicKey, + byte[] pucSponsorTmpPublicKey, + byte[] pucResponsePublicKey, + byte[] pucResponseTmpPublicKey, + PointerByReference phKeyhandle + ); + + /** + * 获取私钥访问权 + * @param phSessionHandle 会话句柄 + * @param uiKeyIndex 密码设备存储私钥的索引值 + * @param pucPassword 使用私钥权限的标识码 + * @param uiPwdLength 私钥访问控制码长度,不少于8字节 + * @return int 响应码 + */ + int SDF_GetPrivateKeyAccessRight(Pointer phSessionHandle, int uiKeyIndex, String pucPassword, int uiPwdLength); + + /** + * 释放私钥访问权 + * @param phSessionHandle 会话句柄 + * @param uiKeyIndex 密码设备存储私钥的索引值 + * @return int 响应码 + */ + int SDF_ReleasePrivateKeyAccessRight(Pointer phSessionHandle, int uiKeyIndex); +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/controller/TransactionController.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/controller/TransactionController.java new file mode 100644 index 0000000..db768d2 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/controller/TransactionController.java @@ -0,0 +1,35 @@ +package com.sunyard.ssp.modules.monitor.transaction.controller; + +import com.sunyard.ssp.common.Result; +import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalParam; +import com.sunyard.ssp.modules.monitor.transaction.service.TransactionService; +import com.sunyard.ssp.utils.ResultUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@Slf4j +@Api(description = "系统监控-交易监控", tags = "系统监控-交易监控") +@RequestMapping("/monitor/transaction") +@Transactional +public class TransactionController { + + @Autowired + private TransactionService transactionService; + + @RequestMapping(value = "/getTransactionData", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "获得交易监控的数据") + public Result getStaticInfo(@ModelAttribute StatisticalParam statisticalParam) { + Object result = transactionService.getTransactionData(statisticalParam); + return new ResultUtil().setData(result); + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalConstant.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalConstant.java new file mode 100644 index 0000000..3ec5a45 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalConstant.java @@ -0,0 +1,28 @@ +package com.sunyard.ssp.modules.monitor.transaction.entity; + +public interface StatisticalConstant { + + String STATISTICAL_METHOD_PIE_CHART = "pieChart"; + + String STATISTICAL_METHOD_LINE_CHART_TIME_INTERVAL= "lineChartTimeInterval"; + + String STATISTICAL_METHOD_LINE_CHART_KEY_GROUP = "lineChartKeyGroup"; + + String TIME_MONTH_FORMAT = "yyyy-mm"; + + String TIME_MONTH_WEAK_FORMAT = "yyyy-mm-w"; + + String TIME_WEAK_FORMAT = "yyyy-iw"; + + String TIME_DAY_FORMAT = "yyyy-mm-dd"; + + String TIME_HOUR_FORMAT = "yyyy-mm-dd HH24"; + + String TIME_METHOD_MONTH = "month"; + + String TIME_METHOD_DAY = "day"; + + String TIME_METHOD_WEAK = "week"; + + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalParam.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalParam.java new file mode 100644 index 0000000..a4b49e4 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalParam.java @@ -0,0 +1,40 @@ +package com.sunyard.ssp.modules.monitor.transaction.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDate; + +@Data +@ApiModel(value="", description="统计参数") +public class StatisticalParam { + + @ApiModelProperty(value = "统计方式(lineChartTimeInterval-不带对称秘钥 lineChartKeyGroup-带对称秘钥)(必传)") + private String statisticalMethod; + + @ApiModelProperty(value = "服务名") + private String server; + + @ApiModelProperty(value = "渠道Id") + private String channelId; + + @ApiModelProperty(value = "方案Id") + private String solutionNumber; + + @ApiModelProperty(value = "秘钥类型") + private String group; + + @ApiModelProperty(value = "统计时间") + private String inputStatisticalTime; + + private LocalDate sqlStatisticalTime; + + @ApiModelProperty(value = "统计时间方式(月-month 周-weak 日-day)(必传)") + private String timeInterval; + + private String timeIntervalFormat; + + private String sqlStatisticalTimeFormat; + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalResult.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalResult.java new file mode 100644 index 0000000..bc5befd --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/entity/StatisticalResult.java @@ -0,0 +1,13 @@ +package com.sunyard.ssp.modules.monitor.transaction.entity; + +import lombok.Data; + +@Data +public class StatisticalResult { + + private Integer successCount; + + private Integer failCount; + + private String statisticalTime; +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/mapper/StatisticalMapper.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/mapper/StatisticalMapper.java new file mode 100644 index 0000000..520865a --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/mapper/StatisticalMapper.java @@ -0,0 +1,71 @@ +package com.sunyard.ssp.modules.monitor.transaction.mapper; + +import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalParam; +import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalResult; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface StatisticalMapper { + +// @Select("") + StatisticalResult countPieChart(@Param("statisticalParam") StatisticalParam statisticalParam); + +// @Select("") + List countLineChartByTimeInterval(@Param("statisticalParam") StatisticalParam statisticalParam); + +// @Select("") + List countLineChartByKeyGroup(@Param("statisticalParam") StatisticalParam statisticalParam); +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/service/TransactionService.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/service/TransactionService.java new file mode 100644 index 0000000..710c487 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/service/TransactionService.java @@ -0,0 +1,14 @@ +package com.sunyard.ssp.modules.monitor.transaction.service; + +import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalParam; + +public interface TransactionService { + + /** + * 统计 + * @param statisticalParam + * @return + */ + Object getTransactionData(StatisticalParam statisticalParam); + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/serviceImpl/StatisticalServiceImpl.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/serviceImpl/StatisticalServiceImpl.java new file mode 100644 index 0000000..09e44cb --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/monitor/transaction/serviceImpl/StatisticalServiceImpl.java @@ -0,0 +1,90 @@ +package com.sunyard.ssp.modules.monitor.transaction.serviceImpl; + +import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalConstant; +import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalParam; +import com.sunyard.ssp.modules.monitor.transaction.entity.StatisticalResult; +import com.sunyard.ssp.modules.monitor.transaction.mapper.StatisticalMapper; +import com.sunyard.ssp.modules.monitor.transaction.service.TransactionService; +import com.sunyard.ssp.utils.DateUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@Transactional +@Slf4j +public class StatisticalServiceImpl implements TransactionService { + + @Autowired + private StatisticalMapper statisticalMapper; + + @Override + public Object getTransactionData(StatisticalParam statisticalParam) { + statisticalParam = dealWithTimeFormat(statisticalParam); + if (StatisticalConstant.STATISTICAL_METHOD_PIE_CHART.equals(statisticalParam.getStatisticalMethod())) { + return statisticalMapper.countPieChart(statisticalParam); + } else if (StatisticalConstant.STATISTICAL_METHOD_LINE_CHART_TIME_INTERVAL.equals(statisticalParam.getStatisticalMethod())) { + List statisticalResults = statisticalMapper.countLineChartByTimeInterval(statisticalParam); + return dealReturnTimeFormat(statisticalResults, statisticalParam.getTimeInterval()); + } else if (StatisticalConstant.STATISTICAL_METHOD_LINE_CHART_KEY_GROUP.equals(statisticalParam.getStatisticalMethod())) { + List statisticalResults = statisticalMapper.countLineChartByKeyGroup(statisticalParam); + return dealReturnTimeFormat(statisticalResults, statisticalParam.getTimeInterval()); + } else { + return null; + } + } + + /** + * 处理时间格式 + * + * @param statisticalParam + * @return + */ + private StatisticalParam dealWithTimeFormat(StatisticalParam statisticalParam) { + statisticalParam.setSqlStatisticalTime(DateUtil.StringToDate(statisticalParam.getInputStatisticalTime())); + if (StatisticalConstant.TIME_METHOD_MONTH.equals(statisticalParam.getTimeInterval())) { + statisticalParam.setSqlStatisticalTimeFormat(StatisticalConstant.TIME_MONTH_FORMAT); + statisticalParam.setTimeIntervalFormat(StatisticalConstant.TIME_MONTH_WEAK_FORMAT); + } else if (StatisticalConstant.TIME_METHOD_WEAK.equals(statisticalParam.getTimeInterval())) { + statisticalParam.setSqlStatisticalTimeFormat(StatisticalConstant.TIME_WEAK_FORMAT); + statisticalParam.setTimeIntervalFormat(StatisticalConstant.TIME_DAY_FORMAT); + } else { + statisticalParam.setSqlStatisticalTimeFormat(StatisticalConstant.TIME_DAY_FORMAT); + statisticalParam.setTimeIntervalFormat(StatisticalConstant.TIME_HOUR_FORMAT); + } + return statisticalParam; + } + + /** + * 出来返回时间 + * + * @param statisticalResults + * @param timeMethod + * @return + */ + private List dealReturnTimeFormat(List statisticalResults, String timeMethod) { + if (StatisticalConstant.TIME_METHOD_MONTH.equals(timeMethod)) { + statisticalResults.forEach(statisticalResult -> { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(statisticalResult.getStatisticalTime()); + stringBuilder.setCharAt(7, '月'); + stringBuilder.insert(8, " 第"); + stringBuilder.append("周"); + statisticalResult.setStatisticalTime(stringBuilder.toString()); + }); + } else if (StatisticalConstant.TIME_METHOD_DAY.equals(timeMethod)) { + statisticalResults.forEach(statisticalResult -> { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(statisticalResult.getStatisticalTime()); + stringBuilder.append("时"); + statisticalResult.setStatisticalTime(stringBuilder.toString()); + }); + } else { + + } + return statisticalResults; + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/controller/ScCipherMachineController.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/controller/ScCipherMachineController.java new file mode 100644 index 0000000..4e28a96 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/controller/ScCipherMachineController.java @@ -0,0 +1,230 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.controller; + +import com.sun.jna.Pointer; +import com.sun.jna.ptr.PointerByReference; +import com.sunyard.proto.Util; +import com.sunyard.ssp.common.Result; +import com.sunyard.ssp.common.annotation.AuditControllerLog; +import com.sunyard.ssp.common.exception.SspwebException; +import com.sunyard.ssp.modules.jna.CipherJna; +import com.sunyard.ssp.modules.sysconf.cipherunit.entity.ScCipherMachine; +import com.sunyard.ssp.modules.sysconf.cipherunit.entity.ScCipherMachineVo; +import com.sunyard.ssp.modules.sysconf.cipherunit.enums.RetEnum; +import com.sunyard.ssp.modules.sysconf.cipherunit.service.ScCipherMachineService; +import com.sunyard.ssp.modules.sysconf.cipherunit.utils.IniFileUpdater; +import com.sunyard.ssp.modules.sysconf.paramconf.entity.ParamConf; +import com.sunyard.ssp.modules.sysconf.paramconf.service.IParamConfService; +import com.sunyard.ssp.utils.ResultUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + + +/** + * 密码部件管理控制层 + * + * @author admin + */ +@Controller +@Slf4j +@Api(description = "关键密码部件管理接口", tags = "关键密码部件管理") +@RequestMapping("/cipherMachine") +public class ScCipherMachineController { + @Autowired + private ScCipherMachineService scCipherMachineService; + + @Autowired + private IParamConfService iParamConfService; + +// @ControllerLog("获取关键密码部件部件") + @RequestMapping(value = "/query", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取关键密码部件部件") + public Result queryCipherMachine() { + log.info("get请求 /cipherMachine/query接口"); + ScCipherMachineVo scCipherMachineVo = scCipherMachineService.queryCipherMachine(); + log.info("获取密码部件功能响应结果:{}", scCipherMachineVo); + return new ResultUtil().setData(scCipherMachineVo); + } + +// @ControllerLog("添加关键密码部件配置") + @RequestMapping(value = "/add", method = RequestMethod.POST) + @AuditControllerLog(description = "添加关键密码部件配置",operateType = "增加") + @ResponseBody + @ApiOperation(value = "添加关键密码部件配置") + public Result addCipherMachine(@RequestBody ScCipherMachine scCipherMachine) { + try { + ScCipherMachine scCipherMachineVo = scCipherMachineService.addCipherMachine(scCipherMachine); + IniFileUpdater.updateIniFile(scCipherMachine.getIp(),(String) scCipherMachine.getPort()); + return new ResultUtil<>().setData(scCipherMachineVo); + } catch (SspwebException e) { + return new ResultUtil().setErrorMsg(e.getMsg()); + } + } +// @ControllerLog("检测") + @RequestMapping(value = "/detection", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "检测") + public Result detection() { + int size = 16; + PointerByReference phDeviceHandle = new PointerByReference(); + PointerByReference phSessionHandle = new PointerByReference(); + int code = RetEnum.SUCCESS.getCode(); + try { + + // 打开设备 + int ret = CipherJna.INSTANCE.SDF_OpenDevice(phDeviceHandle); + if (ret != code) { + return new ResultUtil().setErrorMsg(ret, "打开设备失败,密码模块初始化失败"); + } + Pointer hDeviceHandle = phDeviceHandle.getValue(); + // 打开会话 + ret = CipherJna.INSTANCE.SDF_OpenSession(hDeviceHandle, phSessionHandle); + if (ret != code) { + return new ResultUtil().setErrorMsg(ret, "打开会话失败,密码模块初始化失败"); + } + byte[] nakedSign = new byte[size]; + // 生成随机数 + ret = CipherJna.INSTANCE.SDF_GenerateRandom(phSessionHandle.getValue(), 16, nakedSign); + if (ret != code) { + return new ResultUtil().setErrorMsg(ret, "生成随机数失败,密码模块初始化失败"); + } + // 返回结果 + String result = Util.bytes2HexString(nakedSign); + log.info("检测功能响应结果:{}", result); + return new ResultUtil<>().setData(result); + } catch (SspwebException e) { + return new ResultUtil().setErrorMsg(e.getMsg()); + } catch (Throwable e) { + log.error("检测异常:" + e); + return new ResultUtil().setErrorMsg("密码模块初始化失败"); + } finally { + // 关闭会话 + if (phSessionHandle.getValue() != null) { + int ret = CipherJna.INSTANCE.SDF_CloseSession(phSessionHandle.getValue()); + if (ret != code) { + log.error("关闭会话失败:{}", ret); + } + } + // 关闭设备 + if (phDeviceHandle.getValue() != null) { + int ret = CipherJna.INSTANCE.SDF_CloseDevice(phDeviceHandle.getValue()); + if (ret != code) { + log.error("关闭设备失败:{}", ret); + } + } + } + } + +// @ControllerLog("密码模块初始化") + @RequestMapping(value = "/init", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "密码模块初始化") + public Result init() { + int size = 16; + PointerByReference phDeviceHandle = new PointerByReference(); + PointerByReference phSessionHandle = new PointerByReference(); + int code = RetEnum.SUCCESS.getCode(); + try { + +// // 打开设备 +// int ret = CipherJna.INSTANCE.SDF_OpenDevice(phDeviceHandle); +// if (ret != code) { +// return new ResultUtil().setErrorMsg(ret, "打开设备失败"); +// } +// Pointer hDeviceHandle = phDeviceHandle.getValue(); +// // 打开会话 +// ret = CipherJna.INSTANCE.SDF_OpenSession(hDeviceHandle, phSessionHandle); +// if (ret != code) { +// return new ResultUtil().setErrorMsg(ret, "打开会话失败"); +// } +// byte[] nakedSign = new byte[size]; +// // 生成随机数 +// ret = CipherJna.INSTANCE.SDF_GenerateRandom(phSessionHandle.getValue(), 16, nakedSign); +// if (ret != code) { +// return new ResultUtil().setErrorMsg(ret, "生成随机数失败"); +// } +// // 返回结果 +// String result = Util.bytes2HexString(nakedSign); +// log.info("检测功能响应结果:{}", result); + ParamConf paramConf = iParamConfService.selectByKey("initStatus"); + if (paramConf != null) { + paramConf.setValue("1"); + iParamConfService.updateById(paramConf); + } + return new ResultUtil<>().setSuccessMsg("初始化成功"); + } catch (SspwebException e) { + return new ResultUtil().setErrorMsg(e.getMsg()); + } catch (Throwable e) { + log.error("检测异常:" + e); + return new ResultUtil().setErrorMsg("检测失败"); + } finally { + // 关闭会话 + if (phSessionHandle.getValue() != null) { + int ret = CipherJna.INSTANCE.SDF_CloseSession(phSessionHandle.getValue()); + if (ret != code) { + log.error("关闭会话失败:{}", ret); + } + } + // 关闭设备 + if (phDeviceHandle.getValue() != null) { + int ret = CipherJna.INSTANCE.SDF_CloseDevice(phDeviceHandle.getValue()); + if (ret != code) { + log.error("关闭设备失败:{}", ret); + } + } + } + } + +// @ControllerLog("密码模块初始化状态获取") + @RequestMapping(value = "/init/status", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "密码模块初始化状态获取") + public Result initStatus() { + ParamConf paramConf = iParamConfService.selectByKey("initStatus"); + if (paramConf != null) { + return new ResultUtil<>().setData(paramConf.getValue()); + } else { + return new ResultUtil<>().setErrorMsg("获取初始化状态失败"); + } + } + + +// @ControllerLog("编辑关键密码部件配置") + @RequestMapping(value = "/edit", method = RequestMethod.PUT) + @AuditControllerLog(description = "编辑关键密码部件配置",operateType = "修改") + @ResponseBody + @ApiOperation(value = "编辑关键密码部件配置") + public Result editCipherMachine(@RequestBody ScCipherMachine scCipherMachine) { + try { + log.info("put请求 /cipherMachine/edit 请求参数:{}", scCipherMachine); + ScCipherMachine scCipherMachineVo = scCipherMachineService.editCipherMachine(scCipherMachine); + log.info("编辑关键密码部件功能响应结果:{}", scCipherMachineVo); + IniFileUpdater.updateIniFile(scCipherMachine.getIp(),(String) scCipherMachine.getPort()); + return new ResultUtil<>().setData(scCipherMachineVo); + } catch (SspwebException e) { + return new ResultUtil().setErrorMsg(e.getMsg()); + } + } +// @ControllerLog("删除关键密码部件配置") + @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE) + @AuditControllerLog(description = "删除关键密码部件配置",operateType = "删除") + @ResponseBody + @ApiOperation(value = "删除关键密码部件配置") + public Result deleteCipherMachine(@PathVariable("id") Long id) { + try { + log.info("delete请求 /cipherMachine/delete 请求参数:{}", id); + scCipherMachineService.deleteCipherMachine(id); + return new ResultUtil<>().setData(null); + } catch (SspwebException e) { + return new ResultUtil().setErrorMsg(e.getMsg()); + } + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/controller/StatusController.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/controller/StatusController.java new file mode 100644 index 0000000..f788669 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/controller/StatusController.java @@ -0,0 +1,48 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.controller; + +import com.sunyard.ssp.common.Result; +import com.sunyard.ssp.modules.sysconf.paramconf.entity.ParamConf; +import com.sunyard.ssp.modules.sysconf.paramconf.service.IParamConfService; +import com.sunyard.ssp.utils.ResultUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@Slf4j +@Api(description = "密码部件管理接口", tags = "全局密码模块状态显示") +@RequestMapping("/status") +public class StatusController { + @Autowired + IParamConfService iParamConfService; + +// @ControllerLog("获取全局密码模块状态") + @RequestMapping(value = "/query", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取密码模块状态") + public Result queryStatus() { + /* + * status = 0 初始化状态; status = 1 密码主管状态; status = 2 密码主管状态; status = 3 自测试状态; status = 4 错误报警状态; + * status = 5 核准状态; status = 6 关键参数输入状态;status = 7 核准状态 + */ + ParamConf status = iParamConfService.selectByKey("status"); + return new ResultUtil().setData(status.getValue()); + } + +// @ControllerLog("修改全局密码模块状态") + @RequestMapping(value = "/set", method = RequestMethod.PUT) + @ResponseBody + @ApiOperation(value = "修改密码模块状态") + public Result setStatus(@RequestParam("value") String value) { + ParamConf status = iParamConfService.selectByKey("status"); + status.setValue(value); + iParamConfService.updateById(status); + return new ResultUtil().setData(status.getValue()); + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/entity/ScCipherMachine.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/entity/ScCipherMachine.java new file mode 100644 index 0000000..be1ee32 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/entity/ScCipherMachine.java @@ -0,0 +1,134 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 密码部件配置 + * @TableName SC_CIPHER_MACHINE + */ +@TableName(value ="SC_CIPHER_MACHINE") +@Data +public class ScCipherMachine implements Serializable { + /** + * 主键id + */ + @TableId(type = IdType.AUTO) + private Object id; + + /** + * ip + */ + private String ip; + + /** + * 端口号 + */ + private Object port; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + /** + * 预留字段1 + */ + private String c1; + + /** + * 预留字段2 + */ + private String c2; + + /** + * 预留字段3 + */ + private String c3; + + /** + * 预留字段4 + */ + private String c4; + + /** + * 预留字段5 + */ + private String c5; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + ScCipherMachine other = (ScCipherMachine) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getIp() == null ? other.getIp() == null : this.getIp().equals(other.getIp())) + && (this.getPort() == null ? other.getPort() == null : this.getPort().equals(other.getPort())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) + && (this.getC1() == null ? other.getC1() == null : this.getC1().equals(other.getC1())) + && (this.getC2() == null ? other.getC2() == null : this.getC2().equals(other.getC2())) + && (this.getC3() == null ? other.getC3() == null : this.getC3().equals(other.getC3())) + && (this.getC4() == null ? other.getC4() == null : this.getC4().equals(other.getC4())) + && (this.getC5() == null ? other.getC5() == null : this.getC5().equals(other.getC5())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getIp() == null) ? 0 : getIp().hashCode()); + result = prime * result + ((getPort() == null) ? 0 : getPort().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + result = prime * result + ((getC1() == null) ? 0 : getC1().hashCode()); + result = prime * result + ((getC2() == null) ? 0 : getC2().hashCode()); + result = prime * result + ((getC3() == null) ? 0 : getC3().hashCode()); + result = prime * result + ((getC4() == null) ? 0 : getC4().hashCode()); + result = prime * result + ((getC5() == null) ? 0 : getC5().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", ip=").append(ip); + sb.append(", port=").append(port); + sb.append(", createTime=").append(createTime); + sb.append(", updateTime=").append(updateTime); + sb.append(", c1=").append(c1); + sb.append(", c2=").append(c2); + sb.append(", c3=").append(c3); + sb.append(", c4=").append(c4); + sb.append(", c5=").append(c5); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/entity/ScCipherMachineVo.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/entity/ScCipherMachineVo.java new file mode 100644 index 0000000..a8f12ab --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/entity/ScCipherMachineVo.java @@ -0,0 +1,30 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.io.Serializable; + +/** + * 密码部件vo类 + * @author admin + */ +@Data +public class ScCipherMachineVo implements Serializable{ + /** + * 主键id + */ + @TableId(type = IdType.AUTO) + private Object id; + + /** + * ip + */ + private String ip; + + /** + * 端口号 + */ + private Object port; +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/ConfigEnum.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/ConfigEnum.java new file mode 100644 index 0000000..7193a74 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/ConfigEnum.java @@ -0,0 +1,29 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.enums; + +/** + * c配置文件的枚举类 + * @author admin + */ +public enum ConfigEnum { + /** + * 配置项头 + */ + TARGET_SECTION("DEV-0") + , + /** + * 配置文件路径 + */ + CONFIG_FILE_PATH("./config/SYD_SDF.ini"); + + /** + * 配置项 + */ + private final String value; + + ConfigEnum(String value) { + this.value = value; + } + public String getValue() { + return value; + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/LibEnum.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/LibEnum.java new file mode 100644 index 0000000..796afdf --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/LibEnum.java @@ -0,0 +1,28 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.enums; + +/** + * 动态库枚举类 + * @author admin + */ +public enum LibEnum { + + /** + * 动态库路径 + */ + LIB_PATH("./lib"), + LIB_NAME("sydsdf"), + LIB_CONFIG_FILE("./config/SYD_SDF.ini"); + + /** + * 值 + */ + private final String value; + + LibEnum(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/RetEnum.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/RetEnum.java new file mode 100644 index 0000000..d57cfa7 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/enums/RetEnum.java @@ -0,0 +1,35 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.enums; + +/** + * 响应码枚举类 + * @author admin + */ +public enum RetEnum { + /** + * 成功 + */ + SUCCESS(0, "成功"); + + /** + * 响应码 + */ + private final int code; + /** + * 响应描述 + */ + private final String desc; + + RetEnum(int code, String desc) { + this.code = code; + this.desc = desc; + } + + public int getCode() { + return code; + } + + + public String getDesc() { + return desc; + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/mapper/ScCipherMachineMapper.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/mapper/ScCipherMachineMapper.java new file mode 100644 index 0000000..6591e06 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/mapper/ScCipherMachineMapper.java @@ -0,0 +1,18 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.sunyard.ssp.modules.sysconf.cipherunit.entity.ScCipherMachine; + +/** +* @author admin +* @description 针对表【SC_CIPHER_MACHINE(密码部件配置)】的数据库操作Mapper +* @createDate 2024-05-16 14:20:57 +* @Entity com.sunyard.ssp.modules.sysconf.cipherunit.entity.ScCipherMachine +*/ +public interface ScCipherMachineMapper extends BaseMapper { + +} + + + + diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/service/ScCipherMachineService.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/service/ScCipherMachineService.java new file mode 100644 index 0000000..3a71937 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/service/ScCipherMachineService.java @@ -0,0 +1,38 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.sunyard.ssp.modules.sysconf.cipherunit.entity.ScCipherMachine; +import com.sunyard.ssp.modules.sysconf.cipherunit.entity.ScCipherMachineVo; + +/** +* @author admin +* @description 针对表【SC_CIPHER_MACHINE(密码部件配置)】的数据库操作Service +* @createDate 2024-05-16 14:20:57 +*/ +public interface ScCipherMachineService extends IService { + /** + * 查询密码部件配置 + * @return 密码部件vo类 ScCipherMachine + */ + ScCipherMachineVo queryCipherMachine(); + + /** + * 添加密码部件配置 + * @param scCipherMachine 密码部件配置 + * @return scCipherMachine 添加后的结果 + */ + ScCipherMachine addCipherMachine(ScCipherMachine scCipherMachine); + + /** + * 修改密码部件配置 + * @param scCipherMachine 密码部件配置 + * @return scCipherMachine 添加后的结果 + */ + ScCipherMachine editCipherMachine(ScCipherMachine scCipherMachine); + + /** + * 删除密码部件配置 + * @param id 要删除的id + */ + void deleteCipherMachine(Long id); +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/service/impl/ScCipherMachineServiceImpl.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/service/impl/ScCipherMachineServiceImpl.java new file mode 100644 index 0000000..e9882bb --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/service/impl/ScCipherMachineServiceImpl.java @@ -0,0 +1,78 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.sunyard.ssp.common.exception.SspwebException; +import com.sunyard.ssp.modules.sysconf.cipherunit.entity.ScCipherMachine; +import com.sunyard.ssp.modules.sysconf.cipherunit.entity.ScCipherMachineVo; +import com.sunyard.ssp.modules.sysconf.cipherunit.mapper.ScCipherMachineMapper; +import com.sunyard.ssp.modules.sysconf.cipherunit.service.ScCipherMachineService; +import org.springframework.stereotype.Service; + +import java.util.Objects; + +/** +* @author admin +* @description 针对表【SC_CIPHER_MACHINE(密码部件配置)】的数据库操作Service实现 +* @createDate 2024-05-16 14:20:57 +*/ +@Service +public class ScCipherMachineServiceImpl extends ServiceImpl + implements ScCipherMachineService{ + + @Override + public ScCipherMachineVo queryCipherMachine() { + ScCipherMachine scCipherMachine = baseMapper.selectOne(new QueryWrapper<>()); + ScCipherMachineVo scCipherMachineVo = new ScCipherMachineVo(); + BeanUtil.copyProperties(scCipherMachine,scCipherMachineVo); + return scCipherMachineVo; + } + + @Override + public ScCipherMachine addCipherMachine(ScCipherMachine scCipherMachine) { + if (Objects.isNull(scCipherMachine)){ + throw new SspwebException("必要参数不能为空"); + } + Long count = baseMapper.selectCount(new QueryWrapper<>()); + if (count>=1){ + throw new SspwebException("已经存在密码部件配置"); + } + int insert = baseMapper.insert(scCipherMachine); + if (insert<=0){ + throw new SspwebException("添加失败"); + } + return scCipherMachine; + } + + @Override + public ScCipherMachine editCipherMachine(ScCipherMachine scCipherMachine) { + if (Objects.isNull(scCipherMachine)){ + throw new SspwebException("必要参数不能为空"); + } + Long count = baseMapper.selectCount(new QueryWrapper().eq("id",scCipherMachine.getId())); + if (count<1){ + throw new SspwebException("不存在密码部件配置"); + } + int update = baseMapper.updateById(scCipherMachine); + if (update<=0){ + throw new SspwebException("修改失败"); + } + return scCipherMachine; + } + + @Override + public void deleteCipherMachine(Long id) { + if (Objects.isNull(id)){ + throw new SspwebException("必要参数不能为空"); + } + int i = baseMapper.deleteById(id); + if (i<1){ + throw new SspwebException("删除失败"); + } + } +} + + + + diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/utils/IniFileUpdater.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/utils/IniFileUpdater.java new file mode 100644 index 0000000..f24ec59 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/cipherunit/utils/IniFileUpdater.java @@ -0,0 +1,62 @@ +package com.sunyard.ssp.modules.sysconf.cipherunit.utils; + +import com.sunyard.ssp.modules.sysconf.cipherunit.enums.ConfigEnum; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * ini文件更新工具类 + * + */ +public class IniFileUpdater { + + /** + * 更新ini文件 + * + * @param ip IP地址 + * @param port 端口号 + */ + public static void updateIniFile(String ip, String port) { + String filePath = ConfigEnum.CONFIG_FILE_PATH.getValue(); + String targetSection = ConfigEnum.TARGET_SECTION.getValue(); + try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { + StringBuilder content = new StringBuilder(); + String line; + boolean sectionFound = false; + + while ((line = reader.readLine()) != null) { + if (line.trim().startsWith("[" + targetSection + "]")) { + // 找到目标部分 + sectionFound = true; + content.append(line).append(System.lineSeparator()); + + // 修改[DEV-0]部分的配置 + content.append("IP=").append(ip).append(System.lineSeparator()); + content.append("PORT=").append(port).append(System.lineSeparator()); + // 添加回车符 + content.append(System.lineSeparator()); + } else if (sectionFound && line.trim().startsWith("[")) { + // 目标部分已处理完毕,遇到下一个部分 + sectionFound = false; + content.append(line).append(System.lineSeparator()); + } else if (!sectionFound) { + // 非目标部分 + content.append(line).append(System.lineSeparator()); + } + } + + // 将修改后的内容写回原始文件 + FileWriter writer = new FileWriter(filePath); + writer.write(content.toString()); + writer.close(); + + System.out.println("INI file updated successfully."); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/controller/ScDictController.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/controller/ScDictController.java new file mode 100644 index 0000000..4d37307 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/controller/ScDictController.java @@ -0,0 +1,140 @@ +package com.sunyard.ssp.modules.sysconf.dict.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.sunyard.ssp.common.PageVo; +import com.sunyard.ssp.common.Result; +import com.sunyard.ssp.common.annotation.AuditControllerLog; +import com.sunyard.ssp.common.constant.SqlConstant; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDict; +import com.sunyard.ssp.modules.sysconf.dict.service.IScDictDataService; +import com.sunyard.ssp.modules.sysconf.dict.service.IScDictService; +import com.sunyard.ssp.utils.ResultUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.List; +import java.util.Map; + +/** + *

+ * 前端控制器 + *

+ * + * @author fyc + * @since 2020-03-13 + */ +@Controller +@Slf4j +@RequestMapping("/sysconf/scDict") +@Transactional +@Api(description = "系统配置-字典管理", tags = "系统配置-字典管理") +public class ScDictController { + + @Autowired + IScDictService iScDictService; + + @Autowired + IScDictDataService iScDictDataService; + + @RequestMapping(value = "/search", method = RequestMethod.GET) + @ResponseBody + @ApiOperation("根据字典关键字查询") + public Result> search(@RequestParam String key) { + List scDicts = iScDictService.selectByKey(key); + return new ResultUtil>().setData(scDicts); + + } + + @RequestMapping(value = "/getById", method = RequestMethod.GET) + @ResponseBody + @ApiOperation("根据ID获取字典") + public Result get(@RequestParam String id) { + ScDict entity = iScDictService.getById(id); + return new ResultUtil().setData(entity); + } + + @RequestMapping(value = "/getAll", method = RequestMethod.GET) + @ResponseBody + @ApiOperation("获取所以字典(不分页)") + public Result> getAll() { + + List list = iScDictService.list(new QueryWrapper().orderByAsc(SqlConstant.DB_SORT_COLUMN)); + return new ResultUtil>().setData(list); + } + + @RequestMapping(value = "/page", method = RequestMethod.GET) + @ResponseBody + @ApiOperation("获取所有字典(分页)") + public Result> getByPage(@ModelAttribute PageVo page) { + Page data = new Page<>(page.getPageNumber(), page.getPageSize()); + IPage iPage = iScDictService.page(data); + return new ResultUtil>().setData(iPage); + } + + @RequestMapping(value = "/save", method = RequestMethod.POST) + @ResponseBody + @ApiOperation("添加字典") + @AuditControllerLog(description = "添加字典", operateType = "新增") + public Result save(@ModelAttribute ScDict entity) { + Map checkData = iScDictService.checkInputForm(entity); + if (!(Boolean) checkData.get("status")) { + return new ResultUtil().setErrorMsg((String) checkData.get("message")); + } + try { + boolean e = iScDictService.save(entity); + if (!e) { + return new ResultUtil().setErrorMsg("添加失败"); + } + return new ResultUtil().setSuccessMsg("添加成功"); + } catch (DuplicateKeyException e) { + return new ResultUtil().setErrorMsg("字典名称或字典类型已经存在"); + } + } + + @RequestMapping(value = "/update", method = RequestMethod.PUT) + @ResponseBody + @ApiOperation("更新字典") + @AuditControllerLog(description = "更新字典", operateType = "更新") + public Result> update(@ModelAttribute ScDict entity) { + Map checkData = iScDictService.checkInputForm(entity); + if (!(Boolean) checkData.get("status")) { + return new ResultUtil>().setErrorMsg((String) checkData.get("message")); + } + try { + boolean e = iScDictService.updateById(entity); + if (!e) { + return new ResultUtil>().setErrorMsg("更新失败"); + } + return new ResultUtil>().setSuccessMsg("更新成功"); + } catch (DuplicateKeyException e) { + return new ResultUtil>().setErrorMsg("字典名称或字典类型已经存在"); + } + } + + @RequestMapping(value = "/deleteByIds", method = RequestMethod.DELETE) + @ResponseBody + @ApiOperation("删除字典(批量)") + @AuditControllerLog(description = "删除字典", operateType = "删除") + public Result delAllByIds(@RequestParam String[] ids) { + + for (String id : ids) { + iScDictService.removeById(id); + iScDictDataService.deleteByDictId(Long.valueOf(id)); + } + return new ResultUtil().setSuccessMsg("批量通过id删除数据成功"); + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/controller/ScDictDataController.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/controller/ScDictDataController.java new file mode 100644 index 0000000..b7ebee3 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/controller/ScDictDataController.java @@ -0,0 +1,171 @@ +package com.sunyard.ssp.modules.sysconf.dict.controller; + + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.sunyard.ssp.common.PageVo; +import com.sunyard.ssp.common.Result; +import com.sunyard.ssp.common.annotation.AuditControllerLog; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDictData; +import com.sunyard.ssp.modules.sysconf.dict.service.IScDictDataService; +import com.sunyard.ssp.modules.sysconf.dict.service.IScDictService; +import com.sunyard.ssp.utils.ResultUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + *

+ * 前端控制器 + *

+ * + * @author fyc + * @since 2020-03-13 + */ +@Controller +@Slf4j +@RequestMapping("/sysconf/scDictData") +@Transactional +@Api(description = "系统配置-字典数据管理",tags = "系统配置-字典数据管理") +public class ScDictDataController { + + @Autowired + IScDictDataService iScDictDataService; + + @Autowired + IScDictService iScDictService; + + @RequestMapping(value = "/getById",method = RequestMethod.GET) + @ResponseBody + @ApiOperation("根据Id获取字典数据") + public Result get(@RequestParam String id){ + + ScDictData entity = iScDictDataService.getById(id); + log.info("根据Id获取字典数据"); + return new ResultUtil().setData(entity); + } + + @RequestMapping(value = "/selectByType",method = RequestMethod.GET) + @ResponseBody + @ApiOperation("根据类型获取字典数据") + public Result> selectByType(@RequestParam String type){ + List list = iScDictDataService.selectByDictType(type); + log.info("根据类型获取字典数据"); + return new ResultUtil>().setData(list); + } + + @RequestMapping(value = "/selectVersion",method = RequestMethod.GET) + @ResponseBody + @ApiOperation("根据类型获取系统版本号") + public Result selectVersion(){ + List list = iScDictDataService.selectByDictType("version"); + if (Objects.isNull(list)||list.size()<=0) { + return new ResultUtil<>().setErrorMsg("未获取到版本号"); + } + ScDictData scDictData = list.get(0); + log.info("根据类型获取字典数据"); + return new ResultUtil<>().setData(scDictData.getValue()); + } + + @ApiOperation("条件查询接口") + @RequestMapping(value = "/queryList",method = RequestMethod.POST) + @ResponseBody + public Result> queryList(@RequestBody ScDictData scDictData){ + try { + IPage scDictDataIPage = iScDictDataService.queryList(scDictData); + log.info("条件查询接口"); + return new ResultUtil>().setData(scDictDataIPage); + }catch (Exception e){ + log.error(e.getMessage()); + return null; + } + } + + @RequestMapping(value = "/getAll",method = RequestMethod.GET) + @ResponseBody + @ApiOperation("获取全部字典数据(不分页)") + public Result> getAll(){ + List list = iScDictDataService.list(); + return new ResultUtil>().setData(list); + + } + + @RequestMapping(value = "/page",method = RequestMethod.GET) + @ResponseBody + @ApiOperation("获取全部字典数据(分页)") + public Result> getByPage(@ModelAttribute PageVo page){ + Page data = new Page<>( page.getPageNumber(),page.getPageSize()); + IPage iPage = iScDictDataService.page(data); + return new ResultUtil>().setData(iPage); + } + + @RequestMapping(value = "/save",method = RequestMethod.POST) + @ResponseBody + @ApiOperation("添加字典数据") + @AuditControllerLog(description = "添加字典数据",operateType = "新增") + public Result save(@ModelAttribute ScDictData entity){ + Map checkData = iScDictDataService.checkInputData(entity); + if(!(Boolean)checkData.get("status")){ + return new ResultUtil().setErrorMsg((String)checkData.get("message")); + } + entity.setCreateTime(LocalDateTime.now()); + try { + boolean e = iScDictDataService.save(entity); + if (!e) { + return new ResultUtil().setErrorMsg("添加失败"); + } + return new ResultUtil().setSuccessMsg("添加成功"); + }catch (DuplicateKeyException e){ + return new ResultUtil().setErrorMsg("数据名称已经存在"); + } + } + + @RequestMapping(value = "/update",method = RequestMethod.PUT) + @ResponseBody + @ApiOperation("更新字典数据") + @AuditControllerLog(description = "更新字典数据",operateType = "更新") + public Result> update(@ModelAttribute ScDictData entity){ + Map checkData = iScDictDataService.checkInputData(entity); + if(!(Boolean)checkData.get("status")){ + return new ResultUtil>().setErrorMsg((String)checkData.get("message")); + } + try { + boolean e = iScDictDataService.updateById(entity); + if (!e) { + return new ResultUtil>().setErrorMsg("更新失败"); + } + return new ResultUtil>().setSuccessMsg("更新成功"); + }catch (DuplicateKeyException e){ + return new ResultUtil>().setErrorMsg("数据名称已经存在"); + } + } + + @RequestMapping(value = "/deleteByIds",method = RequestMethod.DELETE) + @ResponseBody + @ApiOperation("根据字典数据ID删除数据(批量)") + @AuditControllerLog(description = "删除字典数据",operateType = "删除") + public Result delAllByIds(@RequestParam String[] ids){ + + for(String id:ids){ + iScDictDataService.removeById(id); + } + return new ResultUtil().setSuccessMsg("批量通过id删除数据成功"); + } + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/entity/ScDict.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/entity/ScDict.java new file mode 100644 index 0000000..44a7138 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/entity/ScDict.java @@ -0,0 +1,75 @@ +package com.sunyard.ssp.modules.sysconf.dict.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.List; + +/** + *

+ * + *

+ * + * @author fyc + * @since 2020-03-13 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("SC_DICT") +public class ScDict implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId("ID") + private Long id; + + @TableField("CREATE_TIME") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + /** + * 备注 + */ + @TableField("DESCRIPTION") + private String description; + + /** + * 字典名称 + */ + @TableField("TITLE") + private String title; + + /** + * 字典类型 + */ + @TableField("TYPE") + private String type; + + /** + * 作用范围(仅对平台创建字典有效) 1 全部 2 隐藏 + */ + @TableField("SCOPE") + private Integer scope; + + /** + * 排序值 + */ + @TableField("SORT_ORDER") + private Double sortOrder; + + /** + * 字典数据,非表映射关系 + */ + @TableField(exist = false) + private List scDictDataList; + + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/entity/ScDictData.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/entity/ScDictData.java new file mode 100644 index 0000000..7ec94a0 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/entity/ScDictData.java @@ -0,0 +1,78 @@ +package com.sunyard.ssp.modules.sysconf.dict.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.sunyard.ssp.common.PageVo; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * + *

+ * + * @author fyc + * @since 2020-03-13 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("SC_DICT_DATA") +@ApiModel(value="", description="") +public class ScDictData extends PageVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId("ID") + private Long id; + + @ApiModelProperty(value = "创建时间") + @TableField("CREATE_TIME") +// @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + /** + * 备注 + */ + @TableField("DESCRIPTION") + private String description; + + /** + * 所属字典 + */ + @TableField("DICT_ID") + private Long dictId; + + /** + * 排序值 + */ + @TableField("SORT_ORDER") + private Double sortOrder; + + /** + * 是否启用 0启用 -1禁用 + */ + @TableField("STATUS") + private Long status; + + /** + * 数据名称 + */ + @TableField("TITLE") + private String title; + + /** + * 数据值 + */ + @TableField("VALUE") + private String value; + + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/mapper/ScDictDataMapper.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/mapper/ScDictDataMapper.java new file mode 100644 index 0000000..72f1586 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/mapper/ScDictDataMapper.java @@ -0,0 +1,62 @@ +package com.sunyard.ssp.modules.sysconf.dict.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDictData; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + *

+ * Mapper 接口 + *

+ * + * @author fyc + * @since 2020-03-13 + */ +@Repository +public interface ScDictDataMapper extends BaseMapper { + + /** + * 按条件查询数据字典 + * @param iPage 分页 + * @param scDictData 条件参数 + * @return + */ + @Select("") + List queryList(IPage iPage,@Param("scDictData") ScDictData scDictData); + + /** + * 根据字典id 获取字典数据 + * @param scDictId 字典边ID + * @return + */ + @Select("") + List selectByDictId(@Param("scDictId") Long scDictId); + + + @Delete("") + void deleteByDictId(@Param("scDictId") Long scDictId); +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/mapper/ScDictMapper.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/mapper/ScDictMapper.java new file mode 100644 index 0000000..12427b4 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/mapper/ScDictMapper.java @@ -0,0 +1,25 @@ +package com.sunyard.ssp.modules.sysconf.dict.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDict; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Repository; + +/** + *

+ * Mapper 接口 + *

+ * + * @author fyc + * @since 2020-03-13 + */ +@Repository +public interface ScDictMapper extends BaseMapper { + + @Select("") + ScDict selectByType(@Param("type") String type); + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/service/IScDictDataService.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/service/IScDictDataService.java new file mode 100644 index 0000000..5fe4e45 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/service/IScDictDataService.java @@ -0,0 +1,48 @@ +package com.sunyard.ssp.modules.sysconf.dict.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDictData; + +import java.util.List; +import java.util.Map; + +/** + *

+ * 服务类 + *

+ * + * @author fyc + * @since 2020-03-13 + */ +public interface IScDictDataService extends IService { + + /** + * 获取字典数据列表 + * @param scDictData 查询参数 + * @return + */ + IPage queryList(ScDictData scDictData); + + /** + * 根据字典类型返回字典数据 + * @param type 字典类型 + * @return + */ + List selectByDictType(String type); + + + /** + * 通过字典ID删除字典数据 + * @param dictId + */ + void deleteByDictId(Long dictId); + + /** + * 检测传入数据 + * @param scDictData + * @return + */ + Map checkInputData(ScDictData scDictData); + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/service/IScDictService.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/service/IScDictService.java new file mode 100644 index 0000000..3ec7632 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/service/IScDictService.java @@ -0,0 +1,22 @@ +package com.sunyard.ssp.modules.sysconf.dict.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDict; + +import java.util.List; +import java.util.Map; + +/** + *

+ * 服务类 + *

+ * + * @author fyc + * @since 2020-03-13 + */ +public interface IScDictService extends IService { + + List selectByKey(String key); + + Map checkInputForm(ScDict scDict); +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/serviceimpl/ScDictDataServiceImpl.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/serviceimpl/ScDictDataServiceImpl.java new file mode 100644 index 0000000..e2aa115 --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/serviceimpl/ScDictDataServiceImpl.java @@ -0,0 +1,116 @@ +package com.sunyard.ssp.modules.sysconf.dict.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.sunyard.ssp.common.constant.SqlConstant; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDict; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDictData; +import com.sunyard.ssp.modules.sysconf.dict.mapper.ScDictDataMapper; +import com.sunyard.ssp.modules.sysconf.dict.mapper.ScDictMapper; +import com.sunyard.ssp.modules.sysconf.dict.service.IScDictDataService; +import com.sunyard.ssp.utils.CommonUtil; +import lombok.extern.slf4j.Slf4j; +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.HashMap; +import java.util.List; +import java.util.Map; + +/** + *

+ * 服务实现类 + *

+ * + * @author fyc + * @since 2020-03-13 + */ +@Slf4j +@Service +@Transactional +public class ScDictDataServiceImpl extends ServiceImpl implements IScDictDataService { + + @Autowired + private ScDictDataMapper scDictDataMapper; + + @Autowired + private ScDictMapper scDictMapper; + + @Override + public IPage queryList(ScDictData scDictData){ + if(scDictData.getSort()==null || scDictData.getSort()==""){ + scDictData.setSort(SqlConstant.DB_SORT_COLUMN); + }else { + String sort = CommonUtil.underscoreName(scDictData.getSort()); + scDictData.setSort(sort); + } + Page scDictDataPage = new Page<>(scDictData.getPageNumber(),scDictData.getPageSize()); + IPage scDictDataIPage = scDictDataPage.setRecords(scDictDataMapper.queryList(scDictDataPage,scDictData)); + return scDictDataIPage; + } + + @Override + public List selectByDictType(String type) { + ScDict scDict = scDictMapper.selectByType(type); + List scDictDataList = new ArrayList<>(); + if(scDict != null){ + scDictDataList = scDictDataMapper.selectByDictId(scDict.getId()); + } + return scDictDataList; + } + + @Override + public void deleteByDictId(Long dictId) { + scDictDataMapper.deleteByDictId(dictId); + } + + @Override + public Map checkInputData(ScDictData scDictData) { + Map result = new HashMap(); + + //检测数据是否为空 + if(scDictData == null){ + result.put("status",false); + result.put("message","传入数据不合法"); + return result; + } + + //检测字段是否为空 + if(scDictData.getDictId()==null || scDictData.getTitle()== null || scDictData.getValue()==null){ + result.put("status",false); + result.put("message","传入数据不合法"); + return result; + } + + //检测字典标题是否超过上限 + if(scDictData.getTitle().length()>255){ + result.put("status",false); + result.put("message","名称字符超过上限"); + return result; + } + + //检测字典数据值是否超过上限 + if(scDictData.getValue().length()>255){ + result.put("status",false); + result.put("message","数据值字符超过上限"); + return result; + } + + //检测描述是否超过上限 + if(scDictData.getDescription()!=null) { + if (scDictData.getDescription().length() > 255) { + result.put("status", false); + result.put("message", "备注字符超过上限"); + return result; + } + } + + result.put("status",true); + return result; + } + + +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/serviceimpl/ScDictServiceImpl.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/serviceimpl/ScDictServiceImpl.java new file mode 100644 index 0000000..3b4e2bb --- /dev/null +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/dict/serviceimpl/ScDictServiceImpl.java @@ -0,0 +1,76 @@ +package com.sunyard.ssp.modules.sysconf.dict.serviceimpl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.sunyard.ssp.common.constant.SqlConstant; +import com.sunyard.ssp.modules.sysconf.dict.entity.ScDict; +import com.sunyard.ssp.modules.sysconf.dict.mapper.ScDictMapper; +import com.sunyard.ssp.modules.sysconf.dict.service.IScDictService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + *

+ * 服务实现类 + *

+ * + * @author fyc + * @since 2020-03-13 + */ +@Slf4j +@Service +@Transactional +public class ScDictServiceImpl extends ServiceImpl implements IScDictService { + + @Autowired + private ScDictMapper scDictMapper; + + @Override + public List selectByKey(String key) { + QueryWrapper queryWrapper = new QueryWrapper().like("TITLE",key).orderByAsc(SqlConstant.DB_SORT_COLUMN); + List dicts = scDictMapper.selectList(queryWrapper); + return dicts; + } + + @Override + public Map checkInputForm(ScDict scDict) { + Map result = new HashMap(); + //是否为空检测 + if(scDict == null){ + result.put("status",false); + result.put("message","传入数据不合法"); + return result; + } + + //字典名称长度检测 + if(scDict.getTitle().length()>255){ + result.put("status",false); + result.put("message","字典名称字符超出上限"); + return result; + } + //字典类型长度检测 + if(scDict.getType().length()>255){ + result.put("status",false); + result.put("message","字典类型字符超出上限"); + return result; + } + + //备注字符长度检测 + if(scDict.getDescription()!=null) { + if (scDict.getDescription().length() > 255) { + result.put("status", false); + result.put("message", "备注字符超出上限"); + return result; + } + } + + result.put("status",true); + return result; + } +} diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/paramconf/mapper/ParamConfMapper.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/paramconf/mapper/ParamConfMapper.java index ec16605..b76c96f 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/paramconf/mapper/ParamConfMapper.java +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/modules/sysconf/paramconf/mapper/ParamConfMapper.java @@ -19,9 +19,9 @@ import java.util.List; @Repository public interface ParamConfMapper extends BaseMapper { -// @Select("") + @Select("") ParamConf selectByKey(@Param("key")String key); @Select("