Commit b4c0b7eb authored by huyuchen's avatar huyuchen

huych-入职登记商险待办提交

parent 09c8efcc
......@@ -1036,19 +1036,6 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
**/
@Override
public TEmployeeProjectBelongDept getZeroRegistrationAndUpdateTwo(TEmployeeProjectBelongDeptSearchCspVo searchCspVo) {
// EmployeeRegistration registration = baseMapper.selectOne(Wrappers.<EmployeeRegistration>query().lambda()
// .eq(EmployeeRegistration::getDeptId, searchCspVo.getDeptId())
// .eq(EmployeeRegistration::getEmpIdcard, searchCspVo.getEmpIdCard())
// .eq(EmployeeRegistration::getProcessStatus, CommonConstants.ZERO_STRING)
// .eq(EmployeeRegistration::getDataSource,CommonConstants.TWO_STRING)
// .last(CommonConstants.LAST_ONE_SQL));
// if (Common.isNotNull(registration)) {
// registration.setProcessStatus(CommonConstants.TWO_STRING);
// baseMapper.updateById(registration);
// logService.saveInnerLog(registration.getId(), CommonConstants.ZERO_STRING, RegistConstants.MESSAGE_FINISH, searchCspVo.getEmpCreateAndLeaveTime(),
// searchCspVo.getEmpCreateAndLeaveUser(),null,searchCspVo.getUserId() );
// return null;
// } else {
List<TEmployeeProjectBelongDept> belongDeptList = baseMapper.getZeroRegistrationByIdCard(searchCspVo);
if (belongDeptList != null && !belongDeptList.isEmpty()) {
// 1:加日志
......@@ -1059,7 +1046,6 @@ public class EmployeeRegistrationServiceImpl extends ServiceImpl<EmployeeRegistr
} else {
return null;
}
// }
}
/**
......
......@@ -120,13 +120,13 @@ public class InsuranceAutoParam implements Serializable {
* 保单开始时间
*/
@Schema(description = "保单开始时间")
private LocalDate policyStart;
private String policyStart;
/**
* 保单结束时间
*/
@Schema(description = "保单结束时间")
private LocalDate policyEnd;
private String policyEnd;
/**
* 替换员工姓名
......
package com.yifu.cloud.plus.v1.yifu.insurances.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);
}
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.yifu.insurances.service.insurance;
import com.baomidou.mybatisplus.core.metadata.IPage;
......
......@@ -9,23 +9,26 @@ 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.vo.EmployeeRegistrationCustomerUserUpdateVo;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmployeeRegistrationPreVo;
import com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainRegistListVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ClientNameConstants;
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.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.DateUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.LocalDateTimeUtils;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.ArchivesDaprUtil;
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.config.WxConfig;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TEmployeeInsurancePre;
import com.yifu.cloud.plus.v1.yifu.insurances.mapper.insurances.TEmployeeInsurancePreMapper;
import com.yifu.cloud.plus.v1.yifu.insurances.service.insurance.ScheduleService;
import com.yifu.cloud.plus.v1.yifu.insurances.service.insurance.TEmployeeInsurancePreService;
import com.yifu.cloud.plus.v1.yifu.insurances.service.insurance.TInsuranceDetailService;
import com.yifu.cloud.plus.v1.yifu.insurances.util.LocalDateUtil;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
......@@ -36,13 +39,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.web.client.RestTemplate;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -68,6 +71,12 @@ public class TEmployeeInsurancePreServiceImpl extends ServiceImpl<TEmployeeInsur
@Lazy
private ScheduleService scheduleService;
@Autowired
private WxConfig wxConfig;
@Autowired
private UpmsDaprUtils upmsDaprUtils;
/**
* 商险待办任务表简单分页查询
*
......@@ -145,6 +154,7 @@ public class TEmployeeInsurancePreServiceImpl extends ServiceImpl<TEmployeeInsur
}
@Override
@Transactional
public R batchDispatcherInsurance(List<String> idList) {
List<TEmployeeInsurancePre> insurancePreList = baseMapper.selectList(Wrappers.<TEmployeeInsurancePre>query()
.lambda().in(TEmployeeInsurancePre::getId, idList)
......@@ -152,6 +162,7 @@ public class TEmployeeInsurancePreServiceImpl extends ServiceImpl<TEmployeeInsur
if (Common.isEmpty(insurancePreList)) {
return R.failed(CommonConstants.NO_DATA_TO_HANDLE);
}
List<String> pushIdList = insurancePreList.stream().map(TEmployeeInsurancePre::getId).collect(Collectors.toList());
List<InsuranceAddParam> addParamList = new ArrayList<>();
List<InsuranceBatchParam> batchAddParamList = new ArrayList<>();
List<InsuranceReplaceParam> replaceAddParamList = new ArrayList<>();
......@@ -239,6 +250,49 @@ public class TEmployeeInsurancePreServiceImpl extends ServiceImpl<TEmployeeInsur
replaceParamList.stream().map(this::convertReplaceParam)
)
).collect(Collectors.toList());
if (autoAddParamList.isEmpty()) {
LambdaUpdateWrapper<TEmployeeInsurancePre> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.in(TEmployeeInsurancePre::getId,pushIdList)
.set(TEmployeeInsurancePre::getProcessStatus, CommonConstants.THREE_STRING);
} else {
// 将 autoAddParamList 中的身份证和项目等信息提取出来,放入一个 Set 中
Set<String> autoAddParamSet = autoAddParamList.stream()
.map(param -> param.getEmpIdcardNo() + "-" + param.getDeptNo()
+ "-" + param.getBuyStandard()+ "-" + param.getInsuranceTypeName()
+ "-" + param.getInsuranceCompanyName() + "-" + param.getPolicyStart()
+ "-" + param.getPolicyEnd())
.collect(Collectors.toSet());
// 找出 insurancePreList 中在 autoAddParamList 中存在的数据
List<TEmployeeInsurancePre> existingList = insurancePreList.stream()
.filter(pre -> autoAddParamSet.contains(pre.getEmpIdcard() + "-" + pre.getDeptNo()
+ "-" + pre.getBuyStandard()+ "-" + pre.getInsuranceTypeName()
+ "-" + pre.getInsuranceCompanyName() + "-" + pre.getPolicyStart()
+ "-" + pre.getPolicyEnd()))
.collect(Collectors.toList());
// 找出 insurancePreList 中在 autoAddParamList 中不存在的数据
List<TEmployeeInsurancePre> nonExistingList = insurancePreList.stream()
.filter(pre -> !autoAddParamSet.contains(pre.getEmpIdcard() + "-" + pre.getDeptNo()
+ "-" + pre.getBuyStandard()+ "-" + pre.getInsuranceTypeName()
+ "-" + pre.getInsuranceCompanyName() + "-" + pre.getPolicyStart()
+ "-" + pre.getPolicyEnd()))
.collect(Collectors.toList());
//派单成功的更新状态为代投保,派单失败更新成派单失败
if (!existingList.isEmpty()){
List<String> onIdList = insurancePreList.stream().map(TEmployeeInsurancePre::getId).collect(Collectors.toList());
LambdaUpdateWrapper<TEmployeeInsurancePre> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.in(TEmployeeInsurancePre::getId,onIdList)
.set(TEmployeeInsurancePre::getProcessStatus, CommonConstants.TWO_STRING);
}
if (!nonExistingList.isEmpty()){
List<String> unIdList = insurancePreList.stream().map(TEmployeeInsurancePre::getId).collect(Collectors.toList());
LambdaUpdateWrapper<TEmployeeInsurancePre> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.in(TEmployeeInsurancePre::getId,unIdList)
.set(TEmployeeInsurancePre::getProcessStatus, CommonConstants.THREE_STRING);
}
}
return R.ok(autoAddParamList);
}
......@@ -327,8 +381,9 @@ public class TEmployeeInsurancePreServiceImpl extends ServiceImpl<TEmployeeInsur
//获取所有预计派单时间为当天而且状态是待确认的商险待购买数据
List<TEmployeeInsurancePre> unConfirmList = baseMapper.getAllUnconfimData();
if (Common.isNotNull(unConfirmList) && !unConfirmList.isEmpty()) {
for(TEmployeeInsurancePre pre : unConfirmList) {
sendMessageToWx(pre,CommonConstants.ONE_STRING);
}
}
}
......@@ -376,8 +431,8 @@ public class TEmployeeInsurancePreServiceImpl extends ServiceImpl<TEmployeeInsur
autoParam.setDeptNo(addParam.getDeptNo());
autoParam.setInsuranceCompanyName(addParam.getInsuranceCompanyName());
autoParam.setInsuranceTypeName(addParam.getInsuranceTypeName());
autoParam.setPolicyStart(LocalDateUtil.parseLocalDate(addParam.getPolicyStart()));
autoParam.setPolicyEnd(LocalDateUtil.parseLocalDate(addParam.getPolicyEnd()));
autoParam.setPolicyStart(addParam.getPolicyStart());
autoParam.setPolicyEnd(addParam.getPolicyEnd());
autoParam.setBuyStandard(addParam.getBuyStandard());
autoParam.setInsuranceProvinceName(addParam.getInsuranceProvinceName());
autoParam.setInsuranceCityName(addParam.getInsuranceCityName());
......@@ -414,8 +469,8 @@ public class TEmployeeInsurancePreServiceImpl extends ServiceImpl<TEmployeeInsur
autoParam.setInsuranceCompanyName(replaceParam.getInsuranceCompanyName());
autoParam.setInsuranceTypeName(replaceParam.getInsuranceTypeName());
autoParam.setBuyStandard(replaceParam.getBuyStandard());
autoParam.setPolicyStart(LocalDateUtil.parseLocalDate(replaceParam.getPolicyStart()));
autoParam.setPolicyEnd(LocalDateUtil.parseLocalDate(replaceParam.getPolicyEnd()));
autoParam.setPolicyEnd(replaceParam.getPolicyEnd());
autoParam.setPolicyStart(replaceParam.getPolicyStart());
autoParam.setPost(replaceParam.getPost());
autoParam.setReplaceEmpName(replaceParam.getReplaceEmpName());
autoParam.setReplaceDeptNo(replaceParam.getReplaceDeptNo());
......@@ -423,4 +478,65 @@ public class TEmployeeInsurancePreServiceImpl extends ServiceImpl<TEmployeeInsur
return autoParam;
}
//发送企业微信待办
private void sendMessageToWx(TEmployeeInsurancePre insurancePre, String type) {
//获取前端客服
SysUser user;
if (Common.isEmpty(insurancePre.getCustomerUserLoginname())) {
return;
}
R<SysUser> res = upmsDaprUtils.getSimpleUserByLoginName(insurancePre.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<>();
Map<String, Object> textcard = new HashMap<>();
String authUrl = String.format(SecurityConstants.WX_GET_MESSAGE_AUTH_URL, wxConfig.getCorpid(), wxConfig.getDomainName() + "/auth/oauth/wxLogin", "6" + insurancePre.getId());
StringBuilder description = new StringBuilder();
String result;
int buyType = insurancePre.getBuyType();
switch (buyType) {
case CommonConstants.ONE_INT:
result = "新增";
break;
case CommonConstants.THREE_INT:
result = "批增";
break;
default:
result = "替换";
}
String title = "商险投保确认";
if (CommonConstants.ONE_STRING.equals(type)) {
description.append("项目名称:").append(insurancePre.getDeptName()).append("<br>");
description.append("项目编码:").append(insurancePre.getDeptNo()).append("<br>");
description.append("员工姓名:").append(insurancePre.getEmployeeName()).append("<br>");
description.append("身份证号:").append(insurancePre.getEmpIdcard()).append("<br>");
description.append("购买类型:").append(result).append("<br>");
} else {
// 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);
}
}
}
}
......@@ -35,3 +35,10 @@ ekp:
docStatus: '20'
LoginName: 'admin'
docSubject : '接口发起流程'
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
\ No newline at end of file
......@@ -35,3 +35,10 @@ ekp:
docStatus: '20'
LoginName: 'admin'
docSubject : '接口发起流程'
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
......@@ -36,4 +36,11 @@ ekp:
LoginName: 'admin'
docSubject : '接口发起流程'
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
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