This commit is contained in:
donqi 2022-08-04 23:28:18 +08:00
commit e75f738c4d
38 changed files with 782 additions and 43 deletions

View File

@ -95,6 +95,12 @@
<groupId>com.ghy</groupId>
<artifactId>ghy-worker</artifactId>
</dependency>
<dependency>
<groupId>com.ghy</groupId>
<artifactId>ghy-message</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>

View File

@ -0,0 +1,36 @@
package com.ghy.web.controller.message;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.ExceptionUtil;
import com.ghy.message.domain.JimUser;
import com.ghy.message.service.JimUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/jim/user")
public class JimUserController extends BaseController {
@Autowired
private JimUserService jimUserService;
@PostMapping("/register")
public AjaxResult register(){
try {
JimUser jimUser = new JimUser();
jimUser.setUserName("clunt");
jimUser.setPassword("password");
jimUserService.registerJimUser(jimUser);
return AjaxResult.success("注册成功!");
}catch (Exception e){
e.printStackTrace();
logger.error(ExceptionUtil.getExceptionMessage(e));
return AjaxResult.error("注册失败!");
}
}
}

View File

@ -0,0 +1,79 @@
package com.ghy.web.controller.tool;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ghy.common.config.SmsConfig;
import com.ghy.common.constant.SmsConstants;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.CacheUtils;
import com.ghy.common.utils.ExceptionUtil;
import com.ghy.common.utils.http.HttpUtils;
import com.ghy.common.utils.security.Md5Utils;
import com.ghy.web.pojo.vo.SmsRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 容联云短信
* @author clunt
*/
@Slf4j
@Controller
@RequestMapping("/tool/sms")
public class SMSController {
private static final ThreadLocal<SimpleDateFormat> timeFormat = ThreadLocal.withInitial(()->new SimpleDateFormat("yyyyMMddHHmmss"));
@Autowired
private SmsConfig smsConfig;
@PostMapping("/send")
@ResponseBody
public AjaxResult sendSms(@RequestBody SmsRequest request){
try {
// 短信验证码
String code = String.valueOf((int)((Math.random() * 9 + 1) * Math.pow(10,5)));
// 拼接请求题
List<String> dataList = new ArrayList<>();
dataList.add(code);
dataList.add("3");
request.setAppId(smsConfig.getAppId());
request.setTemplateId(SmsConstants.TEMPLATE_ID);
request.setDatas(dataList);
String url = (smsConfig.getUrl() + SmsConstants.TEMPLATE_PATH).replace("{accountSid}", smsConfig.getAccount());
String time = timeFormat.get().format(new Date());
String sigParameter = Md5Utils.hash(smsConfig.getAccount() + smsConfig.getToken() + time).toUpperCase();
String authorization = Base64.getEncoder().encodeToString((smsConfig.getAccount() + ":" + time).getBytes(StandardCharsets.UTF_8));
url = url.replace("{SigParameter}", sigParameter);
Map<String, String> headerMap = new HashMap<>();
headerMap.put("Content-Type", "application/json;charset=utf-8");
headerMap.put("Accept", "application/json;");
headerMap.put("Authorization", authorization);
// 调用第三方短信服务
String result = HttpUtils.sendPost(url, JSON.toJSONString(request), headerMap);
if("000000".equals(JSONObject.parseObject(result).getString("statusCode"))){
// 将短信验证码放进系统内存
CacheUtils.put(request.getTo(), code);
return AjaxResult.success("验证码发送成功!");
}else {
return AjaxResult.error(result);
}
}catch (Exception e){
e.printStackTrace();
log.error(ExceptionUtil.getExceptionMessage(e));
return AjaxResult.error(e.getMessage());
}
}
}

View File

@ -0,0 +1,21 @@
package com.ghy.web.pojo.vo;
import lombok.Data;
import java.util.List;
/**
* 容联短信请求体
* @author clunt
*/
@Data
public class SmsRequest {
private String to;
private String appId;
private String templateId;
private List<String> datas;
private String subAppend;
private String reqId;
}

View File

@ -59,7 +59,7 @@ spring:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
profiles:
active: dev
active: druid
# 文件上传
servlet:
multipart:
@ -122,11 +122,17 @@ adapay:
notifyUrl: 'https://www.opsoul.com/adapay/callback'
jim:
appKey: ''
masterSecret: ''
maxRetryTimes: ''
appKey: '110e8830290152d76e2f1d97'
masterSecret: 'ec49918a5d89526722b05924'
maxRetryTimes: '3'
# 百度地图应用api
baidu:
ak: 'ZQTgMW7W0GTuE7Ripb0HDp5TqRaOI6PZ'
url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=#AK#&output=json&coordtype=wgs84ll&location='
sms:
url: 'https://app.cloopen.com:8883'
account: '8a216da85f008800015f0eb223620557'
appId: '8a216da85f008800015f0eb224db055d'
token: '3cef1bc80d814637a236d93004e7ffa5'

View File

@ -65,6 +65,7 @@
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
modalName: "类目",
expandAll: false,
columns: [{
field: 'selectItem',
radio: true

View File

@ -0,0 +1,137 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改部门')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-dept-edit" th:object="${goodsCategory}">
<input name="goodsCategoryId" type="hidden" th:field="*{goodsCategoryId}" />
<input id="treeId" name="parentCategoryId" type="hidden" th:field="*{parentCategoryId}" />
<!-- <div class="form-group">-->
<!-- <label class="col-sm-3 control-label">上级部门:</label>-->
<!-- <div class="col-sm-8">-->
<!-- <div class="input-group">-->
<!-- <input class="form-control" type="text" id="treeName" onclick="selectDeptTree()" readonly="true" th:field="*{parentName}">-->
<!-- <span class="input-group-addon"><i class="fa fa-search"></i></span>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group">
<label class="col-sm-3 control-label is-required">上级类目:</label>
<div class="col-sm-8">
<div class="input-group">
<input class="form-control" type="text" onclick="selectDeptTree()" id="treeName" readonly="true" th:value="${goodsCategoryName}" required>
<span class="input-group-addon"><i class="fa fa-search"></i></span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label is-required">类别名称:</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="goodsCategoryName" th:field="*{goodsCategoryName}" id="goodsCategoryName" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label is-required">类别编码:</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="goodsCategoryCode" th:field="*{goodsCategoryCode}" id="goodsCategoryCode" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label is-required">显示排序:</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="categorySort" th:field="*{categorySort}" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">类目类别:</label>
<div class="col-sm-8">
<div class="radio-box" th:each="dict : ${@dict.getType('goods_category_type')}">
<input type="radio" th:id="${dict.dictCode}" name="type" th:value="${dict.dictValue}" th:checked="${dict.default}">
<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">类目状态:</label>
<div class="col-sm-8">
<div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
</div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
var prefix = ctx + "goods/category";
$("#form-dept-edit").validate({
onkeyup: false,
rules:{
deptName:{
remote: {
url: prefix + "/checkDeptNameUnique",
type: "post",
dataType: "json",
data: {
"parentCategoryId": function() {
return $("input[name='parentCategoryId']").val();
},
"goodsCategoryName" : function() {
return $.common.trim($("#goodsCategoryName").val());
}
},
dataFilter: function(data, type) {
return $.validate.unique(data);
}
}
},
categorySort:{
digits:true
}
},
messages: {
"goodsCategoryName": {
remote: "类目已经存在"
}
},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-dept-edit').serialize());
}
}
/*部门管理-修改-选择部门树*/
function selectDeptTree() {
var treeId = $("#treeId").val();
if ($.common.isEmpty(treeId)) {
$.modal.alertWarning("请先添加用户所属的类目!");
return;
}
var options = {
title: '类目选择',
width: "380",
url: prefix + "/selectGoodsCategoryTree/" + treeId,
callBack: doSubmit
};
$.modal.openOptions(options);
}
function doSubmit(index, layero){
var tree = layero.find("iframe")[0].contentWindow.$._tree;
if ($.tree.notAllowLastLevel(tree)) {
var body = $.modal.getChildFrame(index);
$("#treeId").val(body.find('#treeId').val());
$("#treeName").val(body.find('#treeName').val());
$.modal.close(index);
}
}
</script>
</body>
</html>

View File

@ -36,7 +36,8 @@
var options = {
url: url,
expandLevel: 2,
onClick : zOnClick
onClick : zOnClick,
expandAll: false
};
$.tree.init(options);
});

View File

@ -63,6 +63,7 @@
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
modalName: "类目",
expandAll: false,
columns: [{
field: 'selectItem',
radio: true

View File

@ -63,6 +63,7 @@
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
modalName: "类目",
expandAll: false,
columns: [{
field: 'selectItem',
radio: true

View File

@ -45,7 +45,7 @@
<h4 class="no-margins">登录:</h4>
<p class="m-t-md">你若不离不弃,我必生死相依</p>
<input type="text" name="username" class="form-control uname" placeholder="用户名" value="admin" />
<input type="password" name="password" class="form-control pword" placeholder="密码" value="admin123" />
<input type="password" name="password" class="form-control pword" placeholder="密码" />
<div class="row m-t" th:if="${captchaEnabled==true}">
<div class="col-xs-6">
<input type="text" name="validateCode" class="form-control code" placeholder="验证码" maxlength="5" />

View File

@ -0,0 +1,50 @@
package com.ghy.common.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 容联云短信配置
* @author clunt
*/
@Component
@ConfigurationProperties(prefix = "sms")
public class SmsConfig {
private String url;
private String account;
private String appId;
private String token;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}

View File

@ -0,0 +1,18 @@
package com.ghy.common.constant;
/**
* 容联云短信配置
* @author clunt
*/
public class SmsConstants {
// 短信验证码通知模版
public static final String TEMPLATE_ID = "216263";
// 短信模版发送地址
public static final String TEMPLATE_URL = "https://app.cloopen.com:8883";
// 短信模版发送路径
public static final String TEMPLATE_PATH = "/2013-12-26/Accounts/{accountSid}/SMS/TemplateSMS?sig={SigParameter}";
}

View File

@ -11,7 +11,8 @@ public enum FinancialDetailType {
WORKER_FEE(1, "大师傅/店铺提成金额"),
PLATFORM_FEE(2, "平台提成金额"),
PLACE_FEE(3, "分销金额,可能存在多级"),
RETURN_FEE(4, "退款金额");
RETURN_FEE(4, "退款金额"),
FINE_FEE(5, "超时罚金");
private final Integer code;
private final String desc;

View File

@ -6,6 +6,8 @@ import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
@ -120,6 +122,19 @@ public class HttpUtils
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, String param)
{
return sendPost(url, param, null);
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数请求参数应该是 name1=value1&name2=value2 的形式
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, String param, Map<String, String> header)
{
PrintWriter out = null;
BufferedReader in = null;
@ -135,6 +150,9 @@ public class HttpUtils
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
if(header != null){
header.forEach(conn::setRequestProperty);
}
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
@ -242,22 +260,27 @@ public class HttpUtils
return result;
}
public static String sendSSLPost(String url, String param)
{
public static String sendSSLPost(String url, String param){
return sendSSLPost(url, param, null);
}
public static String sendSSLPost(String url, String param, Map<String, String> header){
StringBuilder result = new StringBuilder();
String urlNameString = url + "?" + param;
try
{
log.info("sendSSLPost - {}", urlNameString);
log.info("sendSSLPost - {}", url);
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
URL console = new URL(urlNameString);
URL console = new URL(url);
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
if(header != null){
header.forEach(conn::setRequestProperty);
}
conn.setDoOutput(true);
conn.setDoInput(true);
@ -271,7 +294,7 @@ public class HttpUtils
{
if (ret != null && !ret.trim().equals(""))
{
result.append(new String(ret.getBytes("ISO-8859-1"), "utf-8"));
result.append(new String(ret.getBytes("utf-8"), "utf-8"));
}
}
log.info("recv - {}", result);

View File

@ -288,6 +288,7 @@ public class ShiroConfig
filterChainDefinitionMap.put("/adapay/**", "anon");
filterChainDefinitionMap.put("/system/area/**", "anon");
filterChainDefinitionMap.put("/customer/address/**", "anon");
filterChainDefinitionMap.put("/jim/**", "anon");
filterChainDefinitionMap.put("/MP_verify_bRFuvYpyQ4WLr0on.txt", "anon");
// 对静态资源设置匿名访问
filterChainDefinitionMap.put("/favicon.ico**", "anon");

View File

@ -74,7 +74,7 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService {
if (category == null) {
return false;
}
return category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId());
return !category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId());
}
@Override
@ -83,7 +83,7 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService {
if (category == null) {
return false;
}
return category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId());
return !category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId());
}
@Override

View File

@ -56,6 +56,7 @@
<if test="goodsCategoryCode != null and goodsCategoryCode != ''">goods_category_code = #{goodsCategoryCode},</if>
<if test="goodsCategoryName != null and goodsCategoryName != ''">goods_category_name = #{goodsCategoryName},</if>
<if test="parentCategoryId != null and parentCategoryId != ''">parent_category_id = #{parentCategoryId},</if>
<if test="categorySort != null and categorySort != ''">category_sort = #{categorySort},</if>
<if test="level != null and level != ''">level = #{level},</if>
<if test="type != null and type != ''">type = #{type},</if>
<if test="remark != null">remark = #{remark},</if>
@ -79,6 +80,7 @@
<if test="goodsCategoryCode != null and goodsCategoryCode != ''">goods_category_code,</if>
<if test="goodsCategoryName != null and goodsCategoryName != ''">goods_category_name,</if>
<if test="parentCategoryId != null and parentCategoryId != ''">parent_category_id,</if>
<if test="categorySort != null and categorySort != ''">category_sort,</if>
<if test="level != null and level != ''">level,</if>
<if test="type != null and type != ''">type,</if>
<if test="remark != null and remark != ''">remark,</if>
@ -89,6 +91,7 @@
<if test="goodsCategoryCode != null and goodsCategoryCode != ''">#{goodsCategoryCode},</if>
<if test="goodsCategoryName != null and goodsCategoryName != ''">#{goodsCategoryName},</if>
<if test="parentCategoryId != null and parentCategoryId != ''">#{parentCategoryId},</if>
<if test="categorySort != null and categorySort != ''">#{categorySort},</if>
<if test="level != null and level != ''">#{level},</if>
<if test="type != null and type != ''">#{type},</if>
<if test="remark != null and remark != ''">#{remark},</if>

View File

@ -10,9 +10,8 @@ import org.springframework.context.annotation.Configuration;
* @author clunt
* 极光消息配置文件
*/
//@Configuration
//@ConfigurationProperties(prefix = "jim")
@Data
@Configuration
@ConfigurationProperties(prefix = "jim")
public class JimConfig {
private String appKey;
@ -21,9 +20,33 @@ public class JimConfig {
private String maxRetryTimes;
@Bean
public JMessageClient jMessageClient(){
return new JMessageClient(appKey,masterSecret,maxRetryTimes);
public String getAppKey() {
return appKey;
}
public void setAppKey(String appKey) {
this.appKey = appKey;
}
public String getMasterSecret() {
return masterSecret;
}
public void setMasterSecret(String masterSecret) {
this.masterSecret = masterSecret;
}
public String getMaxRetryTimes() {
return maxRetryTimes;
}
public void setMaxRetryTimes(String maxRetryTimes) {
this.maxRetryTimes = maxRetryTimes;
}
// @Bean
// public JMessageClient jMessageClient(){
// return new JMessageClient(appKey,masterSecret,maxRetryTimes);
// }
}

View File

@ -0,0 +1,4 @@
package com.ghy.message.domain;
public class JimRegisterInfo {
}

View File

@ -10,6 +10,18 @@ import lombok.Data;
@Data
public class JimUser extends BaseEntity {
// 自增组件
private Long jimUserId;
// D101W7 系统编码
private String sysUser;
private String userName;
private String password;
private String appKey;
}

View File

@ -0,0 +1,14 @@
package com.ghy.message.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 极光推送用户mapper
* @author clunt
*/
@Mapper
public interface JimUserMapper {
}

View File

@ -0,0 +1,12 @@
package com.ghy.message.service;
import com.ghy.message.domain.JimUser;
public interface JimUserService {
/**
* 注册极光推送信息并入库记录
* */
int registerJimUser(JimUser jimUser) throws Exception;
}

View File

@ -0,0 +1,36 @@
package com.ghy.message.service.impl;
import cn.jmessage.api.JMessageClient;
import cn.jmessage.api.common.model.RegisterInfo;
import com.ghy.message.config.JimConfig;
import com.ghy.message.domain.JimUser;
import com.ghy.message.service.JimUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 极光推送用户impl
* @author clunt
*/
@Slf4j
@Service
public class JimUserServiceImpl implements JimUserService {
@Resource
private JimConfig jimConfig;
@Override
public int registerJimUser(JimUser jimUser) throws Exception{
JMessageClient messageClient = new JMessageClient(jimConfig.getAppKey(),jimConfig.getMasterSecret());
RegisterInfo.Builder builder = new RegisterInfo.Builder();
builder.setUsername(jimUser.getUserName());
builder.setPassword(jimUser.getPassword());
RegisterInfo [] registerInfos = new RegisterInfo[1];
registerInfos[0] = builder.build();
String result = messageClient.registerUsers(registerInfos);
return 0;
}
}

View File

@ -1,6 +1,7 @@
package com.ghy.order.mapper;
import com.ghy.order.domain.OrderDetail;
import com.ghy.order.domain.OrderMaster;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -79,4 +80,9 @@ public interface OrderDetailMapper {
* @param orderDetail 子订单
*/
int updateByOrderMasterId(OrderDetail orderDetail);
/**
* 查询指定状态的订单
*/
List<OrderDetail> selectByStatus(List<Integer> status);
}

View File

@ -72,4 +72,9 @@ public interface OrderMasterMapper {
* @return 0失败 1成功
*/
int updateStatus(@Param("orderMasterId") Long orderMasterId, @Param("orderStatus") int orderStatus);
/**
* 查询指定状态的订单
*/
List<OrderMaster> selectByStatus(List<Integer> status);
}

View File

@ -1,6 +1,7 @@
package com.ghy.order.service;
import com.ghy.order.domain.OrderDetail;
import com.ghy.order.domain.OrderMaster;
import java.util.List;
import java.util.Map;
@ -92,4 +93,9 @@ public interface OrderDetailService {
* @param orderDetail 子订单
*/
void updateByOrderMasterId(OrderDetail orderDetail);
/**
* 查询指定状态的订单
*/
List<OrderDetail> selectByStatus(List<Integer> status);
}

View File

@ -99,4 +99,9 @@ public interface OrderMasterService {
* @param agree 0=不同意 1=同意
*/
void cancelAgree(Long orderMasterId, Integer agree);
/**
* 查询指定状态的订单
*/
List<OrderMaster> selectByStatus(List<Integer> status);
}

View File

@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
@ -82,6 +83,7 @@ public class OrderDetailServiceImpl implements OrderDetailService {
for (OrderDetail detail : orderDetailMapper.selectByOrderMasterId(detailInfo.getOrderMasterId())) {
if (detail.getOrderStatus() < orderStatus) {
flag = false;
break;
}
}
if (flag) {
@ -262,4 +264,9 @@ public class OrderDetailServiceImpl implements OrderDetailService {
orderDetailMapper.updateByOrderMasterId(orderDetail);
}
@Override
public List<OrderDetail> selectByStatus(List<Integer> status) {
Assert.isTrue(!CollectionUtils.isEmpty(status), "订单状态为空");
return orderDetailMapper.selectByStatus(status);
}
}

View File

@ -30,6 +30,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
@ -164,7 +165,7 @@ public class OrderMasterServiceImpl implements OrderMasterService {
switch (financialDetail.getFinancialDetailType()) {
case 0:
// 上门师傅结单 要判断一下这个单是否已退款
if (financialDetail.getPayStatus().equals(PayStatus.REFUND.getCode())) {
if (financialDetail.getPayStatus() < 2) {
memberId = AdapayUtils.getWorkerMemberId(financialDetail.getPayeeId(), orderMaster.getDeptId());
memberMap.merge(memberId, financialDetail.getPayMoney(), BigDecimal::add);
}
@ -193,6 +194,10 @@ public class OrderMasterServiceImpl implements OrderMasterService {
case 4:
// 退款
confirmAmt = confirmAmt.subtract(financialDetail.getPayMoney());
case 5:
// 订单超时罚金 归平台所有
memberMap.merge("0", financialDetail.getPayMoney(), BigDecimal::add);
break;
default:
break;
}
@ -324,6 +329,12 @@ public class OrderMasterServiceImpl implements OrderMasterService {
}
}
@Override
public List<OrderMaster> selectByStatus(List<Integer> status) {
Assert.isTrue(!CollectionUtils.isEmpty(status), "订单状态为空");
return orderMasterMapper.selectByStatus(status);
}
/**
* 主订单发起退款
*

View File

@ -223,4 +223,12 @@
</where>
</select>
<select id="selectByStatus" resultType="com.ghy.order.domain.OrderDetail">
<include refid="selectOrderDetail"/>
WHERE `order_status` IN
<foreach collection="list" item="orderStatus" open="(" separator="," close=")">
#{orderStatus}
</foreach>
</select>
</mapper>

View File

@ -256,4 +256,12 @@
WHERE `code` = #{orderMasterCode}
</select>
<select id="selectByStatus" resultType="com.ghy.order.domain.OrderMaster">
<include refid="selectOrderMaster"/>
WHERE `order_status` IN
<foreach collection="list" item="orderStatus" open="(" separator="," close=")">
#{orderStatus}
</foreach>
</select>
</mapper>

View File

@ -3,6 +3,7 @@ package com.ghy.payment.domain;
import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.Date;
@ -12,6 +13,7 @@ import java.util.Date;
* 财务细单(可能是师傅分佣后的细单关联也可能是分佣账单平台提成账单等类型)
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class FinancialDetail extends BaseEntity {
private static final long serialVersionUID = 1L;
@ -46,14 +48,14 @@ public class FinancialDetail extends BaseEntity {
@Excel(name = "实付金额", cellType = Excel.ColumnType.STRING)
private BigDecimal payMoney;
@Excel(name = "财务子单类型,1师傅转派/2多级分销/3平台抽成/4撤销支付或退款", cellType = Excel.ColumnType.NUMERIC)
@Excel(name = "财务子单类型,1师傅转派/2多级分销/3平台抽成/4撤销支付或退款/5超时罚金", cellType = Excel.ColumnType.NUMERIC)
private Integer financialDetailType;
/**
* 收款人ID
* 当财务子单类型是师傅转派时 收款人ID是师傅或徒弟的workerId
* 当财务子单类型是多级分销时 收款人ID是分销者的customerId
* 当财务子单类型是平台抽成和退款 无需填写收款人ID
* 当财务子单类型是4或5 无需填写收款人ID
*/
@Excel(name = "收款人ID", cellType = Excel.ColumnType.NUMERIC)
private Long payeeId;

View File

@ -0,0 +1,33 @@
package com.ghy.payment.domain;
import lombok.Data;
import java.util.Date;
/**
* 订单扣款记录
*
* @author HH 2022/8/4
*/
@Data
public class OrderFineRecord {
private Long id;
private Long orderDetailId;
private Integer fineType;
private Integer orderStatus;
private Date createTime;
public OrderFineRecord() {
}
public OrderFineRecord(Long orderDetailId, Integer fineType, Integer orderStatus) {
this.orderDetailId = orderDetailId;
this.fineType = fineType;
this.orderStatus = orderStatus;
}
}

View File

@ -0,0 +1,15 @@
package com.ghy.payment.mapper;
import com.ghy.payment.domain.OrderFineRecord;
import java.util.List;
/**
* 订单扣款记录
*/
public interface OrderFineRecordMapper {
List<OrderFineRecord> selectList(OrderFineRecord orderFineRecord);
int insert(OrderFineRecord orderFineRecord);
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ghy.payment.mapper.OrderFineRecordMapper">
<resultMap id="OrderFineRecordResult" type="com.ghy.payment.domain.OrderFineRecord">
<id property="id" column="id"/>
<result property="orderDetailId" column="order_detail_id"/>
<result property="fineType" column="fine_type"/>
<result property="orderStatus" column="order_status"/>
<result property="createTime" column="create_time"/>
</resultMap>
<sql id="selectOrderFineRecord">
SELECT id, order_detail_id, fine_type, order_status, create_time
FROM order_fine_record
</sql>
<select id="selectList" parameterType="com.ghy.payment.domain.OrderFineRecord"
resultMap="OrderFineRecordResult">
<include refid="selectOrderFineRecord"/>
<where>
<if test="orderDetailId != null">
AND order_detail_id = #{orderDetailId}
</if>
<if test="orderStatus != null">
AND order_status = #{orderStatus}
</if>
</where>
</select>
<insert id="insert" parameterType="com.ghy.payment.domain.OrderFineRecord" useGeneratedKeys="true"
keyProperty="id">
INSERT INTO order_fine_record (order_detail_id, fine_type, order_status)
VALUES (#{orderDetailId}, #{fineType}, #{orderStatus})
</insert>
</mapper>

View File

@ -1,35 +1,144 @@
package com.ghy.quartz.service.impl;
import com.ghy.common.enums.FinancialDetailType;
import com.ghy.common.enums.OrderStatus;
import com.ghy.order.domain.OrderDetail;
import com.ghy.order.domain.OrderMaster;
import com.ghy.order.service.OrderDetailService;
import com.ghy.order.service.OrderMasterService;
import com.ghy.payment.service.FinancialMasterService;
import com.ghy.payment.domain.FinancialDetail;
import com.ghy.payment.domain.OrderFineRecord;
import com.ghy.payment.mapper.OrderFineRecordMapper;
import com.ghy.payment.service.FinancialDetailService;
import com.ghy.quartz.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private OrderMasterService orderMasterService;
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
/**
* 一小时的毫秒数
*/
private static final long HOUR_TIME_MILLIS = 60 * 60 * 1000L;
/**
* 超时罚金2元
*/
private static final BigDecimal TIMEOUT_MONEY = BigDecimal.valueOf(2);
@Autowired
private FinancialMasterService financialMasterService;
/**
* 需要超时扣款的订单状态
*/
@Value("${order.timeout.status:-4,-3,-2,1,2,3}")
private List<Integer> timeoutOrderStatus;
@Resource
private ThreadPoolTaskExecutor executor;
@Resource
private OrderMasterService orderMasterService;
@Resource
private OrderDetailService orderDetailService;
@Resource
private OrderFineRecordMapper orderFineRecordMapper;
@Resource
private FinancialDetailService financialDetailService;
@Override
public void overTimeOrder(String orderStatus) {
// 查询符合超时的单
LocalDateTime now = LocalDateTime.now();
int nowDay = now.getDayOfMonth();
int nowHour = now.getHour();
if (nowHour > 17 || nowHour < 9) {
// 如果处于休息时间 定时任务不执行
return;
}
// 更新对应单的状态
// 查询符合超时的单
List<OrderDetail> orders = orderDetailService.selectByStatus(timeoutOrderStatus);
for (OrderDetail order : orders) {
Date updateTime = order.getUpdateTime();
Calendar instance = Calendar.getInstance();
instance.setTime(updateTime);
if (instance.get(Calendar.DAY_OF_MONTH) == nowDay) {
// 如果订单更新的时间是今天
if (System.currentTimeMillis() - updateTime.getTime() > HOUR_TIME_MILLIS * 4) {
// 并且距离上一次更新时间已经超过4h 则判定超时
executor.execute(() -> orderTimeout(order));
}
} else {
// 如果订单更新的时间不是今天
if (System.currentTimeMillis() - updateTime.getTime() > HOUR_TIME_MILLIS * 19) {
// 并且距离上一次更新时间已经超过15h 则判定超时
executor.execute(() -> orderTimeout(order));
}
}
}
}
@Transactional(rollbackFor = Exception.class)
public void orderTimeout(OrderDetail order) {
// 查询扣款记录 如果已经扣过了 就不处理了
OrderFineRecord orderFineRecord = new OrderFineRecord(order.getId(), 1, order.getOrderStatus());
List<OrderFineRecord> records = orderFineRecordMapper.selectList(orderFineRecord);
if (!CollectionUtils.isEmpty(records)) {
return;
}
// 保存一条扣款记录
orderFineRecordMapper.insert(orderFineRecord);
// 从子订单对应的财务单里扣除2元
FinancialDetail orderFinancial = financialDetailService.selectByOrderDetailId(order.getId());
orderFinancial.setPayMoney(orderFinancial.getPayMoney().subtract(TIMEOUT_MONEY));
financialDetailService.updateFinancialDetail(orderFinancial);
// 生成对应的扣款明细
FinancialDetail fineFinancial = new FinancialDetail();
fineFinancial.setDeptId(orderFinancial.getDeptId());
fineFinancial.setCode(financialDetailService.createCode());
fineFinancial.setFinancialMasterId(orderFinancial.getFinancialMasterId());
fineFinancial.setFinancialMasterCode(orderFinancial.getFinancialMasterCode());
fineFinancial.setPayMoney(TIMEOUT_MONEY);
fineFinancial.setFinancialDetailType(FinancialDetailType.FINE_FEE.getCode());
financialDetailService.insertFinancialDetail(fineFinancial);
}
@Override
public void finishOrder() {
OrderMaster orderMaster = new OrderMaster();
orderMaster.setOrderStatus(OrderStatus.FINISH_CHECK.code());
List<OrderMaster> orders = orderMasterService.selectOrderMasterList(orderMaster);
long now = System.currentTimeMillis();
long day14ago = now - (14 * 24 * 60 * 60 * 1000L);
for (OrderMaster order : orders) {
// 查询符合自动确认的订单
// 更新符合自动确认订单的状态
// 调用分账动作
if (day14ago > order.getUpdateTime().getTime()) {
logger.info("订单自动完成[id={}, code={}]", order.getId(), order.getCode());
try {
// 完单流程(分账与提现)
orderMasterService.finish(order.getId());
// 修改订单状态
orderMasterService.updateStatus(order.getId(), OrderStatus.FINISH.code());
} catch (BaseAdaPayException e) {
logger.error("订单自动完成[id={}, code={}]出错", order.getId(), order.getCode(), e);
}
}
}
}
}

12
pom.xml
View File

@ -313,11 +313,11 @@
</dependency>
<!-- 聊天工具-->
<!-- <dependency>-->
<!-- <groupId>com.ghy</groupId>-->
<!-- <artifactId>ghy-message</artifactId>-->
<!-- <version>${ghy.version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.ghy</groupId>
<artifactId>ghy-message</artifactId>
<version>${ghy.version}</version>
</dependency>
<!-- 通用工具-->
<dependency>
@ -347,7 +347,7 @@
<module>ghy-common</module>
<module>ghy-custom</module>
<module>ghy-worker</module>
<!-- <module>ghy-message</module>-->
<module>ghy-message</module>
</modules>
<packaging>pom</packaging>