Skip to content

Commit

Permalink
Merge pull request #39 from lianluoyi/dev
Browse files Browse the repository at this point in the history
V1.31.0版本更新
  • Loading branch information
lianluoyi committed Jul 24, 2023
2 parents 06bab05 + b380f44 commit 866882b
Show file tree
Hide file tree
Showing 65 changed files with 3,108 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
@Slf4j
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, PageHelperAutoConfiguration.class})
@MapperScan("com.easyink.*.mapper")
@MapperScan(basePackages = {"com.easyink.*.mapper","com.easyink.wecom.openapi.dao"})
@ForestScan(basePackages = {"com.easyink.wecom.client", "com.easyink.wecom.wxclient"})
@EnableAsync(proxyTargetClass = true)
@EnableAspectJAutoProxy(exposeProxy = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.easyink.web.controller.openapi;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.easyink.common.core.domain.AjaxResult;
import com.easyink.common.utils.ServletUtils;
import com.easyink.wecom.login.util.LoginTokenService;
import com.easyink.wecom.openapi.constant.AppInfoConst;
import com.easyink.wecom.openapi.domain.entity.AppCallbackSetting;
import com.easyink.wecom.openapi.domain.resp.BaseOpenApiResp;
import com.easyink.wecom.openapi.domain.vo.AppIdGenVO;
import com.easyink.wecom.openapi.dto.AddCallbackDTO;
import com.easyink.wecom.openapi.dto.EditCallbackDTO;
import com.easyink.wecom.openapi.service.AppCallbackSettingService;
import com.easyink.wecom.openapi.service.AppIdInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 类名: 开发参数生成接口
*
* @author : silver_chariot
* @date : 2022/3/14 11:39
*/
@RestController
@RequestMapping("/wecom/openapi")
@Api(tags = {"开发参数生成接口"})
@Slf4j
@RequiredArgsConstructor
public class AppIdInfoController {

private final AppIdInfoService appIdGenService;
private final AppCallbackSettingService appCallbackSettingService;


@PostMapping("/appInfo/create")
@ApiOperation("生成开发账号")
public AjaxResult<AppIdGenVO> create() {
return AjaxResult.success(appIdGenService.create(LoginTokenService.getLoginUser().getCorpId()));
}

@GetMapping("/appInfo/get")
@ApiOperation("获取开发参数")
public AjaxResult<AppIdGenVO> get() {
return AjaxResult.success(appIdGenService.getVO(LoginTokenService.getLoginUser().getCorpId()));
}

@PostMapping("/appInfo/refreshSecret")
@ApiOperation("刷新appSecret")
public AjaxResult<AppIdGenVO> refreshSecret() {
return AjaxResult.success(appIdGenService.refreshSecret(LoginTokenService.getLoginUser().getCorpId()));
}

@GetMapping("/callback/list")
@ApiOperation("获取消息订阅的回调地址")
public AjaxResult<List<AppCallbackSetting>> getCallbackList() {
return AjaxResult.success(appCallbackSettingService.list(new LambdaQueryWrapper<AppCallbackSetting>()
.eq(AppCallbackSetting::getCorpId, LoginTokenService.getLoginUser().getCorpId())
));
}

@PostMapping("/callback")
@ApiOperation("新增消息订阅的回调地址")
public AjaxResult<Void> addCallbackUrl(@RequestBody AddCallbackDTO dto) {
dto.setCorpId(LoginTokenService.getLoginUser().getCorpId());
return AjaxResult.success(appCallbackSettingService.addUrl(dto));
}
@PutMapping("/callback")
@ApiOperation("编辑消息订阅的回调地址")
public AjaxResult<Void> editCallbackUrl(@RequestBody EditCallbackDTO dto) {
dto.setCorpId(LoginTokenService.getLoginUser().getCorpId());
appCallbackSettingService.editUrl(dto);
return AjaxResult.success();
}

@DeleteMapping("/callback/{id}")
@ApiOperation("删除消息订阅的回调地址")
public AjaxResult<Void> delCallbackUrl( @PathVariable("id")Long id) {
appCallbackSettingService.deleteUrl(id);
return AjaxResult.success();
}





@GetMapping("/validate")
@ApiOperation("校验签名")
public BaseOpenApiResp<Integer> validate() {
log.info("[openApi]收到校验签名请求,{}", ServletUtils.getRequest());
return BaseOpenApiResp.success(AppInfoConst.TICKET_EXPIRE_TIME);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.easyink.web.controller.openapi;


import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 类名: 对外开放的api接口
*
* @author : silver_chariot
* @date : 2022/3/14 15:44
*/
@RestController
@RequestMapping("/open_api")
@Api(tags = {"对外开放的api接口"})
public class OpenApiController {


}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.easyink.web.controller.wecom;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.easyink.common.core.controller.BaseController;
import com.easyink.common.core.domain.AjaxResult;
import com.easyink.common.core.page.TableDataInfo;
import com.easyink.common.enums.ResultTip;
import com.easyink.common.utils.PageInfoUtil;
import com.easyink.wecom.domain.dto.statistics.*;
import com.easyink.wecom.domain.entity.WeUserCustomerMessageStatistics;
import com.easyink.wecom.domain.vo.statistics.*;
import com.easyink.wecom.domain.vo.statistics.emplecode.EmpleCodeDateVO;
import com.easyink.wecom.domain.vo.statistics.emplecode.EmpleCodeUserVO;
Expand Down Expand Up @@ -45,6 +43,12 @@ public class StatisticsController extends BaseController {
private final WeGroupTagService weGroupTagService;
private final WeEmpleCodeStatisticService weEmpleCodeStatisticService;

@PostMapping("/emple/history/update")
@ApiOperation("从活码分析表更新活码统计表历史旧数据")
public AjaxResult empleStatisticUpdate() {
return weEmpleCodeStatisticService.updateHistoryData();
}

@GetMapping("/data")
@ApiOperation("执行对应日期的数据统计任务,执行前需先将we_user_customer_message_statisticsService表中对应日期的数据删除。")
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import com.alibaba.fastjson.JSON;
import com.easyink.common.config.RuoYiConfig;
import com.easyink.common.config.WeCrypt;
import com.easyink.common.config.WechatOpenConfig;
import com.easyink.common.enums.ResultTip;
import com.easyink.common.exception.CustomException;
import com.easyink.common.utils.Threads;
import com.easyink.common.utils.WXBizMsgCrypt;
import com.easyink.common.utils.wecom.WxCryptUtil;
import com.easyink.wecom.domain.vo.WxCpXmlMessageVO;
import com.easyink.wecom.factory.WeCallBackEventFactory;
import com.easyink.wecom.factory.WeEventHandle;
import com.easyink.wecom.openapi.service.AppCallbackSettingService;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.security.AnyTypePermission;
import io.swagger.annotations.Api;
Expand All @@ -23,10 +22,12 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
* 类名: 企业微信回调接口
*
Expand All @@ -40,16 +41,16 @@
public class WeCallBackController {
private final WeEventHandle weEventHandle;
private final RuoYiConfig ruoYiConfig;
private final WechatOpenConfig wechatOpenConfig;
private final AppCallbackSettingService appCallbackSettingService;
@Resource(name = "sendCallbackExecutor")
private ThreadPoolTaskExecutor sendCallbackExecutor;

@Autowired
private RedisTemplate redisTemplate;

@Autowired
public WeCallBackController(WeEventHandle weEventHandle, RuoYiConfig ruoYiConfig, WechatOpenConfig wechatOpenConfig) {
public WeCallBackController(WeEventHandle weEventHandle, RuoYiConfig ruoYiConfig, AppCallbackSettingService appCallbackSettingService) {
this.weEventHandle = weEventHandle;
this.ruoYiConfig = ruoYiConfig;
this.wechatOpenConfig = wechatOpenConfig;
this.appCallbackSettingService = appCallbackSettingService;
}

/**
Expand Down Expand Up @@ -77,14 +78,18 @@ public String receive(@RequestBody String msg, @RequestParam(name = "msg_signatu
if (factory != null) {
Threads.SINGLE_THREAD_POOL.submit(() -> factory.eventHandle(wxCpXmlMessage));
} else {
log.info("[企微回调通知接口]该回调事件不存在对应的处理,{}",wxCpXmlMessage.getEvent());
log.info("[企微回调通知接口]该回调事件不存在对应的处理,{}", wxCpXmlMessage.getEvent());
}
sendCallbackExecutor.execute(()->appCallbackSettingService.sendCallback(wxCpXmlMessage.getToUserName(),msg, signature,timestamp, nonce));
} catch (Exception e) {
log.error("企微回调异常:{}", ExceptionUtils.getStackTrace(e));
}
return "success";
}




/**
* 回调配置校验接口 请求验证URL有效性
*
Expand Down Expand Up @@ -144,6 +149,7 @@ public String receive3rdapp(@RequestBody String msg, @RequestParam(name = "msg_s
} else {
throw new CustomException(ResultTip.TIP_STRATEGY_IS_EMPTY);
}
sendCallbackExecutor.execute(()->appCallbackSettingService.sendCallback(wxCpXmlMessage.getToUserName(),msg, signature,timestamp, nonce));
} catch (Exception e) {
log.error("企微三方应用回调通知接口异常:{}", ExceptionUtils.getStackTrace(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.easyink.common.annotation.Log;
import com.easyink.common.config.ChatRsaKeyConfig;
import com.easyink.common.config.RuoYiConfig;
import com.easyink.common.config.WeCrypt;
import com.easyink.common.constant.Constants;
import com.easyink.common.core.controller.BaseController;
import com.easyink.common.core.domain.AjaxResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand All @@ -23,6 +24,35 @@ public class RedisCache {
@Autowired
public RedisTemplate redisTemplate;

@Resource( name = "empleRedisTemplate")
public RedisTemplate empleRedisTemplate;

/**
* 增加计数
*
* @param key 缓存的键值
* @param hashKey 缓存的hash键值
* @param value 自增的值
*/
public <T> void increment(final String key, final T hashKey, final long value) {
empleRedisTemplate.opsForHash().increment(key, hashKey, value);
}

/**
* 获取缓存的hashValue
*
* @param key 缓存的建
* @param hashKey 缓存的hash键值
*/
public <T> int getHashIncrCnt(final String key, final T hashKey) {
Object incrCnt = empleRedisTemplate.opsForHash().get(key, hashKey);
if (incrCnt == null) {
return 0;
}
return (int) incrCnt;

}

/**
* 缓存基本的对象,Integer、String、实体类等
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ public enum ResultTip {
TIP_ERROR_CREATE_MINI_APP_URL_LINK(9010,"创建小程序url_link 失败"),
TIP_APPEND_MISSING(9012,"附加信息缺失"),

// open api 错误码 从10000 开始
TIP_MAX_CALLBACK_URL_CNT ( 10001,"一个企业最多只能设置三个回调地址"),
HAS_THIS_CALLBACK_URL(10002,"已配置此地址,请勿重复配置"),
EDIT_URL_ERROR(10003,"保存回调地址失败"),
DEL_URL_ERROR(10004,"删除回调地址失败"),
CALLBACK_FAIL(10005,"回调地址请求不通过, 请检查代码"),

;
@Getter
private final Integer code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.easyink.common.enums.callback;

import com.easyink.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
* 类名: 企微回调事件枚举
*
* @author : silver_chariot
* @date : 2023/7/14 10:29
**/
@Getter
@AllArgsConstructor
public enum WecomCallbackEventEnum {
UNKNOWN("unknown"),
/**
* 新增客户
*/
ADD_EXTERNAL_CONTACT("add_external_contact"),
/**
* 流失客户
*/
DEL_FOLLOW_USER("del_follow_user"),
/**
* 编辑客户
*/
EDIT_EXTERNAL_CONTACT("edit_external_contact"),
;


/**
* 类型
*/
private String type;

/**
* 根据类型返回枚举
*
* @param type 回调类型
* @return {@link WecomCallbackEventEnum}
*/

public static WecomCallbackEventEnum getByType(String type) {
if (StringUtils.isBlank(type)) {
return UNKNOWN;
}
return Arrays.stream(values()).filter(a -> type.equals(a.getType())).findFirst().orElse(UNKNOWN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* redis分布式锁配置
*
* @author : wangzimo
* @author : silver_chariot
* @date : 2021-3-17 20:05:34
*/
@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,18 @@ public static String getYesterdayDateBeforeNow() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YYYY_MM_DD);
return yesterday.format(formatter);
}

/**
* 根据传来的日期,获取传来的日期前一天的指定格式的日期
*
* @param date 日期,格式为YYYY-MM-DD
* @param pattern 转换的格式,如YYYY-MM-DD等
* @return 前一天日期
*/
public static String getYesterday(String date, String pattern) {
LocalDate today = LocalDate.parse(date);
LocalDate previousDate = today.minusDays(1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return previousDate.format(formatter);
}
}
Loading

0 comments on commit 866882b

Please sign in to comment.