diff --git a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java index 44ca89df30..3f23ee88c8 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java @@ -9,10 +9,7 @@ import com.epmet.dto.result.UserTokenResultDTO; import com.epmet.service.ThirdLoginService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -219,4 +216,16 @@ public class ThirdLoginController { ValidatorUtils.validateEntity(formDTO); return new Result().ok(thirdLoginService.govLoginInternalDing(formDTO)); } + + /** + * 根据免登授权码, 获取登录用户身份 + * + * @param authCode 烟台认证中心 授权码 + * @return + */ + @PostMapping("sso-govlogin-yantai/{authCode}") + public Result yantaiSSOLogin(@PathVariable(value = "authCode") String authCode) { + return new Result().ok(thirdLoginService.yanTaiSSOLogin(authCode)); + } + } diff --git a/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java b/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java index dff5e129e5..f939656023 100644 --- a/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java +++ b/epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java @@ -117,4 +117,11 @@ public interface ThirdLoginService { * @return */ UserTokenResultDTO govLoginInternalDing(DingAppLoginMdFormDTO formDTO); + + /** + * desc:烟台sso根据authCode 获取本系统token + * @param authCode + * @return + */ + UserTokenResultDTO yanTaiSSOLogin(String authCode); } diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/GovWebServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/GovWebServiceImpl.java index 92e1de27a5..91828cb561 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/GovWebServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/GovWebServiceImpl.java @@ -95,6 +95,7 @@ public class GovWebServiceImpl implements GovWebService, ResultDataResolver { //5.生成token存到redis并返回 UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); + userTokenResultDTO.setCustomerId(formDTO.getCustomerId()); userTokenResultDTO.setToken(this.packagingUserToken(formDTO, resultDTO.getUserId())); return userTokenResultDTO; diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java index 447e2cb1d5..3d2c2ebee0 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java @@ -27,6 +27,8 @@ import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.security.password.PasswordUtils; import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.*; +import com.epmet.commons.tools.utils.api.yt.YantaiApi; +import com.epmet.commons.tools.utils.api.yt.YantaiSSOUser; import com.epmet.commons.tools.validator.PhoneValidatorUtils; import com.epmet.constant.AuthHttpUrlConstant; import com.epmet.constant.SmsTemplateConstant; @@ -35,10 +37,7 @@ import com.epmet.dto.dingres.DingUserDetailDTO; import com.epmet.dto.dingres.V2UserGetuserinfoResDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; -import com.epmet.feign.EpmetMessageOpenFeignClient; -import com.epmet.feign.EpmetUserFeignClient; -import com.epmet.feign.EpmetUserOpenFeignClient; -import com.epmet.feign.GovOrgOpenFeignClient; +import com.epmet.feign.*; import com.epmet.jwt.JwtTokenProperties; import com.epmet.jwt.JwtTokenUtils; import com.epmet.redis.CaptchaRedis; @@ -98,6 +97,8 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol private EpmetUserFeignClient epmetUserFeignClient; @Autowired private GovWebService govWebService; + @Autowired + private ThirdOpenFeignClient thirdOpenFeignClient; /** * @param formDTO @@ -1078,6 +1079,20 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol return govWebService.loginByThirdPlatform(loginGovParam); } + @Override + public UserTokenResultDTO yanTaiSSOLogin(String authCode) { + YantaiSSOUser ssoUserInfo = YantaiApi.getLoginToken(authCode); + if (ssoUserInfo== null){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"登录失败-sso获取用户失败","登录失败-sso获取用户失败"); + } + + GovWebLoginFormDTO loginGovParam = new GovWebLoginFormDTO(); + loginGovParam.setCustomerId("1535072605621841922"); + loginGovParam.setPhone(ssoUserInfo.getMobile()); + + return govWebService.loginByThirdPlatform(loginGovParam); + } + /** * 最原始的企业内部应用开发,不授权给产品服务商 * @param miniAppId diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 49ab921e0f..63f27f195b 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -537,6 +537,14 @@ public class RedisKeys { return rootPrefix.concat("gov:staff:").concat(customerId).concat(StrConstant.COLON).concat(staffId); } + public static String getCustomerAllStaffInfoKey(String customerId) { + return rootPrefix.concat("gov:allCustomerStaff:").concat(customerId).concat(StrConstant.COLON).concat("*"); + } + + public static String getCustomerStaffInfoKeyByMobile(String customerId,String mobile) { + return rootPrefix.concat("gov:allCustomerStaff:").concat(customerId).concat(StrConstant.COLON).concat(mobile); + } + /** * @description 网格信息 * diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java index 37904be02b..66abe790f3 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java @@ -9,6 +9,7 @@ import com.epmet.commons.tools.feign.CommonAggFeignClient; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.redis.common.bean.CustomerStaffInfoCache; +import com.epmet.commons.tools.redis.common.bean.CustomerStaffInfoDTOCache; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import lombok.extern.slf4j.Slf4j; @@ -138,4 +139,32 @@ public class CustomerStaffRedis { return customerStaffRedis.redisUtils.delete(key); } + /** + * Desc: 拉取烟台用户时使用。 + * 根据客户ID 手机号获取工作人员信息,没有返回null + * @param customerId + * @param mobile + * @author zxc + * @date 2022/10/19 14:18 + */ + public static CustomerStaffInfoDTOCache getStaffInfoByMobile(String customerId, String mobile){ + String key = RedisKeys.getCustomerStaffInfoKeyByMobile(customerId, mobile); + Map roleMap = customerStaffRedis.redisUtils.hGetAll(key); + if (!CollectionUtils.isEmpty(roleMap)) { + return ConvertUtils.mapToEntity(roleMap, CustomerStaffInfoDTOCache.class); + } + return null; + } + + /** + * Desc: 【烟台用】删除所有工作人员信息 + * @param customerId + * @author zxc + * @date 2022/10/19 14:28 + */ + public static void delAllCustomerStaff(String customerId){ + String key = RedisKeys.getCustomerAllStaffInfoKey(customerId); + customerStaffRedis.redisUtils.deleteByPattern(key); + } + } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/CustomerStaffInfoDTOCache.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/CustomerStaffInfoDTOCache.java new file mode 100644 index 0000000000..70d5da942a --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/CustomerStaffInfoDTOCache.java @@ -0,0 +1,133 @@ +package com.epmet.commons.tools.redis.common.bean; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @Author zxc + * @DateTime 2022/10/19 14:26 + * @DESC + */ +@Data +public class CustomerStaffInfoDTOCache implements Serializable { + + private static final long serialVersionUID = 6967736754443092229L; + + + /** + * ID + */ + private String id; + + /** + * 关联User表的主键Id + */ + private String userId; + + /** + * 账户 + */ + private String userAccount; + + /** + * 真实姓名 + */ + private String realName; + + /** + * 性别0.未知,1男,2.女 + */ + private Integer gender; + + /** + * 邮箱 + */ + private String email; + + /** + * 手机号-唯一键 + */ + private String mobile; + + /** + * 地址 + */ + private String address; + + /** + * 删除标识 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + + /** + * fulltime专职parttime兼职 + */ + private String workType; + + /** + * 头像 + */ + private String headPhoto; + + /** + * inactive未激活,active已激活 + */ + private String activeFlag; + + /** + * 激活时间 + */ + private Date activeTime; + + /** + * 未禁用enable,已禁用diabled + */ + private String enableFlag; + + /** + * 客户id + */ + private String customerId; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 登录密码 + */ + private String password; + + /** + * 身份证号 + */ + private String idCard; +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/OrgData.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/OrgData.java new file mode 100644 index 0000000000..6c7ea48907 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/OrgData.java @@ -0,0 +1,79 @@ + +package com.epmet.commons.tools.utils.api.yt; + +import lombok.Data; + +import java.io.Serializable; + +/** + * desc:组织机构数据 实体类 + * @author liujianjun + */ +@Data +public class OrgData implements Serializable { + + /** + * 联系人姓名 + */ + private String contact; + /** + * 联系电话号码 + */ + private String contactTelephoneNumber; + + /** + * 详细地址 + */ + private String detailAddress; + + /** + * 组织机构第一名称 + */ + private String firstNameOfOrganization; + + /** + * 组织机构全称 + */ + private String nameOfOrganization; + + /** + * 排序号码 + */ + private String orderNumber; + + /** + * 组织机构简称 + */ + private String organizatioNabbreviation; + + /** + * 组织机构ID + */ + private String organizationId; + + /** + * 组织机构级别 + */ + private String organizationLevel; + + /** + * 组织机构路径 + */ + private String organizationPath; + + /** + * 组织机构类型 + */ + private String organizationType; + /** + * 注册类型 + */ + private String registrationType; + /** + * 统一社会信用代码 + */ + private String unifiedSocialCreditId; + + + +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/SM4UtilsForYanTai.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/SM4UtilsForYanTai.java new file mode 100644 index 0000000000..6c2ca8c60a --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/SM4UtilsForYanTai.java @@ -0,0 +1,199 @@ +package com.epmet.commons.tools.utils.api.yt; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.codec.binary.Base64; +import org.bouncycastle.jce.provider.BouncyCastleProvider; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.Security; + +/** + * 烟台的认证中心-国密sm4加解密 + */ +public class SM4UtilsForYanTai { + private static String SM4_KEY = "yaweisoftware@xy"; + //编码格式 + private static final Charset encryptCharset = StandardCharsets.UTF_8; + + public enum Algorithm { + SM4("SM4","SM4","国密四,key长16byte"); + private String keyAlgorithm; + private String transformation; + private String description;//描述 + Algorithm(String keyAlgorithm, String transformation, String description) { + this.keyAlgorithm = keyAlgorithm; + this.transformation = transformation; + this.description = description; + } + public String getKeyAlgorithm() { + return this.keyAlgorithm; + } + public String getTransformation() { + return this.transformation; + } + public String getDescription() { + return this.description; + } + } + + private static final String PROVIDER_NAME = "BC"; + static { + Security.addProvider(new BouncyCastleProvider()); + } + + /** + * 自定字符串产生密钥 + * @param algorithm 加解密算法 + * @param keyStr 密钥字符串 + * @param charset 编码字符集 + * @return 密钥 + */ + public static SecretKey genKeyByStr(Algorithm algorithm, String keyStr, Charset charset) { + return readKeyFromBytes(algorithm, keyStr.getBytes(charset)); + } + + /** + * 根据指定字节数组产生密钥 + * @param algorithm 加解密算法 + * @param keyBytes 密钥字节数组 + * @return 密钥 + */ + public static SecretKey readKeyFromBytes(Algorithm algorithm, byte[] keyBytes) { + return new SecretKeySpec(keyBytes, algorithm.getKeyAlgorithm()); + } + + /****************************加密*********************************/ + /** + * 加密字符串,并进行base64编码 + * @param algorithm 加解密算法 + * @param key 密钥 + * @param data 明文 + * @param charset 编码字符集 + * @return 密文 + * @throws InvalidKeyException 密钥错误 + */ + public static String encryptBase64(Algorithm algorithm, SecretKey key, String data, Charset charset) throws InvalidKeyException { + return Base64.encodeBase64String(encrypt(algorithm, key, data.getBytes(charset))); + } + + /** + * 加密字节数组 + * @param algorithm 加解密算法 + * @param key 密钥 + * @param data 明文 + * @return 密文 + * @throws InvalidKeyException 密钥错误 + */ + public static byte[] encrypt(Algorithm algorithm, SecretKey key, byte[] data) throws InvalidKeyException { + try { + return cipherDoFinal(algorithm, Cipher.ENCRYPT_MODE, key, data); + } catch (BadPaddingException e) { + throw new RuntimeException(e);//明文没有具体格式要求,不会出错。所以这个异常不需要外部捕获。 + } + } + + /** + * 加解密字节数组 + * @param algorithm 加解密算法 + * @param opmode 操作:1加密,2解密 + * @param key 密钥 + * @param data 数据 + * @throws InvalidKeyException 密钥错误 + * @throws BadPaddingException 解密密文错误(加密模式没有) + */ + private static byte[] cipherDoFinal(Algorithm algorithm, int opmode, SecretKey key, byte[] data) throws InvalidKeyException, BadPaddingException { + Cipher cipher; + try { + cipher = Cipher.getInstance(algorithm.getTransformation(), PROVIDER_NAME); + } catch (Exception e) { + //NoSuchAlgorithmException:加密算法名是本工具类提供的,如果错了业务没有办法处理。所以这个异常不需要外部捕获。 + //NoSuchProviderException:Provider是本工具类提供的,如果错了业务没有办法处理。所以这个异常不需要外部捕获。 + //NoSuchPaddingException:没有特定的填充机制,与环境有关,业务没有办法处理。所以这个异常不需要外部捕获。 + throw new RuntimeException(e); + } + cipher.init(opmode, key); + try { + return cipher.doFinal(data); + } catch (IllegalBlockSizeException e) { + throw new RuntimeException(e);//业务不需要将数据分块(好像由底层处理了),如果错了业务没有办法处理。所以这个异常不需要外部捕获。 + } + } + + /****************************解密*********************************/ + /** + * 对字符串先进行base64解码,再解密 + * @param algorithm 加解密算法 + * @param key 密钥 + * @param data 密文 + * @param charset 编码字符集 + * @return 明文 + * @throws InvalidKeyException 密钥错误 + * @throws BadPaddingException 密文错误 + */ + public static String decryptBase64(Algorithm algorithm, SecretKey key, String data, Charset charset) + throws InvalidKeyException, BadPaddingException { + return new String(decrypt(algorithm, key, Base64.decodeBase64(data)), charset); + } + + /** + * 解密字节数组 + * @param algorithm 加解密算法 + * @param key 密钥 + * @param data 密文 + * @return 明文 + * @throws InvalidKeyException 密钥错误 + * @throws BadPaddingException 密文错误 + */ + public static byte[] decrypt(Algorithm algorithm, SecretKey key, byte[] data) throws InvalidKeyException, BadPaddingException { + return cipherDoFinal(algorithm, Cipher.DECRYPT_MODE, key, data); + } + + public static String Encrypt(String data) throws InvalidKeyException { + SecretKey key = genKeyByStr(Algorithm.SM4, SM4_KEY, encryptCharset); + return encryptBase64(Algorithm.SM4, key, data, encryptCharset); + } + public static String Decrypt(String data) throws BadPaddingException, InvalidKeyException { + SecretKey key = genKeyByStr(Algorithm.SM4, SM4_KEY, encryptCharset); + return decryptBase64(Algorithm.SM4, key, data, encryptCharset); + } + //加密 + public static String dealEncryptData(Object data) throws JsonProcessingException, InvalidKeyException { + ObjectMapper objectMapper = new ObjectMapper(); + String dataString = ""; + try { + if(data instanceof String){ + dataString = (String) data; + }else { + dataString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(data); + } + String dataEncrypt = Encrypt(dataString); + return dataEncrypt; + }catch (Exception e){ + return dataString; + } + } + //解密 + public static String dealDecryptData(Object data) throws JsonProcessingException, BadPaddingException, InvalidKeyException { + String dataString = ""; + try { + ObjectMapper objectMapper = new ObjectMapper(); + if (data instanceof String) { + dataString = (String) data; + } else { + dataString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(data); + } + String dataDecrypt = Decrypt(dataString); + return dataDecrypt; + }catch (Exception e){ + return dataString; + } + } +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/TestMs4.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/TestMs4.java new file mode 100644 index 0000000000..1a9853705d --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/TestMs4.java @@ -0,0 +1,184 @@ +package com.epmet.commons.tools.utils.api.yt; + + +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.spec.SecretKeySpec; +import java.security.*; +import java.util.Arrays; + +/** + * sm4加密算法工具类 + * + * @explain sm4加密、解密与加密结果验证 可逆算法 + * @Autor:jingyao + */ +public class TestMs4 { + static { + Security.addProvider(new BouncyCastleProvider()); + } + + private static final String ENCODING = "UTF-8"; + public static final String ALGORITHM_NAME = "SM4"; + // 加密算法/分组加密模式/分组填充方式 + // PKCS5Padding-以8个字节为一组进行分组加密 + // 定义分组加密模式使用:PKCS5Padding + public static final String ALGORITHM_NAME_ECB_PADDING = "SM4/ECB/PKCS5Padding"; + // 128-32位16进制;256-64位16进制 + public static final int DEFAULT_KEY_SIZE = 128; + + /** + * 生成ECB暗号 + * + * @param algorithmName 算法名称 + * @param mode 模式 + * @param key + * @return + * @throws Exception + * @explain ECB模式(电子密码本模式:Electronic codebook) + */ + private static Cipher generateEcbCipher(String algorithmName, int mode, byte[] key) throws Exception { + Cipher cipher = Cipher.getInstance(algorithmName, BouncyCastleProvider.PROVIDER_NAME); + Key sm4Key = new SecretKeySpec(key, ALGORITHM_NAME); + cipher.init(mode, sm4Key); + return cipher; + } + + /** + * 自动生成密钥 + * + * @return + * @throws NoSuchAlgorithmException + * @throws NoSuchProviderException + * @explain + */ + public static byte[] generateKey() throws Exception { + return generateKey(DEFAULT_KEY_SIZE); + } + + + //加密****************************************** + + /** + * @param keySize + * @return + * @throws Exception + * @explain 系统产生秘钥 + */ + public static byte[] generateKey(int keySize) throws Exception { + KeyGenerator kg = KeyGenerator.getInstance(ALGORITHM_NAME, BouncyCastleProvider.PROVIDER_NAME); + kg.init(keySize, new SecureRandom()); + return kg.generateKey().getEncoded(); + } + + /** + * sm4加密 + * + * @param hexKey 16进制密钥(忽略大小写) + * @param paramStr 待加密字符串 + * @return 返回16进制的加密字符串 + * @throws Exception + * @explain 加密模式:ECB 密文长度不固定,会随着被加密字符串长度的变化而变化 + */ + public static String encryptEcb(String hexKey, String paramStr) throws Exception { + String cipherText = ""; + // 16进制字符串-->byte[] + byte[] keyData = ByteUtils.fromHexString(hexKey); + // String-->byte[] + byte[] srcData = paramStr.getBytes(ENCODING); + // 加密后的数组 + byte[] cipherArray = encrypt_Ecb_Padding(keyData, srcData); + // byte[]-->hexString + cipherText = ByteUtils.toHexString(cipherArray); + return cipherText; + } + + /** + * 加密模式之Ecb + * + * @param key + * @param data + * @return + * @throws Exception + */ + public static byte[] encrypt_Ecb_Padding(byte[] key, byte[] data) throws Exception { + Cipher cipher = generateEcbCipher(ALGORITHM_NAME_ECB_PADDING, Cipher.ENCRYPT_MODE, key);//声称Ecb暗号,通过第二个参数判断加密还是解密 + return cipher.doFinal(data); + } + + //解密**************************************** + + /** + * sm4解密 + * + * @param hexKey 16进制密钥 + * @param cipherText 16进制的加密字符串(忽略大小写) + * @return 解密后的字符串 + * @throws Exception + * @explain 解密模式:采用ECB + */ + public static String decryptEcb(String hexKey, String cipherText) throws Exception { + // 用于接收解密后的字符串 + String decryptStr = ""; + // hexString-->byte[] + byte[] keyData = ByteUtils.fromHexString(hexKey); + // hexString-->byte[] + byte[] cipherData = ByteUtils.fromHexString(cipherText); + // 解密 + byte[] srcData = decrypt_Ecb_Padding(keyData, cipherData); + // byte[]-->String + decryptStr = new String(srcData, ENCODING); + return decryptStr; + } + + /** + * 解密 + * + * @param key + * @param cipherText + * @return + * @throws Exception + * @explain + */ + public static byte[] decrypt_Ecb_Padding(byte[] key, byte[] cipherText) throws Exception { + Cipher cipher = generateEcbCipher(ALGORITHM_NAME_ECB_PADDING, Cipher.DECRYPT_MODE, key);//生成Ecb暗号,通过第二个参数判断加密还是解密 + return cipher.doFinal(cipherText); + } + + /** + * 校验加密前后的字符串是否为同一数据 + * + * @param hexKey 16进制密钥(忽略大小写) + * @param cipherText 16进制加密后的字符串 + * @param paramStr 加密前的字符串 + * @return 是否为同一数据 + * @throws Exception + * @explain + */ + public static boolean verifyEcb(String hexKey, String cipherText, String paramStr) throws Exception { + // 用于接收校验结果 + boolean flag = false; + // hexString-->byte[] + byte[] keyData = ByteUtils.fromHexString(hexKey); + // 将16进制字符串转换成数组 + byte[] cipherData = ByteUtils.fromHexString(cipherText); + // 解密 + byte[] decryptData = decrypt_Ecb_Padding(keyData, cipherData); + // 将原字符串转换成byte[] + byte[] srcData = paramStr.getBytes(ENCODING); + // 判断2个数组是否一致 + flag = Arrays.equals(decryptData, srcData); + return flag; + } + + public static void main(String[] args) throws Exception { + String text = "5d22ea44c7599a48f0d4446b1b7fbb4bb8353922df437d39c3a38549c0f2549cbd021ada00a8be83027ae06203c3daea2eedc5bd0875c7e509c7049045c5349577f2c21bcec328a5ea0bf341191e5bdba978566dddd16f1cf1928ff5cbd826dd33289fb45a8a04585f1f24ab04f59426371a5a0a0f2ee3e7b00d2bdfba7810524ce4c33130eda077546fa4c4191d0117f7a44e1cadac6c69a7d437653be1f958a459e0f025d471e09ab4636c38013032948ffb0827040ed6f3436be090f545186928a7b0b2bfc65782452606607ce8555ba130caacad73998da704428a07276a2699889c9872eebba5de8b72cdbe88705483293b00ab3ecb3aa57d283a4ecab40b71bc0a10e9ec626f07b2293255349fb2270d37e81c5c3d0de0b0f0706ed1872f60f039ce2e51effc39aef9747d67457e072cf3170a9c19589c1bab1a7d9d80"; + String s = TestMs4.decryptEcb("dbcff4c9f4774e6cb56080f279149d59", text); + System.out.println(s); + } + +} + diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/UserData.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/UserData.java new file mode 100644 index 0000000000..b7d3abca4e --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/UserData.java @@ -0,0 +1,50 @@ + +package com.epmet.commons.tools.utils.api.yt; + +import lombok.Data; + +import java.io.Serializable; + +/** + * desc:认证中心-用户信息 + * @author liujianjun + */ +@Data +public class UserData implements Serializable { + + /** + * 性别:todo 不知道是什么值 + */ + private String gender; + /** + * 手机号码 + */ + private String mobileTelephoneNumber; + private String orderNumber; + /** + * 职务 + */ + private String position; + /** + * 职级 + */ + private String positionLevel; + /** + * 电话号码 + */ + private String telephoneNumber; + /** + * 用户编码/id + */ + private String userGuid; + /** + * 用户姓名 + */ + private String userName; + /** + * 人员路径 + */ + private String userPath; + + +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/YantaiApi.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/YantaiApi.java new file mode 100644 index 0000000000..95a54779b0 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/YantaiApi.java @@ -0,0 +1,282 @@ +package com.epmet.commons.tools.utils.api.yt; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.utils.HttpClientManager; +import com.epmet.commons.tools.utils.Result; +import com.fasterxml.jackson.core.JsonProcessingException; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; + +import javax.crypto.BadPaddingException; +import java.security.InvalidKeyException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * desc: + * + * @author: LiuJanJun + * @date: 2022/10/17 3:57 下午 + * @version: 1.0 + */ +@Slf4j +public class YantaiApi { + private static final String SSO_SERVER = "http://172.20.46.155:8080/sso/"; + /** + * 相当于 appKey + */ + private static final String CLIENT_ID = "1000009"; + /** + * 相当于 appSecret 用于解密 他们重定向回来的code 解密他们的token 获取用户嘻嘻 + */ + private static final String CLIENT_SECRET = "a1f9879119bc4080ab5575f832b7d98b"; + /** + * 调用sso后台api接口的 秘钥 + */ + private static final String SSO_API_TOKEN = "iJCDUgCBV/Zk5FkkaxLypA=="; + /** + * 政务网地址 + */ + private static final String SSO_BACKGROUND_SERVER_URL = "http://172.20.46.155:8082/"; + /** + * 互联网地址 + */ + //private static final String SSO_BACKGROUND_SERVER_URL = "http://120.220.248.247:8081/"; + + /** + * desc:根据组织id获取下级组织 + * + * @param organizationId + * @return + */ + public static List getChildOuInfoByGuid(String organizationId) { + try { + if (StringUtils.isBlank(organizationId)) { + throw new EpmetException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg()); + } + //加密 + String organizationIdEn = SM4UtilsForYanTai.dealEncryptData(organizationId); + //pwd = URLEncoder.encode(pwd, "UTF-8"); + String url = SSO_BACKGROUND_SERVER_URL + "person/ouinfo/getChildOuInfoByGuid"; + + Map paramMap = new HashMap<>(); + paramMap.put("organizationId",organizationIdEn); + + log.info("getChildOuInfoByGuid request param:{} url:{}",paramMap, url); + Result result = HttpClientManager.getInstance().sendGet(url, paramMap, getApiHeaderMap()); + log.info("getChildOuInfoByGuid request result:{}", result); + if (!result.success()){ + return new ArrayList<>(); + } + JSONObject jsonObject = JSONObject.parseObject(result.getData()); + String secondCode = jsonObject.getString("code"); + String secondMessage = jsonObject.getString("message"); + if (!"200".equals(secondCode)) { + log.warn("getChildOuInfoByGuid 接口错误"); + return new ArrayList<>(); + } + //解密 + String data = SM4UtilsForYanTai.dealDecryptData(jsonObject.getString("data")); + List orgData = JSON.parseArray(data, OrgData.class); + log.info("getChildOuInfoByGuid request real result:{}", JSON.toJSONString(orgData)); + return orgData; + } catch (Exception e) { + log.error("getChildOuInfoByGuid exception", e); + } + return new ArrayList<>(); + } + + /** + * desc:根据组织id获取下级组织 + * + * @param organizationId + * @return + */ + public static List getUserByOuGuid(String organizationId) { + try { + if (StringUtils.isBlank(organizationId)) { + throw new EpmetException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg()); + } + //加密 + String organizationIdEn = SM4UtilsForYanTai.dealEncryptData(organizationId); + //pwd = URLEncoder.encode(pwd, "UTF-8"); + String url = SSO_BACKGROUND_SERVER_URL + "person/userInfo/getUserByOuGuid"; + + + Map paramMap = new HashMap<>(); + paramMap.put("organizationId",organizationIdEn); + log.info("getUserByOuGuid request param: url:{},param:{}", url, paramMap); + Result result = HttpClientManager.getInstance().sendGet(url, paramMap, getApiHeaderMap()); + log.info("getUserByOuGuid request result:{}", result); + if (!result.success()){ + return new ArrayList<>(); + } + JSONObject jsonObject = JSONObject.parseObject(result.getData()); + String secondCode = jsonObject.getString("code"); + String secondMessage = jsonObject.getString("message"); + if (!"200".equals(secondCode)) { + log.warn("getUserByOuGuid 接口错误"); + return new ArrayList<>(); + } + //解密 + String data = SM4UtilsForYanTai.dealDecryptData(jsonObject.getString("data")); + List userData = JSON.parseArray(data, UserData.class); + log.info("getUserByOuGuid request real result:{}", JSON.toJSONString(userData)); + return userData; + } catch (Exception e) { + log.error("getUserByOuGuid exception", e); + } + return new ArrayList<>(); + } + + /** + * desc:根据组织id获取下级组织 + * + * @param code + * @return + */ + public static YantaiSSOUser getLoginToken(String code) { + try { + if (StringUtils.isBlank(code)) { + throw new EpmetException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg()); + } + //加密 + String organizationIdEn = SM4UtilsForYanTai.dealEncryptData(code); + //pwd = URLEncoder.encode(pwd, "UTF-8"); + log.info("getLoginToken加密组织Id = " + organizationIdEn); + String url = SSO_SERVER + "logintoken?client_id=" + CLIENT_ID + "&client_code=" + code; + + Map headerMap = new HashMap<>(); + Map paramMap = new HashMap<>(); + log.info("getUserByOuGuid request param: url:{},header:{}", url, headerMap); + Result result = HttpClientManager.getInstance().sendGet(url, paramMap, headerMap); + if (!result.success() || StringUtils.isBlank(result.getData())) { + log.info("getUserByOuGuid fail result:{}", JSON.toJSONString(result)); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取token为空", "获取token为空"); + } + log.info("getUserByOuGuid request result:{}", result); + JSONObject jsonObject = JSONObject.parseObject(result.getData()); + //解密 + String errcode = jsonObject.getString("errcode"); + if (!NumConstant.ZERO_STR.equals(errcode)) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取token失败", "获取token失败"); + } + String sencondData = jsonObject.getString("data"); + log.info("getLoginToken jiami data:{}", sencondData); + //String data = SM4UtilsForYanTai.dealDecryptData(sencondData); + + + String data = TestMs4.decryptEcb(CLIENT_SECRET, sencondData); + log.info("getLoginToken jiemi data:{}", sencondData); + YantaiSSOUser userData = JSON.parseObject(data, YantaiSSOUser.class); + log.info("getUserByOuGuid request real result:{}", JSON.toJSONString(userData)); + String userInfoMobile = getUserInfoMobile(userData.getUserGuid()); + userData.setMobile(userInfoMobile); + return userData; + } catch (Exception e) { + log.error("getUserByOuGuid exception", e); + } + return null; + } + + public static String getUserInfoMobile(String userId) { + try { + + String userIdEn = SM4UtilsForYanTai.dealEncryptData(userId); + + String serverUrl = SSO_BACKGROUND_SERVER_URL + "person/userInfo/getUserByUserGuid"; + //String serverUrl = "http://120.220.248.247:8081/person/userInfo/getUserByUserGuid"; + Map param = new HashMap<>(); + param.put("userGuid", userIdEn); + + Result result = HttpClientManager.getInstance().sendGet(serverUrl, param, getApiHeaderMap()); + System.out.println(JSON.toJSONString(result)); + if (!result.success() || StringUtils.isBlank(result.getData())) { + log.info("getUserInfoMobile fail result:{}", JSON.toJSONString(result)); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取用户信息失败", "获取用户信息失败"); + } + String data = result.getData(); + log.info("getUserInfoMobile jiami data:{}", JSON.parseObject(data)); + JSONObject jsonObject = JSON.parseObject(data); + String secondCode = jsonObject.getString("code"); + String secondMessage = jsonObject.getString("message"); + if (!"200".equals(secondCode)) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取人员信息接口返回失败" + secondMessage, "获取人员信息接口返回失败" + secondMessage); + } + String data1 = SM4UtilsForYanTai.dealDecryptData(jsonObject.getString("data")); + String telephoneNumber = JSON.parseObject(data1).getString("mobileTelephoneNumber"); + log.info("getUserInfoMobile jiemi data:{}", telephoneNumber); + return telephoneNumber; + } catch (Exception e) { + log.error("getUserInfoMobile exception", e); + } + return null; + } + + @NotNull + private static Map getApiHeaderMap() { + Map headerMap = new HashMap<>(); + try { + JSONObject token = new JSONObject(); + token.put("token", SSO_API_TOKEN); + // token.put("token","iJCDUgCBV/Zk5FkkaxLypA=="); + token.put("expiration", System.currentTimeMillis()); + + String tokanStr = SM4UtilsForYanTai.dealEncryptData(token.toString()); + headerMap.put("Authorization", "Bearer " + tokanStr); + } catch (Exception e) { + log.error("getApiHeaderMap exception", e); + } + return headerMap; + } + + public static void main(String[] args) throws BadPaddingException, InvalidKeyException, JsonProcessingException { + + //testGetUserByUserId(); + + //code只能用一次 + //getLoginToken("0d554bccfbac4be3846d643252daf92b"); + + String organizationId = "44e05de9-34fa-48f6-b89f-02838d792cf9"; + List childOuInfoByGuid = getChildOuInfoByGuid(organizationId); + System.out.println("childOuInfoByGuid:"+JSON.toJSONString(childOuInfoByGuid)); + //先用他说的有人的组织id联调 + //String orgId = "2b271845-ed51-48aa-9935-00b9e7e06311"; + //orgId = "2b271845-ed51-48aa-9935-00b9e7e05778"; + List userByOuGuid = getUserByOuGuid(organizationId); + System.out.println("getUserByOuGuid:"+JSON.toJSONString(userByOuGuid)); + + Map apiHeaderMap = getApiHeaderMap(); + System.out.println(apiHeaderMap); + //testGetUserByUserId(); + } + + private static void testGetUserByUserId() throws JsonProcessingException, InvalidKeyException, BadPaddingException { + String testUserId = "0ffd76e2-27b5-4b33-be9a-186f9f878bf1"; + + String serverUrl = SSO_BACKGROUND_SERVER_URL +"person/userInfo/getUserByUserGuid"; + //String serverUrl = "http://120.220.248.247:8081/person/userInfo/getUserByUserGuid"; + Map param = new HashMap<>(); + param.put("userGuid", SM4UtilsForYanTai.dealEncryptData(testUserId)); + Result stringResult = HttpClientManager.getInstance().sendGet(serverUrl, param, getApiHeaderMap()); + System.out.println(JSON.toJSONString(stringResult)); + + String data = stringResult.getData(); + JSONObject jsonObject = JSON.parseObject(data); + String secondCode = jsonObject.getString("code"); + String secondMessage = jsonObject.getString("message"); + System.out.println(secondCode); + System.out.println(secondMessage); + String data1 = SM4UtilsForYanTai.dealDecryptData(jsonObject.getString("data")); + System.out.println("======" + data1); + String s = SM4UtilsForYanTai.dealDecryptData("EsOeQX+A8+GG26lzLnuKeuylkBDRFcTbF+gE/jURIzddlVI8RToQQhzK4EHy0WfpS/L4dSAJC93UyVLJhj+r/pup2RFq/GjpH7Md+1Mjg3dM+eyDuGql71bUrldQwJXYnHrQm3Mn7tk5m2eLhEVNkFvdELjuy3Kg8YihZXf2Sox+kxtmK4DSIn/gxhVCoUneWeL0cA6JGHI6jNuq97rzgcNK3Mwen8MxOoWP3n3r+kIpwZCwIlL70MrBjIZ6FHIhcxpqL82gpLSe1K0TFgeWw+9PMo1yv4cGZn7rU86TDlQFoDP86dVa1jrBoyUmW/vvLXrMKwfBaiv9/EUzcCLZWYxEwH93n0X/NYCYem3pfv4uXk5A7/D+Npgj9OKCEIz0ROn0UW5NiXI5Vibz0dywaq4sfsR/LiwjV81QOGY9tsHzN2+MnyTVpQg1l7looNnq1j+wwLneS0aDmbTqBLEn/baph/Hnr2L/9HYpWfXkhz93XRNAdsbxhXdG5ZIiJSwNasHinPR3e2Hmn/02GOsBPFUifbyNUtslt4RS/gwboonBoXz8wrmXi+PfzUXwN8f2CKdBNEHl72USp70NtBSJUPAkHdXZEQPgGRped63Z9GA="); + System.out.println("sssssss:" + s); + } +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/YantaiSSOUser.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/YantaiSSOUser.java new file mode 100644 index 0000000000..d2285ce0f3 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/api/yt/YantaiSSOUser.java @@ -0,0 +1,35 @@ + +package com.epmet.commons.tools.utils.api.yt; + +import lombok.Data; + +import java.io.Serializable; + +/** + * sso:认证中心 用户信息 + * @author liujianjun + */ +@Data +public class YantaiSSOUser implements Serializable { + + private static final long serialVersionUID = -2794280342919451106L; + + /** + * 他说这个是手机号 + */ + private String clientId; + private String departmentCode; + private String expirationTime; + private String ip; + private String issueTime; + private String registerGuid; + private String registerName; + private String userGuid; + private String userName; + + /** + * 二次请求结果 + */ + private String mobile; + +} diff --git a/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/govorg/form/StaffDetailV2FormDTO.java b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/govorg/form/StaffDetailV2FormDTO.java index 4a63e5c8ee..ea1763af18 100644 --- a/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/govorg/form/StaffDetailV2FormDTO.java +++ b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/govorg/form/StaffDetailV2FormDTO.java @@ -42,5 +42,10 @@ public class StaffDetailV2FormDTO implements Serializable { private String orgType = ""; //职责名称列表 private List roles; + /** + * 数字社区里的角色名称 + */ + private List szsqRoles; + private String customerId; } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java index 79f949b525..bbde669a5c 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java @@ -10,6 +10,8 @@ import com.epmet.commons.tools.dto.form.IdAndNameDTO; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.enums.OrgTypeEnum; import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.redis.common.CustomerIcHouseRedis; import com.epmet.commons.tools.redis.common.CustomerResiUserRedis; @@ -20,6 +22,7 @@ import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.IpUtils; +import com.epmet.commons.tools.utils.Result; import com.epmet.constant.BadgeConstant; import com.epmet.constant.NeighborhoodConstant; import com.epmet.constant.OrgInfoConstant; @@ -55,8 +58,11 @@ import com.epmet.dto.UserBaseInfoDTO; import com.epmet.dto.form.DetailByTypeFormDTO; import com.epmet.dto.form.SystemMsgFormDTO; import com.epmet.dto.result.DetailByTypeResultDTO; +import com.epmet.dto.form.GetStaffExistRoleFormDTO; +import com.epmet.dto.result.NewUserRoleResultDTO; import com.epmet.dto.result.StaffRoleResultDTO; import com.epmet.feign.EpmetMessageOpenFeignClient; +import com.epmet.feign.GovAccessFeignClient; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; @@ -117,6 +123,8 @@ public class EpmetUserServiceImpl implements EpmetUserService { private IcPointNucleicMonitoringDao pointNucleicMonitoringDao; @Autowired private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; + @Autowired + private GovAccessFeignClient govAccessFeignClient; /** * @Description 根据UserIds查询 @@ -733,7 +741,8 @@ public class EpmetUserServiceImpl implements EpmetUserService { //基本信息 CustomerStaffDTO dto = customerStaffDao.selectByStaffId(staffId); if (null == dto) { - return result; + // return result; + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"customer_staff is null staffId:"+staffId,"未查询到工作人员基础信息"); } //角色信息 List list = staffRoleDao.selectByStaffId(staffId); @@ -743,7 +752,16 @@ public class EpmetUserServiceImpl implements EpmetUserService { result.setName(dto.getRealName()); result.setGender(dto.getGender().toString()); result.setRoles(list); - + // 获取数字社区里的新角色 + GetStaffExistRoleFormDTO getStaffExistRoleFormDTO = new GetStaffExistRoleFormDTO(); + getStaffExistRoleFormDTO.setStaffId(staffId); + getStaffExistRoleFormDTO.setCustomerId(dto.getCustomerId()); + Result> staffExistRole = govAccessFeignClient.getStaffExistRole(getStaffExistRoleFormDTO); + if (staffExistRole.success()&&CollectionUtils.isNotEmpty(staffExistRole.getData())){ + // 过滤selected=true的 + List szsqRoles=staffExistRole.getData().stream().filter(t->t.getSelected()).map(m -> m.getRoleName()).distinct().collect(Collectors.toList()); + result.setSzsqRoles(szsqRoles); + } return result; } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java index d2ee934888..7265e9bcae 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java @@ -504,8 +504,9 @@ public class GovOrgServiceImpl implements GovOrgService { public StaffDetailV2FormDTO staffDetailV2(StaffDetailV2ResultDTO formDTO) { //1.查询工作人员基本信息、角色信息 StaffDetailV2FormDTO result = epmetUserService.selectByStaffId(formDTO.getStaffId()); - if (null == result) { - return new StaffDetailV2FormDTO(); + if (null == result||StringUtils.isBlank(result.getStaffId())) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"customer_staff is null staffId:"+formDTO.getStaffId(),"未查询到工作人员基本信息"); + // return new StaffDetailV2FormDTO(); } //2.查询工作人员注册组织关系信息 @@ -513,7 +514,7 @@ public class GovOrgServiceImpl implements GovOrgService { staffIdList.add(formDTO.getStaffId()); List list = customerAgencyDao.selelctStaffOrg(staffIdList); if (null == list || list.size() < NumConstant.ONE) { - throw new RenException("未查询到工作人员注册组织信息"); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"未查询到工作人员注册组织信息","未查询到工作人员所属组织信息"); } //3.封装数据并返回 diff --git a/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/YTUserAndOrgPullTask.java b/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/YTUserAndOrgPullTask.java new file mode 100644 index 0000000000..e47d52bcd3 --- /dev/null +++ b/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/YTUserAndOrgPullTask.java @@ -0,0 +1,36 @@ +package com.epmet.task; + +import com.epmet.commons.tools.utils.Result; +import com.epmet.feign.ThirdOpenFeignClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author zxc + * @dscription 拉取yt用户信息和组织信息 + */ +@Slf4j +@Component("YTUserAndOrgPullTask") +public class YTUserAndOrgPullTask implements ITask { + + @Autowired + private ThirdOpenFeignClient thirdOpenFeignClient; + + @Override + public void run(String params) { + Result yanTaiOrgInfo = thirdOpenFeignClient.getYanTaiOrgInfo("44e05de9-34fa-48f6-b89f-02838d792cf9"); + if (yanTaiOrgInfo.success()) { + log.info("yt拉取组织信息定时任务执行成功"); + } else { + log.error("yt拉取组织信息定时任务执行失败:" + yanTaiOrgInfo.getMsg()); + } + + Result yanTaiUserInfo = thirdOpenFeignClient.getYanTaiUserInfo("44e05de9-34fa-48f6-b89f-02838d792cf9"); + if (yanTaiUserInfo.success()) { + log.info("yt拉取用户信息定时任务执行成功"); + } else { + log.error("yt拉取用户信息定时任务执行失败:" + yanTaiUserInfo.getMsg()); + } + } +} diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DataSyncOrgDataDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DataSyncOrgDataDTO.java new file mode 100644 index 0000000000..fd5f9121c7 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DataSyncOrgDataDTO.java @@ -0,0 +1,139 @@ +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +@Data +public class DataSyncOrgDataDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键ID + */ + private String id; + + /** + * 联系人姓名 + */ + private String contact; + + /** + * 联系电话号码 + */ + private String contacttelephoneNumber; + + /** + * 详细地址 + */ + private String detailAddress; + + /** + * 组织机构第一名称 + */ + private String firstnameofOrganization; + + /** + * 组织机构全称 + */ + private String nameofOrganization; + + /** + * 排序号码 + */ + private String orderNumber; + + /** + * 组织机构简称 + */ + private String organizatioNabbreviation; + + /** + * 组织机构ID + */ + private String organizationId; + + /** + * 组织机构级别 + */ + private String organizationLevel; + + /** + * 组织机构路径 + */ + private String organizationPath; + + /** + * 组织机构类型 + */ + private String organizationType; + + /** + * 注册类型 + */ + private String registrationType; + + /** + * 统一社会信用代码 + */ + private String unifiedsocialcreditId; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + + /** + * 客户id;烟台id + */ + private String customerId; + + /** + * 上级组织机构id:ORGANIZATION_ID; 根级组织赋值0 + */ + private String pid; + + /** + * 上级组织机构名称:ORGANIZATIO_NABBREVIATION + */ + private String parentOrgName; + + /** + * 所有上级组织。不包含本身! + */ + private String pids; + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DataSyncUserDataDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DataSyncUserDataDTO.java new file mode 100644 index 0000000000..291d40d7de --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/DataSyncUserDataDTO.java @@ -0,0 +1,124 @@ +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +@Data +public class DataSyncUserDataDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键ID + */ + private String id; + + /** + * 性别:0未知1男2女 + */ + private String gender; + + /** + * 手机号码 + */ + private String mobileTelephoneNumber; + + /** + * 排序号码 + */ + private String orderNumber; + + /** + * 职务 + */ + private String position; + + /** + * 职级 + */ + private String positionLevel; + + /** + * 电话号码 + */ + private String telephoneNumber; + + /** + * 统一用户编码 + */ + private String userGuid; + + /** + * 用户姓名 + */ + private String userName; + + /** + * 人员路径 + */ + private String userPath; + + /** + * data_sync_org_data.组织机构ID; + */ + private String organizationId; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + + /** + * 客户id + */ + private String customerId; + + /** + * 0未创建、1已创建 + */ + private String status; + + /** + * customer_staff.userId + */ + private String staffId; + + /** + * 备注;目前为空 + */ + private String remark; + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/yantai/YtSyncStaffIdFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/yantai/YtSyncStaffIdFormDTO.java new file mode 100644 index 0000000000..522f2926ee --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/yantai/YtSyncStaffIdFormDTO.java @@ -0,0 +1,36 @@ +package com.epmet.dto.form.yantai; + +import com.epmet.commons.tools.validator.group.AddGroup; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @Description 工作端新增完用户后,需要调用此接口,更新data_sync_user_data + * @Author yzm + * @Date 2022/10/18 13:54 + */ +@Data +public class YtSyncStaffIdFormDTO { + /** + * 客户ID + */ + @NotBlank(message = "customerId不能为空",groups = AddGroup.class) + private String customerId; + /** + * 人员ID + */ + @NotBlank(message = "staffId不能为空",groups = AddGroup.class) + private String staffId; + + @NotBlank(message = "name不能为空",groups = AddGroup.class) + private String name; + + @NotBlank(message = "mobile不能为空",groups = AddGroup.class) + private String mobile; + + @NotBlank(message = "当前操作人id不能为空",groups = AddGroup.class) + private String operUserId; + +} + diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/yantai/YtUserPageFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/yantai/YtUserPageFormDTO.java new file mode 100644 index 0000000000..6a3ddda553 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/yantai/YtUserPageFormDTO.java @@ -0,0 +1,36 @@ +package com.epmet.dto.form.yantai; + +import com.epmet.commons.tools.dto.form.PageFormDTO; +import lombok.Data; + +/** + * @Description 运营端,统一认证 列表查询入参 + * @Author yzm + * @Date 2022/10/18 11:12 + */ +@Data +public class YtUserPageFormDTO extends PageFormDTO { + /** + * 0本机 + * 1本级及下级 + */ + private String type; + /** + * 组织id + * data_sync_org_data.ORGANIZATION_ID + */ + private String orgId; + /** + * 姓名 + */ + private String name; + /** + * 手机号 + */ + private String mobile; + /** + * 0未创建、已创建 + */ + private String status; +} + diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/yantai/DataSyncOrgDataDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/yantai/DataSyncOrgDataDTO.java new file mode 100644 index 0000000000..1a3b19a855 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/yantai/DataSyncOrgDataDTO.java @@ -0,0 +1,23 @@ +package com.epmet.dto.result.yantai; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Description + * @Author yzm + * @Date 2022/10/18 14:21 + */ +@Data +public class DataSyncOrgDataDTO implements Serializable { + private static final long serialVersionUID = -3011177998045994250L; + private String orgId; + private String orgName; + private String pid; + /** + * true代表有下级 + */ + private Boolean haveChild; +} + diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/yantai/YtUserPageResDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/yantai/YtUserPageResDTO.java new file mode 100644 index 0000000000..38da48f7a9 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/yantai/YtUserPageResDTO.java @@ -0,0 +1,56 @@ +package com.epmet.dto.result.yantai; + +import lombok.Data; + +/** + * @Description 运营端,统一认证 列表返参 + * @Author yzm + * @Date 2022/10/18 11:53 + */ +@Data +public class YtUserPageResDTO { + /** + * 统一用户编码 + */ + private String userGuid; + /** + * data_sync_org_data.组织机构ID; + */ + private String organizationId; + /** + * XXX-XXX + */ + private String orgName; + /** + * 用户姓名 + */ + private String userName; + + /** + * 电话号码 + */ + private String telephoneNumber; + + /** + * 性别:0未知1男2女 + */ + private String gender; + + /** + * 0未创建、已创建 + */ + private String status; + + /** + * customer_staff.userId + */ + private String staffId; + + /** + * 备注;目前为空 + */ + private String remark; + + private String customerId; +} + diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/EpmetThirdOpenFeignClient.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/EpmetThirdOpenFeignClient.java index f0fef19e58..0638d340be 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/EpmetThirdOpenFeignClient.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/EpmetThirdOpenFeignClient.java @@ -5,6 +5,7 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.BlockChainCreateProjectFormDTO; import com.epmet.dto.form.BlockChainProcessProjectFormDTO; import com.epmet.dto.form.ProjectApplyAssistFormDTO; +import com.epmet.dto.form.yantai.YtSyncStaffIdFormDTO; import com.epmet.dto.result.ProjectAssistResult; import com.epmet.dto.result.UploadFileResultDTO; import com.epmet.feign.fallback.EpmetThirdOpenFeignClientFallbackFactory; @@ -75,6 +76,9 @@ public interface EpmetThirdOpenFeignClient { @PostMapping("/third/blockchain/project/process") Result blockChainProcessProject(@RequestBody BlockChainProcessProjectFormDTO input); + @PostMapping("/third/dataSync/update-staff") + Result dataSyncUpdateStaff(@RequestBody YtSyncStaffIdFormDTO ytSyncStaffIdFormDTO); + class MultipartSupportConfig { @Autowired diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java index 7b19e3efde..1f0f16c314 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/ThirdOpenFeignClient.java @@ -8,6 +8,7 @@ import com.epmet.feign.fallback.ThirdOpenFeignClientFallbackFactory; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -69,4 +70,23 @@ public interface ThirdOpenFeignClient { */ @PostMapping("/third/blockchain/project/process") Result blockChainProcessProject(@RequestBody BlockChainProcessProjectFormDTO input); + + /** + * Desc: 从统一认证中心 拉取组织信息 + * @param orgId + * @author zxc + * @date 2022/10/18 16:50 + */ + @PostMapping("/third/dataSync/yanTai/sync/org") + Result getYanTaiOrgInfo(@RequestParam("orgId") String orgId); + + /** + * Desc: 从统一认证中心 拉取用户信息 + * @param orgId + * @author zxc + * @date 2022/10/18 16:50 + */ + @PostMapping("/third/dataSync/yanTai/sync/user") + Result getYanTaiUserInfo(@RequestParam("orgId") String orgId); + } diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/EpmetThirdOpenFeignClientFallback.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/EpmetThirdOpenFeignClientFallback.java index ebf63b3e49..ec7901a7a1 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/EpmetThirdOpenFeignClientFallback.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/EpmetThirdOpenFeignClientFallback.java @@ -6,6 +6,7 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.BlockChainCreateProjectFormDTO; import com.epmet.dto.form.BlockChainProcessProjectFormDTO; import com.epmet.dto.form.ProjectApplyAssistFormDTO; +import com.epmet.dto.form.yantai.YtSyncStaffIdFormDTO; import com.epmet.dto.result.ProjectAssistResult; import com.epmet.dto.result.UploadFileResultDTO; import com.epmet.feign.EpmetThirdOpenFeignClient; @@ -57,4 +58,8 @@ public class EpmetThirdOpenFeignClientFallback implements EpmetThirdOpenFeignCli return ModuleUtils.feignConError(ServiceConstant.EPMET_THIRD_SERVER, "processProject", input); } + @Override + public Result dataSyncUpdateStaff(YtSyncStaffIdFormDTO ytSyncStaffIdFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_THIRD_SERVER, "updateStaff", ytSyncStaffIdFormDTO); + } } diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java index 973342dc57..006122b075 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/feign/fallback/ThirdOpenFeignClientFallback.java @@ -40,4 +40,14 @@ public class ThirdOpenFeignClientFallback implements ThirdOpenFeignClient { public Result blockChainProcessProject(BlockChainProcessProjectFormDTO input) { return ModuleUtils.feignConError(ServiceConstant.EPMET_THIRD_SERVER, "blockChainProcessProject", input); } + + @Override + public Result getYanTaiOrgInfo(String orgId) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_THIRD_SERVER, "getYanTaiOrgInfo", orgId); + } + + @Override + public Result getYanTaiUserInfo(String orgId) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_THIRD_SERVER, "getYanTaiUserInfo", orgId); + } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/YanTaiConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/YanTaiConstant.java new file mode 100644 index 0000000000..74e1d13560 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/YanTaiConstant.java @@ -0,0 +1,12 @@ +package com.epmet.constant; + +/** + * @Author zxc + * @DateTime 2022/10/18 16:43 + * @DESC + */ +public interface YanTaiConstant { + + String YT_CUSTOMER_ID = "1535072605621841922"; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgController.java new file mode 100644 index 0000000000..80f3a2f056 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgController.java @@ -0,0 +1,84 @@ +package com.epmet.controller.yantai; + +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.commons.tools.validator.group.AddGroup; +import com.epmet.dto.form.yantai.YtSyncStaffIdFormDTO; +import com.epmet.dto.form.yantai.YtUserPageFormDTO; +import com.epmet.dto.result.yantai.DataSyncOrgDataDTO; +import com.epmet.dto.result.yantai.YtUserPageResDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * desc: 从各个平台-同步用户和组织数据到本地 用于生成本系统账号 + * + * @author LiuJanJun + * @date 2022/10/17 3:41 下午 + */ +@RestController +@RequestMapping("dataSync") +public class DataSyncUserAndOrgController { + + @Autowired + private DataSyncUserAndOrgService dataSyncUserAndOrgService; + + /** + * desc:从统一认证中心 拉取用户信息 + * @return + */ + @PostMapping("yanTai/sync/user") + public Result getYanTaiUserInfo(@RequestParam("orgId")String orgId) { + Boolean flag = dataSyncUserAndOrgService.yanTaiSyncUser(orgId); + return new Result().ok(flag); + } + + /** + * desc:从统一认证中心 拉取组织信息 + * @return + */ + @PostMapping("yanTai/sync/org") + public Result getYanTaiOrgInfo(@RequestParam("orgId")String orgId) { + Boolean extJson = dataSyncUserAndOrgService.yanTaiSyncOrg(orgId); + return new Result().ok(extJson); + } + + + /** + * 运营端,统一认证 列表查询 + * + * @param formDTO + * @return + */ + @PostMapping("page-user") + public Result> pageUser(@RequestBody YtUserPageFormDTO formDTO) { + return new Result>().ok(dataSyncUserAndOrgService.pageUser(formDTO)); + } + + /** + * 工作端新增完用户后,需要调用此接口,更新data_sync_user_data + * + * @param formDTO + * @return + */ + @PostMapping("update-staff") + public Result updateStaff(@RequestBody YtSyncStaffIdFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, AddGroup.class); + dataSyncUserAndOrgService.updateStaff(formDTO.getCustomerId(),formDTO.getOperUserId(),formDTO.getStaffId(),formDTO.getName(),formDTO.getMobile()); + return new Result(); + } + + /** + * 运营端,统一认证 列表查询条件 那颗树 调用此接口 + * @param formDTO + * @return + */ + @PostMapping("ytorglist") + public Result> ytOrgList(@RequestBody YtUserPageFormDTO formDTO){ + List list=dataSyncUserAndOrgService.ytOrgList(formDTO.getOrgId()); + return new Result>().ok(list); + } +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgService.java new file mode 100644 index 0000000000..eedd580077 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgService.java @@ -0,0 +1,41 @@ +package com.epmet.controller.yantai; + +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.form.yantai.YtUserPageFormDTO; +import com.epmet.dto.result.yantai.DataSyncOrgDataDTO; +import com.epmet.dto.result.yantai.YtUserPageResDTO; + +import java.util.List; + +/** + * @author liujianjun + */ +public interface DataSyncUserAndOrgService { + Boolean yanTaiSyncUser(String organizationId); + + Boolean yanTaiSyncOrg(String organizationId); + + /** + * 运营端-统一认证 + * 用户列表 + * @param formDTO + * @return + */ + PageData pageUser(YtUserPageFormDTO formDTO); + + /** + * 工作端新增完用户后,需要调用此接口,更新data_sync_user_data + * @param customerId + * @param staffId + * @param name + * @param mobile + */ + int updateStaff(String customerId,String operUserId, String staffId, String name, String mobile); + + /** + * 根据组织id查询下级组织 + * @param pid + * @return + */ + List ytOrgList(String pid); +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgServiceImpl.java new file mode 100644 index 0000000000..7179573098 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgServiceImpl.java @@ -0,0 +1,180 @@ +package com.epmet.controller.yantai; + +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.redis.common.CustomerStaffRedis; +import com.epmet.commons.tools.redis.common.bean.CustomerStaffInfoDTOCache; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.api.yt.OrgData; +import com.epmet.commons.tools.utils.api.yt.UserData; +import com.epmet.commons.tools.utils.api.yt.YantaiApi; +import com.epmet.dao.yantai.DataSyncOrgDataDao; +import com.epmet.dao.yantai.DataSyncUserDataDao; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.form.yantai.YtUserPageFormDTO; +import com.epmet.dto.result.yantai.DataSyncOrgDataDTO; +import com.epmet.dto.result.yantai.YtUserPageResDTO; +import com.epmet.entity.yantai.DataSyncOrgDataEntity; +import com.epmet.entity.yantai.DataSyncUserDataEntity; +import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.service.DataSyncOrgDataService; +import com.epmet.service.DataSyncUserDataService; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static com.epmet.constant.YanTaiConstant.YT_CUSTOMER_ID; + +/** + * desc:烟台 从认证中心同步组织和用户信息 到本地 + * + * @author: LiuJanJun + * @date: 2022/10/17 3:42 下午 + * @version: 1.0 + */ +@Service +@Slf4j +public class DataSyncUserAndOrgServiceImpl implements DataSyncUserAndOrgService { + @Autowired + private DataSyncUserDataDao dataSyncUserDataDao; + @Autowired + private DataSyncOrgDataDao dataSyncOrgDataDao; + @Autowired + private DataSyncOrgDataService dataSyncOrgDataService; + @Autowired + private DataSyncUserDataService dataSyncUserDataService; + @Autowired + private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + + /** + * Desc: 从org表查询组织,在根据组织去查询用户 + * @param organizationId + * @author zxc + * @date 2022/10/19 13:27 + */ + @Override + public Boolean yanTaiSyncUser(String organizationId) { + String customerId = YT_CUSTOMER_ID; + // 缓存初始化staffs + epmetUserOpenFeignClient.allCustomerStaffInCache(customerId); + Integer no = NumConstant.ONE; + Integer size; + do { + // 分批获取org + PageInfo pageInfo = PageHelper.startPage(no, NumConstant.ONE_HUNDRED).doSelectPageInfo(() -> dataSyncOrgDataDao.getAllList(customerId)); + size = pageInfo.getList().size(); + if (CollectionUtils.isNotEmpty(pageInfo.getList())){ + List needInsert = new ArrayList<>(); + pageInfo.getList().forEach(org -> { + // 根据org查用户 + List data = YantaiApi.getUserByOuGuid(org.getOrganizationId()); + if (CollectionUtils.isNotEmpty(data)){ + for (UserData u : data) { + CustomerStaffInfoDTOCache staffInfo = CustomerStaffRedis.getStaffInfoByMobile(customerId, u.getMobileTelephoneNumber()); + DataSyncUserDataEntity entity = ConvertUtils.sourceToTarget(u, DataSyncUserDataEntity.class); + entity.setCustomerId(customerId); + entity.setRemark(""); + if (null == staffInfo){ + entity.setStatus(NumConstant.ZERO_STR); + entity.setOrganizationId(""); + entity.setStaffId(""); + }else { + CustomerStaffInfoCacheResult staffInfo1 = CustomerStaffRedis.getStaffInfo(customerId, staffInfo.getUserId()); + entity.setStatus(NumConstant.ONE_STR); + entity.setOrganizationId(null == staffInfo1 ? "" : staffInfo1.getAgencyId()); + entity.setStaffId(staffInfo.getUserId()); + } + needInsert.add(entity); + } + } + }); + dataSyncUserDataService.insertBatch(needInsert,NumConstant.FIVE_HUNDRED); + } + no++; + }while (size == NumConstant.ONE_HUNDRED); + // 删除staffs缓存 + CustomerStaffRedis.delAllCustomerStaff(customerId); + return false; + } + + @Override + public Boolean yanTaiSyncOrg(String organizationId) { + List data = YantaiApi.getChildOuInfoByGuid(organizationId); + if (CollectionUtils.isNotEmpty(data)){ + List needInsert = new ArrayList<>(); + data.forEach(d -> { + needInsert.add(d); + disposeYanTaiSyncOrg(d.getOrganizationId(),needInsert); + }); + List entities = needInsert.stream().map(m -> { + DataSyncOrgDataEntity entity = ConvertUtils.sourceToTarget(m, DataSyncOrgDataEntity.class); + entity.setCustomerId(YT_CUSTOMER_ID); + entity.setPid(""); + entity.setParentOrgName(""); + entity.setPids(""); + return entity; + }).collect(Collectors.toList()); + dataSyncOrgDataService.insertBatch(entities, NumConstant.ONE_HUNDRED); + } + return false; + } + + public void disposeYanTaiSyncOrg(String organizationId, List needInsert){ + List data = YantaiApi.getChildOuInfoByGuid(organizationId); + if (CollectionUtils.isNotEmpty(data)){ + needInsert.addAll(data); + data.forEach(d -> { + disposeYanTaiSyncOrg(d.getOrganizationId(),needInsert); + }); + } + } + + + /** + * 运营端-统一认证 + * 用户列表 + * + * @param formDTO + * @return + */ + @Override + public PageData pageUser(YtUserPageFormDTO formDTO) { + PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize(), formDTO.getIsPage()); + List list = dataSyncUserDataDao.pageUser(formDTO); + PageInfo pageInfo = new PageInfo<>(list); + return new PageData<>(list, pageInfo.getTotal()); + } + + /** + * 工作端新增完用户后,需要调用此接口,更新data_sync_user_data + * + * @param customerId + * @param staffId + * @param name + * @param mobile + */ + @Override + public int updateStaff(String customerId, String operUserId,String staffId, String name, String mobile) { + return dataSyncUserDataDao.updateStaff(customerId,operUserId,staffId,name,mobile); + } + + /** + * 根据组织id查询下级组织 + * + * @param pid + * @return + */ + @Override + public List ytOrgList(String pid) { + List list=dataSyncOrgDataDao.queryList(pid); + return list; + } +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/SM4UtilsForYanTai.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/SM4UtilsForYanTai.java new file mode 100644 index 0000000000..35d90d20ca --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/SM4UtilsForYanTai.java @@ -0,0 +1,199 @@ +package com.epmet.controller.yantai; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.codec.binary.Base64; +import org.bouncycastle.jce.provider.BouncyCastleProvider; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.Security; + +/** + * 烟台的认证中心-国密sm4加解密 + */ +public class SM4UtilsForYanTai { + private static String SM4_KEY = "yaweisoftware@xy"; + //编码格式 + private static final Charset encryptCharset = StandardCharsets.UTF_8; + + public enum Algorithm { + SM4("SM4","SM4","国密四,key长16byte"); + private String keyAlgorithm; + private String transformation; + private String description;//描述 + Algorithm(String keyAlgorithm, String transformation, String description) { + this.keyAlgorithm = keyAlgorithm; + this.transformation = transformation; + this.description = description; + } + public String getKeyAlgorithm() { + return this.keyAlgorithm; + } + public String getTransformation() { + return this.transformation; + } + public String getDescription() { + return this.description; + } + } + + private static final String PROVIDER_NAME = "BC"; + static { + Security.addProvider(new BouncyCastleProvider()); + } + + /** + * 自定字符串产生密钥 + * @param algorithm 加解密算法 + * @param keyStr 密钥字符串 + * @param charset 编码字符集 + * @return 密钥 + */ + public static SecretKey genKeyByStr(Algorithm algorithm, String keyStr, Charset charset) { + return readKeyFromBytes(algorithm, keyStr.getBytes(charset)); + } + + /** + * 根据指定字节数组产生密钥 + * @param algorithm 加解密算法 + * @param keyBytes 密钥字节数组 + * @return 密钥 + */ + public static SecretKey readKeyFromBytes(Algorithm algorithm, byte[] keyBytes) { + return new SecretKeySpec(keyBytes, algorithm.getKeyAlgorithm()); + } + + /****************************加密*********************************/ + /** + * 加密字符串,并进行base64编码 + * @param algorithm 加解密算法 + * @param key 密钥 + * @param data 明文 + * @param charset 编码字符集 + * @return 密文 + * @throws InvalidKeyException 密钥错误 + */ + public static String encryptBase64(Algorithm algorithm, SecretKey key, String data, Charset charset) throws InvalidKeyException { + return Base64.encodeBase64String(encrypt(algorithm, key, data.getBytes(charset))); + } + + /** + * 加密字节数组 + * @param algorithm 加解密算法 + * @param key 密钥 + * @param data 明文 + * @return 密文 + * @throws InvalidKeyException 密钥错误 + */ + public static byte[] encrypt(Algorithm algorithm, SecretKey key, byte[] data) throws InvalidKeyException { + try { + return cipherDoFinal(algorithm, Cipher.ENCRYPT_MODE, key, data); + } catch (BadPaddingException e) { + throw new RuntimeException(e);//明文没有具体格式要求,不会出错。所以这个异常不需要外部捕获。 + } + } + + /** + * 加解密字节数组 + * @param algorithm 加解密算法 + * @param opmode 操作:1加密,2解密 + * @param key 密钥 + * @param data 数据 + * @throws InvalidKeyException 密钥错误 + * @throws BadPaddingException 解密密文错误(加密模式没有) + */ + private static byte[] cipherDoFinal(Algorithm algorithm, int opmode, SecretKey key, byte[] data) throws InvalidKeyException, BadPaddingException { + Cipher cipher; + try { + cipher = Cipher.getInstance(algorithm.getTransformation(), PROVIDER_NAME); + } catch (Exception e) { + //NoSuchAlgorithmException:加密算法名是本工具类提供的,如果错了业务没有办法处理。所以这个异常不需要外部捕获。 + //NoSuchProviderException:Provider是本工具类提供的,如果错了业务没有办法处理。所以这个异常不需要外部捕获。 + //NoSuchPaddingException:没有特定的填充机制,与环境有关,业务没有办法处理。所以这个异常不需要外部捕获。 + throw new RuntimeException(e); + } + cipher.init(opmode, key); + try { + return cipher.doFinal(data); + } catch (IllegalBlockSizeException e) { + throw new RuntimeException(e);//业务不需要将数据分块(好像由底层处理了),如果错了业务没有办法处理。所以这个异常不需要外部捕获。 + } + } + + /****************************解密*********************************/ + /** + * 对字符串先进行base64解码,再解密 + * @param algorithm 加解密算法 + * @param key 密钥 + * @param data 密文 + * @param charset 编码字符集 + * @return 明文 + * @throws InvalidKeyException 密钥错误 + * @throws BadPaddingException 密文错误 + */ + public static String decryptBase64(Algorithm algorithm, SecretKey key, String data, Charset charset) + throws InvalidKeyException, BadPaddingException { + return new String(decrypt(algorithm, key, Base64.decodeBase64(data)), charset); + } + + /** + * 解密字节数组 + * @param algorithm 加解密算法 + * @param key 密钥 + * @param data 密文 + * @return 明文 + * @throws InvalidKeyException 密钥错误 + * @throws BadPaddingException 密文错误 + */ + public static byte[] decrypt(Algorithm algorithm, SecretKey key, byte[] data) throws InvalidKeyException, BadPaddingException { + return cipherDoFinal(algorithm, Cipher.DECRYPT_MODE, key, data); + } + + public static String Encrypt(String data) throws InvalidKeyException { + SecretKey key = genKeyByStr(Algorithm.SM4, SM4_KEY, encryptCharset); + return encryptBase64(Algorithm.SM4, key, data, encryptCharset); + } + public static String Decrypt(String data) throws BadPaddingException, InvalidKeyException { + SecretKey key = genKeyByStr(Algorithm.SM4, SM4_KEY, encryptCharset); + return decryptBase64(Algorithm.SM4, key, data, encryptCharset); + } + //加密 + public static String dealEncryptData(Object data) throws JsonProcessingException, InvalidKeyException { + ObjectMapper objectMapper = new ObjectMapper(); + String dataString = ""; + try { + if(data instanceof String){ + dataString = (String) data; + }else { + dataString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(data); + } + String dataEncrypt = Encrypt(dataString); + return dataEncrypt; + }catch (Exception e){ + return dataString; + } + } + //解密 + public static String dealDecryptData(Object data) throws JsonProcessingException, BadPaddingException, InvalidKeyException { + String dataString = ""; + try { + ObjectMapper objectMapper = new ObjectMapper(); + if (data instanceof String) { + dataString = (String) data; + } else { + dataString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(data); + } + String dataDecrypt = Decrypt(dataString); + return dataDecrypt; + }catch (Exception e){ + return dataString; + } + } +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncOrgDataDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncOrgDataDao.java new file mode 100644 index 0000000000..b0b0529b62 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncOrgDataDao.java @@ -0,0 +1,27 @@ +package com.epmet.dao.yantai; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.result.yantai.DataSyncOrgDataDTO; +import com.epmet.entity.yantai.DataSyncOrgDataEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +@Mapper +public interface DataSyncOrgDataDao extends BaseDao { + /** + * 根据pid查询下一级组织列表 + * @param pid + * @return + */ + List queryList(@Param("pid") String pid); + + List getAllList(@Param("customerId") String customerId); +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncUserDataDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncUserDataDao.java new file mode 100644 index 0000000000..f1bc42e2e8 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncUserDataDao.java @@ -0,0 +1,41 @@ +package com.epmet.dao.yantai; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.form.yantai.YtUserPageFormDTO; +import com.epmet.dto.result.yantai.YtUserPageResDTO; +import com.epmet.entity.yantai.DataSyncUserDataEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +@Mapper +public interface DataSyncUserDataDao extends BaseDao { + /** + * 运营端,统一认证 列表查询 + * @param formDTO + * @return + */ + List pageUser(YtUserPageFormDTO formDTO); + + /** + * 更新data_sync_user_data 为已创建、记录staffId + * @param customerId + * @param operUserId + * @param staffId + * @param name + * @param mobile + * @return + */ + int updateStaff(@Param("customerId") String customerId, + @Param("operUserId")String operUserId, + @Param("staffId")String staffId, + @Param("name")String name, + @Param("mobile")String mobile); +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/yantai/DataSyncOrgDataEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/yantai/DataSyncOrgDataEntity.java new file mode 100644 index 0000000000..5c46e0b939 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/yantai/DataSyncOrgDataEntity.java @@ -0,0 +1,106 @@ +package com.epmet.entity.yantai; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("data_sync_org_data") +public class DataSyncOrgDataEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 联系人姓名 + */ + private String contact; + + /** + * 联系电话号码 + */ + private String contacttelephoneNumber; + + /** + * 详细地址 + */ + private String detailAddress; + + /** + * 组织机构第一名称 + */ + private String firstnameofOrganization; + + /** + * 组织机构全称 + */ + private String nameofOrganization; + + /** + * 排序号码 + */ + private String orderNumber; + + /** + * 组织机构简称 + */ + private String organizatioNabbreviation; + + /** + * 组织机构ID + */ + private String organizationId; + + /** + * 组织机构级别 + */ + private String organizationLevel; + + /** + * 组织机构路径 + */ + private String organizationPath; + + /** + * 组织机构类型 + */ + private String organizationType; + + /** + * 注册类型 + */ + private String registrationType; + + /** + * 统一社会信用代码 + */ + private String unifiedsocialcreditId; + + /** + * 客户id;烟台id + */ + private String customerId; + + /** + * 上级组织机构id:ORGANIZATION_ID; 根级组织赋值0 + */ + private String pid; + + /** + * 上级组织机构名称:ORGANIZATIO_NABBREVIATION + */ + private String parentOrgName; + + /** + * 所有上级组织。不包含本身! + */ + private String pids; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/yantai/DataSyncUserDataEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/yantai/DataSyncUserDataEntity.java new file mode 100644 index 0000000000..e0fa956f32 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/yantai/DataSyncUserDataEntity.java @@ -0,0 +1,91 @@ +package com.epmet.entity.yantai; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("data_sync_user_data") +public class DataSyncUserDataEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 性别:0未知1男2女 + */ + private String gender; + + /** + * 手机号码 + */ + private String mobileTelephoneNumber; + + /** + * 排序号码 + */ + private String orderNumber; + + /** + * 职务 + */ + private String position; + + /** + * 职级 + */ + private String positionLevel; + + /** + * 电话号码 + */ + private String telephoneNumber; + + /** + * 统一用户编码 + */ + private String userGuid; + + /** + * 用户姓名 + */ + private String userName; + + /** + * 人员路径 + */ + private String userPath; + + /** + * data_sync_org_data.组织机构ID; + */ + private String organizationId; + + /** + * 客户id + */ + private String customerId; + + /** + * 0未创建、已创建 + */ + private String status; + + /** + * customer_staff.userId + */ + private String staffId; + + /** + * 备注;目前为空 + */ + private String remark; + +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DataSyncOrgDataService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DataSyncOrgDataService.java new file mode 100644 index 0000000000..3a3d40fe2d --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DataSyncOrgDataService.java @@ -0,0 +1,78 @@ +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.DataSyncOrgDataDTO; +import com.epmet.entity.yantai.DataSyncOrgDataEntity; + +import java.util.List; +import java.util.Map; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +public interface DataSyncOrgDataService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2022-10-18 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2022-10-18 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return DataSyncOrgDataDTO + * @author generator + * @date 2022-10-18 + */ + DataSyncOrgDataDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2022-10-18 + */ + void save(DataSyncOrgDataDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2022-10-18 + */ + void update(DataSyncOrgDataDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2022-10-18 + */ + void delete(String[] ids); +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DataSyncUserDataService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DataSyncUserDataService.java new file mode 100644 index 0000000000..0b5e41df00 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/DataSyncUserDataService.java @@ -0,0 +1,78 @@ +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.DataSyncUserDataDTO; +import com.epmet.entity.yantai.DataSyncUserDataEntity; + +import java.util.List; +import java.util.Map; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +public interface DataSyncUserDataService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2022-10-18 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2022-10-18 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return DataSyncUserDataDTO + * @author generator + * @date 2022-10-18 + */ + DataSyncUserDataDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2022-10-18 + */ + void save(DataSyncUserDataDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2022-10-18 + */ + void update(DataSyncUserDataDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2022-10-18 + */ + void delete(String[] ids); +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DataSyncOrgDataServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DataSyncOrgDataServiceImpl.java new file mode 100644 index 0000000000..2191a77c85 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DataSyncOrgDataServiceImpl.java @@ -0,0 +1,83 @@ +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.dao.yantai.DataSyncOrgDataDao; +import com.epmet.dto.DataSyncOrgDataDTO; +import com.epmet.entity.yantai.DataSyncOrgDataEntity; +import com.epmet.service.DataSyncOrgDataService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +@Service +public class DataSyncOrgDataServiceImpl extends BaseServiceImpl implements DataSyncOrgDataService { + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, DataSyncOrgDataDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, DataSyncOrgDataDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public DataSyncOrgDataDTO get(String id) { + DataSyncOrgDataEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, DataSyncOrgDataDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(DataSyncOrgDataDTO dto) { + DataSyncOrgDataEntity entity = ConvertUtils.sourceToTarget(dto, DataSyncOrgDataEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(DataSyncOrgDataDTO dto) { + DataSyncOrgDataEntity entity = ConvertUtils.sourceToTarget(dto, DataSyncOrgDataEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DataSyncUserDataServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DataSyncUserDataServiceImpl.java new file mode 100644 index 0000000000..87ffb7a479 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/DataSyncUserDataServiceImpl.java @@ -0,0 +1,83 @@ +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.dao.yantai.DataSyncUserDataDao; +import com.epmet.dto.DataSyncUserDataDTO; +import com.epmet.entity.yantai.DataSyncUserDataEntity; +import com.epmet.service.DataSyncUserDataService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-10-18 + */ +@Service +public class DataSyncUserDataServiceImpl extends BaseServiceImpl implements DataSyncUserDataService { + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, DataSyncUserDataDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, DataSyncUserDataDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public DataSyncUserDataDTO get(String id) { + DataSyncUserDataEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, DataSyncUserDataDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(DataSyncUserDataDTO dto) { + DataSyncUserDataEntity entity = ConvertUtils.sourceToTarget(dto, DataSyncUserDataEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(DataSyncUserDataDTO dto) { + DataSyncUserDataEntity entity = ConvertUtils.sourceToTarget(dto, DataSyncUserDataEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + +} \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/logback-spring.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/logback-spring.xml index c95ac8b0f3..f8e2164fb7 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/logback-spring.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/logback-spring.xml @@ -140,10 +140,9 @@ - + - @@ -158,7 +157,7 @@ - + diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncOrgDataDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncOrgDataDao.xml new file mode 100644 index 0000000000..14931417d7 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncOrgDataDao.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncUserDataDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncUserDataDao.xml new file mode 100644 index 0000000000..8e7241fcd4 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncUserDataDao.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + UPDATE data_sync_user_data + SET UPDATED_BY = #{operUserId}, + UPDATED_TIME = NOW(), + `STATUS` = '1', + STAFF_ID = #{staffId}, + CUSTOMER_ID = #{customerId} + WHERE + MOBILE_TELEPHONE_NUMBER = #{mobile} + AND USER_NAME = #{name} + AND del_flag = '0' + + \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/StaffOrgRelationDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/StaffOrgRelationDTO.java index 47e3105b3d..e1b2602373 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/StaffOrgRelationDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/StaffOrgRelationDTO.java @@ -60,7 +60,7 @@ public class StaffOrgRelationDTO implements Serializable { private String orgId; /** - * 工作人员添加入口类型(组织:agency;部门:dept;网格:gridId) + * 工作人员的添加入口类型(组织:agency;部门:dept;网格:grid) */ private String orgType; diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffV2FromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffV2FromDTO.java index 705ddfaadb..7bc3b93076 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffV2FromDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffV2FromDTO.java @@ -73,4 +73,9 @@ public class AddStaffV2FromDTO implements Serializable { private String client; private List newRoles; + + /** + * 烟台用:当前登录用户 + */ + private String currentUserId; } diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/GetAgencyListFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/GetAgencyListFormDTO.java index 95c371ad83..64dd258641 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/GetAgencyListFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/GetAgencyListFormDTO.java @@ -1,7 +1,9 @@ package com.epmet.dto.form; +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; import lombok.Data; +import javax.validation.constraints.NotBlank; import java.io.Serializable; /** @@ -14,6 +16,12 @@ public class GetAgencyListFormDTO implements Serializable { private static final long serialVersionUID = -5846836779036328298L; + /** + * 这个接口在运营端统一认证,新增用户事也调用了 + */ + public interface OperAddUserShowGroup extends CustomerClientShowGroup { + } + @NotBlank(message = "运营端调用此接口必须传客户id",groups =OperAddUserShowGroup.class ) private String customerId; diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffInfoFromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffInfoFromDTO.java index 133f0df8a4..9bcd6dcb8c 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffInfoFromDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffInfoFromDTO.java @@ -1,5 +1,6 @@ package com.epmet.dto.form; +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; import lombok.Data; import javax.validation.constraints.NotBlank; @@ -14,6 +15,7 @@ import java.io.Serializable; @Data public class StaffInfoFromDTO implements Serializable { private static final long serialVersionUID = 1L; + public interface EditStaffInitGroup extends CustomerClientShowGroup {} /** * 客户ID */ @@ -26,5 +28,6 @@ public class StaffInfoFromDTO implements Serializable { /** * 用户ID */ - String staffId; + @NotBlank(message = "staffId不能为空",groups = EditStaffInitGroup.class) + private String staffId; } diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java index 36cc283268..87b641b564 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java @@ -13,6 +13,7 @@ import java.util.List; @Data public class StaffInitResultDTO implements Serializable { private static final long serialVersionUID = 1L; + private String customerId; /** * 人员ID */ @@ -46,4 +47,12 @@ public class StaffInitResultDTO implements Serializable { */ private List roleList; private List newRoleList; + /** + * customer_staff_agency.agency_id + */ + private String agencyId; + /** + * xxx-xxx + */ + private String agencyName; } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java index c1aba9bb3c..6a8c433250 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerAgencyController.java @@ -18,6 +18,7 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; @@ -348,8 +349,12 @@ public class CustomerAgencyController { */ @PostMapping("agencylist") public Result getAgencyList(@LoginUser TokenDto tokenDTO,@RequestBody GetAgencyListFormDTO formDTO) { - if (StringUtils.isBlank(formDTO.getCustomerId())){ - formDTO.setCustomerId(tokenDTO.getCustomerId()); + if(AppClientConstant.APP_OPER.equals(tokenDTO.getApp())){ + ValidatorUtils.validateEntity(formDTO.getCustomerId(),GetAgencyListFormDTO.OperAddUserShowGroup.class); + }else{ + if (StringUtils.isBlank(formDTO.getCustomerId())){ + formDTO.setCustomerId(tokenDTO.getCustomerId()); + } } return new Result().ok(customerAgencyService.getAgencyList(formDTO)); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java index 939f740fc1..bcc8e2f55e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java @@ -4,13 +4,17 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.annotation.RequirePermission; +import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.enums.RequirePermissionEnum; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.service.StaffService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -70,6 +74,7 @@ public class StaffController { @PostMapping("editstaffinit") @RequirePermission(requirePermission = RequirePermissionEnum.ORG_STAFF_DETAIL) public Result editStaffInit(@RequestBody StaffInfoFromDTO fromDTO){ + ValidatorUtils.validateEntity(fromDTO,StaffInfoFromDTO.EditStaffInitGroup.class); return staffService.editStaffInit(fromDTO); } @@ -96,9 +101,9 @@ public class StaffController { */ @PostMapping("editstaff") @RequirePermission(requirePermission = RequirePermissionEnum.ORG_STAFF_UPDATE) - public Result editStaff(@LoginUser TokenDto tokenDto, @RequestBody StaffSubmitFromDTO fromDTO){ + public Result editStaff(@RequestBody StaffSubmitFromDTO fromDTO){ ValidatorUtils.validateEntity(fromDTO); - return staffService.editStaff(tokenDto, fromDTO); + return staffService.editStaff(fromDTO); } /** @@ -196,15 +201,27 @@ public class StaffController { /** * 【通讯录】人员添加v2 + * 返回staffId * @author sun */ @PostMapping("addstaffv2") @RequirePermission(requirePermission = RequirePermissionEnum.ORG_STAFF_CREATE) - public Result addStaffV2(@LoginUser TokenDto tokenDto, @RequestBody AddStaffV2FromDTO fromDTO){ + public Result addStaffV2(@LoginUser TokenDto tokenDto, @RequestBody AddStaffV2FromDTO fromDTO){ ValidatorUtils.validateEntity(fromDTO, AddStaffV2FromDTO.AddStaff.class); - fromDTO.setCustomerId(tokenDto.getCustomerId()); - fromDTO.setApp(tokenDto.getApp()); - fromDTO.setClient(tokenDto.getClient()); + if(AppClientConstant.APP_OPER.equals(tokenDto.getApp())){ + if(StringUtils.isBlank(fromDTO.getCustomerId())){ + // 该接口烟台运营端-统一认证也在用,所以客户id,运营端必传。 + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"运营端操作,customerId不能为空","运营端操作,customerId不能为空"); + } + }else{ + //小程序端或者数字社区从token里面取 + fromDTO.setCustomerId(tokenDto.getCustomerId()); + } + //因为添加的是工作人员,这里写死吧! + fromDTO.setApp("gov"); + fromDTO.setClient("wxmp"); + //当前登录用户 + fromDTO.setCurrentUserId(tokenDto.getUserId()); return staffService.addStaffV2(fromDTO); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/StaffOrgRelationEntity.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/StaffOrgRelationEntity.java index 99c242b25d..04ef0c00d2 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/StaffOrgRelationEntity.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/StaffOrgRelationEntity.java @@ -56,7 +56,7 @@ public class StaffOrgRelationEntity extends BaseEpmetEntity { private String orgId; /** - * 工作人员添加入口类型(组织:agency;部门:dept;网格:gridId) + * 工作人员的添加入口类型(组织:agency;部门:dept;网格:grid) */ private String orgType; diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/StaffService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/StaffService.java index fc2f954b02..5a4a989166 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/StaffService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/StaffService.java @@ -62,7 +62,7 @@ public interface StaffService { * @param fromDTO 参数 * @return Result */ - Result editStaff(TokenDto tokenDto,StaffSubmitFromDTO fromDTO); + Result editStaff(StaffSubmitFromDTO fromDTO); /** * 人员编辑 @@ -134,9 +134,10 @@ public interface StaffService { /** * 【通讯录】人员添加v2 + * 返回staffId * @author sun */ - Result addStaffV2(AddStaffV2FromDTO fromDTO); + Result addStaffV2(AddStaffV2FromDTO fromDTO); /** diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java index 6950cbcc3c..a81f868ac5 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java @@ -17,6 +17,7 @@ import com.epmet.dao.CustomerStaffAgencyDao; import com.epmet.dao.StaffOrgRelationDao; import com.epmet.dto.*; import com.epmet.dto.form.*; +import com.epmet.dto.form.yantai.YtSyncStaffIdFormDTO; import com.epmet.dto.result.*; import com.epmet.entity.*; import com.epmet.feign.*; @@ -46,8 +47,6 @@ public class StaffServiceImpl implements StaffService { @Autowired private EpmetUserFeignClient epmetUserFeignClient; @Autowired - private OperCrmFeignClient operCrmFeignClient; - @Autowired private CustomerAgencyService customerAgencyService; @Autowired private CustomerStaffAgencyService customerStaffAgencyService; @@ -76,11 +75,11 @@ public class StaffServiceImpl implements StaffService { @Autowired private StaffOrgRelationService staffOrgRelationService; @Resource - private CustomerStaffRedis customerStaffRedis; - @Resource private StaffOrgRelationDao staffOrgRelationDao; @Autowired private GovAccessFeignClient govAccessFeignClient; + @Autowired + private EpmetThirdOpenFeignClient epmetThirdOpenFeignClient; @Override public Result getStaffInfoForHome(StaffsInAgencyFromDTO fromDTO) { @@ -127,18 +126,44 @@ public class StaffServiceImpl implements StaffService { return epmetUserFeignClient.getStaffList(fromDTO); } + /** + * 人员添加页面初始化 + * 备注:2022.10.18运营端-统一认证也会调用此接口,入参会给customerId + * @param fromDTO 参数 + * @return + */ @Override public Result> addStaffInit(StaffInfoFromDTO fromDTO) { - CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); - fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); + if(StringUtils.isBlank(fromDTO.getCustomerId())){ + if(StringUtils.isNotBlank(fromDTO.getAgencyId())){ + CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); + } + } return epmetUserFeignClient.addStaffInit(fromDTO); } @Override public Result editStaffInit(StaffInfoFromDTO fromDTO) { - CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); - fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); - return epmetUserFeignClient.editStaffInit(fromDTO); + //运营端-统一认证调用此接口时,客户id传值了。 + if(StringUtils.isBlank(fromDTO.getCustomerId())){ + CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); + } + CustomerStaffAgencyDTO customerStaffAgencyDTO=customerStaffAgencyService.getInfoByUserId(fromDTO.getStaffId()); + if (null == customerStaffAgencyDTO) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "customer_staff_agency is null user_id :" + fromDTO.getStaffId(), "查询用户所属组织为空"); + } + //运营端-统一认证那调用的时候, agencyId为空,这里重新赋值下 + if(StringUtils.isBlank(fromDTO.getAgencyId())){ + fromDTO.setAgencyId(customerStaffAgencyDTO.getAgencyId()); + } + Result res=epmetUserFeignClient.editStaffInit(fromDTO); + if (res.success() && null != res.getData()) { + res.getData().setAgencyId(customerStaffAgencyDTO.getAgencyId()); + res.getData().setAgencyName(customerAgencyService.getAgencyName(customerStaffAgencyDTO.getAgencyId())); + } + return new Result().ok(res.getData()); } @Override @@ -179,26 +204,33 @@ public class StaffServiceImpl implements StaffService { return new Result(); } + /** + * + * @param tokenDto TokenDto tokenDto, + * @param fromDTO + * @return + */ @Override - public Result editStaff(TokenDto tokenDto, StaffSubmitFromDTO fromDTO) { - CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); - fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); - - fromDTO.setApp(tokenDto.getApp()); - fromDTO.setClient(tokenDto.getClient()); + public Result editStaff(StaffSubmitFromDTO fromDTO) { + if(StringUtils.isBlank(fromDTO.getCustomerId())){ + CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); + } + // epmetUserFeignClient.editStaff没有用到这俩参数,就注释了。 + // fromDTO.setApp(tokenDto.getApp()); + // fromDTO.setClient(tokenDto.getClient()); Result result = epmetUserFeignClient.editStaff(fromDTO); if (!result.success()) { - if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { - return new Result().error(result.getCode(), result.getMsg()); - } - return new Result().error(EpmetErrorCode.STAFF_EDIT_FAILED.getCode(), EpmetErrorCode.STAFF_EDIT_FAILED.getMsg()); - } - if (tokenDto.getClient().equals("web")){ - Result roleUserAccess = govAccessFeignClient.roleUser(new RoleUserFormDTO(fromDTO.getNewRoles(), fromDTO.getStaffId(),fromDTO.getCustomerId())); - if (!roleUserAccess.success()){ - throw new EpmetException("save data to gov-role-user failure"); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),result.getInternalMsg(),result.getMsg()); + } + // if (tokenDto.getClient().equals("web")){ + if(CollectionUtils.isNotEmpty(fromDTO.getNewRoles())){ + Result roleUserAccess = govAccessFeignClient.roleUser(new RoleUserFormDTO(fromDTO.getNewRoles(), fromDTO.getStaffId(),fromDTO.getCustomerId())); + if (!roleUserAccess.success()){ + throw new EpmetException("save data to gov-role-user failure"); + } } - } + // } //2021.8.24 sun 人员信息编辑时删除工作人员的缓存信息 CustomerStaffRedis.delStaffInfoFormCache(fromDTO.getCustomerId(), fromDTO.getStaffId()); return result; @@ -537,12 +569,12 @@ public class StaffServiceImpl implements StaffService { */ @Override @Transactional(rollbackFor = Exception.class) - public Result addStaffV2(AddStaffV2FromDTO fromDTO) { + public Result addStaffV2(AddStaffV2FromDTO fromDTO) { //1.根据新增人员类型判断查询机关信息 OrgResultDTO orgDTO = customerAgencyDao.selectAgencyDetail(fromDTO.getOrgId(), fromDTO.getOrgType()); if (null == orgDTO) { - logger.error(String.format("工作人员新增,根据新增人员组织类型未查询到相关组织信息,orgId->%s,orgType->%s", fromDTO.getOrgId(), fromDTO.getOrgType())); - throw new RenException("根据新增人员组织类型未查询到相关组织信息"); + logger.warn(String.format("工作人员新增,根据新增人员组织类型未查询到相关组织信息,orgId->%s,orgType->%s", fromDTO.getOrgId(), fromDTO.getOrgType())); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"根据新增人员组织类型未查询到相关组织信息","组织不存在"); } //2.调用user服务,新增用户信息 @@ -550,10 +582,7 @@ public class StaffServiceImpl implements StaffService { submitDTO.setAgencyId(orgDTO.getAgencyId()); Result result = epmetUserFeignClient.addStaff(submitDTO); if (!result.success()) { - if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { - return new Result().error(result.getCode(), result.getMsg()); - } - return new Result().error(EpmetErrorCode.STAFF_ADD_FAILED.getCode(), EpmetErrorCode.STAFF_ADD_FAILED.getMsg()); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),result.getInternalMsg(),result.getMsg()); } //3.人员机关表总人数加一、关系表新增关系数据 @@ -612,8 +641,22 @@ public class StaffServiceImpl implements StaffService { throw new EpmetException("save data to gov-role-user failure"); } } - - return new Result(); + //如果是烟台的需要更新 根据手机号+姓名 更新data_sync_user_data置为已创建、记录staffId + // 开发环境默认:45687aa479955f9d06204d415238f7cc + // 测试环境:0c41b272ee9ee95ac6f184ad548a30eb + // 烟台: 1535072605621841922 + if ("1535072605621841922".equals(fromDTO.getCustomerId()) + || "45687aa479955f9d06204d415238f7cc".equals(fromDTO.getCustomerId()) + || "0c41b272ee9ee95ac6f184ad548a30eb".equals(fromDTO.getCustomerId())) { + YtSyncStaffIdFormDTO ytSyncStaffIdFormDTO = ConvertUtils.sourceToTarget(fromDTO,YtSyncStaffIdFormDTO.class); + ytSyncStaffIdFormDTO.setStaffId(result.getData().getUserId()); + ytSyncStaffIdFormDTO.setOperUserId(fromDTO.getCurrentUserId()); + epmetThirdOpenFeignClient.dataSyncUpdateStaff(ytSyncStaffIdFormDTO); + } + //2022.10.18加个返参,借用下StaffDetailResultDTO不再新建dto了 + StaffDetailResultDTO resultDTO=new StaffDetailResultDTO(); + resultDTO.setStaffId(result.getData().getUserId()); + return new Result().ok(resultDTO); } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java index 1a61d61a3c..98491ccc88 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java @@ -924,4 +924,14 @@ public interface EpmetUserOpenFeignClient { @PostMapping("/epmetuser/dataSyncConfig/natInfoScanTask") Result natInfoScanTask(@RequestBody DataSyncTaskParam formDTO); + + /** + * Desc: 客户下所有工作人员放缓存 + * @param customerId + * @author zxc + * @date 2022/10/19 14:07 + */ + @PostMapping("/epmetuser/customerstaff/allCustomerStaffInCache") + Result allCustomerStaffInCache(@RequestParam("customerId")String customerId); + } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java index 630e838db7..50d566bccf 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java @@ -716,4 +716,9 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien public Result natInfoScanTask(DataSyncTaskParam formDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "natInfoScanTask", formDTO); } + + @Override + public Result allCustomerStaffInCache(String customerId) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "allCustomerStaffInCache", customerId); + } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index 6c9d46dbb5..8bea2e4fbf 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -618,5 +618,16 @@ public class CustomerStaffController { return new Result>().ok(customerStaffService.customerStaff(formDTO)); } + /** + * Desc: 客户下所有工作人员放缓存 + * @param customerId + * @author zxc + * @date 2022/10/19 14:07 + */ + @PostMapping("allCustomerStaffInCache") + public Result allCustomerStaffInCache(@RequestParam("customerId")String customerId){ + customerStaffService.allCustomerStaffInCache(customerId); + return new Result(); + } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java index 1c127d7aa5..682c279996 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java @@ -251,5 +251,7 @@ public interface CustomerStaffDao extends BaseDao { List getStaffByCustomerId(@Param("customerId") String customerId); + List getAllStaffByCustomerId(@Param("customerId") String customerId); + void edit(CustomerStaffDTO formDTO); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java index b2a3442172..8c88c7680d 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java @@ -398,4 +398,6 @@ public interface CustomerStaffService extends BaseService { void editToStaff(CustomerStaffDTO formDTO); List customerStaff(GridStaffUploadtFormDTO formDTO); + + void allCustomerStaffInCache(String customerId); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index 2a4585eb8a..0bcb0b5eee 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -17,6 +17,7 @@ package com.epmet.service.impl; +import cn.hutool.core.bean.BeanUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -60,6 +61,8 @@ import com.epmet.service.GovStaffRoleService; import com.epmet.service.StaffRoleService; import com.epmet.service.UserService; import com.epmet.util.ModuleConstant; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -288,7 +291,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + // return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"手机号已存在","手机号已存在"); } //USER表插入数据 UserEntity userEntity = new UserEntity(); @@ -466,12 +471,14 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + // return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"手机号已存在","手机号已存在"); } CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); //Customer_Staff表插入数据 CustomerStaffEntity staffEntity = new CustomerStaffEntity(); + staffEntity.setCustomerId(customerStaffEntity.getCustomerId()); staffEntity.setId(customerStaffEntity.getId()); staffEntity.setRealName(fromDTO.getName()); staffEntity.setMobile(fromDTO.getMobile()); @@ -490,6 +497,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl pageInfo = PageHelper.startPage(no, NumConstant.ONE_HUNDRED).doSelectPageInfo(() -> baseDao.getAllStaffByCustomerId(customerId)); + size = pageInfo.getList().size(); + if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(pageInfo.getList())){ + pageInfo.getList().forEach(c -> { + String key = RedisKeys.getCustomerStaffInfoKeyByMobile(customerId, c.getMobile()); + Map map = BeanUtil.beanToMap(c, false, true); + redisUtils.hMSet(key,map); + }); + } + no++; + }while (size == NumConstant.ONE_HUNDRED); + } + } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcFollowUpRecordServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcFollowUpRecordServiceImpl.java index 1e3c46f9f1..0999660b0e 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcFollowUpRecordServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcFollowUpRecordServiceImpl.java @@ -83,6 +83,7 @@ public class IcFollowUpRecordServiceImpl extends BaseServiceImpl +