Commit 5159d402 by liyanlin

企业微信通知

parent 0e776427
package com.blt.other.common.config.property;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Author: li.yanlin
* @Description: 企业微信通知
* @Date: Created in
* @Modified by:
*/
@Component
@Data
@ConfigurationProperties("wx-hook")
public class WxWebHook {
/**
* base URL
*/
private String url;
/**
* 最终审核
*/
private String finalReview;
private String test;
}
package com.blt.other.module.cost.service.impl.costcheck; package com.blt.other.module.cost.service.impl.costcheck;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.blt.other.common.config.property.WxWebHook;
import com.blt.other.common.exception.BizRuntimeException; import com.blt.other.common.exception.BizRuntimeException;
import com.blt.other.database.model.CostCompanyDomain; import com.blt.other.database.model.CostCompanyDomain;
import com.blt.other.database.model.CostLogDomain; import com.blt.other.database.model.CostLogDomain;
import com.blt.other.database.model.UserDomain;
import com.blt.other.module.auth.dao.UserDao;
import com.blt.other.module.cost.dao.CostCurrentReviewerMapper; import com.blt.other.module.cost.dao.CostCurrentReviewerMapper;
import com.blt.other.module.cost.dao.CostLogDao; import com.blt.other.module.cost.dao.CostLogDao;
import com.blt.other.module.cost.model.ApprovalHistoryDomain; import com.blt.other.module.cost.model.ApprovalHistoryDomain;
...@@ -14,12 +17,16 @@ import com.blt.other.module.cost.service.ApprovalHistoryService; ...@@ -14,12 +17,16 @@ import com.blt.other.module.cost.service.ApprovalHistoryService;
import com.blt.other.module.sys.model.CostReviewer; import com.blt.other.module.sys.model.CostReviewer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -62,6 +69,32 @@ public class FinalCheckState extends CostState { ...@@ -62,6 +69,32 @@ public class FinalCheckState extends CostState {
costContext.costService.toFinancial(costDomain); costContext.costService.toFinancial(costDomain);
} }
@Resource
WxWebHook webHook;
@Resource
RestTemplate restTemplate;
@Resource
UserDao userDao;
private void sendWxMsg(CostDomain costDomain, Integer currentUserId) {
UserDomain userDomain = userDao.selectByuserid(currentUserId);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String msg = String.format("{\n" +
" \"msgtype\": \"markdown\",\n" +
" \"markdown\": {\n" +
" \"content\": \"单号【<font color=\\\"info\\\">%s</font>】通过最终审核。\\n" +
">金额: <font color=\\\"info\\\">%s</font>\\n" +
">审核人: <font color=\\\"info\\\">%s</font>\\n" +
">审核时间: <font color=\\\"info\\\">%s</font>\"" +
" }\n" +
"}", costDomain.getCostNo(),
"CNY " + costDomain.getAmountRmb(),
userDomain == null ? currentUserId : userDomain.getUsername(),
LocalDateTime.now().format(dtf));
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
restTemplate.postForEntity(webHook.getUrl() + webHook.getFinalReview(), msg, Object.class);
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void handle() { public void handle() {
...@@ -79,6 +112,7 @@ public class FinalCheckState extends CostState { ...@@ -79,6 +112,7 @@ public class FinalCheckState extends CostState {
CostLogDomain costLogDomain = costLogDao.selectDepartmentCheckLog(costDomain.getCostNo()); CostLogDomain costLogDomain = costLogDao.selectDepartmentCheckLog(costDomain.getCostNo());
List<CostCurrentReviewer> costCurrentReviewerList = costCurrentReviewerMapper.selectByCostNo(costDomain.getCostNo()); List<CostCurrentReviewer> costCurrentReviewerList = costCurrentReviewerMapper.selectByCostNo(costDomain.getCostNo());
if (costLogDomain != null && costCurrentReviewerList.stream().map(CostCurrentReviewer::getOaUserId).collect(Collectors.toList()).contains(costLogDomain.getUpdateUserid())) { if (costLogDomain != null && costCurrentReviewerList.stream().map(CostCurrentReviewer::getOaUserId).collect(Collectors.toList()).contains(costLogDomain.getUpdateUserid())) {
log.info("费用单:{}部门审核人和最终审核人是同一个人,最终审核人自动通过。", costDomain.getCostNo()); log.info("费用单:{}部门审核人和最终审核人是同一个人,最终审核人自动通过。", costDomain.getCostNo());
this.autoPass(); this.autoPass();
return; return;
...@@ -119,6 +153,8 @@ public class FinalCheckState extends CostState { ...@@ -119,6 +153,8 @@ public class FinalCheckState extends CostState {
costLogService.save(costDomain.getCostNo(), currentUserId, "最终审核通过", CostLogDomain.FINAL_MANUAL_PASS); costLogService.save(costDomain.getCostNo(), currentUserId, "最终审核通过", CostLogDomain.FINAL_MANUAL_PASS);
approvalHistoryService.save(approvalHistoryDomain); approvalHistoryService.save(approvalHistoryDomain);
sendWxMsg(costDomain, currentUserId);
//流转状态 //流转状态
nextState(unPayState); nextState(unPayState);
//通知财务系统 //通知财务系统
......
...@@ -20,7 +20,7 @@ spring: ...@@ -20,7 +20,7 @@ spring:
publisher-returns: true publisher-returns: true
data: data:
mongodb: mongodb:
uri: 'mongodb://admin:!%40#blt*mongo123@10.0.12.3:27018/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false' uri: 'mongodb://admin:!%40#blt*mongo123@42.193.191.242:27018/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false'
database: bailuntec-cost database: bailuntec-cost
thymeleaf: thymeleaf:
...@@ -107,3 +107,8 @@ net-suite: ...@@ -107,3 +107,8 @@ net-suite:
realm: 6916374 realm: 6916374
do-work: true do-work: true
wx-hook:
url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=
final-review: 87e1dfa2-d54a-4126-afcf-95fbd68e74d8
test: 8ecc859b-0548-4640-a47b-cd03d873b364
...@@ -105,3 +105,7 @@ net-suite: ...@@ -105,3 +105,7 @@ net-suite:
token-secret: d974ba497472b258a06175cc62a2edba6104f94c131afba38143e8c3a2f0e125 token-secret: d974ba497472b258a06175cc62a2edba6104f94c131afba38143e8c3a2f0e125
realm: 6916374_SB1 realm: 6916374_SB1
do-work: false do-work: false
wx-hook:
url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=
final-review: 87e1dfa2-d54a-4126-afcf-95fbd68e74d8
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