From c93e76c57a98e35abbf62d2f514d9ba51efd3243 Mon Sep 17 00:00:00 2001 From: jiangqs <jiangqs> Date: 星期一, 21 八月 2023 19:03:55 +0800 Subject: [PATCH] bug --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysStaffServiceImpl.java | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 146 insertions(+), 1 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysStaffServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysStaffServiceImpl.java index 4033b05..fd20568 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysStaffServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysStaffServiceImpl.java @@ -1,27 +1,37 @@ package com.ruoyi.system.service.impl.staff; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.uuid.IdUtils; +import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.constant.AppErrorConstant; +import com.ruoyi.system.api.constant.SecurityConstant; +import com.ruoyi.system.api.domain.dto.MerEditUserDto; import com.ruoyi.system.api.domain.dto.MgtBaseGetDto; +import com.ruoyi.system.api.domain.dto.MgtShopStaffEditDto; import com.ruoyi.system.api.domain.poji.sys.SysUser; +import com.ruoyi.system.api.service.RemoteShopService; import com.ruoyi.system.domain.dto.MgtStaffEditDto; import com.ruoyi.system.domain.dto.MgtStaffPageDto; +import com.ruoyi.system.domain.dto.MgtSysStaffImportDto; import com.ruoyi.system.domain.pojo.staff.SysStaff; import com.ruoyi.system.domain.vo.MgtDeptStaffListVo; import com.ruoyi.system.domain.vo.MgtStaffPageVo; import com.ruoyi.system.mapper.staff.SysStaffMapper; import com.ruoyi.system.service.staff.SysStaffService; import com.ruoyi.system.service.sys.ISysUserService; +import com.ruoyi.system.util.QiYeUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Date; import java.util.List; +import java.util.concurrent.TimeUnit; /** * <p> @@ -39,6 +49,13 @@ @Resource private ISysUserService sysUserService; + + @Resource + private RedisService redisService; + + @Resource + private RemoteShopService remoteShopService; + /** * @description 获取部门员工列表 @@ -149,6 +166,12 @@ sysStaff.setStaffAvatar(mgtStaffEditDto.getStaffAvatar()); sysStaff.setHeadFlag(mgtStaffEditDto.getHeadFlag()); this.saveOrUpdate(sysStaff); + MgtShopStaffEditDto mgtShopStaffEditDto = new MgtShopStaffEditDto(); + mgtShopStaffEditDto.setUserId(sysStaff.getUserId()); + mgtShopStaffEditDto.setStaffName(sysStaff.getStaffName()); + mgtShopStaffEditDto.setStaffMobile(sysStaff.getStaffMobile()); + mgtShopStaffEditDto.setStaffAvatar(sysStaff.getStaffAvatar()); + remoteShopService.editMgtShopStaff(mgtShopStaffEditDto); } /** @@ -165,7 +188,7 @@ sysStaff.setDelFlag(1); sysStaff.setStaffMobile(sysStaff.getStaffMobile()+":已删除"); this.saveOrUpdate(sysStaff); - sysUserService.deleteUserById(mgtBaseGetDto.getUserId()); + sysUserService.deleteUserById(userId); } /** @@ -195,4 +218,126 @@ queryWrapper.eq(SysStaff::getStaffMobile,mobile); return this.getOne(queryWrapper,false); } + + + + + + /** + * @description 获取企业微信token + * @author jqs + * @date 2023/7/18 19:35 + * @param + * @return String + */ + private String getQYToken(){ + String accessToken = redisService.getCacheObject(SecurityConstant.QY_TOKEN); + if(StringUtils.isBlank(accessToken)){ + try { + accessToken = QiYeUtils.getAccessTokenByQY(); + JSONObject jsonAccessToken = JSONObject.parseObject(accessToken); + String errcode = jsonAccessToken.getString("errcode"); + String errmsg = jsonAccessToken.getString("errmsg"); + if(errcode.equals("0")){ + accessToken = jsonAccessToken.getString("access_token"); + Long expiresIn = jsonAccessToken.getLong("expires_in"); + expiresIn = expiresIn -100; + redisService.setCacheObject(SecurityConstant.QY_TOKEN,accessToken,expiresIn, TimeUnit.SECONDS); + }else{ + throw new ServiceException(errmsg); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + return accessToken; + } + + + /** + * @description 编辑商户员工 + * @author jqs + * @date 2023/7/19 19:42 + * @param merEditUserDto + * @return void + */ + @Override + public void editSysStaffInfo(MerEditUserDto merEditUserDto){ + SysStaff sysStaff = this.getByUserId(merEditUserDto.getUserId()); + Integer editType = merEditUserDto.getEditType(); + switch (editType){ + case 1: + sysStaff.setStaffName(merEditUserDto.getEditValue()); + break; + case 2: + sysStaff.setStaffAvatar(merEditUserDto.getEditValue()); + break; + case 3: + break; + case 4: + break; + default: + break; + } + this.saveOrUpdate(sysStaff); + } + + /** + * @description 导入员工 + * @author jqs + * @date 2023/8/18 16:04 + * @param + * @return void + */ + @Override + public String importSysStaff(List<MgtSysStaffImportDto> staffImportDtoList){ + if (StringUtils.isNull(staffImportDtoList) || staffImportDtoList.size() == 0) { + throw new ServiceException("导入数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + SysStaff sysStaff; + Date nowTime = new Date(); + for (MgtSysStaffImportDto entity : staffImportDtoList) { + try { + /*tagName = entity.getTagName(); + sysTagSame = null; + // 验证是否存在这个用户 + queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysTag::getDelFlag, 0) // 查询条件:delFlag=0 + .eq(SysTag::getTagType, tagType) // 查询条件:tagType=mgtTagEditDto的tagType属性 + .eq(SysTag::getTagName, tagName); // 查询条件:tagName=mgtTagEditDto的tagName属性 + // 执行查询,获取与查询条件匹配的SysTag对象 + sysTagSame = this.getOne(queryWrapper); + if (sysTagSame == null) { + sysTagNew = new SysTag(); + sysTagNew.setDelFlag(0); + sysTagNew.setTagType(tagType); + sysTagNew.setTagName(tagName); + sysTagNew.setCreateTime(nowTime); + sysTagNew.setSynFlag(0); + this.save(sysTagNew); + successNum++; + successMsg.append("<br/>" + successNum + "、标签 " + sysTagNew.getTagName() + " 导入成功"); + } else { + failureNum++; + failureMsg.append("<br/>" + failureNum + "、标签 " + sysTagSame.getTagName() + " 已存在"); + }*/ + } catch (Exception e) { + failureNum++; + String msg = "<br/>" + failureNum + "、标签 " + entity.getStaffName() + " 导入失败:"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new ServiceException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } } -- Gitblit v1.7.1