| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import org.springblade.common.utils.DesensitizedUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springblade.modules.system.service.MyAsyncService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * ftp 数据处理 |
| | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | /** |
| | | @Autowired |
| | | private MyAsyncService myAsyncService; |
| | | |
| | | |
| | | /** |
| | | * 初始化 |
| | | */ |
| | | @PostConstruct |
| | |
| | | handler = this; |
| | | handler.userService = this.userService; |
| | | handler.redisTemplate = this.redisTemplate; |
| | | handler.myAsyncService = this.myAsyncService; |
| | | } |
| | | |
| | | /** |
| | | * 获取保安员证编号位数 |
| | | * @param json |
| | | * @param uuid |
| | | * @return |
| | | */ |
| | | public static Result handlerSecurityNumberBit(String json, String uuid) { |
| | | Map map = JSON.parseObject(json, Map.class); |
| | | //获取结果 |
| | | Object o = map.get(uuid); |
| | | if (null== o || o.equals("")){ |
| | | return new Result(400,null,"uuid 不匹配",null); |
| | | }else { |
| | | //转换 |
| | | Result result = JSON.parseObject(o.toString(), Result.class); |
| | | //返回 |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读取数据 |
| | | * @param json |
| | | * @param uuid |
| | | * @return |
| | | */ |
| | | public static Result handlerList(String json, String uuid) { |
| | | Map map = JSON.parseObject(json, Map.class); |
| | | //获取结果 |
| | | Object o = map.get(uuid); |
| | | if (null== o || o.equals("")){ |
| | | return new Result(400,null,"uuid 不匹配",null); |
| | | }else { |
| | | //转换 |
| | | Result result = JSON.parseObject(o.toString(), Result.class); |
| | | //返回 |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public static Result handler(String json, String uuid){ |
| | | //读取数据 |
| | | List<String> list = Arrays.asList(json.split(";")); |
| | | for (String s : list) { |
| | | Map map = JSON.parseObject(s, Map.class); |
| | | //获取结果 |
| | | Object o = map.get(uuid); |
| | | if (null== o || o.equals("")){ |
| | | return new Result(400,null,"uuid 不匹配",null); |
| | | } |
| | | Map map = JSON.parseObject(json, Map.class); |
| | | //获取结果 |
| | | Object o = map.get(uuid); |
| | | if (null== o || o.equals("")){ |
| | | return new Result(400,null,"uuid 不匹配",null); |
| | | }else { |
| | | List<Result> list = new ArrayList<>(); |
| | | //转换 |
| | | Result result = JSON.parseObject(o.toString(), Result.class); |
| | | //判断结果 |
| | | if (result.getCode()==200){ |
| | | //新增 |
| | | //用户数处理 |
| | | User user = handlerUserInfo(uuid); |
| | | user.setId(result.getUserId()); |
| | | user.setStatus(1); |
| | | //插入数据库 |
| | | // boolean save = handler.userService.insert(user); |
| | | boolean save = handler.userService.save(user); |
| | | if (save){ |
| | | return new Result(200,null,"新增成功",null); |
| | | }else { |
| | | return new Result(400,null,"新增失败",null); |
| | | } |
| | | }else if (result.getCode()==201) { |
| | | //修改 |
| | | //用户数处理 |
| | | User user = handlerUserInfo(uuid); |
| | | user.setId(result.getUserId()); |
| | | //数据修改 |
| | | boolean b = handler.userService.updateById(user); |
| | | if (b) { |
| | | return new Result(200, null, "修改成功", null); |
| | | } else { |
| | | return new Result(400, null, "修改失败", null); |
| | | } |
| | | }else if (result.getCode()==203){ |
| | | //新增 |
| | | //用户数处理 |
| | | User user = handlerUserInfo(uuid); |
| | | user.setId(result.getUserId()); |
| | | //插入数据库 |
| | | boolean save = handler.userService.save(user); |
| | | //失败,返回保安员证编号校验失败消息 |
| | | return new Result(203,null,result.getMsg(),null); |
| | | }else if (result.getCode()==204){ |
| | | //修改 |
| | | //用户数处理 |
| | | User user = handlerUserInfo(uuid); |
| | | user.setId(result.getUserId()); |
| | | //数据修改 |
| | | boolean b = handler.userService.updateById(user); |
| | | //失败,返回保安员证编号校验失败消息 |
| | | return new Result(202,null,result.getMsg(),null); |
| | | }else { |
| | | //失败,返回失败消息 |
| | | return new Result(202,null,result.getMsg(),null); |
| | | } |
| | | list.add(result); |
| | | //返回 |
| | | return new Result(200,null,list); |
| | | } |
| | | return new Result(400,null,"未能找到对应数据",null); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public static User handlerUserInfo(String uuid){ |
| | | User user2 = new User(); |
| | | //从redis 中获取用户数据 |
| | | Object o1 = handler.redisTemplate.opsForValue().get(uuid); |
| | | User user = JSON.parseObject(o1.toString(), User.class); |
| | | //取出后将 redis 删除 |
| | | handler.redisTemplate.delete(uuid); |
| | | //返回的user,需处理敏感数据 |
| | | User user1 = user; |
| | | //敏感数据处理 |
| | | user1.setCardid(DesensitizedUtil.desensitizedIdNumberBy4(user.getCardid())); |
| | | user1.setPhone(DesensitizedUtil.desensitizedPhoneNumber(user.getPhone())); |
| | | user1.setRegistered(DesensitizedUtil.desensitizedAddress(user.getRegistered())); |
| | | if (user.getHold().equals("1")) { |
| | | user1.setSecuritynumber(DesensitizedUtil.desensitizedSecurityNumber(user.getSecuritynumber())); |
| | | }else { |
| | | user1.setSecuritynumber(""); |
| | | if (null!=o1){ |
| | | User user = JSON.parseObject(o1.toString(), User.class); |
| | | //取出后将 redis 删除 |
| | | handler.redisTemplate.delete(uuid); |
| | | //返回的user,需处理敏感数据 |
| | | User user1 = Objects.requireNonNull(BeanUtil.copy(user, User.class)); |
| | | //敏感数据处理 |
| | | user1.setRealName(DesensitizedUtil.desensitizedName(user.getRealName())); |
| | | user1.setCardid(DesensitizedUtil.desensitizedIdNumberBy4(user.getCardid())); |
| | | user1.setPhone(DesensitizedUtil.desensitizedPhoneNumber(user.getPhone())); |
| | | user1.setRegistered(DesensitizedUtil.desensitizedAddress(user.getRegistered())); |
| | | if (user.getHold().equals("1")) { |
| | | user1.setSecuritynumber(DesensitizedUtil.desensitizedSecurityNumber(user.getSecuritynumber())); |
| | | } else { |
| | | user1.setSecuritynumber(""); |
| | | } |
| | | user1.setAvatar(""); |
| | | user1.setEmail(""); |
| | | user1.setFingerprint(""); |
| | | user1.setNation(""); |
| | | user1.setNativeplace(""); |
| | | user1.setEducation(""); |
| | | user1.setPoliticaloutlook(""); |
| | | user1.setMyPicture(""); |
| | | user1.setHeight(""); |
| | | user1.setRtime(null); |
| | | //返回 |
| | | return user1; |
| | | } |
| | | user1.setAvatar(""); |
| | | user1.setEmail(""); |
| | | user1.setFingerprint(""); |
| | | user1.setNation(""); |
| | | user1.setNativeplace(""); |
| | | user1.setEducation(""); |
| | | user1.setPoliticaloutlook(""); |
| | | //返回 |
| | | return user1; |
| | | //返回null |
| | | return user2; |
| | | } |
| | | } |