Commit 03ea93ae authored by shangtx's avatar shangtx

Merge branch 'dev'

parents c855ab08 6ff6b06f
......@@ -35,7 +35,6 @@ import static com.onsiteservice.core.result.ResultGenerator.success;
* @date 2022-07-14 15:11
* @description ServiceOrderController控制类
*/
@ApiIgnore
@Api(tags = "ServiceOrderController")
@RestController
@RequestMapping("/order")
......
......@@ -4,6 +4,7 @@ import com.onsiteservice.common.order.vo.ServiceOrderLogVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
......@@ -34,6 +35,11 @@ public class OrderDetailVO {
@ApiModelProperty(value = "服务数量")
private Integer num;
@ApiModelProperty("订单总价")
private BigDecimal totalPrice;
private BigDecimal price;
@ApiModelProperty(value = "子类服务图片,待受理标题图片url地址")
private String subclassImg;
......
......@@ -49,4 +49,7 @@ public class OrderPageVO {
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("订单总价")
private BigDecimal totalPrice;
}
......@@ -25,7 +25,7 @@ public class OrderListener {
private SocketHandler socketHandler;
private static final String USER_ID = "id";
// 1 用户已付款
// 1 已付款,未派单 2 已付款,已派单
private static final String TYPE = "type";
@RabbitHandler
......
......@@ -3,3 +3,20 @@ spring:
profiles:
include:
- common-dev
logging:
level:
com.onsiteservice.admin.mapper: debug
org.springframework.boot.autoconfigure.security: warn
org.springframework.security.*: warn
com.ulisesbocchio.jasyptspringboot: warn
springfox.documentation.*: error
# 排除启动时Mapper扫描映射的警告 运行无影响
org.mybatis.spring.mapper.*: warn
tk.mybatis.spring.mapper.*: warn
# com.zaxxer.hikari.HikariConfig: error
org.apache.zookeeper.*: warn
root: info
com.onsiteservice.dao.mapper: debug
com.onsiteservice.common.business.pay: info
\ No newline at end of file
......@@ -15,6 +15,8 @@
t.order_status,
t.price,
t.create_time,
t.total_price,
t.price,
ifnull(t2.user_name, t2.nick_name) user_name
from service_order t
join user t2 on t.account_no = t2.id
......
......@@ -16,7 +16,10 @@ import com.onsiteservice.constant.enums.ServiceUserTypeEnum;
import com.onsiteservice.core.exception.ServiceException;
import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.component.RecordComponent;
import com.onsiteservice.dao.mapper.service.*;
import com.onsiteservice.dao.mapper.service.ServiceOrderMapper;
import com.onsiteservice.dao.mapper.service.ServiceValuatorAssignMapper;
import com.onsiteservice.dao.mapper.service.ServiceWorkerAssignMapper;
import com.onsiteservice.dao.mapper.service.ServiceWorkerMapper;
import com.onsiteservice.dao.mapper.sys.SysParamMapper;
import com.onsiteservice.dao.mapper.sys.SysUserMapper;
import com.onsiteservice.dao.mapper.user.UserMapper;
......@@ -27,17 +30,14 @@ import com.onsiteservice.entity.service.ServiceWorkerAssign;
import com.onsiteservice.entity.sys.SysParam;
import com.onsiteservice.entity.sys.SysUser;
import com.onsiteservice.entity.user.User;
import com.onsiteservice.util.aliyun.SmsUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;
......@@ -147,7 +147,11 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
// 判断能发送的状态: 估价后可以发送,预约后可以发送
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.VALUATION.getStatus()) && !serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.RESERVE.getStatus())) {
// 首次发送 或者 第一次的发送已经支付完成并且没有结束订单
boolean canSendOrder = serviceOrder.getOrderStatus() < ServiceOrderStatusEnum.SEND.getStatus()
|| (serviceOrder.getOrderStatus() >= ServiceOrderStatusEnum.PAY.getStatus() && (serviceOrder.getOrderStatus() < ServiceOrderStatusEnum.FINISH.getStatus()));
if (!canSendOrder) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_SEND);
}
......@@ -192,7 +196,7 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_DISPATCH_ORDER, sourceEnum, Sets.newHashSet(ServiceUserTypeEnum.ADMIN));
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.PAY.getStatus())) {
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.PAY.getStatus()) || serviceOrder.getSkipWork()) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_DISPATCH);
}
......@@ -208,6 +212,7 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
Condition c = buildOrderStatusCondition(serviceOrder);
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.DISPATCH.getStatus());
serviceOrder.setModifyBy(userId);
serviceOrder.setSkipWork(true);
int result = serviceOrderMapper.updateByConditionSelective(serviceOrder, c);
commonSmsService.dispatched(serviceOrder.getPhone(), user.getPhone(), serviceOrder.getServiceName());
......@@ -265,7 +270,8 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
log.info("finishOrder dto: {}, userId: {}", dto, userId);
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.DISPATCH.getStatus())) {
// if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.DISPATCH.getStatus())) {
if (!serviceOrder.getSkipWork()) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_FINISH);
}
......
......@@ -14,6 +14,6 @@ import java.io.Serializable;
public class PayNoticeVO implements Serializable {
// 用户id
private String id;
// 类型 1 支付成功
// 类型 1 支付成功,未派单 2 已派单,支付成功
private String type;
}
......@@ -19,6 +19,7 @@ public class BizConstants {
public static class OrderConstants {
public static final String ORDER_ID = "orderId";
public static final String ORDER_STATUS = "orderStatus";
public static final String DUP_ORDER_STATUS = "dupOrderStatus";
public static final long TIMEOUT_CANCEL_LIMIT = 1000 * 60 * 30;
/**
......
......@@ -24,7 +24,8 @@ public enum BizCodeEnum {
SERVICE_ORDER_NOT_EXIST("订单不存在"),
SERVICE_ORDER_CANNOT_VALUATION("订单不能派估价员"),
SERVICE_ORDER_CANNOT_REVALUATION("订单未估价,不能修改"),
SERVICE_ORDER_CANNOT_SEND("订单未受理,不能发送或已发送"),
SERVICE_ORDER_CANNOT_SEND("不能发送或已发送"),
SERVICE_ORDER_CANNOT_RESEND("订单不能重新发送"),
SERVICE_ORDER_CANNOT_PAY("订单未受理,暂不能支付"),
SERVICE_ORDER_CANNOT_CANCEL("订单不能取消"),
SERVICE_ORDER_CANNOT_REFUND("订单不能申请退款"),
......
......@@ -27,11 +27,12 @@ public enum ServiceOrderStatusEnum {
* 已发送
*/
SEND(3, "%s 已发送订单信息"),
RESEND(3, "%s 已重新发送订单信息"),
/**
* 已支付
*/
PAY(4, "用户已付款"),
PAY(4, "用户已付款 %s 元"),
/**
* 已派单
......
......@@ -99,19 +99,31 @@ public class ServiceOrder implements Serializable {
private Boolean readAgreement;
/**
* 订单状态:1已预约,2已派单,3进行中,4完成,5取消,6已评价
* 订单状态:1用户下单,2派估价员或修改估价员,3发送订单,4支付,5派维修工或修改维修工,6完成订单,7取消订单
*/
@Column(name = "order_status")
@ApiModelProperty("订单状态:1已预约,2已派单,3进行中,4完成,5取消,6已评价")
@ApiModelProperty("订单状态:1用户下单,2派估价员或修改估价员,3发送订单,4支付,5派维修工或修改维修工,6完成订单,7取消订单")
private Integer orderStatus;
/**
* 价格
* 重新发送后的订单状态:3发送订单,4支付,5派维修工或修改维修工
*/
@Column(name = "skip_work")
@ApiModelProperty("跳过维修工,派过维修工后,该字段永久为为true")
private Boolean skipWork;
@Column(name = "total_price")
@ApiModelProperty("订单总价格,以元为单位")
private BigDecimal totalPrice;
@Column(name = "price")
@ApiModelProperty("订单价格")
@ApiModelProperty("当前发送订单操作的价格,以元为单位")
private BigDecimal price;
@Column(name = "pay_num")
@ApiModelProperty("支付次数")
private Integer payNum;
/**
* 服务订单备注字段
*/
......
......@@ -29,7 +29,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Positive;
import java.util.Map;
import static com.onsiteservice.core.result.ResultGenerator.fail;
......@@ -109,7 +108,7 @@ public class ServiceOrderController {
@ApiOperation(value = "发送订单")
@ApiIdempotent(interval = 3000L)
@PostMapping("send")
public Result valuation(@RequestBody @NonNull @Validated SendServiceOrderDTO dto, @CurrentUserId Long userId) {
public Result send(@RequestBody @NonNull @Validated SendServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.sendOrder(dto, userId, ServiceOrderOpSourceEnum.MINI_APP) == 1 ? success() : fail("发送失败");
}
......
......@@ -38,6 +38,7 @@ import com.onsiteservice.miniapp.controller.order.vo.ServiceOrderDefDetailVO;
import com.onsiteservice.miniapp.mapper.order.ServiceOrderBizMapper;
import com.onsiteservice.miniapp.service.weixin.pay.WechatNativePay;
import com.onsiteservice.service.order.ServiceOrderService;
import com.onsiteservice.service.order.dto.PayNoticeVO;
import com.onsiteservice.util.AttrCopyUtils;
import com.onsiteservice.util.RandomUtils;
import lombok.extern.slf4j.Slf4j;
......@@ -52,6 +53,7 @@ import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -217,7 +219,6 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
int result = this.insertSelective(serviceOrder);
recordComponent.recordServiceOrderImg(serviceOrder, dto.getUrls());
// 记录流程
if (result == 1) {
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.RESERVE.getStatus(), ServiceOrderStatusEnum.RESERVE.getMsg(), sourceEnum, null, null, null);
......@@ -228,33 +229,38 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
public void paySuccess(String orderNo, String info) {
log.info("支付成功 orderNo: {}, info: {}", orderNo, info);
var no = orderNo.split("-")[0];
var order = selectOneByProperty("orderNo", no);
var order = selectOneByProperty("orderNo", orderNo);
order.setOrderStatus(ServiceOrderStatusEnum.PAY.getStatus());
order.setOrderStatus(order.getSkipWork() ? ServiceOrderStatusEnum.DISPATCH.getStatus() : ServiceOrderStatusEnum.PAY.getStatus());
order.setTotalPrice(order.getTotalPrice() == null? order.getPrice(): order.getTotalPrice().add(order.getPrice()));
order.setPayNum(order.getPayNum() + 1);
int result = serviceOrderMapper.updateByPrimaryKeySelective(order);
// 通知客服
var logCondition = new ServiceOrderLog();
logCondition.setOrderId(order.getId());
logCondition.setProcessId(ServiceOrderStatusEnum.SEND.getStatus());
var orderLog = serviceOrderLogMapper.selectOne(logCondition);
if (orderLog != null) {
var logCondition = new Condition(ServiceOrderLog.class);
logCondition.createCriteria().andEqualTo("orderId", order.getId())
.andEqualTo("processId", ServiceOrderStatusEnum.SEND.getStatus());
logCondition.setOrderByClause("create_time desc limit 1");
var orderLogs = serviceOrderLogMapper.selectByCondition(logCondition);
if (!orderLogs.isEmpty()) {
var orderLog = orderLogs.get(0);
if (ServiceOrderOpSourceEnum.WEB.getId().equals(orderLog.getSource())) {
var sysUser = sysUserMapper.selectByPrimaryKey(orderLog.getHostId());
if (StringUtils.isNotEmpty(sysUser.getPhone())) {
try {
if (order.getPayNum() == 1) { // 首次支付才发短信
commonSmsService.paid(sysUser.getPhone());
amqpTemplate.convertAndSend(SysConstants.Queue.ADMIN_ORDER, Pair.of(sysUser.getId(), 1));
}
amqpTemplate.convertAndSend(SysConstants.Queue.ADMIN_ORDER, PayNoticeVO.builder().id(sysUser.getId().toString()).type(order.getSkipWork() ? "2" : "1").build());
} catch (Exception e) {
e.printStackTrace();
log.error("订单{} 支付成功短信发送失败", orderNo);
}
}
}
if (ServiceOrderOpSourceEnum.MINI_APP.getId().equals(orderLog.getSource())) {
if (ServiceOrderOpSourceEnum.MINI_APP.getId().equals(orderLog.getSource()) && order.getPayNum() == 1) {
var user = userMapper.selectByPrimaryKey(orderLog.getHostId());
try {
commonSmsService.paid(user.getPhone());
......@@ -265,7 +271,8 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
}
}
if (result == 1) {
recordComponent.recordProcess(order.getId(), ServiceOrderStatusEnum.PAY.getStatus(), ServiceOrderStatusEnum.PAY.getMsg(), ServiceOrderOpSourceEnum.MINI_APP, null, null, null);
var payMsg = String.format(ServiceOrderStatusEnum.PAY.getMsg(), order.getPrice());
recordComponent.recordProcess(order.getId(), ServiceOrderStatusEnum.PAY.getStatus(), payMsg, ServiceOrderOpSourceEnum.MINI_APP, null, null, null);
}
}
......@@ -316,7 +323,8 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
var user = userMapper.selectByPrimaryKey(userId);
try {
var params = wechatNativePay.getPayParam("服务预约", order.getOrderNo(), order.getPrice(), notifyUrl,
String orderNo = order.getOrderNo() + "-" + order.getPayNum();
var params = wechatNativePay.getPayParam("服务预约", orderNo, order.getPrice(), notifyUrl,
user.getOpenId(), request);
return new OrderPayVO(params);
} catch (Exception e) {
......@@ -425,12 +433,13 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
/**
* 获取各个状态(前端状态)下的待办数量
*
* @param userId
* @return
*/
public Map<Integer, Integer> getTodoNum(Long userId) {
User user = userMapper.selectByPrimaryKey(userId);
if(!ServiceUserTypeEnum.ADMIN.getId().equals(user.getRoleType())) {
if (!ServiceUserTypeEnum.ADMIN.getId().equals(user.getRoleType())) {
return Map.of(1, 0, 3, 0, 4, 0, 5, 0, 6, 0);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment