Commit 6b3ca06f by HlQ

[chg] 使用 Jackson 替代 Hutool 的json

1 parent 737cb2cc
......@@ -15,7 +15,7 @@
<version>1</version>
<properties>
<java.version>21</java.version>
<hutool.version>6.0.0-M13</hutool.version>
<hutool.version>6.0.0-M16</hutool.version>
<redisson.verion>3.32.0</redisson.verion>
<mapstruct-plus.version>1.4.3</mapstruct-plus.version>
<mp.version>3.5.7</mp.version>
......
......@@ -3,6 +3,7 @@ package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.liaochong.myexcel.core.DefaultExcelBuilder;
import com.github.liaochong.myexcel.core.watermark.Watermark;
import com.github.liaochong.myexcel.utils.WatermarkUtil;
......@@ -14,7 +15,6 @@ import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.text.CharSequenceUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.json.JSONObject;
import org.springframework.web.bind.annotation.*;
import vion.cron.ContractRunner;
import vion.dto.ContractDTO;
......@@ -116,7 +116,7 @@ public class ContractController {
@GetMapping("/contract/calAmount")
@SaCheckPermission(value = "contract:calAmount", orRole = "admin")
public JSONObject calAmount(ContractDTO dto) {
public JsonNode calAmount(ContractDTO dto) {
return contractService.calAmount(dto);
}
......@@ -165,7 +165,7 @@ public class ContractController {
@GetMapping("/contract/getCRMProduct")
@SaCheckPermission(value = "contract:CRMProduct", orRole = "admin")
public JSONObject getCRMProduct(@RequestParam String name,
public JsonNode getCRMProduct(@RequestParam String name,
@RequestParam String code,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "20") Integer pageSize) {
......
......@@ -8,8 +8,6 @@ import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
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;
......@@ -20,6 +18,7 @@ import vion.model.User;
import vion.service.IRStoreUserService;
import vion.service.IStoreService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -74,21 +73,22 @@ public class LogPushRunner {
};
}
JSONObject buildMsg(String storeName, String userid) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
String buildMsg(String storeName, String userid) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = new JSONObject();
var content = new JSONObject();
content.set("title", "项目日志待提交提醒")
.set("text", StrUtil.format("""
var content = JsonUtil.createObj()
.put("title", "项目日志待提交提醒")
.put("text", StrUtil.format("""
### 项目日志待提交提醒
#### 项目:[{}]请及时提交日志
#### 发送时间:{}""", storeName, DateUtil.now()));
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj()
.put("msgtype", "markdown")
.set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
}
......@@ -5,9 +5,6 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;
......@@ -15,6 +12,7 @@ import vion.model.User;
import vion.service.ITaskService;
import vion.service.IUserService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import java.util.stream.Collectors;
......@@ -44,27 +42,27 @@ public class TaskRunner {
log.info("推送未完成工单完成");
}
JSONObject buildMsg(User user) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", user.getUserid());
String buildMsg(User user) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", user.getUserid());
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj()
.set("title", "请查看您未完成的工单~_~")
.set("markdown", """
var content = JsonUtil.createObj()
.put("title", "请查看您未完成的工单~_~")
.put("markdown", """
### 未完成工单提醒
#### 请查看您未完成的工单
#### 发送时间:""" + DateUtil.now())
.set("btn_orientation", "1");
.put("btn_orientation", "1");
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()));
var jsonArray = JsonUtil.createArr()
.add(JsonUtil.createObj().put("title", "查看详情")
.put("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").set("action_card", content);
var msg = JsonUtil.createObj().put("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
}
\ No newline at end of file
package vion.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.yulichang.base.MPJBaseService;
import org.dromara.hutool.json.JSONObject;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import vion.dto.ContractDTO;
......@@ -33,7 +33,7 @@ public interface IContractService extends MPJBaseService<Contract> {
String updateById(Long id, String contractNo, ContractDTO dto);
JSONObject calAmount(ContractDTO dto);
JsonNode calAmount(ContractDTO dto);
Map<String, Object> analyze(ContractDTO dto);
......@@ -49,7 +49,7 @@ public interface IContractService extends MPJBaseService<Contract> {
String createContract(String contractJson);
JSONObject getCRMProduct(String name, String code, Integer page, Integer pageSize);
JsonNode getCRMProduct(String name, String code, Integer page, Integer pageSize);
String syncContractFile(String[] contractNoList);
}
\ No newline at end of file
......@@ -8,8 +8,6 @@ import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import vion.constant.RedisKeyEnum;
......@@ -20,6 +18,7 @@ import vion.service.IDeliverLogService;
import vion.service.IRStoreConfederateService;
import vion.service.IStoreService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import vion.vo.DeliverLogVO;
import java.util.Comparator;
......@@ -126,15 +125,14 @@ public class DeliverLogServiceImpl extends MPJBaseServiceImpl<DeliverLogMapper,
return StrUtil.containsIgnoreCase(pushRes, "ok");
}
JSONObject buildMsg(String userid, String storeName, String confederateName, DeliverLog deliverLog) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
String buildMsg(String userid, String storeName, String confederateName, DeliverLog deliverLog) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = new JSONObject();
var content = new JSONObject();
content.set("title", "项目交付日志提醒")
.set("text", StrUtil.format("""
var content = JsonUtil.createObj()
.put("title", "项目交付日志提醒")
.put("text", StrUtil.format("""
### 项目交付日志提醒
#### 项目:{}
#### 合同编号:{}
......@@ -150,27 +148,26 @@ public class DeliverLogServiceImpl extends MPJBaseServiceImpl<DeliverLogMapper,
deliverLog.getContent(),
DateUtil.now()));
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj().put("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
JSONObject buildMsg1(String[] userIdStr, String dateStr) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", String.join(",", userIdStr));
String buildMsg1(String[] userIdStr, String dateStr) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", String.join(",", userIdStr));
var msg = new JSONObject();
var content = new JSONObject();
content.set("title", "项目交付日志提醒")
.set("text", StrUtil.format("""
var content = JsonUtil.createObj()
.put("title", "项目交付日志提醒")
.put("text", StrUtil.format("""
### 项目交付日志提醒
#### 您的日志还未提交,请尽快提交!
#### 未提交日志日期:{}
#### 发送时间:{}""", dateStr, DateUtil.now()));
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj().put("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
}
......@@ -16,8 +16,6 @@ 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.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.ContractDTO;
......@@ -26,6 +24,7 @@ import vion.mapper.DeliveryRecordMapper;
import vion.model.*;
import vion.service.*;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import vion.vo.DeliveryRecordVO;
import vion.vo.UserVO;
......@@ -150,13 +149,13 @@ public class DeliveryRecordServiceImpl extends MPJBaseServiceImpl<DeliveryRecord
.ifPresent(p -> pointInfoService.designPush(null, p, "发货"));
}
JSONObject buildMsg(String userid, DeliveryRecord rec, Contract contract) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
String buildMsg(String userid, DeliveryRecord rec, Contract contract) {
var jsonNode = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "设备发货提醒");
var msg = JsonUtil.createObj();
var content = JsonUtil.createObj().put("title", "设备发货提醒");
String template = """
#### 发货通知
#### 合同名称:**{}**
......@@ -169,17 +168,18 @@ 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).set("btn_orientation", "1");
content.put("markdown", markdown).put("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%3FdeliveryId%3D" + rec.getId()));
var jsonArray = JsonUtil.createArr()
.add(JsonUtil.createObj()
.put("title", "查看详情")
.put("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").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
msg.put("msgtype", "action_card").set("action_card", content);
jsonNode.set("msg", msg);
return jsonNode.toString();
}
private void saveFile(DeliveryRecordDTO dto, DeliveryRecord deliveryRecord) {
......
package vion.service.impl;
import org.dromara.hutool.core.data.id.IdUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.data.id.IdUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.springframework.stereotype.Service;
import vion.dto.FormDTO;
import vion.mapper.FormMapper;
......@@ -16,6 +15,7 @@ import vion.model.Account;
import vion.model.Form;
import vion.model.Store;
import vion.service.IFormService;
import vion.utils.JsonUtil;
import vion.vo.FormVO;
/**
......@@ -44,7 +44,7 @@ public class FormServiceImpl extends MPJBaseServiceImpl<FormMapper, Form> implem
Form form = converter.convert(dto, Form.class);
String nanoId = IdUtil.nanoId();
form.setUuid(nanoId);
return this.save(form) ? JSONUtil.ofObj().set("id", form.getId()).set("uuid", nanoId) : "创建失败";
return this.save(form) ? JsonUtil.createObj().put("id", form.getId()).put("uuid", nanoId) : "创建失败";
}
@Override
......
......@@ -14,8 +14,6 @@ import org.dromara.hutool.core.map.MapUtil;
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;
......@@ -27,6 +25,7 @@ import vion.service.IContractService;
import vion.service.IInvoiceService;
import vion.service.IRContractUserService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import vion.vo.InvoiceVO;
import vion.vo.RoleVO;
import vion.vo.UserVO;
......@@ -171,13 +170,12 @@ public class InvoiceServiceImpl extends MPJBaseServiceImpl<InvoiceMapper, Invoic
return "金额计算成功";
}
JSONObject buildMsg(String userid, Invoice invoice, Contract contract) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
String buildMsg(String userid, Invoice invoice, Contract contract) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "开票提醒");
var content = JsonUtil.createObj().put("title", "开票提醒");
String template = """
#### 开票提醒
#### 合同编号:**{}**
......@@ -190,10 +188,10 @@ public class InvoiceServiceImpl extends MPJBaseServiceImpl<InvoiceMapper, Invoic
""";
String markdown = StrUtil.format(template,
contract.getContractNo(), contract.getName(), invoice.getInvoiceNo(), invoice.getInvoiceAmount(), DateUtil.formatDate(invoice.getInvoicingTime()), invoice.getRemark(), DateUtil.now());
content.set("text", markdown);
content.put("text", markdown);
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj().put("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
}
package vion.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.dromara.hutool.core.util.ObjUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vion.dto.PaymentDTO;
......@@ -28,6 +26,7 @@ import vion.service.IContractService;
import vion.service.IPaymentService;
import vion.service.IRContractUserService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import vion.vo.PaymentVO;
import vion.vo.RoleVO;
import vion.vo.UserVO;
......@@ -181,13 +180,12 @@ public class PaymentServiceImpl extends MPJBaseServiceImpl<PaymentMapper, Paymen
return "删除成功";
}
JSONObject buildMsg(String userid, Payment payment, Contract contract) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
String buildMsg(String userid, Payment payment, Contract contract) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "收款提醒");
var content = JsonUtil.createObj().put("title", "收款提醒");
String template = """
#### 收款提醒
#### 合同编号:**{}**
......@@ -199,10 +197,10 @@ public class PaymentServiceImpl extends MPJBaseServiceImpl<PaymentMapper, Paymen
""";
String markdown = StrUtil.format(template,
contract.getContractNo(), contract.getName(), payment.getPaymentAmount(), DateUtil.formatDate(payment.getCollectionTime()), payment.getRemark(), DateUtil.now());
content.set("text", markdown);
content.put("text", markdown);
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj().put("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
}
package vion.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.ListUtil;
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.array.ArrayUtil;
import org.dromara.hutool.core.data.id.IdUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......@@ -27,7 +14,18 @@ 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.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.data.id.IdUtil;
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.crypto.SecureUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -39,6 +37,7 @@ import vion.model.*;
import vion.service.*;
import vion.third.DingMod;
import vion.third.WechatMod;
import vion.utils.JsonUtil;
import vion.utils.ResultUtil;
import vion.vo.PointInfoVO;
import vion.vo.UserVO;
......@@ -491,11 +490,11 @@ public class PointInfoServiceImpl extends MPJBaseServiceImpl<PointInfoMapper, Po
}
String buildMsg(String title, String content) {
var jsonObj = JSONUtil.ofObj().set("msgtype", "markdown");
var jsonObj = JsonUtil.createObj().put("msgtype", "markdown");
JSONObject markdown = JSONUtil.ofObj()
.set("title", title)
.set("text", content);
var markdown = JsonUtil.createObj()
.put("title", title)
.put("text", content);
jsonObj.set("markdown", markdown);
return jsonObj.toString();
}
......
......@@ -15,7 +15,6 @@ 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.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.RepairRecDTO;
......@@ -24,6 +23,7 @@ import vion.model.*;
import vion.service.IFileService;
import vion.service.IRepairRecService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import vion.vo.RepairRecVO;
import vion.vo.UserVO;
......@@ -138,12 +138,11 @@ public class RepairRecServiceImpl extends MPJBaseServiceImpl<RepairRecMapper, Re
.map(l -> l.stream().map(RRepairDevice::getDeviceNo).collect(Collectors.joining(",")))
.orElse("暂无");
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "返修设备已发货");
var content = JsonUtil.createObj().put("title", "返修设备已发货");
String text = StrUtil.format("""
### 返修设备已发货
### 项目名称:{}
......@@ -154,12 +153,12 @@ public class RepairRecServiceImpl extends MPJBaseServiceImpl<RepairRecMapper, Re
""", repairRecVO.getProjectName(), Opt.ofBlankAble(repairRecVO.getTrackingNumber()).orElse("暂无"),
deviceNoStr,
Opt.ofBlankAble(DateUtil.formatDate(repairRecVO.getShipDate())).orElse("暂无"), DateUtil.now());
content.set("text", text);
content.put("text", text);
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj().put("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
var pushRes = dingMod.workMsg(jsonObj);
var pushRes = dingMod.workMsg(jsonObj.toString());
return StrUtil.containsIgnoreCase(pushRes, "ok");
}
}
......@@ -15,7 +15,6 @@ 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.JSONUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.SparePartDTO;
......@@ -24,6 +23,7 @@ import vion.model.*;
import vion.service.IFileService;
import vion.service.ISparePartService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import vion.vo.SparePartVO;
import vion.vo.UserVO;
......@@ -132,12 +132,11 @@ public class SparePartServiceImpl extends MPJBaseServiceImpl<SparePartMapper, Sp
.map(l -> l.stream().map(RRepairDevice::getDeviceNo).collect(Collectors.joining(",")))
.orElse("暂无");
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj().set("title", "备件已发货");
var content = JsonUtil.createObj().put("title", "备件已发货");
String text = StrUtil.format("""
### 备件已发货
### 项目名称:{}
......@@ -148,12 +147,12 @@ public class SparePartServiceImpl extends MPJBaseServiceImpl<SparePartMapper, Sp
""", sparePartVO.getProjectName(), Opt.ofBlankAble(sparePartVO.getTrackingNumber()).orElse("暂无"),
deviceNoStr,
Opt.ofBlankAble(DateUtil.formatDate(sparePartVO.getShipDate())).orElse("暂无"), DateUtil.now());
content.set("text", text);
content.put("text", text);
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj().put("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
var pushRes = dingMod.workMsg(jsonObj);
var pushRes = dingMod.workMsg(jsonObj.toString());
return StrUtil.containsIgnoreCase(pushRes, "ok");
}
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.liaochong.myexcel.core.DefaultExcelBuilder;
import com.github.liaochong.myexcel.core.watermark.Watermark;
import com.github.liaochong.myexcel.utils.WatermarkUtil;
......@@ -27,8 +28,6 @@ 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;
......@@ -43,6 +42,7 @@ import vion.mapper.TaskMapper;
import vion.model.*;
import vion.service.*;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import vion.utils.excel.AttachmentExportUtil;
import vion.vo.ContractVO;
import vion.vo.StoreVO;
......@@ -457,17 +457,17 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
### 内容:
> {}
""", storeVO.getName(), user.getUsername(), DateUtil.formatDate(storeLog.getLogDate()), logText);
var markdown = JSONUtil.ofObj()
.set("title", "项目日志提醒")
.set("text", text);
var markdown = JsonUtil.createObj()
.put("title", "项目日志提醒")
.put("text", text);
JSONObject atObj = null;
JsonNode atObj = null;
if (ArrayUtil.isNotEmpty(userIdStr)) {
var arr = JSONUtil.ofArray();
Arrays.stream(userIdStr).forEach(arr::put);
var arr = JsonUtil.createArr();
Arrays.stream(userIdStr).forEach(arr::add);
var atUser = Arrays.stream(userIdStr).collect(Collectors.joining("@", "@", ""));
System.out.println(atUser);
atObj = JSONUtil.ofObj().set("atUserIds", arr);
atObj = JsonUtil.createObj().set("atUserIds", arr);
text = StrUtil.format("""
### 项目日志
### 查收人:{}
......@@ -477,13 +477,14 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
### 内容:
> {}
""", atUser, storeVO.getName(), user.getUsername(), DateUtil.formatDate(storeLog.getLogDate()), logText);
markdown.set("text", text);
markdown.put("text", text);
}
var body = JSONUtil.ofObj()
.set("msgtype", "markdown")
.set("markdown", markdown)
.setOpt("at", atObj);
var body = JsonUtil.createObj()
.put("msgtype", "markdown")
.putPOJO("markdown", markdown)
// fixme atObj is null, dont add it
.putPOJO("at", atObj);
var pushRes = dingMod.robotPush(storeVO.getBotToken(), body.toString());
return StrUtil.containsIgnoreCase(pushRes, "ok");
}
......@@ -684,38 +685,36 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
Collectors.counting())));
}
JSONObject buildMsg(String storeName, String userid) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
String buildMsg(String storeName, String userid) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj()
.set("title", "项目日志提醒")
.set("text", StrUtil.format("""
var content = JsonUtil.createObj()
.put("title", "项目日志提醒")
.put("text", StrUtil.format("""
#### 项目:[{}]请及时提交日志
#### 发送时间:{}""", storeName, DateUtil.now()));
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj().put("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
JSONObject buildMsg1(String storeName, String contractNo, String sourceName,
String buildMsg1(String storeName, String contractNo, String sourceName,
String[] fileNameArr, String[] userIdStr) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", String.join(",", userIdStr));
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", String.join(",", userIdStr));
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
var msg = new JSONObject();
var content = new JSONObject();
String fileNameStr = Arrays.stream(fileNameArr)
.map(v -> StrUtil.format("{}. {}", Arrays.asList(fileNameArr).indexOf(v) + 1, v))
.collect(Collectors.joining("\n"));
String fileNameStr = Arrays.stream(fileNameArr).map(v -> StrUtil.format("{}. {}",
Arrays.asList(fileNameArr).indexOf(v) + 1, v)).collect(Collectors.joining("\n"));
content.set("title", "项目资料提交提醒")
.set("text", StrUtil.format("""
var content = JsonUtil.createObj()
.put("title", "项目资料提交提醒")
.put("text", StrUtil.format("""
### 项目资料提交提醒
#### 项目名称:{}
#### 合同编号:{}
......@@ -726,8 +725,8 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
#### 发送时间:{}""", storeName, contractNo, userVO.getUsername(), sourceName, fileNameStr,
DateUtil.now()));
msg.set("msgtype", "markdown").set("markdown", content);
var msg = JsonUtil.createObj().put("msgtype", "markdown").set("markdown", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
}
......@@ -20,8 +20,6 @@ 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.crypto.SecureUtil;
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;
......@@ -32,6 +30,7 @@ import vion.service.IFileService;
import vion.service.ITaskTempService;
import vion.service.IUserService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import vion.vo.TaskTempVO;
import java.io.File;
......@@ -151,14 +150,11 @@ public class TaskTempServiceImpl extends MPJBaseServiceImpl<TaskTempMapper, Task
return Map.of();
}
JSONObject buildMsg(String userid, TaskTemp taskTemp) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", userid);
String buildMsg(String userid, TaskTemp taskTemp) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", userid);
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj()
.set("title", "客户提交工单,请及时处理哦~_~");
String template = """
### 客户提交工单提醒
#### 门店信息: **{}**
......@@ -169,17 +165,19 @@ 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).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()));
var content = JsonUtil.createObj()
.put("title", "客户提交工单,请及时处理哦~_~")
.put("markdown", markdown).put("btn_orientation", "1");
var jsonArray = JsonUtil.createArr()
.add(JsonUtil.createObj()
.put("title", "查看详情")
.put("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").set("action_card", content);
var msg = JsonUtil.createObj().put("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
return jsonObj.toString();
}
/**
......
package vion.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.text.StrUtil;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
/**
* JSON 工具类
*
* @author ShuQian_Liu
*/
@Slf4j
public class JsonUtil {
private static ObjectMapper objectMapper = new ObjectMapper();
static {
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// 忽略 null 值
// objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
// 解决 LocalDateTime 的序列化
objectMapper.registerModules(new JavaTimeModule());
}
/**
* 初始化 objectMapper 属性
* <p>
* 通过这样的方式,使用 Spring 创建的 ObjectMapper Bean
*
* @param objectMapper ObjectMapper 对象
*/
public static void init(ObjectMapper objectMapper) {
JsonUtil.objectMapper = objectMapper;
}
public static ObjectNode createObj() {
return objectMapper.createObjectNode();
}
public static ArrayNode createArr() {
return objectMapper.createArrayNode();
}
@SneakyThrows
public static String toJsonString(Object object) {
return objectMapper.writeValueAsString(object);
}
@SneakyThrows
public static byte[] toJsonByte(Object object) {
return objectMapper.writeValueAsBytes(object);
}
@SneakyThrows
public static String toJsonPrettyString(Object object) {
return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
}
public static <T> T parseObject(String text, Class<T> clazz) {
if (StrUtil.isEmpty(text)) {
return null;
}
try {
return objectMapper.readValue(text, clazz);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
throw new RuntimeException(e);
}
}
public static <T> T parseObject(String text, String path, Class<T> clazz) {
if (StrUtil.isEmpty(text)) {
return null;
}
try {
JsonNode treeNode = objectMapper.readTree(text);
JsonNode pathNode = treeNode.path(path);
return objectMapper.readValue(pathNode.toString(), clazz);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
throw new RuntimeException(e);
}
}
public static <T> T parseObject(String text, Type type) {
if (StrUtil.isEmpty(text)) {
return null;
}
try {
return objectMapper.readValue(text, objectMapper.getTypeFactory().constructType(type));
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
throw new RuntimeException(e);
}
}
/**
* 将字符串解析成指定类型的对象
* 使用 {@link #parseObject(String, Class)} 时,在@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) 的场景下,
* 如果 text 没有 class 属性,则会报错。此时,使用这个方法,可以解决。
*
* @param text 字符串
* @param clazz 类型
* @return 对象
*/
public static <T> T parseObject2(String text, Class<T> clazz) {
if (StrUtil.isEmpty(text)) {
return null;
}
try {
return objectMapper.readValue(text, clazz);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
public static <T> T parseObject(byte[] bytes, Class<T> clazz) {
if (ArrayUtil.isEmpty(bytes)) {
return null;
}
try {
return objectMapper.readValue(bytes, clazz);
} catch (IOException e) {
log.error("json parse err,json:{}", bytes, e);
throw new RuntimeException(e);
}
}
public static <T> T parseObject(String text, TypeReference<T> typeReference) {
try {
return objectMapper.readValue(text, typeReference);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
throw new RuntimeException(e);
}
}
/**
* 解析 JSON 字符串成指定类型的对象,如果解析失败,则返回 null
*
* @param text 字符串
* @param typeReference 类型引用
* @return 指定类型的对象
*/
public static <T> T parseObjectQuietly(String text, TypeReference<T> typeReference) {
try {
return objectMapper.readValue(text, typeReference);
} catch (IOException e) {
return null;
}
}
public static <T> List<T> parseArray(String text, Class<T> clazz) {
if (StrUtil.isEmpty(text)) {
return new ArrayList<>();
}
try {
return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
throw new RuntimeException(e);
}
}
public static <T> List<T> parseArray(String text, String path, Class<T> clazz) {
if (StrUtil.isEmpty(text)) {
return null;
}
try {
JsonNode treeNode = objectMapper.readTree(text);
JsonNode pathNode = treeNode.path(path);
return objectMapper.readValue(pathNode.toString(), objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
throw new RuntimeException(e);
}
}
public static JsonNode parseTree(String text) {
try {
return objectMapper.readTree(text);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
throw new RuntimeException(e);
}
}
public static JsonNode parseTree(byte[] text) {
try {
return objectMapper.readTree(text);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
throw new RuntimeException(e);
}
}
public static boolean isJson(String jsonString) {
try {
objectMapper.readTree(jsonString);
return true;
} catch (Exception e) {
return false;
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!