|  |  | 
 |  |  | import cn.hutool.core.date.DateUnit; | 
 |  |  | import com.alibaba.fastjson.JSONObject; | 
 |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
 |  |  | import com.doumee.biz.zbom.ZbomZhongTaiService; | 
 |  |  | import com.doumee.biz.zbom.model.IamUserRoleModel; | 
 |  |  | import com.doumee.biz.zbom.model.IamUserTypeModel; | 
 |  |  | import com.doumee.biz.zbom.model.zhongtai.ZTBaseRequst; | 
 |  |  | import com.doumee.biz.zbom.model.zhongtai.ZTConstants; | 
 |  |  | import com.doumee.config.Jwt.JwtPayLoad; | 
 |  |  | import com.doumee.config.Jwt.JwtTokenUtil; | 
 |  |  | import com.doumee.core.annotation.excel.ExcelImporter; | 
 |  |  | 
 |  |  | import com.doumee.core.utils.tyyun.TyyZosUtil; | 
 |  |  | import com.doumee.dao.admin.request.ShopImport; | 
 |  |  | import com.doumee.dao.admin.request.UserImport; | 
 |  |  | import com.doumee.dao.business.MemberMapper; | 
 |  |  | import com.doumee.dao.business.ShopMapper; | 
 |  |  | import com.doumee.core.wx.WxMiniConfig; | 
 |  |  | import com.doumee.dao.business.SmsEmailMapper; | 
 |  |  | 
 |  |  | import com.doumee.dao.system.model.SystemDictData; | 
 |  |  | import com.doumee.dao.system.model.SystemUser; | 
 |  |  | import com.doumee.dao.web.reqeust.EditUsersRequest; | 
 |  |  | import com.doumee.dao.web.reqeust.ContentShareImgDto; | 
 |  |  | import com.doumee.dao.web.response.AccountResponse; | 
 |  |  | import com.doumee.service.business.UsersService; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  | import org.springframework.web.multipart.MultipartFile; | 
 |  |  |  | 
 |  |  | import java.awt.image.BufferedImage; | 
 |  |  | import java.io.InputStream; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.concurrent.Callable; | 
 |  |  | 
 |  |  |     private SmsEmailMapper smsEmailMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private SystemDictDataBiz systemDictDataBiz; | 
 |  |  |     @Autowired | 
 |  |  |     private MemberMapper memberMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ZbomZhongTaiService zbomZhongTaiService; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Long create(Users users) { | 
 |  |  | 
 |  |  |         } | 
 |  |  |         Users users = usersMapper.selectOne(new QueryWrapper<Users>().lambda().eq(Users::getPhone,phone).last("limit 1")); | 
 |  |  |         if(Objects.isNull(users)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到账户信息"); | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,账号信息不存在!"); | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(users.getIsdeleted(), Constants.ZERO)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户已删除"); | 
 |  |  |         } | 
 |  |  |         if(!StringUtils.equals(users.getStatus(),Constants.ZERO+"")){ | 
 |  |  |         if(StringUtils.equals(users.getStatus(),Constants.ZERO+"")){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户已停用,请联系管理员"); | 
 |  |  |         } | 
 |  |  |         //验证短信 | 
 |  |  |         SmsEmail model = smsEmailMapper.selectOne(new QueryWrapper<SmsEmail>().lambda() | 
 |  |  |                 .eq(SmsEmail::getType, Constants.ZERO) | 
 |  |  |                 .eq(SmsEmail::getPhone, phone) | 
 |  |  |                 .eq(SmsEmail::getRemark, code) | 
 |  |  |                 .eq(SmsEmail::getIsdeleted, Constants.ZERO) | 
 |  |  |         ); | 
 |  |  |         if(model == null){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码不正确,请重新发送再试!"); | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(model.getStatus(),Constants.ZERO)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码已失效,请重新发送再试!"); | 
 |  |  |         } | 
 |  |  |         model.setStatus(Constants.ONE); | 
 |  |  |         model.setEditDate(new Date()); | 
 |  |  |         if(model.getCreateDate() !=null && | 
 |  |  |                 System.currentTimeMillis() - model.getCreateDate().getTime() > 3*60*1000){ | 
 |  |  |             smsEmailMapper.updateById(model); | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码已失效,请重新发送再试~"); | 
 |  |  |         } | 
 |  |  |         smsEmailMapper.updateById(model); | 
 |  |  | //        SmsEmail model = smsEmailMapper.selectOne(new QueryWrapper<SmsEmail>().lambda() | 
 |  |  | //                .eq(SmsEmail::getType, Constants.ZERO) | 
 |  |  | //                .eq(SmsEmail::getPhone, phone) | 
 |  |  | //                .eq(SmsEmail::getRemark, code) | 
 |  |  | //                .eq(SmsEmail::getIsdeleted, Constants.ZERO) | 
 |  |  | //        ); | 
 |  |  | //        if(model == null){ | 
 |  |  | //            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码不正确,请重新发送再试!"); | 
 |  |  | //        } | 
 |  |  | //        if(!Constants.equalsInteger(model.getStatus(),Constants.ZERO)){ | 
 |  |  | //            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码已失效,请重新发送再试!"); | 
 |  |  | //        } | 
 |  |  | //        model.setStatus(Constants.ONE); | 
 |  |  | //        model.setEditDate(new Date()); | 
 |  |  | //        if(model.getCreateDate() !=null && | 
 |  |  | //                System.currentTimeMillis() - model.getCreateDate().getTime() > 3*60*1000){ | 
 |  |  | //            smsEmailMapper.updateById(model); | 
 |  |  | //            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码已失效,请重新发送再试~"); | 
 |  |  | //        } | 
 |  |  | //        smsEmailMapper.updateById(model); | 
 |  |  |         //创建token | 
 |  |  |         JwtPayLoad payLoad = new JwtPayLoad(users.getId(),Constants.ONE); | 
 |  |  |         String token = JwtTokenUtil.generateToken(payLoad); | 
 |  |  |         redisTemplate.opsForValue().set(ZTConstants.BUSINESS+"_"+users.getId(),token); | 
 |  |  |         AccountResponse accountResponse = new AccountResponse(); | 
 |  |  |         accountResponse.setToken(token); | 
 |  |  |         accountResponse.setUsers(users); | 
 |  |  | 
 |  |  |             if(!StringUtils.equals(users.getStatus(),Constants.ZERO+"")){ | 
 |  |  |                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户已停用,请联系管理员"); | 
 |  |  |             } | 
 |  |  |             users.setOpenid(openId); | 
 |  |  |             usersMapper.updateById(users); | 
 |  |  |             //创建token | 
 |  |  |             JwtPayLoad payLoad = new JwtPayLoad(users.getId(),Constants.ONE); | 
 |  |  |             String token = JwtTokenUtil.generateToken(payLoad); | 
 |  |  |             redisTemplate.opsForValue().set(ZTConstants.BUSINESS+"_"+users.getId(),token); | 
 |  |  |             accountResponse.setToken(token); | 
 |  |  |             getUsersDetail(users); | 
 |  |  |             accountResponse.setUsers(users); | 
 |  |  |             return accountResponse; | 
 |  |  |         } catch (WxErrorException e) { | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public  String getContentShareImg(Users users, ContentShareImgDto param){ | 
 |  |  |         if(StringUtils.isBlank(param.getImgurl())){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         String shareFolder = systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.SHARES_FILE).getCode(); | 
 |  |  |         String path = systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.RESOURCE_PATH).getCode(); | 
 |  |  |         if(param.getType() == 1){ | 
 |  |  |             //多图带二维码下载 | 
 |  |  |             return dealShareImgWithUser(param,users,shareFolder,path); | 
 |  |  |         }else{ | 
 |  |  |           return dealShareImgNoUser(param,users,shareFolder,path); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private String dealShareImgWithUser(ContentShareImgDto param, Users users, String shareFolder, String path) { | 
 |  |  |         BufferedImage img1 =GeneratePicUtil.getImgIO(param.getImgurl()); | 
 |  |  |         if(img1 ==null){ | 
 |  |  |             return param.getImgurl(); | 
 |  |  |         } | 
 |  |  |       /*  if(img1.getWidth() <200 && img1.getHeight()<100){ | 
 |  |  |             return  param.getImgurl(); | 
 |  |  |         } | 
 |  |  | */ | 
 |  |  |         String defualtHeader = systemDictDataBiz.queryByCode(Constants.WEIXIN_DEFAULT_IMGS, Constants.USER_CARD_HEADER_IMG).getCode(); | 
 |  |  |         String imgurl =StringUtils.isNotBlank(users.getImgurl())?path+(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.USERS_FILE).getCode())+users.getImgurl():defualtHeader; | 
 |  |  |         String url =null; | 
 |  |  |         //内容分享海报图片 | 
 |  |  |         InputStream mpCode =  Constants.generateWxMiniImgStream(systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG, Constants.WX_TOKEN_CUSTOMER).getCode(), | 
 |  |  |                 "userId="+users.getId()+"&articleId="+param.getArticleId(), | 
 |  |  |                 param.getPageUrl());//小程序 | 
 |  |  |  | 
 |  |  |         InputStream inputStream = GeneratePicUtil.generateShareWithUserImg( | 
 |  |  |                 img1 | 
 |  |  |                 ,mpCode | 
 |  |  |                 ,imgurl | 
 |  |  |         ,StringUtils.defaultString(users.getName(),"-")); | 
 |  |  |         TyyZosUtil obs = new TyyZosUtil( systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.ENDPOINT).getCode(), | 
 |  |  |                 systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.ACCESS_ID).getCode(), | 
 |  |  |                 systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.ACCESS_KEY).getCode()); | 
 |  |  |         String key = DateUtil.getNowShortDate()+"/"+UUID.randomUUID().toString() + ".jpg"; | 
 |  |  |         String fileName =shareFolder+ key; | 
 |  |  |         if (obs.uploadInputstreamObject(inputStream,systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.BUCKETNAME).getCode(), fileName)) { | 
 |  |  |             url =  path+fileName; | 
 |  |  |         } | 
 |  |  |         return  url; | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private String dealShareImgNoUser(ContentShareImgDto param, Users users, String shareFolder, String path) { | 
 |  |  |        String url =null; | 
 |  |  |         //内容分享海报图片 | 
 |  |  |         InputStream mpCode =  Constants.generateWxMiniImgStream(systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG, Constants.WX_TOKEN_CUSTOMER).getCode(), | 
 |  |  |                 "userId="+users.getId()+"&articleId="+param.getArticleId(), | 
 |  |  |                 param.getPageUrl());//小程序 | 
 |  |  |  | 
 |  |  |         String title = systemDictDataBiz.queryByCode(Constants.WEIXIN_DEFAULT_IMGS, Constants.SHARE_HAIBAO_HEADER_TITLE).getCode(); | 
 |  |  |         InputStream inputStream = GeneratePicUtil.generateShareImg( | 
 |  |  |                 param.getImgurl() | 
 |  |  |                 ,mpCode | 
 |  |  |                 ,title); | 
 |  |  |         TyyZosUtil obs = new TyyZosUtil( systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.ENDPOINT).getCode(), | 
 |  |  |                 systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.ACCESS_ID).getCode(), | 
 |  |  |                 systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.ACCESS_KEY).getCode()); | 
 |  |  |         String key = DateUtil.getNowShortDate()+"/"+UUID.randomUUID().toString() + ".jpg"; | 
 |  |  |         String fileName =shareFolder+ key; | 
 |  |  |         if (obs.uploadInputstreamObject(inputStream,systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.BUCKETNAME).getCode(), fileName)) { | 
 |  |  |             url =  path+fileName; | 
 |  |  |         } | 
 |  |  |         return  url; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public     String getUserCard(Users users){ | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Users usersDetail(Long userId){ | 
 |  |  |         Users users = usersMapper.selectById(userId); | 
 |  |  |     public Users usersDetailByIamId(String iamId){ | 
 |  |  |         Users users = usersMapper.selectOne(new QueryWrapper<Users>().lambda().eq(Users::getIamId,iamId).last("limit 1")); | 
 |  |  |         if(Objects.isNull(users)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(users.getIsdeleted(),Constants.ZERO)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"用户已禁用"); | 
 |  |  |         } | 
 |  |  |         getUsersDetail(users); | 
 |  |  |         return users; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Users usersDetailById(Long id){ | 
 |  |  |         Users users = usersMapper.selectById(id); | 
 |  |  |         if(Objects.isNull(users)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(users.getIsdeleted(),Constants.ZERO)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"用户已禁用"); | 
 |  |  |         } | 
 |  |  |         getUsersDetail(users); | 
 |  |  |         return users; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void getUsersDetail(Users users){ | 
 |  |  |         String prefix = StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.RESOURCE_PATH).getCode()) + | 
 |  |  |                 StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.USERS_FILE).getCode()); | 
 |  |  |         if(StringUtils.isNotBlank(users.getImgurl())){ | 
 |  |  | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return users; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void updWxMiniToken(){ | 
 |  |  |         DefaultWebSecurityManager manager = new DefaultWebSecurityManager(); | 
 |  |  |         ThreadContext.bind(manager); | 
 |  |  |         String appId = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_APPID_PERSONNEL).getCode(); | 
 |  |  |         String appSecret = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_SECRET_PERSONNEL).getCode(); | 
 |  |  |         //生成微信token | 
 |  |  |         String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+appSecret; | 
 |  |  |         String response = Constants.doGet(url,null); | 
 |  |  |         JSONObject json = JSONObject.parseObject(response); | 
 |  |  |         SystemDictData systemDictData = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_TOKEN_PERSONNEL); | 
 |  |  |         systemDictData.setCode(json.getString("access_token")); | 
 |  |  |         systemDictData.setUpdateTime(new Date()); | 
 |  |  |         systemDictDataBiz.updateByIdNew(systemDictData); | 
 |  |  |     public ZTBaseRequst logOff(Long userId){ | 
 |  |  |         Users users = usersMapper.selectById(userId); | 
 |  |  |         if(Objects.isNull(users)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         if(StringUtils.isBlank(users.getOpenid())){ | 
 |  |  |             redisTemplate.delete(ZTConstants.BUSINESS+"_"+ users.getId()); | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         //校验用户token信息 | 
 |  |  |         MemberServiceImpl.getZTToken(zbomZhongTaiService,memberMapper,usersMapper,systemDictDataBiz,users.getId(), ZTConstants.BUSINESS); | 
 |  |  |         //调起中台注销接口 | 
 |  |  |         ZTBaseRequst ztBaseRequst = new ZTBaseRequst(); | 
 |  |  |         ztBaseRequst.setUserType(ZTConstants.BUSINESS); | 
 |  |  |         ztBaseRequst.setOpenId(users.getOpenid()); | 
 |  |  |         ztBaseRequst.setToken(users.getToken()); | 
 |  |  |         usersMapper.update(new UpdateWrapper<Users>().lambda() | 
 |  |  |                 .set(Users::getOpenid,null) | 
 |  |  |                 .set(Users::getEditDate,new Date()) | 
 |  |  |                 .eq(Users::getId,users.getId()) | 
 |  |  |         ); | 
 |  |  |         redisTemplate.delete(ZTConstants.BUSINESS+"_"+ users.getId()); | 
 |  |  |         return ztBaseRequst; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |