diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/DataEncDecProperties.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/DataEncDecProperties.java new file mode 100644 index 00000000..55bfd512 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/DataEncDecProperties.java @@ -0,0 +1,39 @@ +package net.xnzn.core.common.encrypt; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties( + prefix = "data-config" +) +public class DataEncDecProperties { + public static final String PREFIX = "data-config"; + private String sm4Key; + private boolean encrypted; + private boolean desensitization; + + public String getSm4Key() { + return this.sm4Key; + } + + public boolean isEncrypted() { + return this.encrypted; + } + + public boolean isDesensitization() { + return this.desensitization; + } + + public void setSm4Key(final String sm4Key) { + this.sm4Key = sm4Key; + } + + public void setEncrypted(final boolean encrypted) { + this.encrypted = encrypted; + } + + public void setDesensitization(final boolean desensitization) { + this.desensitization = desensitization; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SM4EncDecHandler.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SM4EncDecHandler.java new file mode 100644 index 00000000..1ee97ca2 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SM4EncDecHandler.java @@ -0,0 +1,43 @@ +package net.xnzn.core.common.encrypt; + +import cn.hutool.core.util.StrUtil; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +@Component +public class SM4EncDecHandler extends BaseTypeHandler { + @Autowired + private DataEncDecProperties dataEncDecProperties; + + public void setNonNullParameter(PreparedStatement preparedStatement, int i, Object parameter, JdbcType jdbcType) throws SQLException { + String columnValue = (String)parameter; + if (StrUtil.isNotEmpty(columnValue) && this.dataEncDecProperties.isEncrypted()) { + preparedStatement.setString(i, SM4EncryptUtils.sm4Encrypt(columnValue)); + } else { + preparedStatement.setString(i, columnValue); + } + + } + + public Object getNullableResult(ResultSet resultSet, String columnName) throws SQLException { + String columnValue = resultSet.getString(columnName); + return StrUtil.isNotBlank(columnValue) && this.dataEncDecProperties.isEncrypted() ? SM4EncryptUtils.sm4Decrypt(columnValue) : columnValue; + } + + public Object getNullableResult(ResultSet resultSet, int columnIndex) throws SQLException { + String columnValue = resultSet.getString(columnIndex); + return StrUtil.isNotBlank(columnValue) && this.dataEncDecProperties.isEncrypted() ? SM4EncryptUtils.sm4Decrypt(columnValue) : columnValue; + } + + public Object getNullableResult(CallableStatement callableStatement, int columnIndex) throws SQLException { + String columnValue = callableStatement.getString(columnIndex); + return StrUtil.isNotBlank(columnValue) && this.dataEncDecProperties.isEncrypted() ? SM4EncryptUtils.sm4Decrypt(columnValue) : columnValue; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SM4EncryptUtils.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SM4EncryptUtils.java new file mode 100644 index 00000000..d121f96e --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SM4EncryptUtils.java @@ -0,0 +1,70 @@ +package net.xnzn.core.common.encrypt; + +import cn.hutool.core.util.DesensitizedUtil; +import cn.hutool.crypto.SecureUtil; +import cn.hutool.crypto.SmUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SM4EncryptUtils { + private static final Logger log = LoggerFactory.getLogger(SM4EncryptUtils.class); + private static final DataEncDecProperties properties = getProperties(); + public static final String SUFFIX = "##encrypted"; + + public static DataEncDecProperties getProperties() { + DataEncDecProperties dataEncDecProperties = new DataEncDecProperties(); + dataEncDecProperties.setSm4Key("jY7bZz6Pjml+H/WZYfNSNA=="); + dataEncDecProperties.setEncrypted(true); + dataEncDecProperties.setDesensitization(true); + return dataEncDecProperties; //(DataEncDecProperties)SpringContextHolder.getBean(DataEncDecProperties.class); + } + + public static String sm4Encrypt(String data) { + try { + return SmUtil.sm4(SecureUtil.decode(properties.getSm4Key())).encryptBase64(data) + "##encrypted"; + } catch (Exception var2) { + log.debug("SM4加密异常:{}", var2.getMessage()); + return data; + } + } + + public static String sm4Encryptbyconfig(String data) { + try { + return properties.isEncrypted() ? SmUtil.sm4(SecureUtil.decode(properties.getSm4Key())).encryptBase64(data) + "##encrypted" : data; + } catch (Exception var2) { + log.debug("SM4加密异常:{}", var2.getMessage()); + return data; + } + } + + public static String desensitizedByConfig(String data, DesensitizedUtil.DesensitizedType desensitizedType) { + try { + if (properties.isDesensitization()) { + return data.endsWith("##encrypted") ? DesensitizedUtil.desensitized(sm4Decrypt(data), desensitizedType) : DesensitizedUtil.desensitized(data, desensitizedType); + } else { + return data; + } + } catch (Exception var3) { + log.debug("脱敏异常:{}", var3.getMessage()); + return data; + } + } + + public static String sm4Decrypt(String data) { + try { + if (data.endsWith("##encrypted")) { + data = data.substring(0, data.length() - "##encrypted".length()); + return SmUtil.sm4(SecureUtil.decode(properties.getSm4Key())).decryptStr(data); + } else { + return data; + } + } catch (Exception var2) { + log.debug("SM4解密异常:{}", var2.getMessage()); + return data; + } + } + + public static void main(String[] args) { + System.out.println(sm4Decrypt("H6INNw7emp3/5pYtE6O7kg==##encrypted")); + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SpringContextHolder.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SpringContextHolder.java new file mode 100644 index 00000000..4bd02416 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/encrypt/SpringContextHolder.java @@ -0,0 +1,51 @@ +package net.xnzn.core.common.encrypt; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; + +@Service +@Lazy(false) +public class SpringContextHolder implements ApplicationContextAware, DisposableBean { + private static final Logger log = LoggerFactory.getLogger(SpringContextHolder.class); + private static ApplicationContext applicationContext = null; + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + public void setApplicationContext(ApplicationContext applicationContext) { + SpringContextHolder.applicationContext = applicationContext; + } + + public static T getBean(String name) { + return (T) applicationContext.getBean(name); + } + + public static T getBean(Class requiredType) { + return applicationContext.getBean(requiredType); + } + + public static void clearHolder() { + if (log.isDebugEnabled()) { + log.debug("清除SpringContextHolder中的ApplicationContext:" + String.valueOf(applicationContext)); + } + + applicationContext = null; + } + + public static void publishEvent(ApplicationEvent event) { + if (applicationContext != null) { + applicationContext.publishEvent(event); + } + } + + public void destroy() { + clearHolder(); + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/CustLoginTypeEnum.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/CustLoginTypeEnum.java new file mode 100644 index 00000000..c6d233a1 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/CustLoginTypeEnum.java @@ -0,0 +1,98 @@ +package net.xnzn.core.customer.constants; + +import java.util.HashMap; +import java.util.Map; + +public enum CustLoginTypeEnum { + NAME_PWD(1, "姓名+密码"), + TEL_PWD(2, "手机号+密码"), + TEL_CODE(3, "手机号+验证码"), + NAME_CUST_NUM_PWD(4, "姓名+工号+密码"), + ID_CARD_PWD(5, "身份证号+密码"); + + private final Integer key; + private final String value; + + private CustLoginTypeEnum(Integer key, String value) { + this.key = key; + this.value = value; + } + + public static Integer getKey(String value) { + CustLoginTypeEnum[] enums = values(); + CustLoginTypeEnum[] var2 = enums; + int var3 = enums.length; + + for(int var4 = 0; var4 < var3; ++var4) { + CustLoginTypeEnum temp = var2[var4]; + if (temp.value().equals(value)) { + return temp.key(); + } + } + + return null; + } + + public static String getValue(Integer key) { + CustLoginTypeEnum[] enums = values(); + CustLoginTypeEnum[] var2 = enums; + int var3 = enums.length; + + for(int var4 = 0; var4 < var3; ++var4) { + CustLoginTypeEnum temp = var2[var4]; + if (temp.key().equals(key)) { + return temp.value(); + } + } + + return null; + } + + public static Map getLoginTypeToMap() { + Map map = new HashMap(); + CustLoginTypeEnum[] enums = values(); + CustLoginTypeEnum[] var2 = enums; + int var3 = enums.length; + + for(int var4 = 0; var4 < var3; ++var4) { + CustLoginTypeEnum temp = var2[var4]; + map.put(temp.key, temp.value); + } + + return map; + } + + public static Map getNeedPasswordLoginTypeToMap() { + HashMap map = new HashMap(); + map.put(TEL_PWD.key, TEL_PWD.value); + map.put(NAME_PWD.key, NAME_PWD.value); + map.put(NAME_CUST_NUM_PWD.key, NAME_CUST_NUM_PWD.value); + map.put(ID_CARD_PWD.key, ID_CARD_PWD.value); + return map; + } + + public static boolean contains(Integer loginType) { + CustLoginTypeEnum[] enums = values(); + CustLoginTypeEnum[] var2 = enums; + int var3 = enums.length; + + for(int var4 = 0; var4 < var3; ++var4) { + CustLoginTypeEnum temp = var2[var4]; + if (temp.key().equals(loginType)) { + return true; + } + } + + return false; + } + + public Integer key() { + return this.key; + } + + public String value() { + return this.value; + } + +} + diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/model/CustInfo.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/model/CustInfo.java new file mode 100644 index 00000000..485bf7ff --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/model/CustInfo.java @@ -0,0 +1,212 @@ +package net.xnzn.core.customer.model; + +import com.baomidou.mybatisplus.annotation.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import net.xnzn.core.common.encrypt.SM4EncDecHandler; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.time.LocalDate; +import java.time.LocalDateTime; + +@TableName( + value = "cust_info", + autoResultMap = true +) +@ApiModel("人员资料表") +@Data +public class CustInfo { + private static final long serialVersionUID = 1L; + @TableId + @ApiModelProperty("主键自增") + private Long id; + @ApiModelProperty("人员id") + private @NotNull() Long custId; + @ApiModelProperty("人员编号") + private @NotBlank() String custNum; + @ApiModelProperty("人员姓名") + @TableField( + value = "cust_name", + typeHandler = SM4EncDecHandler.class + ) + private @NotBlank() String custName; + @ApiModelProperty("人员姓名") + @TableField( + value = "cust_name_like" + ) + private String custNameLike; + @ApiModelProperty("人员限制id") + private Integer custLimitId; + @ApiModelProperty("第三方人员id") + private String custThirdId; + @ApiModelProperty("推送到设备上,生成的用户id") + private String custDeviceId; + @ApiModelProperty("手机号") + @TableField( + value = "mobile", + typeHandler = SM4EncDecHandler.class + ) + private String mobile; + @ApiModelProperty("手机号") + @TableField( + value = "mobile_suffix", + typeHandler = SM4EncDecHandler.class + ) + private String mobileSuffix; + @ApiModelProperty("登录密码") + private String pwd; + @ApiModelProperty("身份证号") + @TableField( + value = "id_card", + typeHandler = SM4EncDecHandler.class + ) + private String idCard; + @ApiModelProperty("邮箱") + private String email; + @ApiModelProperty("性别 1-男 2-女") + private Integer sex; + @ApiModelProperty("年龄") + private Integer age; + @ApiModelProperty("生日") + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + private LocalDate birthday; + @ApiModelProperty("民族编码") + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + private Integer ethnicityCode; + @ApiModelProperty("籍贯") + private String nativePlace; + @ApiModelProperty("人脸照片地址") + private String custPhotoUrl; + @ApiModelProperty("头像地址") + private String headPortraitUrl; + @ApiModelProperty("所属组织id") + private @NotNull() Long orgId; + @ApiModelProperty("机构编号") + private String orgNum; + @ApiModelProperty("机构全称") + private String orgFullName; + @ApiModelProperty("成本中心id") + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + private Long costCenterId; + @ApiModelProperty("所属位置") + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + private Long placeId; + @ApiModelProperty("所属位置名称") + private String placeFullName; + @ApiModelProperty("人员类别") + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + private Integer psnType; + @ApiModelProperty("人员类别名称") + private String psnTypeName; + @ApiModelProperty("家庭地址") + private String homeAddr; + @ApiModelProperty("QQ") + private String qq; + @ApiModelProperty("微信") + private String wechat; + @ApiModelProperty("企业微信") + private String companyWechat; + @ApiModelProperty("钉钉") + private String dingtalk; + @ApiModelProperty("支付宝openid") + private String alipayOpenid; + @ApiModelProperty("紧急联系人") + private String emerContactPerson; + @ApiModelProperty("紧急联系电话") + private String emerContactNum; + @ApiModelProperty("紧急联系人身份证号") + private String emerContactCard; + @ApiModelProperty("职位") + private String job; + @ApiModelProperty("职位等级") + private String jobRank; + @ApiModelProperty("职位级别") + private String jobLevel; + @ApiModelProperty("职称") + private String jobTitle; + @ApiModelProperty("职称等级") + private String jobTitleRank; + @ApiModelProperty("编制") + private String authStrength; + @ApiModelProperty("职务") + private String position; + @ApiModelProperty("入职日期") + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + private LocalDate entryDate; + @ApiModelProperty("合同签订日期") + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + private LocalDate signingDate; + @ApiModelProperty("合同到期日期") + @TableField( + updateStrategy = FieldStrategy.IGNORED + ) + private LocalDate expiryDate; + @ApiModelProperty("人员状态 1-正常 2-注销") + private Integer custState; + @ApiModelProperty("点赞调查批次号") + private Long likeBatch; + @ApiModelProperty("乐观锁") + private Integer revision; + @TableField( + value = "crby", + fill = FieldFill.INSERT + ) + @ApiModelProperty("创建人") + private String crby; + @TableField( + value = "crtime", + fill = FieldFill.INSERT + ) + @ApiModelProperty("创建时间") + private LocalDateTime crtime; + @TableField( + value = "upby", + fill = FieldFill.UPDATE + ) + @ApiModelProperty("更新人") + private String upby; + @TableField( + value = "uptime", + fill = FieldFill.UPDATE + ) + @ApiModelProperty("更新时间") + private LocalDateTime uptime; + @ApiModelProperty("就诊号") + private String doctorNum; + @ApiModelProperty("住院号") + private String hospitalNum; + @ApiModelProperty("医嘱") + private String doctorInstruct; + @ApiModelProperty("住院日期") + private LocalDateTime hospitalDate; + @ApiModelProperty("最近下单时间") + private LocalDateTime orderTime; + @ApiModelProperty("银行卡号") + private String bankCardNum; + @ApiModelProperty("扩展字段1(日期 yyyy-MM-dd)") + private LocalDate extendDate; + @ApiModelProperty("扩展字段2(日期 yyyy-MM-dd HH:mm:ss)") + private LocalDateTime extendDateTime; + @ApiModelProperty("扩展字段3(字符串)") + private String extendStr1; + @ApiModelProperty("扩展字段4(字符串)") + private String extendStr2; + @ApiModelProperty("婚姻状态 0-保密 1-未婚 2-已婚") + private Integer maritalStatus; + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/vo/CustInfoAppIdLoginDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/vo/CustInfoAppIdLoginDTO.java new file mode 100644 index 00000000..c3c2d2bf --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/vo/CustInfoAppIdLoginDTO.java @@ -0,0 +1,25 @@ +package net.xnzn.core.customer.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.io.Serializable; + +@Data +public class CustInfoAppIdLoginDTO implements Serializable { + @ApiModelProperty("人员编号") + private String custNum; + @ApiModelProperty("人员姓名") + private String custName; + @ApiModelProperty("手机号") + private String mobile; + @ApiModelProperty("appId") + private String appId; + @ApiModelProperty("登录类型") + private Integer loginType; + @ApiModelProperty("登录密码") + private String password; + @ApiModelProperty("身份证号") + private String idCard; + @ApiModelProperty("验证码") + private String code; +}