Commit 0214496f authored by huyuchen's avatar huyuchen

huych-入离职登记提交

parent 63947b73
......@@ -2,6 +2,7 @@ package com.yifu.cloud.plus.v1.csp.entity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
......@@ -82,9 +83,21 @@ public class EmployeeRegistration extends BaseEntity {
@Schema(description = "客服姓名")
private String customerUsername;
@Schema(description = "客服姓名")
@Schema(description = "客服登录名")
private String customerUserLoginname;
@Schema(description = "项目立项时间")
@TableField(exist = false)
private LocalDateTime projectCreateTime;
@Schema(description = "入职登记人数")
@TableField(exist = false)
private int inNum;
@Schema(description = "离职登记人数")
@TableField(exist = false)
private int outNum;
}
package com.yifu.cloud.plus.v1.csp.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.CheckedException;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* @Author: huyc
* @Date: 2023/7/28
* @Description:
* @return: 企业微信配置
**/
@Configuration
@Data
@Slf4j
public class WxConfig {
@Value("${wx.corpid}")
private String corpid;
@Value("${wx.corpsecret}")
private String corpsecret;
@Value("${wx.agentid}")
private String agentid;
@Value("${wx.authUrl}")
private String authUrl;
@Value("${wx.domainName}")
private String domainName;
@Autowired
private RedisTemplate redisTemplate;
//未授权
private String accossTokenInvliad = "40014";
/**
* @param
* @Author: huyc
* @Date: 2023/7/28
* @Description: 获取微信accos_token
* @return: java.lang.String
**/
public String getAccessToken(RestTemplate restTemplate) {
if (Common.isNotNull(agentid)) {
return this.getToken(restTemplate, CacheConstants.WX_ACCOSS_TOKEN.concat(agentid), corpsecret);
}
return this.getToken(restTemplate, CacheConstants.WX_ACCOSS_TOKEN, corpsecret);
}
public String getAccessToken(RestTemplate restTemplate,String corpsecret)throws AuthenticationServiceException {
if(Common.isEmpty(corpsecret)){
throw new AuthenticationServiceException("未找到对应的corpsecret请联系管理员配置");
}
return this.getToken(restTemplate, CacheConstants.WX_ACCOSS_TOKEN.concat(agentid), corpsecret);
}
/**
* @param restTemplate
* @param tokenKey
* @param corpsecretKey
* @Description: 获取token
* @Author: huyc
* @Date: 2023/7/28 14:46
* @return: java.lang.String
**/
public String getToken(RestTemplate restTemplate,String tokenKey, String corpsecretKey) {
Object wxToken = redisTemplate.opsForValue().get(tokenKey);
if (null != wxToken) {
return String.valueOf(wxToken);
}
String requestTokenUrl = String.format(SecurityConstants.WX_GET_ACCOSS_TOKEN, corpid, corpsecretKey);
String result = restTemplate.getForObject(requestTokenUrl, String.class);
if (Common.isEmpty(result)) {
throw new CheckedException("微信授权失败");
}
String token = JSON.parseObject(result).getString("access_token");
if (Common.isEmpty(token)) {
log.info(result);
throw new CheckedException("获取微信token失败");
}
redisTemplate.opsForValue().set(tokenKey, token);
redisTemplate.expire(tokenKey, 3600, TimeUnit.SECONDS);
return token;
}
/**
* @param
* @Author: huyc
* @Date: 2023/7/28 14:43
* @Description: 移除微信accossToken
* @return: java.lang.String
**/
public void removeAccessToken() {
redisTemplate.delete(CacheConstants.WX_ACCOSS_TOKEN);
}
/**
* @param restTemplate
* @param requestMap 请求内容
* @Author: huyc
* @Date: 2023/7/28 14:48
* @Description: 发送卡片消息
* @return: java.lang.String
**/
public boolean sendTextCard(RestTemplate restTemplate, Map<String, Object> requestMap) {
// 必须加上header说明
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
Gson gson = new Gson();
log.debug("发企业微信===请求:{}", gson.toJson(requestMap));
HttpEntity<String> requestEntity = new HttpEntity<>(gson.toJson(requestMap), headers);
String accessToken = getAccessToken(restTemplate);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(String.format(SecurityConstants.WX_SEND_MESSAGE, accessToken), requestEntity, String.class);
log.debug("发企业微信===返回:{}",JSON.toJSONString(responseEntity));
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(responseEntity));
JSONObject jsonBody = jsonObject.getJSONObject("body");
if (jsonBody != null) {
String errcode = jsonBody.getString("errcode");
if (accossTokenInvliad.equals(errcode)) {
//删除accossToken缓存
removeAccessToken();
return false;
}
if (!CommonConstants.ZERO_STRING.equals(errcode)) { //非正常,则打印错误日志
log.info(jsonObject.toJSONString());
}
} else {
log.info(jsonObject.toJSONString());
}
return true;
}
/**
* 功能描述: 获取微信accos_token
* @Author: huyc
* @Date: 2023/7/28 14:50
* @return: java.lang.String
*/
public String getAppAccessToken(RestTemplate restTemplate) {
return this.getToken(restTemplate, CacheConstants.WX_ACCOSS_TOKEN, corpsecret);
}
}
......@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.csp.config.WxConfig;
import com.yifu.cloud.plus.v1.csp.constants.RegistConstants;
import com.yifu.cloud.plus.v1.csp.entity.EmployeeRegistration;
import com.yifu.cloud.plus.v1.csp.mapper.EmployeeRegistrationMapper;
......@@ -21,6 +22,7 @@ import com.yifu.cloud.plus.v1.csp.vo.EmployeeRegistrationExportVo;
import com.yifu.cloud.plus.v1.csp.vo.EmployeeRegistrationHrExportVo;
import com.yifu.cloud.plus.v1.csp.vo.EmployeeRegistrationSearchVo;
import com.yifu.cloud.plus.v1.csp.vo.EmployeeRegistrationVo;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmpProjectStatusVo;
import com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainSelectVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
......@@ -30,6 +32,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprArchivesProperties;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.ArchivesDaprUtil;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.HttpDaprUtil;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.UpmsDaprUtils;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import com.yifu.cloud.plus.v1.yifu.insurances.util.ValidityUtil;
import lombok.AllArgsConstructor;
......@@ -37,6 +40,7 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
......@@ -69,6 +73,12 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
@Autowired
private ArchivesDaprUtil archivesDaprUtil;
@Autowired
private WxConfig wxConfig;
@Autowired
private UpmsDaprUtils upmsDaprUtils;
private final TOperationLogService logService;
/**
......@@ -185,8 +195,10 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
YifuUser user = SecurityUtils.getUser();
//获取项目信息
R<TSettleDomainSelectVo> domainR = archivesDaprUtil.getSettleDomainSelectVoById(deptId);
if (null == domainR || null == domainR.getData()) {
errorMessageList.add(new ErrorMessage(-1, "访问员工基础服务异常:"));
return R.ok(errorMessageList);
}
TSettleDomainSelectVo selectVo = domainR.getData();
// 写法2:
......@@ -197,7 +209,7 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
/**
* 单次缓存的数据量
*/
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT;
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT1;
/**
*临时存储
*/
......@@ -245,9 +257,10 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
private void importEmployeeRegistration(List<EmployeeRegistrationVo> excelVOList,
List<ErrorMessage> errorMessageList,YifuUser user,TSettleDomainSelectVo selectVo) {
List<EmployeeRegistration> successList = new ArrayList<>();
Map<String, String> exitMap = new HashMap<>();
EmployeeRegistrationVo excel;
int inNum = 0;
int outNum = 0;
for (int i = 0; i < excelVOList.size(); i++) {
excel = excelVOList.get(i);
// 插入
......@@ -273,12 +286,26 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
continue;
}
initRegistInfo(insert,user, selectVo);
successList.add(insert);
}
// 执行数据插入操作 组装
if (!successList.isEmpty()) {
this.saveBatch(successList);
//新增记录,新增操作记录
baseMapper.insert(insert);
if (CommonConstants.ONE_STRING.equals(insert.getFeedbackType())) {
inNum ++;
} else {
outNum ++;
}
logService.saveLog(insert.getId(), CommonConstants.ZERO_STRING,RegistConstants.MESSAGE_REGIST, LocalDateTime.now(),
insert.getRegistorUsername(),null);
}
//发送企业微信待办
EmployeeRegistration msgRegistration = new EmployeeRegistration();
msgRegistration.setInNum(inNum);
msgRegistration.setOutNum(outNum);
msgRegistration.setCustomerUserLoginname(selectVo.getCsLoginName());
msgRegistration.setDeptName(selectVo.getDepartName());
msgRegistration.setDeptNo(selectVo.getDepartNo());
//企业微信消息提醒
sendMessageToWx(msgRegistration,CommonConstants.THREE_STRING);
}
public R registAdd(EmployeeRegistration registration) {
......@@ -291,6 +318,8 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
} else {
baseMapper.insert(registration);
}
//企业微信消息提醒
sendMessageToWx(registration,registration.getFeedbackType());
//操作记录
logService.saveLog(registration.getId(), CommonConstants.ZERO_STRING,RegistConstants.MESSAGE_REGIST, LocalDateTime.now(),
registration.getRegistorUsername(),null);
......@@ -389,9 +418,62 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
insert.setEmpDeptname(user.getDeptName());
insert.setCustomerPhone(selectVo.getCsPhone());
insert.setCustomerUsername(selectVo.getCsName());
insert.setCustomerUserLoginname(selectVo.getCsLoginName());
insert.setDeptNo(selectVo.getDepartNo());
insert.setDeptName(selectVo.getDepartName());
insert.setDeptId(selectVo.getId());
}
//发送企业微信待办
private void sendMessageToWx(EmployeeRegistration registration, String type) {
//获取前端客服
SysUser user;
R<SysUser> res = upmsDaprUtils.getSimpleUserByLoginName(registration.getCustomerUserLoginname());
if (Common.isNotNull(res) && Common.isNotNull(res.getData())){
user = res.getData();
}else {
return;
}
StringBuilder sendUser = null;
if (Common.isNotKong(user.getWxMessage())) {
sendUser = new StringBuilder(user.getWxMessage());
}
if (sendUser != null) {
RestTemplate restTemplate = new RestTemplate();
Map<String, Object> requestMap = new HashMap<>();
// String authUrl = null;
Map<String, Object> textcard = new HashMap<>();
// authUrl = String.format(SecurityConstants.WX_GET_MESSAGE_AUTH_URL, wxConfig.getCorpid(), wxConfig.getDomainName()+"/auth/oauth/wxLogin", "01"+registration.getId());
StringBuilder description = new StringBuilder();
String title = "";
if (CommonConstants.ONE_STRING.equals(type) || CommonConstants.TWO_STRING.equals(type)) {
title = "人员入职提醒";
description.append(CommonConstants.ONE_STRING.equals(type) ? "入职日期:":"离职日期:")
.append(registration.getJoinLeaveDate()).append("<br>");
description.append("项目名称:").append(registration.getDeptName()).append("<br>");
description.append("项目编码:").append(registration.getDeptNo()).append("<br>");
description.append("员工姓名:").append(registration.getEmployeeName()).append("<br>");
description.append("身份证号:").append(registration.getEmpIdcard()).append("<br>");
description.append("手机号码:").append(registration.getEmpPhone()).append("<br>");
} else {
title = "人员批量入离职提醒";
description.append("项目名称:").append(registration.getDeptName()).append("<br>");
description.append("项目编码:").append(registration.getDeptNo()).append("<br>");
description.append("入职人数:").append(registration.getInNum()).append("<br>");
description.append("离职人数:").append(registration.getOutNum()).append("<br>");
}
textcard.put("title", title);
// textcard.put("url", authUrl);
textcard.put("description", description.toString());
requestMap.put("touser", sendUser);
requestMap.put("agentid", wxConfig.getAgentid());
requestMap.put("msgtype", "textcard");
requestMap.put("textcard", textcard);
// 必须加上header说明
if (!wxConfig.sendTextCard(restTemplate, requestMap)) {
wxConfig.sendTextCard(restTemplate, requestMap);
}
}
}
}
......@@ -37,4 +37,11 @@ security:
urls:
- /v3/api-docs
- /actuator/**
- /swagger-ui/**
\ No newline at end of file
- /swagger-ui/**
wx:
corpid: wwbcb090af0dfe50e5
corpsecret: R0nKkvsY-oF41fuQvUXZ-kFG3_g_Ce0bpZt6mByx524
agentid: 1000009
authUrl: https://wx.worfu.com/yifu-auth/method/oauth/wxLogin
domainName: https://wx.worfu.com
\ No newline at end of file
......@@ -38,3 +38,10 @@ security:
- /v3/api-docs
- /actuator/**
- /swagger-ui/**
wx:
corpid: wwbcb090af0dfe50e5
corpsecret: 16kqEL_eU-ARwYyqLgEBWHgxm8gXVnkzv_eJMLy9NpU
agentid: 1000010
authUrl: https://test-wx.worfu.com/yifu-auth/method/oauth/wxLogin
domainName: https://test-wx.worfu.com
......@@ -224,6 +224,18 @@ public class UserController {
return userService.updatePassword(vo);
}
/**
* 修改密码
*
* @param vo 用户信息
* @return R
*/
@SysLog("重置密码")
@PostMapping("/resetPassword")
public R<String> resetPassword(@RequestBody UserPasswordVo vo) {
return userService.resetPassword(vo);
}
/**
* 分页查询用户
*
......
......@@ -86,6 +86,15 @@ public interface SysUserService extends IService<SysUser> {
**/
R<String> updatePassword(UserPasswordVo vo);
/**
* @param vo
* @Description: 重置密码
* @Author: hgw
* @Date: 2025/3/3 9:25
* @return: java.lang.Boolean
**/
R<String> resetPassword(UserPasswordVo vo);
/**
* 通过ID查询用户信息
* @param id 用户ID
......
......@@ -329,6 +329,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return R.ok();
}
@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#vo.userName")
public R<String> resetPassword(UserPasswordVo vo) {
SysUser sysUser = this.getOne(Wrappers.<SysUser>query().lambda()
.eq(SysUser::getUserId, vo.getUserId())
.eq(SysUser::getType, CommonConstants.FOUR_STRING));
if (Common.isNotNull(sysUser)) {
sysUser.setPassword(ENCODER.encode("123456"));
}
this.updateById(sysUser);
return R.ok();
}
/**
* 查询上级部门的用户信息
* @param username 用户名
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment