Commit 277228ac by HlQ

[add] 添加项目日志推送功能和日志催写功能

1 parent e7a0e032
......@@ -166,4 +166,22 @@ public class StoreController {
return storeService.fileDetail(storeIdList);
}
@GetMapping("/store/logNotify")
@SaCheckPermission(value = "store:logNotify", orRole = "admin")
public String logNotify(Long id, String[] userIdStr) {
return storeService.logNotify(id, userIdStr) ? "钉钉提醒成功" : "钉钉提醒失败";
}
@GetMapping("/store/addCron")
@SaCheckPermission(value = "store:addCron", orRole = "admin")
public String addCron(Long storeId, String storeName, String cronStr, String userId) {
return storeService.addCron(storeId, storeName, cronStr, userId);
}
@GetMapping("/store/stopCron")
@SaCheckPermission(value = "store:stopCron", orRole = "admin")
public String stopCron(Long storeId) {
return storeService.stopCron(storeId);
}
}
......@@ -126,6 +126,7 @@ public class ContractRunner {
insOrUpdContractList.add(contract);
}
if (CollUtil.isNotEmpty(insOrUpdContractList)) {
var noList = insOrUpdContractList.stream().map(Contract::getContractNo).toList();
var noStr = insOrUpdContractList.stream().map(Contract::getContractNo).distinct().collect(Collectors.joining("','", "'", "'"));
String productTemplate = """
SELECT c.cInvName as product_name,c.cInvCode as product_code,c.cInvStd as product_model,a.hetongluru_name as contract_no,b.hetongluru_d_dec01 as num,b.hetongluru_d_dec02 as tax_price,b.hetongluru_d_dec03 as tax_rate,b.hetongluru_d_dec04 as no_tax_price,b.hetongluru_d_dec05 as discount_rate,b.hetongluru_d_dec06 as actual_price,b.hetongluru_d_dec07 as total_price,b.hetongluru_d_dec08 as erase from tcu_hetongluru a left join tcu_hetongluru_d b on a.hetongluru_id=b.m_id LEFT JOIN Inventory c on b.ref_obj_id=c.cInvCode where a.hetongluru_name in ({})
......@@ -149,6 +150,7 @@ public class ContractRunner {
contractProduct.setTotalPrice(rs1.getBigDecimal("total_price"));
productList.add(contractProduct);
}
contractProductService.lambdaUpdate().in(RContractProduct::getContractNo, noList).remove();
contractProductService.saveBatch(productList);
}
}
......
package vion.cron;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.ObjUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.cron.CronUtil;
import org.dromara.hutool.cron.task.Task;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import vion.constant.RedisKeyEnum;
import vion.model.RStoreUser;
import vion.model.Store;
import vion.model.User;
import vion.service.IRStoreUserService;
import vion.service.IStoreService;
import vion.third.DingMod;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author HlQ
* @date 2024/4/23
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class LogPushRunner {
private final IStoreService storeService;
private final IRStoreUserService storeUserService;
private final DingMod dingMod;
private final RedissonClient redissonClient;
@Bean
public void scheduledPush() {
var storeList = storeService.lambdaQuery().isNotNull(Store::getCronStr).list();
Opt.ofEmptyAble(storeList)
.ifPresent(list -> {
var idList = list.stream().map(Store::getId).toList();
var storeUserMap = storeUserService.lambdaQuery()
.in(RStoreUser::getStoreId, idList).list()
.stream()
.filter(v -> v.getIsMain().equals(1))
.collect(Collectors.toMap(RStoreUser::getStoreId, RStoreUser::getUserId));
for (Store store : list) {
var task = getTask(store, storeUserMap);
CronUtil.schedule(store.getCronStr(), task);
}
if (!CronUtil.getScheduler().isStarted()) {
CronUtil.setMatchSecond(true);
CronUtil.start();
}
});
}
public Task getTask(Store store, Map<Long, Long> storeUserMap) {
return () -> {
var userId = storeUserMap.get(store.getId());
if (ObjUtil.isNull(userId)) {
log.info("storeId:{},该项目未设置项目经理,不发送日志提醒", store.getId());
return;
}
var user = (User) redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + userId).get();
dingMod.workMsg(buildMsg(store.getName(), user.getUserid()));
log.info("storeId:{},项目发送日志提醒,提醒人:{}({})", store.getId(), user.getUsername(), user.getUserid());
};
}
JSONObject buildMsg(String storeName, String userid) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
var msg = new JSONObject();
var content = new JSONObject();
content.set("title", "项目日志提醒")
.set("text", StrUtil.format("""
#### 项目:[{}]请及时提交日志
#### 发送时间:{}""", storeName, DateUtil.now()));
msg.set("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
}
}
......@@ -7,6 +7,7 @@ import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.json.JSONArray;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vion.model.Task;
......@@ -45,23 +46,25 @@ public class TaskRunner {
}
JSONObject buildMsg(User user) {
var jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", user.getUserid());
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", user.getUserid());
var msg = new JSONObject();
var content = new JSONObject();
content.set("title", "请查看您未完成的工单~_~");
content.set("markdown", "#### 请查看您未完成的工单" +
" \n #### 发送时间:" + DateUtil.now());
content.set("btn_orientation", "1");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj()
.set("title", "请查看您未完成的工单~_~")
.set("markdown", "#### 请查看您未完成的工单" +
" \n #### 发送时间:" + DateUtil.now())
.set("btn_orientation", "1");
var jsonArray = new JSONArray();
jsonArray.add(new JSONObject().set("title", "查看详情").set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FuserId%3D" + user.getId()));
JSONArray jsonArray = JSONUtil.ofArray()
.put(JSONUtil.ofObj().set("title", "查看详情")
.set("action_url", """
https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FuserId%3D
""" + user.getId()));
content.set("btn_json_list", jsonArray);
msg.set("msgtype", "action_card");
msg.set("action_card", content);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......
......@@ -32,7 +32,7 @@ public class FileInfo {
* <br>16客户提交的门店图纸,17点位设计图,18合同范本,19客户上传的合同,20安装上线,与总部邮件截图</br>
* <br>21服务单等表单富文本编辑器里传图用这个类型</br>
* <br>22备件,23返修</br>
* <br>24验收报告,25竣工图纸,26点位表,27项目总结</br>
* <br>24验收报告,25竣工图纸,26点位表,27项目总结,28前期勘察</br>
*/
private Integer sourceType;
/** 文件来源id */
......
......@@ -155,4 +155,19 @@ public class Store {
*/
private Integer constructionCount;
/**
* 钉钉机器人推送地址的token
*/
private String botToken;
/**
* 定时任务id
*/
private String scheduleId;
/**
* cron表达式
*/
private String cronStr;
}
......@@ -26,4 +26,10 @@ public interface IStoreService extends MPJBaseService<Store> {
String addTag(Long id, List<Long> tagIdList);
List<Map<String, Number>> fileDetail(@RequestParam List<Long> storeIdList);
boolean logNotify(Long id, String[] userIdStr);
String addCron(Long storeId, String storeName, String cronStr, String userId);
String stopCron(Long storeId);
}
......@@ -581,9 +581,9 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd());
if (StrUtil.isNotBlank(dto.getOperator()) && ObjUtil.isNotNull(dto.getAmount())) {
String ope = dto.getOperator();
if (">".equals(ope)) {
if (">" .equals(ope)) {
wrapper.gt(getCol(dto), dto.getAmount());
} else if ("<".equals(ope)) {
} else if ("<" .equals(ope)) {
wrapper.lt(getCol(dto), dto.getAmount());
} else {
wrapper.eq(getCol(dto), dto.getAmount());
......@@ -605,13 +605,12 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
}
JSONObject buildMsg(String userid, Contract contract, String applicantName) {
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "合同施工申请,请及时处理哦~_~");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "合同施工申请,请及时处理哦~_~");
String template = """
#### 合同编号: **{}**" +
#### 合同名称:**{}**
......@@ -622,20 +621,18 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
contract.getContractNo(), contract.getName(), applicantName, DateUtil.now());
content.set("markdown", markdown);
msg.set("msgtype", "action_card");
msg.set("action_card", content);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
JSONObject buildMsg(String userid, ContractDTO dto, Contract contract, String statusStr) {
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "验收提醒");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "验收提醒");
String template = """
#### 验收提醒" +
#### 合同编号:**{}**" +
......@@ -648,8 +645,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
contract.getContractNo(), contract.getName(), statusStr, DateUtil.formatDate(dto.getNodeDate()), DateUtil.now());
content.set("text", markdown);
msg.set("msgtype", "markdown");
msg.set("markdown", content);
msg.set("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......
......@@ -16,8 +16,8 @@ import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.json.JSONArray;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.ContractDTO;
......@@ -147,13 +147,12 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
}
JSONObject buildMsg(String userid, DeliveryRecord rec, Contract contract) {
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "设备发货提醒");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "设备发货提醒");
String template = """
#### 发货通知
#### 合同名称:**{}**
......@@ -166,15 +165,16 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
""";
String markdown = StrUtil.format(template,
contract.getName(), contract.getContractNo(), rec.getCourierCompany(), rec.getTrackingNumber(), rec.getConsignee(), DateUtil.formatDate(rec.getShipDate()), DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
content.set("markdown", markdown).set("btn_orientation", "1");
JSONArray jsonArray = new JSONArray();
jsonArray.add(new JSONObject().set("title", "查看详情").set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FdeliveryId%3D" + rec.getId()));
var jsonArray = JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("title", "查看详情")
.set("action_url", """
https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FdeliveryId%3D""" + rec.getId()));
content.set("btn_json_list", jsonArray);
msg.set("msgtype", "action_card");
msg.set("action_card", content);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......
......@@ -15,6 +15,7 @@ import org.dromara.hutool.core.math.NumberUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vion.dto.InvoiceDTO;
......@@ -171,13 +172,12 @@ public class InvoiceServiceImpl extends MPJBaseServiceImpl<InvoiceMapper, Invoic
}
JSONObject buildMsg(String userid, Invoice invoice, Contract contract) {
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "开票提醒");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "开票提醒");
String template = """
#### 开票提醒
#### 合同编号:**{}**
......@@ -192,8 +192,7 @@ public class InvoiceServiceImpl extends MPJBaseServiceImpl<InvoiceMapper, Invoic
contract.getContractNo(), contract.getName(), invoice.getInvoiceNo(), invoice.getInvoiceAmount(), DateUtil.formatDate(invoice.getInvoicingTime()), invoice.getRemark(), DateUtil.now());
content.set("text", markdown);
msg.set("msgtype", "markdown");
msg.set("markdown", content);
msg.set("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......
......@@ -15,6 +15,7 @@ import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.json.JSONUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vion.dto.PaymentDTO;
......@@ -181,13 +182,12 @@ public class PaymentServiceImpl extends MPJBaseServiceImpl<PaymentMapper, Paymen
}
JSONObject buildMsg(String userid, Payment payment, Contract contract) {
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "收款提醒");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "收款提醒");
String template = """
#### 收款提醒
#### 合同编号:**{}**
......@@ -201,8 +201,7 @@ public class PaymentServiceImpl extends MPJBaseServiceImpl<PaymentMapper, Paymen
contract.getContractNo(), contract.getName(), payment.getPaymentAmount(), DateUtil.formatDate(payment.getCollectionTime()), payment.getRemark(), DateUtil.now());
content.set("text", markdown);
msg.set("msgtype", "markdown");
msg.set("markdown", content);
msg.set("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......
......@@ -27,6 +27,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import org.dromara.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -488,12 +489,11 @@ public class PointInfoServiceImpl extends MPJBaseServiceImpl<PointInfoMapper, Po
}
String buildMsg(String title, String content) {
JSONObject jsonObj = new JSONObject();
jsonObj.set("msgtype", "markdown");
var jsonObj = JSONUtil.ofObj().set("msgtype", "markdown");
JSONObject markdown = new JSONObject();
markdown.set("title", title);
markdown.set("text", content);
JSONObject markdown = JSONUtil.ofObj()
.set("title", title)
.set("text", content);
jsonObj.set("markdown", markdown);
return jsonObj.toString();
}
......
package vion.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
......@@ -9,6 +8,7 @@ import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.ListUtil;
......@@ -16,19 +16,28 @@ import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.io.file.FileNameUtil;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.cron.CronUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.http.html.HtmlUtil;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;
import vion.constant.RedisKeyEnum;
import vion.dto.StatusDTO;
import vion.dto.StoreDTO;
import vion.mapper.StoreMapper;
import vion.mapper.TaskMapper;
import vion.model.*;
import vion.service.*;
import vion.third.DingMod;
import vion.vo.ContractVO;
import vion.vo.StoreVO;
import vion.vo.TagVO;
......@@ -42,6 +51,7 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@Slf4j
public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> implements IStoreService {
private final IAccountService accountService;
......@@ -57,8 +67,10 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
private final IRStoreUserService storeUserService;
private final IStoreLogService storeLogService;
private final Converter converter;
private final DingMod dingMod;
// 引入 taskService 会循环依赖
private final TaskMapper taskMapper;
private final RedissonClient redissonClient;
@Value("${fileUrl:}")
private String fileUrl;
......@@ -79,8 +91,8 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
var store = converter.convert(data, Store.class);
var storeList = this.lambdaQuery(store)
.in(ObjUtil.notEquals(storeIdListByTagId.get(0), -1L), Store::getId, storeIdListByTagId)
.in(ObjUtil.notEquals(storeIdListByMainUser.get(0), -1L), Store::getId, storeIdListByMainUser)
.in(ObjUtil.isNotNull(data.getTagId()), Store::getId, storeIdListByTagId)
.in(ObjUtil.isNotNull(data.getMainUser()), Store::getId, storeIdListByMainUser)
.orderByDesc(Store::getIsImportant, Store::getCreateTime)
.page(Page.of(data.getPageNum(), data.getPageSize()));
// todo 缓存
......@@ -386,9 +398,9 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
var fileList = fileService.lambdaQuery()
.in(FileInfo::getSourceId, storeIdList)
.in(FileInfo::getStoreId, storeIdList)
.in(FileInfo::getSourceType, 1, 24, 25, 26, 27)
.in(FileInfo::getSourceType, 1, 24, 25, 26, 27, 28)
.list();
var storeId2FileMap = fileList.stream().collect(Collectors.groupingBy(FileInfo::getStoreId,Collectors.groupingBy(FileInfo::getSourceType)));
var storeId2FileMap = fileList.stream().collect(Collectors.groupingBy(FileInfo::getStoreId, Collectors.groupingBy(FileInfo::getSourceType)));
return storeIdList.stream().map(storeId -> {
var fileMap = storeId2FileMap.getOrDefault(storeId, MapUtil.empty());
Map<String, Number> map = new HashMap<>();
......@@ -398,7 +410,129 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
map.put("25", fileMap.getOrDefault(25, List.of()).size());
map.put("26", fileMap.getOrDefault(26, List.of()).size());
map.put("27", fileMap.getOrDefault(27, List.of()).size());
map.put("28", fileMap.getOrDefault(28, List.of()).size());
return map;
}).collect(Collectors.toList());
}
@Override
public boolean logNotify(Long id, String[] userIdStr) {
MPJLambdaWrapper<Store> wrapper = new MPJLambdaWrapper<Store>()
.select(Store::getName, Store::getBotToken)
.selectCollection(StoreLog.class, StoreVO::getStoreLog)
.leftJoin(StoreLog.class, StoreLog::getStoreId, Store::getId)
.eq(StoreLog::getId, id);
var storeVO = this.selectJoinOne(StoreVO.class, wrapper);
var storeLog = storeVO.getStoreLog().get(0);
var user = (User) redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + storeLog.getCreateUser()).get();
var content = storeLog.getContent();
var content1 = StrUtil.replace(content, "<br>", "\n");
var logText = HtmlUtil.cleanHtmlTag(content1);
var text = StrUtil.format("""
### 项目日志
### 项目:{}
### 提交人:{}
### 提交日期:{}
### 内容:
> {}
""", storeVO.getName(), user.getUsername(), DateUtil.formatDate(storeLog.getLogDate()), logText);
var markdown = JSONUtil.ofObj()
.set("title", "项目日志提醒")
.set("text", text);
JSONObject atObj = null;
if (ArrayUtil.isNotEmpty(userIdStr)) {
var arr = JSONUtil.ofArray();
Arrays.stream(userIdStr).forEach(arr::put);
var atUser = Arrays.stream(userIdStr).collect(Collectors.joining("@", "@", ""));
System.out.println(atUser);
atObj = JSONUtil.ofObj().set("atUserIds", arr);
text = StrUtil.format("""
### 项目日志
### 查收人:{}
### 项目:{}
### 提交人:{}
### 提交日期:{}
### 内容:
> {}
""", atUser, storeVO.getName(), user.getUsername(), DateUtil.formatDate(storeLog.getLogDate()), logText);
markdown.set("text", text);
}
var body = JSONUtil.ofObj()
.set("msgtype", "markdown")
.set("markdown", markdown)
.setOpt("at", atObj);
System.out.println(body);
var pushRes = dingMod.robotPush(storeVO.getBotToken(), body.toString());
return StrUtil.containsIgnoreCase(pushRes, "ok");
}
@Override
@Transactional(rollbackFor = Exception.class)
public String addCron(Long storeId, String storeName, String cronStr, String userId) {
String scheduleId = null;
try {
var update = this.lambdaUpdate().eq(Store::getId, storeId).set(Store::getCronStr, cronStr).update();
if (update) {
scheduleId = CronUtil.schedule(cronStr, (org.dromara.hutool.cron.task.Task) () -> {
if (StrUtil.isBlank(userId)) {
log.info("storeId:{},该项目未设置项目经理,不发送日志提醒", storeId);
return;
}
var user = (User) redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + userId).get();
dingMod.workMsg(buildMsg(storeName, user.getUserid()));
log.info("storeId:{},项目发送日志提醒,提醒人:{}({})", storeId, user.getUsername(), user.getUserid());
});
if (!CronUtil.getScheduler().isStarted()) {
CronUtil.setMatchSecond(true);
CronUtil.start();
}
this.lambdaUpdate().eq(Store::getId, storeId).set(Store::getScheduleId, scheduleId).update();
return "定时提醒任务添加成功";
}
} catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return "定时提醒任务添加失败";
} finally {
if (StrUtil.isNotBlank(scheduleId)) {
CronUtil.remove(scheduleId);
}
}
return "定时提醒任务添加失败";
}
@Override
public String stopCron(Long storeId) {
var store = this.getById(storeId);
var update = this.lambdaUpdate()
.eq(Store::getId, storeId)
.set(Store::getCronStr, null)
.set(Store::getScheduleId, null)
.update();
if (update) {
CronUtil.remove(store.getScheduleId());
return "定时提醒任务移除成功";
}
return "定时提醒任务移除失败";
}
JSONObject buildMsg(String storeName, String userid) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj()
.set("title", "项目日志提醒")
.set("text", StrUtil.format("""
#### 项目:[{}]请及时提交日志
#### 发送时间:{}""", storeName, DateUtil.now()));
msg.set("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
}
}
......@@ -22,8 +22,8 @@ import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.json.JSONArray;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
......@@ -524,13 +524,12 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
JSONObject buildMsg(String userid, String storeName, Task task) {
RMap<Integer, String> orderStatusMap = redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "您有一条新工单请及时处理哦~_~");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "您有一条新工单请及时处理哦~_~");
String template = """
#### 门店信息: **{}** [FullOfVitality]" +
#### 任务编号:{}
......@@ -542,27 +541,26 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
""";
String markdown = StrUtil.format(template,
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus()), task.getFaultDescription(), DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
content.set("markdown", markdown).set("btn_orientation", "1");
JSONArray jsonArray = new JSONArray();
jsonArray.add(new JSONObject().set("title", "查看详情").set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FstoreId%3D" + task.getStoreId() + "%26taskId%3D" + task.getId()));
var jsonArray = JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("title", "查看详情")
.set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FstoreId%3D" + task.getStoreId() + "%26taskId%3D" + task.getId()));
content.set("btn_json_list", jsonArray);
msg.set("msgtype", "action_card");
msg.set("action_card", content);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
JSONObject buildMsg2(String userid, String storeName, Task task) {
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "工单消息提醒");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "工单消息提醒");
String template = """
#### 门店信息: **{}**
#### 报修人:{}
......@@ -572,15 +570,16 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
""";
String markdown = StrUtil.format(template,
storeName, task.getRepairPeople(), task.getRepairPhone(), task.getFaultDescription(), DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
content.set("markdown", markdown).set("btn_orientation", "1");
JSONArray jsonArray = new JSONArray();
jsonArray.add(new JSONObject().set("title", "查看详情").set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FtaskUuid%3D" + task.getUuid()));
var jsonArray = JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("title", "查看详情")
.set("action_url", """
https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FtaskUuid%3D""" + task.getUuid()));
content.set("btn_json_list", jsonArray);
msg.set("msgtype", "action_card");
msg.set("action_card", content);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......@@ -588,13 +587,10 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
JSONObject buildMsg3(String userid, String storeName, Task task) {
RMap<Integer, String> orderStatusMap = redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj().set("agent_id", 2358374016L).set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "工单转发提醒");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "工单转发提醒");
String template = """
#### 门店信息: **{}** [FullOfVitality]`
#### 任务编号:{}
......@@ -606,15 +602,16 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
""";
String markdown = StrUtil.format(template,
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus()), task.getFaultDescription(), DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
content.set("markdown", markdown).set("btn_orientation", "1");
JSONArray jsonArray = new JSONArray();
jsonArray.add(new JSONObject().set("title", "查看详情").set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FtaskUuid%3D" + task.getUuid()));
var jsonArray = JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("title", "查看详情")
.set("action_url", """
https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FtaskUuid%3D""" + task.getUuid()));
content.set("btn_json_list", jsonArray);
msg.set("msgtype", "action_card");
msg.set("action_card", content);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......@@ -622,13 +619,12 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
JSONObject buildMsg4(String userid, String storeName, Task task, String remark) {
RMap<Integer, String> orderStatusMap = redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "工单催办提醒");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "工单催办提醒");
String template = """
#### 门店信息: **{}** [FullOfVitality]
#### 任务编号:{}
......@@ -640,15 +636,15 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
""";
String markdown = StrUtil.format(template,
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus()), remark, DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
content.set("markdown", markdown).set("btn_orientation", "1");
JSONArray jsonArray = new JSONArray();
jsonArray.add(new JSONObject().set("title", "查看详情").set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FstoreId%3D" + task.getStoreId() + "%26taskId%3D" + task.getId()));
var jsonArray = JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("title", "查看详情")
.set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FstoreId%3D" + task.getStoreId() + "%26taskId%3D" + task.getId()));
content.set("btn_json_list", jsonArray);
msg.set("msgtype", "action_card");
msg.set("action_card", content);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......
......@@ -16,8 +16,8 @@ import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.json.JSONArray;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.TaskTempDTO;
......@@ -138,13 +138,13 @@ public class TaskTempServiceImpl extends MPJBaseServiceImpl<TaskTempMapper, Task
}
JSONObject buildMsg(String userid, TaskTemp taskTemp) {
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
jsonObj.set("userid_list", userid);
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
JSONObject msg = new JSONObject();
JSONObject content = new JSONObject();
content.set("title", "客户提交工单,请及时处理哦~_~");
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj()
.set("title", "客户提交工单,请及时处理哦~_~");
String template = """
#### 门店信息: **{}**
#### 客户姓名:{}
......@@ -154,15 +154,17 @@ public class TaskTempServiceImpl extends MPJBaseServiceImpl<TaskTempMapper, Task
""";
String markdown = StrUtil.format(template,
taskTemp.getStoreName(), taskTemp.getRepairPeople(), taskTemp.getRepairPhone(), taskTemp.getFaultDescription(), DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
JSONArray jsonArray = new JSONArray();
jsonArray.add(new JSONObject().set("title", "查看详情").set("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FtaskTempId%3D" + taskTemp.getId()));
content.set("markdown", markdown).set("btn_orientation", "1");
var jsonArray = JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("title", "查看详情")
.set("action_url", """
https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FtaskTempId%3D
""" + taskTemp.getId()));
content.set("btn_json_list", jsonArray);
msg.set("msgtype", "action_card");
msg.set("action_card", content);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
......
......@@ -336,8 +336,8 @@ public class DingMod {
return StrUtil.format("https://oapi.dingtalk.com/sns/getuserinfo_bycode?accessKey=dingkrzwks0jpi2di3uo&timestamp={}&signature={}", timestamp, encodeSign);
}
public String robotPush(String access_token, String body) {
String res = HttpUtil.post("https://oapi.dingtalk.com/robot/send?access_token=" + access_token, body);
public String robotPush(String accessToken, String body) {
String res = HttpUtil.post("https://oapi.dingtalk.com/robot/send?access_token=" + accessToken, body);
log.info("钉钉机器人消息推送:{}", res);
return res;
}
......
......@@ -163,4 +163,19 @@ public class StoreVO {
* 工单日志数量
*/
private Integer logCount;
/**
* 钉钉机器人推送地址的token
*/
private String botToken;
/**
* 定时任务id
*/
private String scheduleId;
/**
* cron表达式
*/
private String cronStr;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!