Commit 40ab518f authored by 钱坤's avatar 钱坤

Merge remote-tracking branch 'origin/master' into v0.0.1-day-subject

# Conflicts:
#	src/main/java/com/tanpu/feo/feojob/jobs/DaySubJob.java
parents 28e8826e 3ce5a327
package com.tanpu.feo.feojob.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.tanpu.common.api.CommonResp;
import com.tanpu.feo.feojob.dao.user.entity.DaySubjectEntity;
import com.tanpu.feo.feojob.dto.OrgSyncDto;
import com.tanpu.feo.feojob.jobs.DaySubJob;
import com.tanpu.feo.feojob.jobs.OrgSyncByWxcpJob;
......@@ -9,13 +11,13 @@ import com.tanpu.feo.feojob.service.OrgSyncByJyzyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@Api(tags = "手动执行 早报推送")
......@@ -33,4 +35,15 @@ public class DaySubjectController {
return CommonResp.success("执行完成");
}
@RequestMapping(value = "/sendOneOrgDaySubject", method = RequestMethod.GET)
@ApiOperation(value = "单机构早报推送")
public CommonResp<String> sendOneOrgDaySubject(@RequestParam String orgId, @RequestParam String date) {
List<DaySubjectEntity> daySubjectList = daySubJob.getDaySubject(date, orgId);
List<DaySubjectEntity> list = daySubjectList.stream().filter(p -> StringUtils.equals(p.getDsPt(), orgId))
.collect(Collectors.toList());
String oneMorningTitle = daySubJob.getOneMorningTitle();
daySubJob.sendDaySubject(orgId, list, oneMorningTitle);
return CommonResp.success("执行完成");
}
}
......@@ -13,6 +13,8 @@ public class OrgInfoDto {
private String orgId;
private String orgQrCodeUrl;
private List<UserInfoEntity> userInfoList;
private List<EmployeeEntity> employeeList;
......
package com.tanpu.feo.feojob.feign;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 接口返回对象基类
*
* @description:
* @author: wanglei
* @created: 2020/04/08 23:52
*/
@Data
@ApiModel("BaseRep")
public class BaseRep<T> {
@ApiModelProperty(value = "返回码")
public String statusCode;
@ApiModelProperty(value = "返回码对应描述")
public String message;
@ApiModelProperty(value = "业务数据")
public T attributes;
}
package com.tanpu.feo.feojob.feign;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel("CommonResp")
public class CommonResp<T> extends BaseRep<T> {
public CommonResp() {
}
public static <T> CommonResp<T> success() {
return success(null);
}
public static <T> CommonResp<T> success(T data) {
return new CommonResp<>(STATUS_CODE_SUCCESS, FAILURE_MESSAGE_SUCCESS, data);
}
public static <T> CommonResp<T> error() {
return new CommonResp<>(STATUS_CODE_FAILURE_DEFAULT, FAILURE_MESSAGE_DEFAULT, null);
}
public static <T> CommonResp<T> error(String msg) {
CommonResp<T> error = error();
error.setMessage(msg);
return error;
}
public static <T> CommonResp<T> error(String code, String msg) {
return new CommonResp(code, msg, null);
}
public static <T> CommonResp<T> error(String code, String msg, T t) {
return new CommonResp(code, msg, t);
}
public CommonResp(String statusCode, String message, T attributes) {
this.statusCode = statusCode;
this.message = message;
this.attributes = attributes;
}
@JsonIgnore
public boolean isSuccess() {
return STATUS_CODE_SUCCESS.equals(statusCode);
}
@JsonIgnore
public boolean isNotSuccess() {
return !isSuccess();
}
public static final String STATUS_CODE_SUCCESS = "0000";
public static final String FAILURE_MESSAGE_SUCCESS = "成功";
public static final String STATUS_CODE_UNKNOWN = "0010";
public static final String FAILURE_MESSAGE_UNKNOWN = "未知错误";
public static final String STATUS_CODE_INSUFFICIENT_PRIVILEGE = "0020";
public static final String FAILURE_MESSAGE_INSUFFICIENT_PRIVILEGE = "权限不足";
public static final String STATUS_CODE_DANGER_OPERATION = "0030";
public static final String MESSAGE_CANNOT_OPERATE = "危险操作";
public static final String STATUS_CODE_WRONG_SIGN = "0040";
public static final String MESSAGE_WRONG_SIGN = "签名未通过";
public static final String STATUS_CODE_FAILURE_DEFAULT = "9999";
public static final String FAILURE_MESSAGE_DEFAULT = "处理失败";
public static final String STATUS_CODE_NOT_LOGIN = "9000";
public static final String MESSAGE_NOT_LOGIN = "未登录";
public static final String STATUS_CODE_TOKEN_EXPIRE = "9001";
public static final String MESSAGE_TOKEN_EXPIRE = "TOKEN失效";
public static final String STATUS_CODE_APPVERSIONLOW_EXPIRE = "9002";
public static final String MESSAGE_APPVERSIONLOW_EXPIRE = "App版本过低,请更新最新版本!";
public static final String FREQ_ERROR_STATUS_CODE = "1000";
public static final String FREQ_ERROR_MESSAGE = "请求处理中,请勿频繁操作!";
public static final String NET_ERROR_STATUS_CODE = "1001";
public static final String NET_ERROR_MESSAGE = "网络异常,请稍后重试";
public static final String DATA_USED_STATUS_CODE = "1002";
public static final String DATA_USED_ERROR_MESSAGE = "数据被已被引用,不可删除";
public static final String ROOM_NOT_FOUND_STATUS_CODE = "1005";
public static final String ROOM_NOT_FOUND_MESSAGE = "直播间找不到";
public static final String ARTICLE_NOT_EXIST_STATUS_CODE = "1026";
public static final String ARTICLE_NOT_EXIST_MESSAGE = "文章不存在";
public static final String RISK_RZ_ERROR_STATUS_CODE = "1027";
public static final String RISK_RZ_ERROR_MESSAGE = "用户评测流程异常";
public static final String ARTICLE_ALREADY_EXIST_STATUS_CODE = "15001";
public static final String ARTICLE_ALREADY_EXIST_MESSAGE = "文章已存在";
public static final String ROOM_NOT_EXIST_STATUS_CODE = "2001";
public static final String ROOM_NOT_EXIST_MESSAGE = "直播间不存在";
public static final String MEMBER_NOT_EXIST_STATUS_CODE = "2002";
public static final String MEMBER_NOT_EXIST_MESSAGE = "成员不存在";
public static final String PARAMETER_INVALID_STATUS_CODE = "2003";
public static final String PARAMETER_INVALID_MESSAGE = "参数错误";
public static final String FILE_NOT_EXIST_STATUS_CODE = "2004";
public static final String FILE_NOT_EXIST_MESSAGE = "文件不存在";
public static final String USER_PHONE_EXIST_STATUS_CODE = "2005";
public static final String USER_PHONE_EXIST_MESSAGE = "该手机号码已绑定其他微信,如非本人绑定,请联系客服: 021-65681889。";
public static final String SMS_CODE_EXCEPTION_STATUS_CODE = "2006";
public static final String SMS_CODE_EXCEPTION_MESSAGE = "短信验证码错误";
public static final String TELPHONE_VALID_EXCEPTION_STATUS_CODE = "2007";
public static final String TELPHONE_VALID_EXCEPTION_MESSAGE = "手机格式不正确";
public static final String SMS_CODE_OVER_LIMIT_EXCEPTION_STATUS_CODE = "2008";
public static final String SMS_CODE_OVER_LIMIT_EXCEPTION_MESSAGE = "短信发送过于频繁,请稍后再试";
public static final String SMS_CODE_SEND_FAIL_EXCEPTION_STATUS_CODE = "2009";
public static final String SMS_CODE_SEND_FAIL_EXCEPTION_MESSAGE = "短信发送失败";
public static final String JIFEN_EXCEPTION_STATUS_CODE = "2010";
public static final String JIFEN_EXCEPTION_MESSAGE = "积分不足";
public static final String LOGIN_EXCEPTION_STATUS_CODE = "2012";
public static final String LOGIN_EXCEPTION_MESSAGE = "账号或密码错误";
public static final String LOGIN_PHONE_HAVABIND_EXCEPTION_STATUS_CODE = "2013";
public static final String LOGIN_PHONE_HAVABIND_EXCEPTION_MESSAGE = "该手机号已绑定";
public static final String USER_HAVABINDPHONE_EXCEPTION_STATUS_CODE = "2014";
public static final String USER_HAVABINDPHONE_EXCEPTION_MESSAGE = "该用户已绑定手机号";
public static final String USER_INVESTORRZ_EXCEPTION_STATUS_CODE = "2015";
public static final String USER_INVESTORRZ_EXCEPTION_MESSAGE = "用户已进行过合格投资者认证说明";
public static final String OBJECT_NOT_FOUND_EXCEPTION_STATUS_CODE = "2016";
public static final String OBJECT_NOT_FOUND_EXCEPTION_MESSAGE = "对象不存在";
public static final String USER_NOT_IFA_EXCEPTION_STATUS_CODE = "2017";
public static final String USER_NOT_IFA__EXCEPTION_MESSAGE = "用户为非理财师用户";
public static final String OBJECT_ALREADY_EXIST_EXCEPTION_STATUS_CODE = "2018";
public static final String OBJECT_ALREADY_EXIST_EXCEPTION_MESSAGE = "对象已存在";
public static final String ALREADY_FINANCIAL_PRACTITIONER_CODE = "2018";
public static final String ALREADY_FINANCIAL_PRACTITIONER_MESSAGE = "您已经是{0},无需再次认证";
public static final String APPLICATION_STATE_AUDITING_CODE = "2019";
public static final String APPLICATION_STATE_AUDITING_MESSAGE = "您的申请正在审核中,请耐心等待";
public static final String APPLICATION_STATE_PASS_CODE = "2020";
public static final String APPLICATION_STATE_PASS_MESSAGE = "您的申请已通过";
public static final String APPLICATION_STATE_REJECT_CODE = "2021";
public static final String APPLICATION_STATE_REJECT_MESSAGE = "您的申请已被驳回";
public static final String OBJECT_ALREADY_EXISTS_STATUS_CODE = "2022";
public static final String OBJECT_ALREADY_EXISTS_STATUS_MESSAGE = "对象已存在";
public static final String WECHAT_IN_USER_CODE = "2023";
public static final String WECHAT_IN_USER_MESSAGE = "该微信已绑定其他手机号码,如非本人绑定,请联系客服: 021-65681889。";
public static final String ZHIBO_APPOINTMENT_EXIST_STATUS_CODE = "3001";
public static final String ZHIBO_APPOINTMENT_EXIST_MESSAGE = "已预约过直播";
public static final String ERROR_CODE_CAN_NOT_BROADCAST = "3002";
public static final String ERROR_MSG_CAN_NOT_BROADCAST = "不可转播";
public static final String CHECK_PASSWORD_EXCEPTION_STATUS_CODE = "3003";
public static final String CHECK_PASSWORD_EXCEPTION_MESSAGE = "进入直播间密码错误";
public static final String ERROR_CODE_NOT_FOUND = "4004";
public static final String ERROR_MSG_NOT_FOUND = "接口不可用";
public static final String ERROR_FORWORDARTICLE_CODE = "4005";
public static final String ERROR_FORWORDARTICLE_MESSAGE = "文章转载解析失败";
public static final String ADDRESS_NOT_FOUND_CODE = "4006";
public static final String ADDRESS_NOT_FOUND_MESSAGE = "联系地址未填写";
public static final String MOBILE_INVALIDATE_CODE = "4007";
public static final String MOBILE_INVALIDATE_MESSAGE = "手机号不正确";
public static final String CARD_NO_INVALIDATE_CODE = "4008";
public static final String CARD_NO_INVALIDATE_MESSAGE = "身份证号码不正确";
public static final String ACCOUNT_INVALIDATE_CODE = "4009";
public static final String ACCOUNT_NO_INVALIDATE_MESSAGE = "账号信息不正确";
public static final String ALREADY_CERTIFIED_CODE= "4010";
public static final String ALREADY_CERTIFIED_MESSAGE = "已实名认证";
public static final String CARD_NO_IN_USER_CODE= "4011";
public static final String CARD_NO_IN_USER_MESSAGE = "身份证号已经被使用";
public static final String CERTIFY_FAIL_CODE = "4012";
public static final String CERTIFY_FAIL_MESSAGE = "实名认证失败";
public static final String USER_UNKNOWN_CODE = "4020";
public static final String USER_UNKNOWN_MESSAGE = "用户不存在,请联系管理员添加";
public static final String EXCEL_RESOLVE_FAIL_CODE = "4021";
public static final String EXCEL_RESOLVE_FAIL_MESSAGE = "EXCEL文件解析失败";
public static final String BUSINESS_CARD_UPLOAD_EXCEPTION_CODE = "4013";
public static final String BUSINESS_CARD_UPLOAD_EXCEPTION_MESSAGE = "实名认证失败";
/* 运营活动相关 start */
public static final String ACTIVITY_NOT_FOUND_CODE = "4014";
public static final String ACTIVITY_NOT_FOUND_MESSAGE = "活动未配置";
public static final String ACTIVITY_NOT_STARTED_CODE = "4015";
public static final String ACTIVITY_NOT_STARTED_MESSAGE = "活动未开始";
public static final String ACTIVITY_HAVE_FINISHED_CODE = "4016";
public static final String ACTIVITY_HAVE_FINISHED_MESSAGE = "活动已结束";
/* 运营活动相关 end */
/* 优惠券相关 start */
public static final String COUPON_NOT_FOUND_CODE = "4017";
public static final String COUPON_NOT_FOUND_MESSAGE = "优惠券不存在";
public static final String COUPON_UNSHELVE_CODE = "4018";
public static final String COUPON_UNSHELVE_MESSAGE = "优惠券已下架";
public static final String COUPON_WAS_OUT_OF_STOCK_CODE = "4019";
public static final String COUPON_WAS_OUT_OF_STOCK_MESSAGE = "优惠券已领完";
public static final String COUPON_OVER_PER_USER_LIMIT_CODE = "4020";
public static final String COUPON_OVER_PER_USER_LIMIT_MESSAGE = "优惠券领取达到上限";
/* 优惠券相关 end */
public static final String APPLE_PUBLICK_KEY_ERROR_CODE = "5001";
public static final String APPLE_PUBLICK_KEY_ERROR_MESSAGE = "转换苹果公钥失败!";
public static final String APPLE_TOKEN_EXPIRED_CODE = "5002";
public static final String APPLE_TOKEN_EXPIRED_MESSAGE = "苹果token过期,请重试!";
public static final String APPLE_VERIFY_FAIL_CODE = "5003";
public static final String APPLE_VERIFY_FAIL_MESSAGE = "苹果登录校验失败!";
public static final String PROCESS_CREATE_FAIL_CODE = "6000";
public static final String PROCESS_CREATE_FAIL_MESSAGE = "流程创建失败!";
public static final String PROCESS_HANGUP_FAIL_CODE = "6001";
public static final String PROCESS_HANGUP_FAIL_MESSAGE = "此流程已经挂起,请联系系统管理员!";
public static final String PROCESS_INSTANCE_NOT_EXIST_CODE = "6002";
public static final String PROCESS_INSTANCE_NOT_EXIST_MESSAGE = "不存在运行的流程实例,请确认!";
public static final String PROCESS_TASK_NOT_EXIST_CODE = "6003";
public static final String PROCESS_TASK_NOT_EXIST_MESSAGE = "不存在此任务,请确认!";
public static final String PROCESS_NEXT_STAP_ERROE_CODE = "6004";
public static final String PROCESS_NEXT_STAP_ERROE_MESSAGE = "流程流转失败!";
public static final String HOLDSHARES_NOT_ENOUGH_ERROE_CODE = "6005";
public static final String HOLDSHARES_NOT_ENOUGH_ERROE_MESSAGE = "用户持仓份额小于赎回份额!";
public static final String DOUBLERECORD_APPOINTMENT_ERROE_CODE = "6006";
public static final String DOUBLERECORD_APPOINTMENT_ERROE_MESSAGE = "当前时间段不可预约!";
public static final String ORDER_LOCK_ERROE_CODE = "6007";
public static final String ORDER_LOCK_ERROE_MESSAGE = "用户正在修改订单,当前订单已锁定!";
public static final String ORDER_PUBFUND_CREATE_IDCARD_ERROE_CODE = "6008";
public static final String ORDER_PUBFUND_CREATE_IDCARD_ERROE_MESSAGE = "请先填写投资人身份证信息!";
public static final String ORDER_DECODE_ERROE_CODE = "7001";
public static final String ORDER_DECODE_ERROE_MESSAGE = "解码失败!";
public static final String ILLEGAL_OPERATION_STATUS_ERROR_CODE = "9003";
public static final String ILLEGAL_OPERATION_STATUS_ERROR_MESSAGE = "非法操作!";
/** 内容检查不通过*/
public static final String CONTENT_ILLEGAL = "7001";
public static final String ORG_DEPARTMENT_CAN_NOT_BE_REMOVE_CODE = "8001";
public static final String ORG_DEPARTMENT_CAN_NOT_BE_REMOVE_MESSAGE = "部门不允许被删除";
public static final String ORG_DEPARTMENT_PARENT_ERROR_CODE = "8002";
public static final String ORG_DEPARTMENT_PARENT_ERROR_MESSAGE = "部门的新上级部门不能是其子部门";
public static final String DUPLICATE_ERROR_CODE = "8003";
public static final String DUPLICATE_ERROR_MESSAGE = "已存在重复";
public static final String NOT_EXIST_ERROR_CODE = "8004";
public static final String NOT_EXIST_ERROR_MESSAGE = "不存在";
public static final String TOKEN_ERROR = "5001";
public static final String TOKEN_NULL = "5000";
/* 大家写错误码的时候按照编号依次写,不然后面多的话会重复!*/
}
package com.tanpu.feo.feojob.feign.fatools;
import com.tanpu.feo.feojob.feign.CommonResp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
//@FeignClient(value = "fatools", contextId = "fatoolsUser", fallbackFactory = FeignbackForFatools.class, url = "http://localhost:8189/fatools")
@FeignClient(value = "fatools", url = "${tanpu.feo-fatools.svc:}", path = "/fatools")
public interface FeignClientForFatools {
@GetMapping("/api/org/get-qrcode-url")
CommonResp<String> getQrCodeUrl(@RequestParam("orgId") String orgId);
}
......@@ -4,8 +4,6 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......@@ -15,18 +13,15 @@ import com.tanpu.feo.feojob.dao.user.entity.*;
import com.tanpu.feo.feojob.dao.user.mapper.*;
import com.tanpu.feo.feojob.feign.wxcp.FeignClientForWxCp;
import com.tanpu.feo.feojob.feign.wxmp.FeignClientForWxMp;
import com.tanpu.feo.feojob.service.RedirectService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -60,6 +55,8 @@ public class DaySubJob {
private DaySelectionMapper daySelectionMapper;
@Resource
private OrgMapper orgMapper;
@Resource
private RedirectService redirectService;
@Scheduled(cron = "0 30 7 * * ? ") //
......@@ -82,77 +79,112 @@ public class DaySubJob {
Map<String, List<DaySubjectEntity>> stringListMap = daySubjectList.stream().collect(Collectors.groupingBy(DaySubjectEntity::getDsPt));
int size = morningPaperProperties.getMainTitles().size();
String mainTitle = morningPaperProperties.getMainTitles().get(RandomUtil.randomInt(0, size));
stringListMap.keySet().forEach(orgId -> {
// 查询 机构配置信息
OrgExtEntity orgExtEntity = orgExtMapper.selectOne(new LambdaQueryWrapper<OrgExtEntity>()
.eq(OrgExtEntity::getOrgId, orgId)
.eq(OrgExtEntity::getDeleteTag, BizStatus.DeleteTag.tag_init_str));
String jsonKey = ObjectUtil.isNotNull(orgExtEntity) ? orgExtEntity.getJsonWxcpKey() : null;
if (StrUtil.isNotBlank(jsonKey)) {
//在orgExt 表中有查到 jsonKey 执行消息推送任务
JSONObject jsonKeyInfo = JSONUtil.parseObj(jsonKey);
// 查询该机构下 用户
LambdaQueryWrapper<UserInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UserInfoEntity::getDeletetag, BizStatus.DeleteTag.tag_init_str)
.eq(UserInfoEntity::getOrgId, orgId)
.eq(UserInfoEntity::getLevel, "2");
List<UserInfoEntity> userInfoEntities = userInfoMapper.selectList(queryWrapper);
//查询orgCode
OrgEntity orgEntity = orgMapper.selectOne(new LambdaQueryWrapper<OrgEntity>().eq(OrgEntity::getId, orgId).last("limit 1"));
if (ObjectUtil.isNotNull(orgEntity)) {
userInfoEntities.stream().forEach(userInfoEntity -> {
List<DaySubjectEntity> daySubjectEntities = stringListMap.get(orgId);
daySubjectEntities.forEach(daySubjectEntity -> {
HashMap<String, String> parmMap = new HashMap<>();
parmMap.put("type", "text");
String wxOpenId = userInfoEntity.getUiOpenid();
String wxcpUId = userInfoEntity.getWxcpUid();
// if (StringUtils.isNotBlank(wxcpUId)) {
if (StringUtils.isNotBlank(wxcpUId)) {
// 1 企业微信 推送
String agentId = jsonKeyInfo.getStr("agentId");
String corpId = jsonKeyInfo.getStr("corpId");
// ww=corpId&orgCode=orgCode
StringBuilder sb = new StringBuilder();
sb.append(mainTitle).append("\n\n")
.append(morningPaperProperties.getSubTitle()).append("\n\n")
.append("<a href=\"")
.append(String.format(daySubjectUrl, corpId, orgEntity.getOrgCode(), daySubjectEntity.getId())).append("\">")
.append("快去转发获客吧")
.append("</a>\n\n");
parmMap.put("content", sb.toString());
log.info("===企业微信 推送===userID:{} agentId:{} corpId:{} wxcpUId:{} parmMap:{}",userInfoEntity.getId() , agentId, corpId, wxcpUId, JSONUtil.toJsonStr(parmMap));
if (StrUtil.isNotBlank(agentId) && StrUtil.isNotBlank(corpId) && StrUtil.isNotBlank(wxcpUId) && StrUtil.isNotBlank(JSONUtil.toJsonStr(parmMap))) {
feignClientForWxCp.sendMessage(agentId, corpId, wxcpUId, JSONUtil.toJsonStr(parmMap));
}
}else if (StringUtils.isNotBlank(wxOpenId)) {
// 2 公众号推送
String wxAppID = jsonKeyInfo.getStr("sendMessageAppId");
// ww=wxAppID&orgCode=orgCode
StringBuilder sb = new StringBuilder();
sb.append(mainTitle).append("\n\n")
.append(morningPaperProperties.getSubTitle()).append("\n\n")
.append("<a href=\"")
.append(String.format(daySubjectUrl, wxAppID, orgEntity.getOrgCode(), daySubjectEntity.getId())).append("\">")
.append("快去转发获客吧")
.append("</a>\n\n");
parmMap.put("content", sb.toString());
log.info("===公众号 推送=== userID:{} wxAppID:{} wxOpenId:{} parmMap:{}",userInfoEntity.getId() , wxAppID, wxOpenId, JSONUtil.toJsonStr(parmMap));
if (StrUtil.isNotBlank(wxAppID) && StrUtil.isNotBlank(wxOpenId) && StrUtil.isNotBlank(JSONUtil.toJsonStr(parmMap))) {
feignClientForWxMp.sendMessage(wxAppID, wxOpenId, JSONUtil.toJsonStr(parmMap));
}
} else {
log.error("======用户ID:{} 没有微信或企业微信id======", userInfoEntity.getId());
}
});
});
}
for (String orgId : stringListMap.keySet()) {
log.info("开始推送机构(orgId={})的早报", orgId);
//查询orgCode
OrgEntity orgEntity = orgMapper.selectOne(new LambdaQueryWrapper<OrgEntity>().eq(OrgEntity::getId, orgId).last("limit 1"));
if (ObjectUtil.isNull(orgEntity)) {
log.error("找不到机构(orgId={})的信息", orgId);
return;
}
});
List<DaySubjectEntity> daySubjectEntities = stringListMap.get(orgId);
if (CollectionUtils.isEmpty(daySubjectEntities)) {
log.warn("当前机构(orgCode={})没有要推送的早报", orgEntity.getOrgCode());
return;
}
sendDaySubject(orgId, daySubjectEntities, mainTitle);
}
}
public void sendDaySubject(String orgId, List<DaySubjectEntity> daySubjectList,String mainTitle){
if (CollectionUtils.isEmpty(daySubjectList) || StringUtils.isBlank(orgId) || StringUtils.isBlank(mainTitle)) {
return;
}
OrgEntity orgEntity = orgMapper.selectOne(new LambdaQueryWrapper<OrgEntity>().eq(OrgEntity::getId, orgId).last("limit 1"));
if (orgEntity == null) {
return;
}
// 查询 机构配置信息
OrgExtEntity orgExtEntity = orgExtMapper.selectOne(new LambdaQueryWrapper<OrgExtEntity>()
.eq(OrgExtEntity::getOrgId, orgId)
.eq(OrgExtEntity::getDeleteTag, BizStatus.DeleteTag.tag_init_str));
String jsonKey = ObjectUtil.isNotNull(orgExtEntity) ? orgExtEntity.getJsonWxcpKey() : null;
if (StringUtils.isBlank(jsonKey)) {
return;
}
//在orgExt 表中有查到 jsonKey 执行消息推送任务
JSONObject jsonKeyInfo = JSONUtil.parseObj(jsonKey);
// 查询该机构下 用户
LambdaQueryWrapper<UserInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UserInfoEntity::getDeletetag, BizStatus.DeleteTag.tag_init_str)
.eq(UserInfoEntity::getOrgId, orgId)
.eq(UserInfoEntity::getLevel, "2");
List<UserInfoEntity> userInfoEntities = userInfoMapper.selectList(queryWrapper);
if (CollectionUtils.isEmpty(userInfoEntities)) {
log.info("机构(orgCode={})没有需要推送早报的人员", orgEntity.getOrgCode());
return;
}
log.info("机构(orgCode={})本次推送{}人,早报文章{}篇", orgEntity.getOrgCode(), userInfoEntities.size(), daySubjectList.size());
for (UserInfoEntity userInfoEntity : userInfoEntities) {
for (DaySubjectEntity daySubjectEntity : daySubjectList) {
HashMap<String, String> parmMap = new HashMap<>();
parmMap.put("type", "text");
String wxOpenId = userInfoEntity.getUiOpenid();
String wxcpUId = userInfoEntity.getWxcpUid();
if (StringUtils.isNotBlank(wxcpUId)) {
// 1 企业微信 推送
String agentId = jsonKeyInfo.getStr("agentId");
String corpId = jsonKeyInfo.getStr("corpId");
// ww=corpId&orgCode=orgCode
String link = String.format(daySubjectUrl, corpId, orgEntity.getOrgCode(), daySubjectEntity.getId());
String url = redirectService.getRedirectLink(link);
log.info("早报推送使用重定向链接, redirect-url: {}, origin-url: {}", url, link);
StringBuilder sb = new StringBuilder();
sb.append(mainTitle).append("\n\n")
.append(morningPaperProperties.getSubTitle()).append("\n\n")
.append("<a href=\"")
.append(url).append("\">")
.append("快去转发获客吧")
.append("</a>\n\n");
parmMap.put("content", sb.toString());
log.info("===企业微信 推送===userID:{} agentId:{} corpId:{} wxcpUId:{} parmMap:{}", userInfoEntity.getId(), agentId, corpId, wxcpUId, JSONUtil.toJsonStr(parmMap));
if (StrUtil.isNotBlank(agentId) && StrUtil.isNotBlank(corpId) && StrUtil.isNotBlank(wxcpUId) && StrUtil.isNotBlank(JSONUtil.toJsonStr(parmMap))) {
feignClientForWxCp.sendMessage(agentId, corpId, wxcpUId, JSONUtil.toJsonStr(parmMap));
}
}else if (StringUtils.isNotBlank(wxOpenId)) {
// 2 公众号推送
String wxAppID = jsonKeyInfo.getStr("sendMessageAppId");
// ww=wxAppID&orgCode=orgCode
String link = String.format(daySubjectUrl, wxAppID, orgEntity.getOrgCode(), daySubjectEntity.getId());
String url = redirectService.getRedirectLink(link);
log.info("早报推送使用重定向链接, redirect-url: {}, origin-url: {}", url, link);
StringBuilder sb = new StringBuilder();
sb.append(mainTitle).append("\n\n")
.append(morningPaperProperties.getSubTitle()).append("\n\n")
.append("<a href=\"")
.append(url).append("\">")
.append("快去转发获客吧")
.append("</a>\n\n");
parmMap.put("content", sb.toString());
log.info("===公众号 推送=== userID:{} wxAppID:{} wxOpenId:{} parmMap:{}", userInfoEntity.getId(), wxAppID, wxOpenId, JSONUtil.toJsonStr(parmMap));
if (StrUtil.isNotBlank(wxAppID) && StrUtil.isNotBlank(wxOpenId) && StrUtil.isNotBlank(JSONUtil.toJsonStr(parmMap))) {
feignClientForWxMp.sendMessage(wxAppID, wxOpenId, JSONUtil.toJsonStr(parmMap));
}
} else {
if (userInfoEntity.getUiTelphone() != null && userInfoEntity.getUiTelphone().startsWith("1700000")) {
log.info("内部测试账号,跳过, uid: {}, telphone: {}", userInfoEntity.getId(), userInfoEntity.getUiTelphone());
continue;
}
log.error("======用户ID:{} 没有微信或企业微信id======", userInfoEntity.getId());
}
}
}
}
private List<DaySubjectEntity> getDaySubList(String today) {
public List<DaySubjectEntity> getDaySubList(String today) {
//查询今日早报 已上架
LambdaQueryWrapper<DaySubjectEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DaySubjectEntity::getDeletetag, BizStatus.DeleteTag.tag_init_str)
......@@ -170,6 +202,20 @@ public class DaySubJob {
return daySubjectEntityList;
}
public List<DaySubjectEntity> getDaySubject(String date, String orgId) {
LambdaQueryWrapper<DaySubjectEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DaySubjectEntity::getDeletetag, BizStatus.DeleteTag.tag_init_str)
.eq(DaySubjectEntity::getDsDate, DateUtil.parseDate(date))
.eq(DaySubjectEntity::getDsPt, orgId)
.eq(DaySubjectEntity::getDsStatus, "1");
return daySubjectMapper.selectList(queryWrapper);
}
public String getOneMorningTitle() {
int size = morningPaperProperties.getMainTitles().size();
return morningPaperProperties.getMainTitles().get(RandomUtil.randomInt(0, size));
}
public static void main(String[] args) throws Exception {
log.info("=========================");
......
......@@ -12,6 +12,8 @@ import com.tanpu.feo.feojob.dto.WorkDataDto;
import com.tanpu.feo.feojob.dto.WxCpDepartDto;
import com.tanpu.feo.feojob.enums.EmployeeDutyEnum;
import com.tanpu.feo.feojob.enums.RoleTypeEnum;
import com.tanpu.feo.feojob.feign.CommonResp;
import com.tanpu.feo.feojob.feign.fatools.FeignClientForFatools;
import com.tanpu.feo.feojob.service.*;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
......@@ -64,8 +66,10 @@ public class OrgSyncByWxcpJob {
private OrgSyncService orgSyncService;
@Value("${tanpu.sync.job.skipped:true}")
private boolean jobSkipped;
@Resource
private FeignClientForFatools feignClientForFatools;
@Scheduled(cron = "0 30 6,10,15 * * ?") //每日凌晨6点30执行
@Scheduled(cron = "0 30 6-19/1 * * ?") //每日凌晨6点30开始执行
public void execute() {
log.info("====== 开始执行OrgSyncByWxcpJob ======");
try {
......@@ -115,10 +119,12 @@ public class OrgSyncByWxcpJob {
continue;
}
String qrCodeUrl = getQrCodeUrl(orgEntity.getId());
//5 开始比对 5张表 数据 user_info employee department department_employee employee_role
log.info("======开始比对 5张表 数据 ======");
String corpId = wxCpDefaultConfig.getCorpId();
WorkDataDto<UserInfoEntity> workUserInfo = userInfoWork(orgEntity.getId(), wxCpDepartDtoList, corpId);
WorkDataDto<UserInfoEntity> workUserInfo = userInfoWork(orgEntity.getId(), wxCpDepartDtoList, corpId, qrCodeUrl);
WorkDataDto<EmployeeEntity> workEmployee = employeeWork(orgEntity.getId(), wxCpDepartDtoList, corpId);
WorkDataDto<DepartmentEntity> workDepartment = departmentWork(orgEntity.getId(), wxCpDepartDtoList);
WorkDataDto<DepartmentEmployeeEntity> workDepartmentEmployee = departmentEmployeeWork(orgEntity.getId(), wxCpDepartDtoList, corpId);
......@@ -135,6 +141,14 @@ public class OrgSyncByWxcpJob {
}
private String getQrCodeUrl(String orgId) {
CommonResp<String> commonResp = feignClientForFatools.getQrCodeUrl(orgId);
if (commonResp.isNotSuccess()) {
throw new RuntimeException(commonResp.statusCode + ", " + commonResp.getMessage());
}
return commonResp.getAttributes();
}
/**
* @description: 整理 员工与角色关联关系 数据
* @Author: zejia zj wu
......@@ -401,7 +415,7 @@ public class OrgSyncByWxcpJob {
* @Author: zejia zj wu
* @date: 2021/5/27 3:10 下午
*/
private WorkDataDto<UserInfoEntity> userInfoWork(String orgId, List<WxCpDepartDto> wxCpDepartDtoList, String corpId) {
private WorkDataDto<UserInfoEntity> userInfoWork(String orgId, List<WxCpDepartDto> wxCpDepartDtoList, String corpId, String qrCodeUrl) {
WorkDataDto<UserInfoEntity> workDataDto = new WorkDataDto<>();
List<UserInfoEntity> insertList = new ArrayList<>();
List<UserInfoEntity> deleteList = new ArrayList<>();
......@@ -429,14 +443,16 @@ public class OrgSyncByWxcpJob {
continue;
}
// 更新
if (!userInfo.getUiUsername().equals(wxCpUser.getName()) || StrUtil.isBlankIfStr(userInfo.getUiHeadimgMp())
if (!StringUtils.equals(userInfo.getUiNickname(), wxCpUser.getName()) ||
!userInfo.getUiUsername().equals(wxCpUser.getName()) || StrUtil.isBlankIfStr(userInfo.getUiHeadimgMp())
|| !wxCpUser.getUserId().equals(userInfo.getWxcpUid()) || StrUtil.isBlankIfStr(userInfo.getUiWechatXcxQrcode())
|| !userInfo.getUiShenfen().equals(String.valueOf(wxCpUser.getIsLeader()))) {
userInfo.setUiNickname(wxCpUser.getName());
userInfo.setUiUsername(wxCpUser.getName());
userInfo.setUiHeadimgMp(wxCpUser.getThumbAvatar());
userInfo.setWxcpUid(wxCpUser.getUserId());
userInfo.setUiShenfen(String.valueOf(wxCpUser.getIsLeader()));
userInfo.setUiWechatXcxQrcode(orgSyncService.createWechatXcxQrcode(userInfo.getId(), wxCpUser.getThumbAvatar()));
userInfo.setUiWechatXcxQrcode(orgSyncService.createWechatXcxQrcode(userInfo.getId(), wxCpUser.getThumbAvatar(), qrCodeUrl));
updateList.add(userInfo);
}
hashMap.remove(id);
......@@ -449,6 +465,7 @@ public class OrgSyncByWxcpJob {
Gender gender = wxCpUser.getGender();
String sex = gender.getCode().equals("1") ? BaseConstant.Gender.MAN : BaseConstant.Gender.WOMEN;
userInfo.setUiSex(sex);
userInfo.setUiNickname(wxCpUser.getName());
userInfo.setUiHeadimg(wxCpUser.getThumbAvatar());
userInfo.setUiHeadimgMp(wxCpUser.getThumbAvatar());
userInfo.setOrgId(orgId);
......@@ -470,7 +487,7 @@ public class OrgSyncByWxcpJob {
userInfo.setUiRegisterTime(userInfo.getCreatetime());
userInfo.setUiChannel(null);
userInfo.setWxcpUid(wxCpUser.getUserId());
userInfo.setUiWechatXcxQrcode(orgSyncService.createWechatXcxQrcode(userInfo.getId(), userInfo.getUiHeadimgMp()));
userInfo.setUiWechatXcxQrcode(orgSyncService.createWechatXcxQrcode(userInfo.getId(), userInfo.getUiHeadimgMp(), qrCodeUrl));
insertList.add(userInfo);
}
workDataDto.setDeleteList(deleteList);
......
......@@ -15,6 +15,7 @@ import com.tanpu.feo.feojob.dao.jyzyuser.entity.JyzyTeamEntity;
import com.tanpu.feo.feojob.dao.jyzyuser.entity.JyzyUserInfoEntity;
import com.tanpu.feo.feojob.enums.EmployeeDutyEnum;
import com.tanpu.feo.feojob.enums.RoleTypeEnum;
import com.tanpu.feo.feojob.feign.fatools.FeignClientForFatools;
import com.tanpu.feo.feojob.service.jyzy.JyzyOrgService;
import com.tanpu.feo.feojob.service.jyzy.JyzyTeamService;
import com.tanpu.feo.feojob.service.jyzy.JyzyUserInfoService;
......@@ -50,6 +51,8 @@ public class OrgSyncByJyzyService {
private JyzyUserInfoService jyzyUserInfoService;
@Resource
private OrgSyncService orgSyncService;
@Resource
private FeignClientForFatools feignClientForFatools;
public CommonResp<String> orgSyncByJyzy(OrgSyncDto orgSyncDto) {
try {
......@@ -104,7 +107,7 @@ public class OrgSyncByJyzyService {
if (!jyzyUserInfo.getMD5().equals(userInfo.getMD5()) || StrUtil.isBlank(userInfo.getUiWechatXcxQrcode())) {
userInfo.update(jyzyUserInfo);
if (StrUtil.isBlank(userInfo.getUiWechatXcxQrcode())) { //重新生成 小程序 球形码
userInfo.setUiWechatXcxQrcode(orgSyncService.createWechatXcxQrcode(userInfo.getId(), userInfo.getUiHeadimg()));
userInfo.setUiWechatXcxQrcode(orgSyncService.createWechatXcxQrcode(userInfo.getId(), userInfo.getUiHeadimg(), orgInfoDto.getOrgQrCodeUrl()));
}
updateUserInfoList.add(userInfo);
}
......@@ -117,7 +120,7 @@ public class OrgSyncByJyzyService {
userInfo.setLevel(2);
userInfo.setUiGrade("0");
userInfo.setUiRegisterTime(DateTime.now());
userInfo.setUiWechatXcxQrcode(orgSyncService.createWechatXcxQrcode(userInfo.getId(), userInfo.getUiHeadimg()));
userInfo.setUiWechatXcxQrcode(orgSyncService.createWechatXcxQrcode(userInfo.getId(), userInfo.getUiHeadimg(), orgInfoDto.getOrgQrCodeUrl()));
insertUserInfoList.add(userInfo);
});
......@@ -316,7 +319,7 @@ public class OrgSyncByJyzyService {
throw new Exception("feoOrgCode 不存在");
}
String orgId = org.getId();
orgInfoDtoBuilder.orgId(orgId);
orgInfoDtoBuilder.orgId(orgId).orgQrCodeUrl(getQrCodeUrl(org.getId()));
// 2 根据 orgId 获取 userInfoList信息
List<UserInfoEntity> userInfoList = userInfoService.getUserInfoListByOrgId(orgId);
orgInfoDtoBuilder.userInfoList(userInfoList);
......@@ -367,4 +370,12 @@ public class OrgSyncByJyzyService {
}
}
private String getQrCodeUrl(String orgCode) {
com.tanpu.feo.feojob.feign.CommonResp<String> commonResp = feignClientForFatools.getQrCodeUrl(orgCode);
if (commonResp.isNotSuccess()) {
throw new RuntimeException(commonResp.statusCode + ", " + commonResp.getMessage());
}
return commonResp.getAttributes();
}
}
......@@ -67,28 +67,34 @@ public class OrgSyncService {
}
}
public String createWechatXcxQrcode(String userId, String headImg) {
public String createWechatXcxQrcode(String userId, String headImg, String qrCodeUrl) {
String url = null;
long startTime = System.currentTimeMillis();
try {
if (StrUtil.isBlank(headImg)) {
headImg = wxDefaultImg;
}
String res = restTemplate.getForObject(qrcodeurl + "?userId=" + userId + "&headimage=" + headImg + "&params=" + userId, String.class);
String res = restTemplate.getForObject(qrCodeUrl + "?userId=" + userId + "&headimage=" + headImg + "&params=" + userId, String.class);
JSONObject jsonObject = JSONUtil.parseObj(res);
String statusCode = (String) jsonObject.get("statusCode");
if ("0000".equals(statusCode)) {
url = (String) jsonObject.get("attributes");
} else {
log.error("小程序球码生成失败, userId:{}, qrCodeUrl: {}, resp: {}", userId, qrCodeUrl, jsonObject);
}
} catch (Exception e) {
log.error("======用户:{} 生成小程序球形码失败: {}======", userId, e.getMessage());
}
log.info("======用户:{} 生成小程序球形码成功 耗时: {}======", userId, System.currentTimeMillis() - startTime);
log.info("======用户:{} 生成小程序球形码结束 耗时: {}======", userId, System.currentTimeMillis() - startTime);
return url;
}
private String getQrCodeUrl(String urlTemplate, String miniAppId){
return String.format(urlTemplate,miniAppId);
}
private void deleteAdmin(String orgId, WorkDataDto<UserInfoEntity> workUserInfo, WorkDataDto<EmployeeEntity> workEmployee, WorkDataDto<EmployeeRoleEntity> workEmployeeRole) {
// 获取 role
Map<String, String> roleMap = roleService.findInfoNoAdmin();
......
package com.tanpu.feo.feojob.service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
@Service
public class RedirectService {
@Value("${tanpu.redirect.url:}")
private String redirectUrl;
public String getRedirectLink(String url) {
if (StringUtils.isBlank(url)) {
return "";
}
String u = Base64.getEncoder().encodeToString(url.getBytes(StandardCharsets.UTF_8));
return redirectUrl + u;
}
}
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