diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/controller/VerificationFreeUserController.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/controller/VerificationFreeUserController.java new file mode 100644 index 0000000..e235f63 --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/controller/VerificationFreeUserController.java @@ -0,0 +1,137 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.controller; + +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.validator.AssertUtils; +import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; +import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; +import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; +import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; +import com.elink.esua.epdc.dto.VerificationFreeUserDTO; +import com.elink.esua.epdc.service.VerificationFreeUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + + +/** + * 免校验PC用户(针对隐私数据,免验证码校验) + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2021-12-22 + */ +@RestController +@RequestMapping("verificationfreeuser") +public class VerificationFreeUserController { + + @Autowired + private VerificationFreeUserService verificationFreeUserService; + + @GetMapping("page") + public Result> page(@RequestParam Map params){ + PageData page = verificationFreeUserService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id){ + VerificationFreeUserDTO data = verificationFreeUserService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody VerificationFreeUserDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + verificationFreeUserService.save(dto); + return new Result(); + } + + @PutMapping + public Result update(@RequestBody VerificationFreeUserDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + verificationFreeUserService.update(dto); + return new Result(); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + verificationFreeUserService.delete(ids); + return new Result(); + } + + /** + * 隐私数据导出前,校验当前登录人 + * 返回 code:0 表示免校验 + * 返回 code:1 表示需要校验 msg 中返回的手机号 + * + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author zhangyong + * @Date 10:47 2021-12-22 + **/ + @GetMapping("preCheckLoginUser") + public Result preCheckLoginUser() { + return verificationFreeUserService.preCheckLoginUser(); + } + + /** + * 给当前登录用户,发送短信 + * + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author zhangyong + * @Date 14:57 2021-12-22 + **/ + @GetMapping("sendSMS") + public Result sendSMS() { + return verificationFreeUserService.sendSMS(); + } + + /** + * 验证码校验 + * + * @param smsCode + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author zhangyong + * @Date 16:22 2021-12-22 + **/ + @GetMapping("postCheckSMSCode/{smsCode}") + public Result postCheckSMSCode(@PathVariable("smsCode") String smsCode) { + return verificationFreeUserService.postCheckSMSCode(smsCode); + } + + /** + * 设置系统用户,对于隐私数据的访问权限 + * + * @param dto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author zhangyong + * @Date 11:06 2021-12-23 + **/ + @PostMapping("setAccessPermissions") + public Result setAccessPermissions(@RequestBody VerificationFreeUserDTO dto) { + return verificationFreeUserService.setAccessPermissions(dto); + } +} diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/dao/VerificationFreeUserDao.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/dao/VerificationFreeUserDao.java new file mode 100644 index 0000000..1ef61f8 --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/dao/VerificationFreeUserDao.java @@ -0,0 +1,81 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.dao; + +import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.dto.VerificationFreeUserDTO; +import com.elink.esua.epdc.entity.VerificationFreeUserEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +/** + * 免校验PC用户(针对隐私数据,免验证码校验) + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2021-12-22 + */ +@Mapper +public interface VerificationFreeUserDao extends BaseDao { + + /** + * 是否需要校验当前登录人的手机号 + * true 为不需要 + * false 为需要 + * + * @param sysUserId + * @return java.lang.Boolean + * @Author zhangyong + * @Date 09:52 2021-12-23 + **/ + Boolean isVerificationBySysUserId(@Param("sysUserId") Long sysUserId); + + /** + * 指定系统用户,是否已设置过 隐私数据权限 + * true 设置过 + * false 未设置 + * + * @param sysUserId + * @return java.lang.Boolean + * @Author zhangyong + * @Date 09:52 2021-12-23 + **/ + Boolean isExistBySysUserId(@Param("sysUserId") Long sysUserId); + + /** + * 查询系统用户信息 + * + * @param params + * @return java.util.List + * @Author zhangyong + * @Date 09:54 2021-12-23 + **/ + List selectListSysUserInfo(Map params); + + /** + * 修改系统用户,访问隐私数据的数据权限 + * + * @param dto + * @return void + * @Author zhangyong + * @Date 11:10 2021-12-23 + **/ + void updateVerificationFlagBySysUserId(VerificationFreeUserDTO dto); +} diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/entity/VerificationFreeUserEntity.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/entity/VerificationFreeUserEntity.java new file mode 100644 index 0000000..8d69eb1 --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/entity/VerificationFreeUserEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 免校验PC用户(针对隐私数据,免验证码校验) + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2021-12-22 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_verification_free_user") +public class VerificationFreeUserEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 1L; + + /** + * 用户管理表主键 + */ + private Long sysUserId; + + /** + * 校验标识 0:否,1:是 + */ + private String verificationFlag; + +} \ No newline at end of file diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/feign/MessageFeignClient.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/feign/MessageFeignClient.java new file mode 100644 index 0000000..e77586e --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/feign/MessageFeignClient.java @@ -0,0 +1,29 @@ +package com.elink.esua.epdc.feign; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.feign.fallback.MessageFeignClientFallback; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * 文件对象模块 + * + * @Author zy + * @Date 2019/9/8 18:24 + */ +@FeignClient(name = ServiceConstant.EPDC_MESSAGE_SERVER, fallback = MessageFeignClientFallback.class) +public interface MessageFeignClient { + + /** + * 发送短信验证码 + * + * @param mobile + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author yujintao + * @date 2019/9/11 20:59 + */ + @GetMapping("message/epdc-app/sms/sendCode") + Result sendCode(String mobile); + +} diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/VerificationFreeUserService.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/VerificationFreeUserService.java new file mode 100644 index 0000000..01fc55c --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/VerificationFreeUserService.java @@ -0,0 +1,138 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.service; + +import com.elink.esua.epdc.commons.mybatis.service.BaseService; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.VerificationFreeUserDTO; +import com.elink.esua.epdc.entity.VerificationFreeUserEntity; + +import java.util.List; +import java.util.Map; + +/** + * 免校验PC用户(针对隐私数据,免验证码校验) + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2021-12-22 + */ +public interface VerificationFreeUserService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2021-12-22 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2021-12-22 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return VerificationFreeUserDTO + * @author generator + * @date 2021-12-22 + */ + VerificationFreeUserDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2021-12-22 + */ + void save(VerificationFreeUserDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2021-12-22 + */ + void update(VerificationFreeUserDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2021-12-22 + */ + void delete(String[] ids); + + /** + * 隐私数据导出前,校验当前登录人 + * 返回 code:0 表示免校验 + * 返回 code:1 表示需要校验 msg 中返回的手机号 + * + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author zhangyong + * @Date 10:47 2021-12-22 + **/ + Result preCheckLoginUser(); + + /** + * 给当前登录用户,发送短信 + * + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author zhangyong + * @Date 14:57 2021-12-22 + **/ + Result sendSMS(); + + /** + * 验证码校验 + * + * @param smsCode + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author zhangyong + * @Date 16:22 2021-12-22 + **/ + Result postCheckSMSCode(String smsCode); + + /** + * 设置系统用户,对于隐私数据的访问权限 + * + * @param dto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author zhangyong + * @Date 11:06 2021-12-23 + **/ + Result setAccessPermissions(VerificationFreeUserDTO dto); +} diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/VerificationFreeUserServiceImpl.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/VerificationFreeUserServiceImpl.java new file mode 100644 index 0000000..b592668 --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/VerificationFreeUserServiceImpl.java @@ -0,0 +1,173 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; +import com.elink.esua.epdc.commons.tools.constant.FieldConstant; +import com.elink.esua.epdc.commons.tools.constant.NumConstant; +import com.elink.esua.epdc.commons.tools.exception.RenException; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.redis.RedisKeys; +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; +import com.elink.esua.epdc.commons.tools.security.user.UserDetail; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dao.VerificationFreeUserDao; +import com.elink.esua.epdc.dto.VerificationFreeUserDTO; +import com.elink.esua.epdc.entity.VerificationFreeUserEntity; +import com.elink.esua.epdc.feign.MessageFeignClient; +import com.elink.esua.epdc.service.VerificationFreeUserService; +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; + +/** + * 免校验PC用户(针对隐私数据,免验证码校验) + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2021-12-22 + */ +@Service +public class VerificationFreeUserServiceImpl extends BaseServiceImpl implements VerificationFreeUserService { + + @Autowired + private RedisUtils redisUtils; + @Autowired + private MessageFeignClient messageFeignClient; + + @Override + public PageData page(Map params) { + IPage page = getPage(params); + List list = baseDao.selectListSysUserInfo(params); + return new PageData<>(list, page.getTotal()); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, VerificationFreeUserDTO.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 VerificationFreeUserDTO get(String id) { + VerificationFreeUserEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, VerificationFreeUserDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(VerificationFreeUserDTO dto) { + VerificationFreeUserEntity entity = ConvertUtils.sourceToTarget(dto, VerificationFreeUserEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(VerificationFreeUserDTO dto) { + VerificationFreeUserEntity entity = ConvertUtils.sourceToTarget(dto, VerificationFreeUserEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public Result preCheckLoginUser() { + // 如果当前登录账号,设置了免校验,则直接下载隐私数据 + UserDetail user = SecurityUser.getUser(); + if (user == null) { + throw new RenException("用户未登录"); + } + // 免校验么? + Boolean noVerification = baseDao.isVerificationBySysUserId(user.getId()); + if (!noVerification) { + // 如果当前登录账号的手机号在 30分钟内校验成功过,则本次下载免校验 + String phoneKey = RedisKeys.getPrivaceDataEpidemicUserInfoKey(user.getMobile()); + Object value = redisUtils.get(phoneKey); + if (null == value) { + // 手机号需校验 + Result result = new Result(); + result.setCode(NumConstant.ONE); + result.setMsg(user.getMobile()); + return result; + } + return new Result(); + } + return new Result(); + } + + @Override + public Result sendSMS() { + UserDetail user = SecurityUser.getUser(); + if (user == null) { + throw new RenException("用户未登录"); + } + return messageFeignClient.sendCode(user.getMobile()); + } + + @Override + public Result postCheckSMSCode(String smsCode) { + UserDetail user = SecurityUser.getUser(); + if (user == null) { + throw new RenException("用户未登录"); + } + String phoneKey = RedisKeys.getPhoneSmsCodeKey(user.getMobile()); + Object redisSmsCode = redisUtils.get(phoneKey); + if (null == redisSmsCode || !redisSmsCode.toString().equals(smsCode)) { + throw new RenException("验证码错误"); + } + redisUtils.set(RedisKeys.getPrivaceDataEpidemicUserInfoKey(user.getMobile()), "verified", RedisUtils.MINUTE_THIRTY_EXPIRE); + return new Result(); + } + + @Override + public Result setAccessPermissions(VerificationFreeUserDTO dto) { + Boolean existBySysUserId = baseDao.isExistBySysUserId(dto.getSysUserId()); + if (existBySysUserId) { + // 设置过了,修改 + baseDao.updateVerificationFlagBySysUserId(dto); + } else { + // 未设置,新增 + VerificationFreeUserEntity entity = ConvertUtils.sourceToTarget(dto, VerificationFreeUserEntity.class); + insert(entity); + } + return new Result(); + } +} diff --git a/epdc-cloud-admin/src/main/resources/mapper/VerificationFreeUserDao.xml b/epdc-cloud-admin/src/main/resources/mapper/VerificationFreeUserDao.xml new file mode 100644 index 0000000..db2189c --- /dev/null +++ b/epdc-cloud-admin/src/main/resources/mapper/VerificationFreeUserDao.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + UPDATE epdc_verification_free_user + SET + VERIFICATION_FLAG = #{verificationFlag,jdbcType=VARCHAR}, + UPDATED_TIME = now() + WHERE SYS_USER_ID = #{sysUserId,jdbcType=BIGINT} + AND del_flag = '0' + +