Commit f93860bd authored by lining's avatar lining

feat: 修改指派维修工,修改估价员接口

parent b01050ff
......@@ -7,13 +7,12 @@ import com.onsiteservice.admin.controller.service.dto.UpdateServiceValuatorDTO;
import com.onsiteservice.admin.controller.service.vo.ServiceValuatorVO;
import com.onsiteservice.admin.mapper.service.ServiceValuatorBizMapper;
import com.onsiteservice.constant.enums.BizCodeEnum;
import com.onsiteservice.constant.enums.ServiceUserTypeEnum;
import com.onsiteservice.core.exception.ServiceException;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.core.result.ResultGenerator;
import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.onsiteservice.dao.common.page.PageParams;
import com.onsiteservice.dao.mapper.service.ServiceValuatorMapper;
import com.onsiteservice.dao.mapper.user.UserMapper;
import com.onsiteservice.entity.service.ServiceValuator;
import com.onsiteservice.entity.service.ServiceWorker;
......@@ -109,7 +108,7 @@ public class ServiceValuatorService extends AbstractMapper<ServiceValuator> {
private void checkAuth(Long userId) {
User user = userMapper.selectByPrimaryKey(userId);
if (Objects.isNull(user) || !user.getAdmin()) {
if (Objects.isNull(user) || !user.getRoleType().equals(ServiceUserTypeEnum.ADMIN.getId())) {
throw new ServiceException(BizCodeEnum.NO_AUTH);
}
}
......
......@@ -8,6 +8,7 @@ import com.onsiteservice.admin.controller.service.vo.ServiceWorkerKindVO;
import com.onsiteservice.admin.controller.service.vo.ServiceWorkerVO;
import com.onsiteservice.admin.mapper.service.ServiceWorkerBizMapper;
import com.onsiteservice.constant.enums.BizCodeEnum;
import com.onsiteservice.constant.enums.ServiceUserTypeEnum;
import com.onsiteservice.constant.enums.ServiceWorkerEnum;
import com.onsiteservice.core.exception.ServiceException;
import com.onsiteservice.core.result.Result;
......@@ -16,7 +17,6 @@ import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.onsiteservice.dao.mapper.service.ServiceWorkerMapper;
import com.onsiteservice.dao.mapper.user.UserMapper;
import com.onsiteservice.entity.order.ServiceOrder;
import com.onsiteservice.entity.service.ServiceWorker;
import com.onsiteservice.entity.user.User;
import com.onsiteservice.util.AttrCopyUtils;
......@@ -111,7 +111,7 @@ public class ServiceWorkerService extends AbstractMapper<ServiceWorker> {
private void checkAuth(Long userId) {
User user = userMapper.selectByPrimaryKey(userId);
if (Objects.isNull(user) || !user.getAdmin()) {
if (Objects.isNull(user) || !user.getRoleType().equals(ServiceUserTypeEnum.ADMIN.getId())) {
throw new ServiceException(BizCodeEnum.NO_AUTH);
}
}
......
......@@ -9,4 +9,9 @@ public class BizConstants {
public static final String ACCOUNT_NO = "accountNo";
}
public static class OrderConstants {
public static final String ORDER_ID = "orderId";
}
}
......@@ -15,20 +15,25 @@ public enum BizCodeEnum {
* 订单分组
*/
SERVICE_ORDER_NOT_EXIST("订单不存在"),
SERVICE_ORDER_CANNOT_VALUATION("订单未提交,不能估价"),
SERVICE_ORDER_CANNOT_SEND("订单未估价,不能发送给客户"),
SERVICE_ORDER_CANNOT_VALUATION("订单未提交,不能派估价员"),
SERVICE_ORDER_CANNOT_REVALUATION("订单未指派估价员,不能修改"),
SERVICE_ORDER_CANNOT_SEND("订单未受理,不能发送给客户"),
SERVICE_ORDER_CANNOT_PAY("订单未受理,暂不能支付"),
SERVICE_ORDER_CANNOT_CANCEL("订单不能取消"),
SERVICE_ORDER_CANNOT_REFUND("订单不能申请退款"),
SERVICE_ORDER_CANNOT_DISPATCH("订单未支付,不能派单"),
SERVICE_ORDER_CANNOT_DISPATCH("订单未支付,不能派维修工"),
SERVICE_ORDER_CANNOT_REDISPATCH("订单未指派维修工,不能修改"),
SERVICE_ORDER_CANNOT_FINISH("订单未派单,不能完成本次服务"),
/**
* 权限相关
*/
NO_AUTH_VALUATION_ORDER("您不能指派估价员"),
NO_AUTH_SEND_ORDER("您不能发送订单"),
NO_AUTH_DISPATCH_ORDER("您不能派单"),
NO_AUTH_VALUATION_ORDER("没有权限指派估价员"),
NO_AUTH_REVALUATION_ORDER("没有权限修改估价员"),
NO_AUTH_SEND_ORDER("没有权限发送订单"),
NO_AUTH_DISPATCH_ORDER("没有权限派单"),
NO_AUTH_REDISPATCH_ORDER("没有权限修改派单"),
NO_AUTH_FINISH_ORDER("没有权限完成服务"),
NO_AUTH("无操作权限"),
/**
......
......@@ -15,37 +15,39 @@ public enum ServiceOrderStatusEnum {
/**
* 已提交
*/
SUBMIT(1, "用户已下单"),
RESERVE(1, "用户已下单"),
/**
* 已受理:估价+发送客户
*/
VALUATION(2, "已指派估价员"),
VALUATION(2, "客服: %s 已派估价员 %s"),
REVALUATION(2, "客服: %s 已重新派估价员 %s"),
/**
* 已发送
*/
SEND(3, "已发送"),
SEND(3, "%s: %s 已发送订单信息"),
/**
* 已支付
*/
PAY(4, "已支付"),
PAY(4, "用户已付款"),
/**
* 已派单
*/
DISPATCH(5, "已派单"),
DISPATCH(5, "客服: %s 已派维修工 %s"),
REDISPATCH(5, "客服: %s 已重新派维修工 %s"),
/**
* 已确认
*/
FINISH(6, "已完成"),
FINISH(6, "%s 已确认完成服务"),
/**
*
* 取消订单
*/
CANCEL(7, "已取消"),
CANCEL(7, "用户已取消订单"),
/**
* 退款状态
......
package com.onsiteservice.constant.enums;
import lombok.Getter;
/**
* <P>用户角色枚举类</P>
*
* @author 李宁
* @version v1.0
* @since 2022/7/11 16:08
*/
public enum ServiceUserTypeEnum {
VALUATOR(2, "估价员: "),
ADMIN(1, "客服: "),
USER(0, "用户");
@Getter
private Integer id;
@Getter
private String name;
private ServiceUserTypeEnum(Integer id, String name) {
this.id = id;
this.name = name;
}
}
......@@ -31,7 +31,7 @@ public class ServiceOrderLog implements Serializable {
private Long orderId;
/**
* 流程id
* 流程id <link>ServiceOrderStatusEnum</link>
*/
@Column(name = "process_id")
@ApiModelProperty("流程id")
......@@ -42,7 +42,7 @@ public class ServiceOrderLog implements Serializable {
*/
@Column(name = "host_id")
@ApiModelProperty("维修工id或估价员id")
private Integer hostId;
private Long hostId;
/**
* 步骤说明
......@@ -63,12 +63,5 @@ public class ServiceOrderLog implements Serializable {
@ApiModelProperty("创建时间")
private Date createTime;
/**
* 创建人
*/
@Column(name = "create_by")
@ApiModelProperty("创建人")
private String createBy;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import javax.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import tk.mybatis.mapper.annotation.LogicDelete;
@Getter
@Setter
......@@ -55,5 +56,17 @@ public class ServiceValuatorAssign implements Serializable {
@ApiModelProperty("修改时间")
private Date modifyTime;
@Column(name = "create_by")
@ApiModelProperty("创建人")
private String createBy;
@Column(name = "modify_by")
@ApiModelProperty("修改人")
private String modifyBy;
@ApiModelProperty("删除标记")
@LogicDelete
private Boolean deleted;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import javax.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import tk.mybatis.mapper.annotation.LogicDelete;
@Getter
@Setter
......@@ -55,5 +56,17 @@ public class ServiceWorkerAssign implements Serializable {
@ApiModelProperty("修改时间")
private Date modifyTime;
@Column(name = "create_by")
@ApiModelProperty("创建人")
private String createBy;
@Column(name = "modify_by")
@ApiModelProperty("修改人")
private String modifyBy;
@ApiModelProperty("删除标记")
@LogicDelete
private Byte deleted;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
......@@ -102,9 +102,9 @@ public class User implements Serializable {
@ApiModelProperty("即时通讯id")
private String imUserId;
@Column(name = "admin")
@Column(name = "role_type")
@ApiModelProperty("管理员")
private Boolean admin;
private Integer roleType;
/**
* 是否启用 0: 禁用 1: 启用
......
......@@ -61,6 +61,12 @@ public class ServiceOrderController {
return serviceOrderService.valuation(dto, userId) == 1 ? success() : fail("估价失败");
}
@ApiOperation(value = "修改估价")
@PostMapping("revaluation")
public Result revaluation(@RequestBody @NonNull @Validated ValuationServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.revaluation(dto, userId) == 1 ? success() : fail("修改估价失败");
}
/**
* 发送订单 已估价订单才能发送 <link>ServiceOrderStatusEnum</link>
*/
......@@ -82,6 +88,12 @@ public class ServiceOrderController {
return serviceOrderService.dispatch(dto, userId) == 1 ? success() : fail("派单失败");
}
@ApiOperation(value = "修改派单")
@PostMapping("redispatch")
public Result redispatch(@RequestBody @NonNull @Validated DispatchServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.redispatch(dto, userId) == 1 ? success() : fail("修改派单失败");
}
/**
* 未派单之前不能完成,已申请退款的也可以点击完成
*/
......@@ -94,11 +106,11 @@ public class ServiceOrderController {
/**
* 订单退款 订单已付款,未派单之前可以取消 <link>ServiceOrderStatusEnum</link>
*/
@ApiOperation(value = "订单退款")
@PostMapping("refund")
public Result refund(@RequestBody @NonNull @Validated RefundServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.refundOrder(dto, userId) == 1 ? success() : fail("退款失败");
}
// @ApiOperation(value = "订单退款")
// @PostMapping("refund")
// public Result refund(@RequestBody @NonNull @Validated RefundServiceOrderDTO dto, @CurrentUserId Long userId) {
// return serviceOrderService.refundOrder(dto, userId) == 1 ? success() : fail("退款失败");
// }
/**
* 取消订单: 未支付之前可取消订单 <link>ServiceOrderStatusEnum</link>
......
......@@ -7,6 +7,7 @@ import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
/**
* <P></P>
......@@ -16,16 +17,22 @@ import java.math.BigDecimal;
* @since 2022/7/7 15:20
*/
@Data
@ApiModel("发送订单请求模型")
@ApiModel("单请求模型")
public class DispatchServiceOrderDTO {
@ApiModelProperty(value = "订单id", required = true)
@NotNull(message = "请选择订单")
private Long id;
@ApiModelProperty(value = "订单价格,维修价格不能低于1元", required = true)
@Min(value = 1, message = "维修价格不能低于1元")
@NotNull(message = "请输入维修价格")
private BigDecimal price;
@ApiModelProperty(value = "维修工id", required = true)
@NotNull(message = "请选择维修工")
private Long hostId;
@ApiModelProperty(value = "派单备注")
private String remark;
@ApiModelProperty(value = "期望维修工上门时间", required = true)
@NotNull(message = "请选择上门时间")
private Date expectArrivalTime;
}
......@@ -9,6 +9,7 @@ import org.checkerframework.checker.units.qual.A;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
/**
* <P></P>
......@@ -25,4 +26,15 @@ public class ValuationServiceOrderDTO {
@NotNull(message = "请输入订单ID")
private Long id;
@ApiModelProperty(value = "估价员id", required = true)
@NotNull(message = "请选择估价员")
private Long hostId;
@ApiModelProperty(value = "估价备注")
private String remark;
@ApiModelProperty(value = "期望估价员上门时间", required = true)
@NotNull(message = "请选择上门时间")
private Date expectArrivalTime;
}
......@@ -4,29 +4,29 @@ import com.github.pagehelper.PageHelper;
import com.onsiteservice.constant.constant.BizConstants;
import com.onsiteservice.constant.enums.BizCodeEnum;
import com.onsiteservice.constant.enums.ServiceOrderStatusEnum;
import com.onsiteservice.constant.enums.ServiceUserTypeEnum;
import com.onsiteservice.core.exception.ServiceException;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.core.result.ResultGenerator;
import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.onsiteservice.dao.mapper.service.ServiceAddressMapper;
import com.onsiteservice.dao.mapper.service.ServiceOrderMapper;
import com.onsiteservice.dao.mapper.service.ServiceSubclassMapper;
import com.onsiteservice.dao.mapper.service.*;
import com.onsiteservice.dao.mapper.user.UserMapper;
import com.onsiteservice.entity.address.ServiceAddress;
import com.onsiteservice.entity.category.ServiceSubclass;
import com.onsiteservice.entity.order.ServiceOrder;
import com.onsiteservice.entity.service.*;
import com.onsiteservice.entity.user.User;
import com.onsiteservice.miniapp.controller.order.dto.*;
import com.onsiteservice.miniapp.controller.order.vo.ServiceOrderVO;
import com.onsiteservice.miniapp.mapper.order.ServiceOrderBizMapper;
import com.onsiteservice.miniapp.service.address.ServiceAddressService;
import com.onsiteservice.util.AttrCopyUtils;
import com.onsiteservice.util.RandomUtils;
import com.onsiteservice.util.aliyun.SmsUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
......@@ -63,6 +63,19 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
@Resource
private ServiceSubclassMapper serviceSubclassMapper;
@Resource
private ServiceOrderLogMapper serviceOrderLogMapper;
@Resource
private ServiceWorkerMapper serviceWorkerMapper;
@Resource
private ServiceWorkerAssignMapper serviceWorkerAssignMapper;
@Resource
private ServiceValuatorMapper serviceValuatorMapper;
@Resource
private ServiceValuatorAssignMapper serviceValuatorAssignMapper;
@Resource
private UserMapper userMapper;
......@@ -123,7 +136,16 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
// 客户手机号
serviceOrder.setPhone(serviceAddress.getPhone());
return this.insertSelective(serviceOrder);
int result = this.insertSelective(serviceOrder);
// TODO 发短信通知所有客服
// 记录流程
if (result == 1) {
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.RESERVE.getStatus(), ServiceOrderStatusEnum.RESERVE.getMsg(), null, null);
}
return result;
}
......@@ -133,22 +155,79 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
public int valuation(ValuationServiceOrderDTO dto, Long userId) {
log.info("order valuation dto: {}, userId: {}", dto, userId);
checkAuth(userId, BizCodeEnum.NO_AUTH_VALUATION_ORDER);
User user = checkAuth(userId, BizCodeEnum.NO_AUTH_VALUATION_ORDER);
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.SUBMIT.getStatus())) {
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.RESERVE.getStatus())) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_VALUATION);
}
ServiceValuator serviceValuator = serviceValuatorMapper.selectByPrimaryKey(dto.getHostId());
if (Objects.isNull(serviceValuator)) {
throw new ServiceException(BizCodeEnum.SERVICE_VALUATOR_NOT_EXIST);
}
// 存估价员服务时间
ServiceValuatorAssign serviceValuatorAssign = new ServiceValuatorAssign();
// 估价员id
serviceValuatorAssign.setValuatorId(dto.getHostId());
// 订单id
serviceValuatorAssign.setOrderId(dto.getId());
// 估价员上门时间
serviceValuatorAssign.setAssignTime(dto.getExpectArrivalTime());
// 创建人
serviceValuatorAssign.setCreateBy(user.getUserName());
serviceValuatorAssignMapper.insertSelective(serviceValuatorAssign);
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.VALUATION.getStatus());
int result = this.updateByPrimaryKeySelective(serviceOrder);
if (result == 1) {
String description = String.format(ServiceOrderStatusEnum.VALUATION.getMsg(), user.getUserName(), serviceValuator.getName());
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.VALUATION.getStatus(), description, serviceValuator.getId(), dto.getRemark());
}
return result;
}
// TODO 短信通知估价员 去估价
public int revaluation(ValuationServiceOrderDTO dto, Long userId) {
log.info("order revaluation dto: {}, userId: {}", dto, userId);
User user = checkAuth(userId, BizCodeEnum.NO_AUTH_REVALUATION_ORDER);
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.VALUATION.getStatus())) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_REVALUATION);
}
// TODO 短信 "您的订单已为您指派估价员,请保持手机畅通!"
ServiceValuator serviceValuator = serviceValuatorMapper.selectByPrimaryKey(dto.getHostId());
if (Objects.isNull(serviceValuator)) {
throw new ServiceException(BizCodeEnum.SERVICE_VALUATOR_NOT_EXIST);
}
// TODO 小程序通知客户 "您的订单已为您指派估价员,请保持手机畅通!"
Condition c = new Condition(ServiceValuatorAssign.class);
c.createCriteria().andEqualTo(BizConstants.OrderConstants.ORDER_ID, serviceOrder.getId());
serviceValuatorAssignMapper.deleteByCondition(c);
// 存估价员服务时间
ServiceValuatorAssign serviceValuatorAssign = new ServiceValuatorAssign();
// 估价员id
serviceValuatorAssign.setValuatorId(dto.getHostId());
// 订单id
serviceValuatorAssign.setOrderId(dto.getId());
// 估价员上门时间
serviceValuatorAssign.setAssignTime(dto.getExpectArrivalTime());
// 创建人
serviceValuatorAssign.setCreateBy(user.getUserName());
int result = serviceValuatorAssignMapper.insertSelective(serviceValuatorAssign);
if (result == 1) {
String description = String.format(ServiceOrderStatusEnum.REVALUATION.getMsg(), user.getUserName(), serviceValuator.getName());
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.REVALUATION.getStatus(), description, serviceValuator.getId(), dto.getRemark());
}
return this.updateByPrimaryKeySelective(serviceOrder);
return result;
}
......@@ -159,11 +238,16 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
log.info("sendOrder dto: {}, userId: {}", dto, userId);
// 判断发送者权限
checkAuth(userId, BizCodeEnum.NO_AUTH_SEND_ORDER);
User user = userMapper.selectByPrimaryKey(userId);
if (Objects.isNull(user)
|| (!user.getRoleType().equals(ServiceUserTypeEnum.ADMIN.getId()) && !user.getRoleType().equals(ServiceUserTypeEnum.VALUATOR.getId()))) {
throw new ServiceException(BizCodeEnum.NO_AUTH_SEND_ORDER);
}
// 判断能发送的状态
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.VALUATION.getStatus())) {
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.VALUATION.getStatus())
&& !serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.RESERVE.getStatus())) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_SEND);
}
......@@ -183,9 +267,14 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
// TODO 小程序通知客户完成支付
if (result == 1) {
boolean isAdmin = user.getRoleType().equals(ServiceUserTypeEnum.ADMIN.getId());
String description = String.format(ServiceOrderStatusEnum.SEND.getMsg(),
(isAdmin ? ServiceUserTypeEnum.ADMIN.getName() : ServiceUserTypeEnum.VALUATOR.getName()) + user.getUserName());
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.SEND.getStatus(), description, null, null);
}
return result;
}
......@@ -202,28 +291,42 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
int result = serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
// TODO 调用微信支付接口
// TODO 短信 通知管理员 -> 用户已经支付完成,请尽快指派维修工
// TODO 小程序 通知管理员 -> 用户已经支付完成,请尽快指派维修工
if (result == 1) {
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.PAY.getStatus(), ServiceOrderStatusEnum.PAY.getMsg(), null, null);
}
return result;
}
public int dispatch(DispatchServiceOrderDTO dto, Long userId) {
log.info("dispatch dto: {}, userId: {}", dto, userId);
log.info("order dispatch dto: {}, userId: {}", dto, userId);
checkAuth(userId, BizCodeEnum.NO_AUTH_DISPATCH_ORDER);
User user = checkAuth(userId, BizCodeEnum.NO_AUTH_DISPATCH_ORDER);
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.PAY.getStatus())) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_DISPATCH);
}
ServiceWorker serviceWorker = serviceWorkerMapper.selectByPrimaryKey(dto.getHostId());
if (Objects.isNull(serviceWorker)) {
throw new ServiceException(BizCodeEnum.SERVICE_WORKER_NOT_EXIST);
}
// 存维修工服务时间
ServiceWorkerAssign serviceWorkerAssign = new ServiceWorkerAssign();
// 维修工id
serviceWorkerAssign.setWorkerId(dto.getHostId());
// 订单id
serviceWorkerAssign.setOrderId(dto.getId());
// 期望维修工上门时间
serviceWorkerAssign.setAssignTime(dto.getExpectArrivalTime());
serviceWorkerAssign.setCreateBy(user.getUserName());
serviceWorkerAssignMapper.insertSelective(serviceWorkerAssign);
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.DISPATCH.getStatus());
int result = serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
......@@ -231,23 +334,86 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
// TODO 小程序通知 您的订单已为您指派维修工~~~
if (result == 1) {
String description = String.format(ServiceOrderStatusEnum.DISPATCH.getMsg(), user.getUserName(), serviceWorker.getName());
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.DISPATCH.getStatus(), description, serviceWorker.getId(), dto.getRemark());
}
return result;
}
public int redispatch(DispatchServiceOrderDTO dto, Long userId) {
log.info("order redispatch dto: {}, userId: {}", dto, userId);
User user = checkAuth(userId, BizCodeEnum.NO_AUTH_REDISPATCH_ORDER);
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.PAY.getStatus())) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_REDISPATCH);
}
ServiceWorker serviceWorker = serviceWorkerMapper.selectByPrimaryKey(dto.getHostId());
if (Objects.isNull(serviceWorker)) {
throw new ServiceException(BizCodeEnum.SERVICE_WORKER_NOT_EXIST);
}
Condition c = new Condition(ServiceWorkerAssign.class);
c.createCriteria().andEqualTo(BizConstants.OrderConstants.ORDER_ID, serviceOrder.getId());
serviceWorkerAssignMapper.deleteByCondition(c);
// 存维修工服务时间
ServiceWorkerAssign serviceWorkerAssign = new ServiceWorkerAssign();
// 维修工id
serviceWorkerAssign.setWorkerId(dto.getHostId());
// 订单id
serviceWorkerAssign.setOrderId(dto.getId());
// 期望维修工上门时间
serviceWorkerAssign.setAssignTime(dto.getExpectArrivalTime());
serviceWorkerAssign.setCreateBy(user.getUserName());
int result = serviceWorkerAssignMapper.insertSelective(serviceWorkerAssign);
// TODO 短信 "您的订单已为您重新指派维修工,请保持手机畅通!"
// TODO 小程序通知 您的订单已为您重新指派维修工~~~
if (result == 1) {
String description = String.format(ServiceOrderStatusEnum.REDISPATCH.getMsg(), user.getUserName(), serviceWorker.getName());
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.REDISPATCH.getStatus(), description, serviceWorker.getId(), dto.getRemark());
}
return result;
}
/**
* 完成 TODO 添加定时任务已派单的 "?天" 自动完成
* 完成
*/
public int finishOrder(FinishServiceOrderDTO dto, Long userId) {
log.info("finishOrder dto: {}, userId: {}", dto, userId);
ServiceOrder serviceOrder = checkOrder(dto.getId(), userId);
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.DISPATCH.getStatus())) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_FINISH);
}
User user = userMapper.selectByPrimaryKey(userId);
// 既不是客户 又不是客服
boolean isUser = serviceOrder.getAccountNo().equals(userId);
boolean isAdmin = !Objects.isNull(user) && user.getRoleType().equals(ServiceUserTypeEnum.ADMIN.getId());
if (!isUser && !isAdmin) {
throw new ServiceException(BizCodeEnum.NO_AUTH_FINISH_ORDER);
}
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.FINISH.getStatus());
return serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
int result = serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
if (result == 1) {
String description = String.format(ServiceOrderStatusEnum.FINISH.getMsg(), isUser ? ServiceUserTypeEnum.USER.getName() : ServiceUserTypeEnum.ADMIN.getName() + user.getUserName());
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.FINISH.getStatus(), description, null, null);
}
return result;
}
......@@ -260,40 +426,44 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
}
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.CANCEL.getStatus());
return serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
}
/**
* 未派单订单 用户可实时退款
* 已派单订单 需要管理员审批
*/
public int refundOrder(RefundServiceOrderDTO dto, Long userId) {
log.info("refundOrder dto: {}, userId: {}", dto, userId);
ServiceOrder serviceOrder = checkOrder(dto.getId(), userId);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.PAY.getStatus())) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_REFUND);
}
// 已申请退款
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.REFUND_APPLY.getStatus());
int result = serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
try {
// TODO 调用微信接口退款 ??
// TODO 通知web
} catch (Exception e) {
if (result == 1) {
recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.CANCEL.getStatus(), ServiceOrderStatusEnum.CANCEL.getMsg(), null, null);
}
return result;
}
/**
* 未派单订单 用户可实时退款
* 已派单订单 需要管理员审批
*/
// public int refundOrder(RefundServiceOrderDTO dto, Long userId) {
// log.info("refundOrder dto: {}, userId: {}", dto, userId);
//
// ServiceOrder serviceOrder = checkOrder(dto.getId(), userId);
// if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.PAY.getStatus())) {
// throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_REFUND);
// }
//
// // 已申请退款
// serviceOrder.setOrderStatus(ServiceOrderStatusEnum.REFUND_APPLY.getStatus());
// int result = serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
//
//
// try {
// // 调用微信接口退款 ??
//
// // 通知web
// } catch (Exception e) {
//
// }
//
//
// return result;
// }
private ServiceOrder checkOrder(Long id, Long userId) {
Condition c = new Condition(ServiceOrder.class);
......@@ -311,11 +481,26 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
}
private void checkAuth(Long userId, BizCodeEnum biz) {
private User checkAuth(Long userId, BizCodeEnum biz) {
User user = userMapper.selectByPrimaryKey(userId);
if (Objects.isNull(user) || !user.getAdmin()) {
if (Objects.isNull(user) || !user.getRoleType().equals(ServiceUserTypeEnum.ADMIN.getId())) {
throw new ServiceException(biz);
}
return user;
}
@Async
public void recordProcess(Long orderId, Integer processId, String description, Long hostId, String remark) {
ServiceOrderLog serviceOrderLog = new ServiceOrderLog();
serviceOrderLog.setOrderId(orderId);
serviceOrderLog.setProcessId(processId);
serviceOrderLog.setDescription(description);
serviceOrderLog.setHostId(hostId);
serviceOrderLog.setRemark(remark);
serviceOrderLogMapper.insertSelective(serviceOrderLog);
}
......
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