| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| | | 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.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.GeneratePicUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | 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.business.UsersMapper; |
| | | import com.doumee.dao.business.model.Multifile; |
| | | import com.doumee.dao.business.model.News; |
| | | import com.doumee.dao.business.model.Shop; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.Users; |
| | | import com.doumee.dao.business.model.*; |
| | | 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.reqeust.GenerateQRCodeRequest; |
| | | import com.doumee.dao.web.reqeust.WxPhoneRequest; |
| | | import com.doumee.dao.web.response.AccountResponse; |
| | | import com.doumee.service.business.UsersService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.yulichang.interfaces.MPJBaseJoin; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import okhttp3.Response; |
| | | import org.apache.catalina.User; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.util.ThreadContext; |
| | | import org.apache.shiro.web.mgt.DefaultWebSecurityManager; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | import java.util.concurrent.Callable; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | |
| | | import static com.aliyun.api.internal.util.AliyunWebUtils.doGet; |
| | | |
| | | /** |
| | | * 员工信息表Service实现 |
| | |
| | | * @date 2024/07/04 14:40 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class UsersServiceImpl implements UsersService { |
| | | |
| | | |
| | |
| | | @Autowired |
| | | private ShopMapper shopMapper; |
| | | @Autowired |
| | | private SmsEmailMapper smsEmailMapper; |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | @Autowired |
| | | private ZbomZhongTaiService zbomZhongTaiService; |
| | | |
| | | @Override |
| | | public Long create(Users users) { |
| | |
| | | |
| | | @Override |
| | | public Users findById(Long id) { |
| | | return usersMapper.selectById(id); |
| | | MPJLambdaWrapper<Users> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.leftJoin(Shop.class,Shop::getId,Users::getDepartmentId) |
| | | .selectAs(Shop::getName,Users::getShopName) |
| | | .selectAs(Shop::getAddress,Users::getShopAddress) |
| | | .selectAs(Shop::getType,Users::getShopType) |
| | | .selectAs(Shop::getSecondType,Users::getShopSecType) |
| | | .selectAll(Users.class) |
| | | .eq(Users::getId,id); |
| | | return usersMapper.selectJoinOne(Users.class,queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | |
| | | .selectAs(Shop::getSecondType,Users::getShopSecType) |
| | | .selectAll(Users.class); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | if (StringUtils.isNotBlank(pageWrap.getModel().getPhone())) { |
| | | queryWrapper.apply(" t.id in ( select c.USER_ID from customer_user c where c.isdeleted = 0 and c.phone = '"+pageWrap.getModel().getPhone()+"' ) "); |
| | | } |
| | | if (Objects.nonNull(pageWrap.getModel().getMemberId())) { |
| | | queryWrapper.apply(" t.id in ( select c.USER_ID from customer_user c where c.isdeleted = 0 and c.member_id = '"+pageWrap.getModel().getMemberId()+"' ) "); |
| | | } |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.eq(Users::getId, pageWrap.getModel().getId()); |
| | | } |
| | |
| | | f.setQrcodeImgFull(path + f.getQrcodeImg()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return pageData; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public AccountResponse phoneLogin(String phone,String code){ |
| | | public AccountResponse phoneLogin(String phone,String code,String openid){ |
| | | if(StringUtils.isEmpty(phone)||StringUtils.isEmpty(code)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | 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(),"当前账户已停用,请联系管理员"); |
| | | } |
| | | //TODO 验证短信信息 |
| | | if(!StringUtils.equals(code,"123456")){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"验证码错误"); |
| | | if(StringUtils.isNotBlank(openid)){ |
| | | usersMapper.update(null,new UpdateWrapper<Users>().lambda().set(Users::getOpenid,null).eq(Users::getOpenid,openid).ne(Users::getId,users.getId())); |
| | | users.setOpenid(openid); |
| | | users.setEditDate(new Date()); |
| | | usersMapper.updateById(users); |
| | | } |
| | | //验证短信 |
| | | // 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); |
| | | // JwtPayLoad payLoad = new JwtPayLoad(users.getId(),Constants.ONE); |
| | | // String token = JwtTokenUtil.generateToken(payLoad); |
| | | // redisTemplate.opsForValue().set(ZTConstants.BUSINESS+"_"+users.getId(),token); |
| | | String token = JwtTokenUtil.generateTokenForZb(users.getId(),ZTConstants.BUSINESS,JSONObject.toJSON(users).toString(),redisTemplate); |
| | | AccountResponse accountResponse = new AccountResponse(); |
| | | accountResponse.setToken(token); |
| | | accountResponse.setUsers(users); |
| | |
| | | accountResponse.setSessionKey(session.getSessionKey()); |
| | | Users users = usersMapper.selectOne(new QueryWrapper<Users>().lambda().eq(Users::getOpenid,openId).last("limit 1")); |
| | | if(Objects.isNull(users)){ |
| | | accountResponse.setOpenid(openId); |
| | | accountResponse.setSessionKey(session.getSessionKey()); |
| | | return accountResponse; |
| | | } |
| | | 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.ONE+"")){ |
| | | 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); |
| | | String token = JwtTokenUtil.generateTokenForZb(users.getId(),ZTConstants.BUSINESS,JSONObject.toJSON(users).toString(),redisTemplate); |
| | | accountResponse.setToken(token); |
| | | getUsersDetail(users); |
| | | accountResponse.setSessionKey(session.getSessionKey()); |
| | | accountResponse.setUsers(users); |
| | | return accountResponse; |
| | | } catch (WxErrorException e) { |
| | |
| | | |
| | | |
| | | @Override |
| | | public void bindingOpenid(String code,Long userId){ |
| | | public AccountResponse getWxMiniPhoneLogin(WxPhoneRequest wxPhoneRequest){ |
| | | try { |
| | | //获取微信敏感数据 |
| | | WxMaJscode2SessionResult session = WxMiniConfig.wxPersonnelService.getUserService().getSessionInfo(code); |
| | | String openId = session.getOpenid(); |
| | | if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(openId)) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"获取openid失败!请联系管理员"); |
| | | WxMaPhoneNumberInfo userPhoneInfo = WxMiniConfig.wxPersonnelService.getUserService().getPhoneNoInfo( |
| | | wxPhoneRequest.getSessionKey(), wxPhoneRequest.getEncryptedData(), wxPhoneRequest.getIv()); |
| | | //获取手机号 |
| | | String phone= userPhoneInfo.getPurePhoneNumber(); |
| | | if(Objects.isNull(phone)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未获取到手机号"); |
| | | } |
| | | usersMapper.update(new UpdateWrapper<Users>().lambda().set(Users::getOpenid,null).eq(Users::getOpenid,openId)); |
| | | Users users = usersMapper.selectById(userId); |
| | | users.setOpenid(openId); |
| | | users.setEditDate(new Date()); |
| | | usersMapper.updateById(users); |
| | | } catch (WxErrorException e) { |
| | | Users users = usersMapper.selectOne(new QueryWrapper<Users>().lambda() |
| | | .eq(Users::getPhone,phone).last("limit 1")); |
| | | AccountResponse accountResponse = new AccountResponse(); |
| | | accountResponse.setPhone( Constants.desensitizationPhone(phone)); |
| | | if(Objects.isNull(users)){ |
| | | return accountResponse; |
| | | }else{ |
| | | if(StringUtils.isNotBlank(wxPhoneRequest.getOpenid())){ |
| | | usersMapper.update(null,new UpdateWrapper<Users>().lambda().set(Users::getOpenid,null) |
| | | .eq(Users::getOpenid,wxPhoneRequest.getOpenid())); |
| | | users.setOpenid(wxPhoneRequest.getOpenid()); |
| | | usersMapper.updateById(users); |
| | | } |
| | | } |
| | | accountResponse.setUsers(users); |
| | | String token = JwtTokenUtil.generateTokenForZb(users.getId(),ZTConstants.BUSINESS,JSONObject.toJSON(users).toString(),redisTemplate); |
| | | accountResponse.setToken(token); |
| | | return accountResponse; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"获取手机号失败"); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void bindingOpenid(String openid,Long userId){ |
| | | usersMapper.update(new UpdateWrapper<Users>().lambda().set(Users::getOpenid,null).eq(Users::getOpenid,openid)); |
| | | Users users = usersMapper.selectById(userId); |
| | | users.setOpenid(openid); |
| | | users.setEditDate(new Date()); |
| | | usersMapper.updateById(users); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | private void dealUserDataBiz(List<UserImport> finalDataList, Date date, LoginUserInfo loginUserInfo) { |
| | | |
| | | private void dealUserDataBiz(List<UserImport> dataList, Date date, LoginUserInfo loginUserInfo) { |
| | | try { |
| | | List<Users> list = usersMapper.selectJoinList(Users.class,new MPJLambdaWrapper<Users>() |
| | | .selectAll(Users.class) |
| | | ); |
| | | List<Users> insertList = new ArrayList<>(); |
| | | List<Users> updateList = new ArrayList<>(); |
| | | for(int i=0;i<dataList.size();i++){ |
| | | UserImport model = dataList.get(i); |
| | | if(StringUtils.isBlank(model.getName()) |
| | | &&StringUtils.isBlank(model.getCode()) ){ |
| | | continue; |
| | | } |
| | | Users user = checkModelParam(model,insertList,updateList,i,loginUserInfo,list,date); |
| | | } |
| | | if(insertList .size() >0){ |
| | | int temp = 0; |
| | | while(temp < insertList.size()){ |
| | | int index; |
| | | if(temp + 500 <= insertList.size()){ |
| | | index = temp+500; |
| | | }else{ |
| | | index = insertList.size(); |
| | | } |
| | | usersMapper.insert(insertList.subList(temp,index)); |
| | | temp = index; |
| | | } |
| | | } |
| | | if(updateList .size() >0){ |
| | | for(Users s : updateList){ |
| | | //遍历更新数据 |
| | | usersMapper.updateById(s); |
| | | } |
| | | } |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | }catch (Exception e){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"信息导入失败,请稍后重试"); |
| | | }finally { |
| | | executor.shutdown(); |
| | | redisTemplate.delete(Constants.RedisKeys.IMPORTING_USERS); |
| | | } |
| | | } |
| | | private Users getUserByUserID(String userId, List<Users> list) { |
| | | if(list ==null || list.size() ==0){ |
| | | return null; |
| | | } |
| | | for(Users s :list){ |
| | | if(StringUtils.equals(s.getIamId(),userId)){ |
| | | return s; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private Users checkModelParam(UserImport model, List<Users> insertList, List<Users> updateList, int index, LoginUserInfo loginUserInfo, List<Users> list, Date date) { |
| | | |
| | | if(StringUtils.isBlank(model.getUserId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【编码】信息不完整,请检查表格内容!"); |
| | | } |
| | | if(StringUtils.isBlank(model.getName())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【姓名】信息不完整,请检查表格内容!"); |
| | | } |
| | | if(StringUtils.isBlank(model.getAccountNo())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【登录账号】信息不完整,请检查表格内容!"); |
| | | } |
| | | if(StringUtils.isBlank(model.getPhone())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第"+(index+3)+"行【手机号】信息不完整,请检查表格内容!"); |
| | | } |
| | | Users users = getUserByUserID(model.getUserId(),list); |
| | | if(users == null){ |
| | | users = new Users(); |
| | | users.setCreator(loginUserInfo.getId()); |
| | | users.setCreateDate(date); |
| | | initUsersInfo(users,model,date,loginUserInfo); |
| | | insertList.add(users); |
| | | }else { |
| | | initUsersInfo(users,model,date,loginUserInfo); |
| | | updateList.add(users); |
| | | } |
| | | return users; |
| | | } |
| | | |
| | | private void initUsersInfo(Users users, UserImport model,Date date,LoginUserInfo loginUserInfo ){ |
| | | users.setEditor(loginUserInfo.getId()); |
| | | users.setEditDate(date); |
| | | users.setName(model.getName()); |
| | | users.setIamUsername(model.getAccountNo()); |
| | | users.setPhone(model.getPhone()); |
| | | users.setStatus(model.getStatus()); |
| | | users.setEmail(model.getEmail()); |
| | | users.setIamId(model.getUserId()); |
| | | users.setCode(model.getCode()); |
| | | users.setSex(model.getSex()); |
| | | users.setStatus(model.getStatus()); |
| | | users.setIsdeleted(Constants.ZERO); |
| | | users.setRoleIds(""); |
| | | users.setRoleNames(""); |
| | | users.setRoleCodes(""); |
| | | users.setUserTypes(""); |
| | | users.setIamOrgId(""); |
| | | getDepartidByParam(users,model.getOrgIds()); |
| | | setRolesInfo(users,model); |
| | | getUserTypesByParam(users,model.getTypeCodes()); |
| | | } |
| | | |
| | | private String getUserTypesByParam(Users users,String typeCodes) { |
| | | if( typeCodes !=null){ |
| | | String[] codes =typeCodes.split(","); |
| | | for(String t : codes){ |
| | | if(StringUtils.isBlank(users.getUserTypes())){ |
| | | users.setUserTypes(""); |
| | | } |
| | | users.setUserTypes(users.getUserTypes()+"["+t+"];"); |
| | | } |
| | | } |
| | | return users.getUserTypes(); |
| | | } |
| | | |
| | | private void setRolesInfo(Users users, UserImport model) { |
| | | if( model.getRoleCodes() !=null){ |
| | | String[] codes = model.getRoleCodes().split(","); |
| | | for(String t : codes){ |
| | | if(StringUtils.isBlank(users.getRoleCodes())){ |
| | | users.setRoleCodes(""); |
| | | } |
| | | users.setRoleCodes(users.getRoleCodes()+"["+t+"];"); |
| | | } |
| | | } |
| | | if( model.getRoleIds() !=null){ |
| | | String[] codes = model.getRoleIds().split(","); |
| | | for(String t : codes){ |
| | | if(StringUtils.isBlank(users.getRoleIds())){ |
| | | users.setRoleIds(""); |
| | | } |
| | | users.setRoleIds(users.getRoleIds()+"["+t+"];"); |
| | | } |
| | | } |
| | | if( model.getRoleNames() !=null){ |
| | | String[] codes = model.getRoleNames().split(","); |
| | | for(String t : codes){ |
| | | if(StringUtils.isBlank(users.getRoleNames())){ |
| | | users.setRoleNames(""); |
| | | } |
| | | users.setRoleNames(users.getRoleNames()+"["+t+"];"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private Shop getDepartidByParam(Users users , String orgIds) { |
| | | if( orgIds ==null){ |
| | | return null; |
| | | } |
| | | String[] orgArray = orgIds.split(","); |
| | | if( orgArray !=null && orgArray.length>0){ |
| | | for(String t : orgArray){ |
| | | Shop shop = shopMapper.selectOne(new QueryWrapper<Shop>().lambda() |
| | | .eq(Shop::getOrgId,t) |
| | | .last("limit 1")); |
| | | if(shop!=null) { |
| | | users.setIamOrgId(t); |
| | | users.setDepartmentId(shop.getId()); |
| | | return shop; |
| | | } |
| | | } |
| | | } |
| | | users.setIamOrgId(orgIds+"--尚未同步到组织"); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String getContentShareImg(Users users, ContentShareImgDto param){ |
| | | log.error("======================start===========:海报开始"+JSONObject.toJSONString(param)); |
| | | users = usersMapper.selectById(users.getId()); |
| | | this.getUsersDetail(users); |
| | | 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.getArticleId()+"_"+users.getId(), |
| | | 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; |
| | | log.error("======================start===========:海报开始"); |
| | | InputStream mpCode = Constants.generateWxMiniImgStream(systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG, Constants.WX_TOKEN_CUSTOMER).getCode(), |
| | | //"userId="+users.getId()+"&articleId="+param.getArticleId(), |
| | | param.getArticleId()+"_"+users.getId(), |
| | | param.getPageUrl());//小程序 |
| | | |
| | | log.error("======================mpcode===========:获取小程序码开始"); |
| | | String title = systemDictDataBiz.queryByCode(Constants.WEIXIN_DEFAULT_IMGS, Constants.SHARE_HAIBAO_HEADER_TITLE).getCode(); |
| | | InputStream inputStream = GeneratePicUtil.generateShareImg( |
| | | param.getImgurl() |
| | | ,mpCode |
| | | ,title); |
| | | |
| | | log.error("======================huatu===========:画图结束"); |
| | | 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){ |
| | | users = usersMapper.selectById(users.getId()); |
| | | this.getUsersDetail(users); |
| | | String path = systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.RESOURCE_PATH).getCode(); |
| | | String folder = systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.USERS_FILE).getCode(); |
| | | if(StringUtils.isNotBlank(users.getCardImg()) && !StringUtils.equals(users.getCardImg(),"-")){ |
| | | return path + folder+users.getCardImg(); |
| | | } |
| | | String defualtHeader = systemDictDataBiz.queryByCode(Constants.WEIXIN_DEFAULT_IMGS, Constants.USER_CARD_HEADER_IMG).getCode(); |
| | | String defualtPhone = systemDictDataBiz.queryByCode(Constants.WEIXIN_DEFAULT_IMGS, Constants.USER_CARD_PHONE_IMG).getCode(); |
| | | String defualtAddr = systemDictDataBiz.queryByCode(Constants.WEIXIN_DEFAULT_IMGS, Constants.USER_CARD_ADDR_IMG).getCode(); |
| | | String defualtShop = systemDictDataBiz.queryByCode(Constants.WEIXIN_DEFAULT_IMGS, Constants.USER_CARD_SHOP_IMG).getCode(); |
| | | String defualtLogo = systemDictDataBiz.queryByCode(Constants.WEIXIN_DEFAULT_IMGS, Constants.USER_CARD_LOGO_IMG).getCode(); |
| | | String imgurl =StringUtils.isNotBlank(users.getImgurl())?path+folder+users.getImgurl():defualtHeader; |
| | | String qrcode =StringUtils.isNotBlank(users.getQrcodeImg())?path+folder+users.getQrcodeImg():null; |
| | | InputStream inputStream = GeneratePicUtil.generateUserCardImg( |
| | | imgurl |
| | | ,qrcode |
| | | ,StringUtils.defaultString(users.getName(),"-") |
| | | ,"导购" |
| | | ,StringUtils.defaultString(users.getPhone(),"-") |
| | | ,StringUtils.defaultString(users.getShopAddress(),"-") |
| | | , StringUtils.defaultString(users.getShopName(),"-") |
| | | ,defualtPhone |
| | | ,defualtAddr |
| | | ,defualtShop |
| | | ,defualtLogo); |
| | | 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 =folder+ key; |
| | | if (obs.uploadInputstreamObject(inputStream,systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE, Constants.BUCKETNAME).getCode(), fileName)) { |
| | | Users update = new Users(); |
| | | update.setId(users.getId()); |
| | | update.setCardImg(key); |
| | | usersMapper.updateById(update); |
| | | return path+fileName; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | 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())){ |
| | | users.setImgurlFull(prefix + users.getImgurl()); |
| | | } |
| | | if(StringUtils.isNotBlank(users.getQrcodeImg())){ |
| | | users.setQrcodeImgFull(prefix + users.getQrcodeImg()); |
| | | } |
| | | if(StringUtils.isNotBlank(users.getCompanyQrcodeImg())){ |
| | | users.setCompanyQrcodeImgFull(prefix + users.getCompanyQrcodeImg()); |
| | | } |
| | | if(StringUtils.isBlank(users.getSlogans())){ |
| | | users.setSlogans(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.ZBOM_CUSTOMIZED,Constants.USER_LABEL).getCode())); |
| | | } |
| | | users.setManageShop(false); |
| | | if(StringUtils.isNotBlank(users.getRoleCodes())){ |
| | | if(users.getRoleCodes().indexOf(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.ZBOM_CUSTOMIZED,Constants.USERS_MANAGE_CODE).getCode()))>=0){ |
| | | users.setManageShop(true); |
| | | } |
| | | } |
| | | if(Objects.nonNull(users.getDepartmentId())){ |
| | | Shop shop = shopMapper.selectById(users.getDepartmentId()); |
| | | if(Objects.nonNull(shop)){ |
| | | users.setShopName(shop.getName()); |
| | | if(StringUtils.isNotBlank(shop.getAddress())){ |
| | | users.setShopAddress(shop.getAddress()); |
| | | }else{ |
| | | if(!(StringUtils.isBlank(shop.getProvinceName())||StringUtils.isBlank(shop.getCityName())||StringUtils.isBlank(shop.getAreaName()))){ |
| | | users.setShopAddress(shop.getProvinceName()+shop.getCityName()+shop.getAreaName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void editUserInfo(EditUsersRequest editUsersRequest){ |
| | | if(Objects.isNull(editUsersRequest)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Users users = usersMapper.selectById(editUsersRequest.getUserId()); |
| | | if(Objects.isNull(users)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | //TODO 调起 中台接口 |
| | | usersMapper.update(new UpdateWrapper<Users>() |
| | | .lambda() |
| | | .set(Users::getCardImg,null) //重置名片为 - |
| | | .set(StringUtils.isNotBlank(editUsersRequest.getImgurl()),Users::getImgurl,editUsersRequest.getImgurl()) |
| | | .set(StringUtils.isNotBlank(editUsersRequest.getName()),Users::getName,editUsersRequest.getName()) |
| | | .set(StringUtils.isNotBlank(editUsersRequest.getPhone()),Users::getPhone,editUsersRequest.getPhone()) |
| | | .set(StringUtils.isNotBlank(editUsersRequest.getCompanyQrcodeImg()),Users::getCompanyQrcodeImg,editUsersRequest.getCompanyQrcodeImg()) |
| | | .set(StringUtils.isNotBlank(editUsersRequest.getQrcodeImg()),Users::getQrcodeImg,editUsersRequest.getQrcodeImg()) |
| | | .set(StringUtils.isNotBlank(editUsersRequest.getSlogans()),Users::getSlogans,editUsersRequest.getSlogans()) |
| | | .set(Objects.nonNull(editUsersRequest.getCostomerNum()),Users::getCostomerNum,editUsersRequest.getCostomerNum()) |
| | | .set(Objects.nonNull(editUsersRequest.getJobDate()),Users::getJobDate,editUsersRequest.getJobDate()) |
| | | .set(StringUtils.isNotBlank(editUsersRequest.getPhone()),Users::getPhone,editUsersRequest.getPhone()) |
| | | .eq(Users::getId,editUsersRequest.getUserId())); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public ZTBaseRequst logOff(Long userId,String token){ |
| | | Users users = usersMapper.selectById(userId); |
| | | if(Objects.isNull(users)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | //校验用户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::getOpenid,users.getOpenid()) |
| | | ); |
| | | redisTemplate.delete(token); |
| | | return ztBaseRequst; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public InputStream getQrCode(GenerateQRCodeRequest generateQRCodeRequest){ |
| | | if(Objects.isNull(generateQRCodeRequest) |
| | | ||StringUtils.isBlank(generateQRCodeRequest.getIamId()) |
| | | || StringUtils.isBlank(generateQRCodeRequest.getBusinessId()) |
| | | || Objects.isNull(generateQRCodeRequest.getBusinessType())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | if(generateQRCodeRequest.getBusinessType()<Constants.ZERO || generateQRCodeRequest.getBusinessType() > Constants.THREE){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"业务类型错误"); |
| | | } |
| | | Users users = usersMapper.selectOne(new QueryWrapper<Users>().lambda().eq(Users::getIamId, |
| | | generateQRCodeRequest.getIamId()).last("limit 1")); |
| | | if(Objects.isNull(users)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到员工信息"); |
| | | } |
| | | InputStream inputStream = Constants.generateWxMiniImgStream( |
| | | systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG, Constants.WX_TOKEN_CUSTOMER).getCode(), |
| | | generateQRCodeRequest.getBusinessId()+"_"+generateQRCodeRequest.getBusinessType()+"_"+users.getId(), |
| | | null);//小程序 |
| | | return inputStream; |
| | | // try { |
| | | // ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | // byte[] buffer = new byte[1024]; |
| | | // int len = -1; |
| | | // while ((len = inputStream.read(buffer)) != -1) { |
| | | // baos.write(buffer, 0, len); |
| | | // } |
| | | // return "data:mediatype;base64," + Base64.getEncoder().encodeToString(baos.toByteArray()); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"二维码生成失败"); |
| | | } |
| | | } |
| | | |