Commit 09cd2053 authored by shangtx's avatar shangtx

Merge branch 'dev' into 'master'

Dev

See merge request !1
parents 9be2457e 307a5fac
......@@ -5,6 +5,7 @@ import com.onsiteservice.admin.controller.order.vo.OrderDetailVO;
import com.onsiteservice.admin.controller.order.vo.OrderPageVO;
import com.onsiteservice.admin.service.order.AdminOrderService;
import com.onsiteservice.common.annotation.dict.Dict;
import com.onsiteservice.common.annotation.idempotent.ApiIdempotent;
import com.onsiteservice.common.annotation.user.CurrentUserId;
import com.onsiteservice.common.order.dto.DispatchServiceOrderDTO;
import com.onsiteservice.common.order.dto.FinishServiceOrderDTO;
......
package com.onsiteservice.common.service;
import com.onsiteservice.common.redis.RedisUtils;
import com.onsiteservice.util.aliyun.SmsUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* 业务短信服务
*/
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class CommonSmsService {
@Value("${spring.profiles.active}")
private String env;
@Value("${aliyun.sms.template-code.change-phone}")
private String changePhoneTmpCode; // 手机号换绑
@Value("${aliyun.sms.template-code.payable}")
private String payableTmpCode; // 通知用户完成估价请支付
@Value("${aliyun.sms.template-code.dispatched}")
private String dispatchedTmpCode; // 通知用户已经派单
@Value("${aliyun.sms.template-code.redispatched}")
private String redispatchedTmpCode; // 通知用户已经重新派单
@Value("${aliyun.sms.template-code.paid}")
private String paidTmpCode; // 手机号换绑
@Value("${aliyun.sms.template-code.valuator}")
private String valuatorTmpCode; // 通知客户已派估价员
@Value("${aliyun.sms.template-code.revaluator}")
private String revaluatorTmpCode; // 通知客户已重新指派估价员
@Value("${aliyun.sms.sign}")
private String sign;
@Resource
private SmsUtils smsUtils;
@Resource
private RedisUtils redisUtil;
/***
* 禁用短信方法
*/
private boolean disableSms() {
// return "dev".equals(env);
return false;
}
/***
* 发送改变信息验证码
*/
public void sendChangePhone(String code, String phone) {
if (StringUtils.isEmpty(phone)) {
return;
}
try {
smsUtils.send(sign, changePhoneTmpCode, code, phone);
} catch (Exception e) {
log.error("发送短信错误", e);
}
}
public void payable(String phone) {
if (StringUtils.isEmpty(phone)) {
return;
}
try {
smsUtils.send(sign, payableTmpCode, null, phone);
} catch (Exception e) {
log.error("发送短信错误", e);
}
}
public void dispatched(String phone) {
if (StringUtils.isEmpty(phone)) {
return;
}
try {
smsUtils.send(sign, dispatchedTmpCode, null, phone);
} catch (Exception e) {
log.error("发送短信错误", e);
}
}
public void redispatched(String phone) {
if (StringUtils.isEmpty(phone)) {
return;
}
try {
smsUtils.send(sign, redispatchedTmpCode, null, phone);
} catch (Exception e) {
log.error("发送短信错误", e);
}
}
public void paid(String phone) {
if (StringUtils.isEmpty(phone)) {
return;
}
try {
smsUtils.send(sign, paidTmpCode, null, phone);
} catch (Exception e) {
log.error("发送短信错误", e);
}
}
public void valuator(String phone) {
if (StringUtils.isEmpty(phone)) {
return;
}
try {
smsUtils.send(sign, valuatorTmpCode, null, phone);
} catch (Exception e) {
log.error("发送短信错误", e);
}
}
public void revaluator(String phone) {
if (StringUtils.isEmpty(phone)) {
return;
}
try {
smsUtils.send(sign, revaluatorTmpCode, null, phone);
} catch (Exception e) {
log.error("发送短信错误", e);
}
}
}
package com.onsiteservice.service.order;
import com.google.common.collect.Sets;
import com.onsiteservice.common.order.dto.DispatchServiceOrderDTO;
import com.onsiteservice.common.order.dto.FinishServiceOrderDTO;
import com.onsiteservice.common.order.dto.SendServiceOrderDTO;
import com.onsiteservice.common.order.dto.ValuationServiceOrderDTO;
import com.onsiteservice.common.service.CommonSmsService;
import com.onsiteservice.constant.constant.BizConstants;
import com.onsiteservice.constant.constant.SysParamConstants;
import com.onsiteservice.constant.enums.BizCodeEnum;
......@@ -18,7 +20,6 @@ import com.onsiteservice.dao.mapper.sys.SysParamMapper;
import com.onsiteservice.dao.mapper.sys.SysUserMapper;
import com.onsiteservice.dao.mapper.user.UserMapper;
import com.onsiteservice.entity.order.ServiceOrder;
import com.onsiteservice.entity.service.ServiceValuator;
import com.onsiteservice.entity.service.ServiceValuatorAssign;
import com.onsiteservice.entity.service.ServiceWorker;
import com.onsiteservice.entity.service.ServiceWorkerAssign;
......@@ -38,6 +39,8 @@ import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Service
@Slf4j
......@@ -48,10 +51,8 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
/**
* 短信相关
*/
@Value("${aliyun.sms.sign}")
private String sign;
@Autowired
private SmsUtils smsUtils;
private CommonSmsService commonSmsService;
@Resource
private ServiceOrderMapper serviceOrderMapper;
......@@ -85,7 +86,7 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
public int valuation(ValuationServiceOrderDTO dto, Long userId, ServiceOrderOpSourceEnum sourceEnum) {
log.info("order valuation dto: {}, userId: {}", dto, userId);
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_VALUATION_ORDER, sourceEnum);
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_VALUATION_ORDER, sourceEnum, Sets.newHashSet(ServiceUserTypeEnum.ADMIN));
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.RESERVE.getStatus())) {
......@@ -97,15 +98,18 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
throw new ServiceException(BizCodeEnum.SERVICE_VALUATOR_NOT_EXIST);
}
serviceValuatorAssignMapper.insertSelective(buildServiceValuatorAssign(dto, userId));
Condition c = buildOrderStatusCondition(serviceOrder);
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.VALUATION.getStatus());
serviceOrder.setModifyBy(userId);
serviceOrder.setValuatorId(valuatorUser.getId());
int result = this.updateByPrimaryKeySelective(serviceOrder);
int result = serviceOrderMapper.updateByConditionSelective(serviceOrder, c);
if (result == 1) {
// 记录估价员指派时间
serviceValuatorAssignMapper.insertSelective(buildServiceValuatorAssign(dto, userId));
// 通知用户
commonSmsService.valuator(serviceOrder.getPhone());
String description = String.format(ServiceOrderStatusEnum.VALUATION.getMsg(), user.getName(), valuatorUser.getUserName());
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.VALUATION.getStatus(), description,
sourceEnum, valuatorUser.getId(), dto.getRemark(), dto.getExpectArrivalTime());
......@@ -118,7 +122,7 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
public int revaluation(ValuationServiceOrderDTO dto, Long userId, ServiceOrderOpSourceEnum sourceEnum) {
log.info("order revaluation dto: {}, userId: {}", dto, userId);
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_REVALUATION_ORDER, sourceEnum);
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_REVALUATION_ORDER, sourceEnum, Sets.newHashSet(ServiceUserTypeEnum.ADMIN));
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.VALUATION.getStatus())) {
......@@ -130,14 +134,16 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
throw new ServiceException(BizCodeEnum.SERVICE_VALUATOR_NOT_EXIST);
}
disableServiceValuatorAssign(serviceOrder, userId, false);
serviceValuatorAssignMapper.insertSelective(buildServiceValuatorAssign(dto, userId));
serviceOrder.setValuatorId(dto.getHostId());
int result = this.updateByPrimaryKeySelective(serviceOrder);
if (result == 1) {
// 取消之前被指派的估价员时间
disableServiceValuatorAssign(serviceOrder, userId, false);
// 设置新的估计员世间
serviceValuatorAssignMapper.insertSelective(buildServiceValuatorAssign(dto, userId));
// 通知用户
commonSmsService.revaluator(serviceOrder.getPhone());
String description = String.format(ServiceOrderStatusEnum.REVALUATION.getMsg(), user.getName(), valuatorUser.getUserName());
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.REVALUATION.getStatus(), description,
sourceEnum, valuatorUser.getId(), dto.getRemark(), dto.getExpectArrivalTime());
......@@ -154,16 +160,15 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
log.info("sendOrder dto: {}, userId: {}", dto, userId);
// 判断发送者权限 只有客服和估价员可以发送订单
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_SEND_ORDER, sourceEnum);
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_SEND_ORDER, sourceEnum, Sets.newHashSet(ServiceUserTypeEnum.ADMIN, ServiceUserTypeEnum.VALUATOR));
// 判断能发送的状态: 估价可以发送,下单可以直接发送
// 判断能发送的状态: 估价后可以发送,预约后可以发送
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.VALUATION.getStatus()) && !serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.RESERVE.getStatus())) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_CANNOT_SEND);
}
disableServiceValuatorAssign(serviceOrder, userId, null);
Condition c = buildOrderStatusCondition(serviceOrder);
// 估价价格
serviceOrder.setPrice(dto.getPrice());
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.SEND.getStatus());
......@@ -174,21 +179,21 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
List<SysParam> sysParamList = sysParamMapper.selectByCondition(sysParamCondition);
long timeOut = CollectionUtils.isEmpty(sysParamList) ? BizConstants.OrderConstants.TIMEOUT_CANCEL_LIMIT : Long.parseLong(sysParamList.get(0).getValue());
serviceOrder.setCancelTime(new Date(System.currentTimeMillis() + timeOut));
int result = serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
int result = serviceOrderMapper.updateByConditionSelective(serviceOrder, c);
try {
// 发短信
log.info("sendOrder send msg to phone: {}", serviceOrder.getPhone());
// TODO 短信通知客户完成支付
smsUtils.send(sign, "", "", serviceOrder.getPhone());
commonSmsService.payable(serviceOrder.getPhone());
} catch (Exception e) {
log.error("sendOrder error, ", e);
}
// TODO 小程序通知客户完成支付
if (result == 1) {
// 置估价员指派时间为失效
disableServiceValuatorAssign(serviceOrder, userId, null);
String description = String.format(ServiceOrderStatusEnum.SEND.getMsg(), (user.getIsAdmin() ? ServiceUserTypeEnum.ADMIN.getName() : ServiceUserTypeEnum.VALUATOR.getName()) + user.getName());
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.SEND.getStatus(), description, sourceEnum, userId, null, null);
}
......@@ -200,7 +205,7 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
public int dispatch(DispatchServiceOrderDTO dto, Long userId, ServiceOrderOpSourceEnum sourceEnum) {
log.info("order dispatch dto: {}, userId: {}", dto, userId);
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_DISPATCH_ORDER, sourceEnum);
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())) {
......@@ -216,18 +221,17 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
throw new ServiceException(BizCodeEnum.SERVICE_WORKER_NOT_EXIST);
}
serviceWorkerAssignMapper.insertSelective(buildServiceWorkerAssign(dto, serviceOrder, userId));
Condition c = buildOrderStatusCondition(serviceOrder);
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.DISPATCH.getStatus());
serviceOrder.setModifyBy(userId);
int result = serviceOrderMapper.updateByConditionSelective(serviceOrder, c);
int result = serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
// TODO 短信 "您的订单已为您指派维修工,请保持手机畅通!"
// TODO 小程序通知 您的订单已为您指派维修工~~~
commonSmsService.dispatched(serviceOrder.getPhone());
if (result == 1) {
// 记录维修工时间
serviceWorkerAssignMapper.insertSelective(buildServiceWorkerAssign(dto, serviceOrder, userId));
String description = String.format(ServiceOrderStatusEnum.DISPATCH.getMsg(), user.getName(), serviceWorker.getName());
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.DISPATCH.getStatus(), description, sourceEnum, serviceWorker.getId(), dto.getRemark(), null);
}
......@@ -239,7 +243,7 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
public int redispatch(DispatchServiceOrderDTO dto, Long userId, ServiceOrderOpSourceEnum sourceEnum) {
log.info("order redispatch dto: {}, userId: {}", dto, userId);
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_REDISPATCH_ORDER, sourceEnum);
WorkUser user = checkAuth(userId, BizCodeEnum.NO_AUTH_REDISPATCH_ORDER, sourceEnum, Sets.newHashSet(ServiceUserTypeEnum.ADMIN));
ServiceOrder serviceOrder = checkOrder(dto.getId(), null);
if (!serviceOrder.getOrderStatus().equals(ServiceOrderStatusEnum.DISPATCH.getStatus())) {
......@@ -259,9 +263,7 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
int result = serviceWorkerAssignMapper.insertSelective(buildServiceWorkerAssign(dto, serviceOrder, userId));
// TODO 短信 "您的订单已为您重新指派维修工,请保持手机畅通!"
// TODO 小程序通知 您的订单已为您重新指派维修工~~~
commonSmsService.redispatched(serviceOrder.getPhone());
if (result == 1) {
String description = String.format(ServiceOrderStatusEnum.REDISPATCH.getMsg(), user.getName(), serviceWorker.getName());
......@@ -297,15 +299,15 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
user = new WorkUser(sysUser.getId(), sysUser.getRealName(), true);
}
disableServiceWorkerAssign(serviceOrder, userId, null);
Condition c = buildOrderStatusCondition(serviceOrder);
serviceOrder.setOrderStatus(ServiceOrderStatusEnum.FINISH.getStatus());
serviceOrder.setModifyBy(userId);
int result = serviceOrderMapper.updateByPrimaryKeySelective(serviceOrder);
int result = serviceOrderMapper.updateByConditionSelective(serviceOrder, c);
if (result == 1) {
// 取消维修工服务时间
disableServiceWorkerAssign(serviceOrder, userId, null);
String description = String.format(ServiceOrderStatusEnum.FINISH.getMsg(), user.getIsAdmin() ? ServiceUserTypeEnum.ADMIN.getName() + user.getName() : ServiceUserTypeEnum.USER.getName());
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.FINISH.getStatus(), description, sourceEnum, null, null, null);
}
......@@ -330,12 +332,17 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
}
private WorkUser checkAuth(Long userId, BizCodeEnum biz, ServiceOrderOpSourceEnum source) {
private WorkUser checkAuth(Long userId, BizCodeEnum biz, ServiceOrderOpSourceEnum source, Set<ServiceUserTypeEnum> roles) {
if (source == ServiceOrderOpSourceEnum.MINI_APP) {
User user = userMapper.selectByPrimaryKey(userId);
if (Objects.isNull(user) || !user.getRoleType().equals(ServiceUserTypeEnum.ADMIN.getId())) {
if (Objects.isNull(user)) {
throw new ServiceException(biz);
}
if (!roles.parallelStream().map(ServiceUserTypeEnum::getId).collect(Collectors.toSet()).contains(user.getRoleType())) {
throw new ServiceException(biz);
}
return new WorkUser(user.getId(), user.getUserName(), user.getRoleType().equals(ServiceUserTypeEnum.ADMIN.getId()));
}
SysUser sysUser = sysUserMapper.selectByPrimaryKey(userId);
......@@ -420,5 +427,13 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
serviceWorkerAssignMapper.updateByConditionSelective(serviceWorkerAssign, c);
}
private Condition buildOrderStatusCondition(ServiceOrder serviceOrder) {
Condition c = new Condition(ServiceOrder.class);
c.createCriteria()
.andEqualTo("id", serviceOrder.getId())
.andEqualTo(BizConstants.OrderConstants.ORDER_STATUS, serviceOrder.getOrderStatus());
return c;
}
}
......@@ -22,16 +22,16 @@ public enum BizCodeEnum {
* 订单分组
*/
SERVICE_ORDER_NOT_EXIST("订单不存在"),
SERVICE_ORDER_CANNOT_VALUATION("处于非预约状态的订单不能派估价员"),
SERVICE_ORDER_CANNOT_REVALUATION("订单未指派估价员,不能修改"),
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_REDISPATCH("订单未指派维修工,不能修改"),
SERVICE_ORDER_TIMEOUT_CANNOT_DISPATCH("已过上门维修时间,不能派维修工"),
SERVICE_ORDER_CANNOT_FINISH("订单未派单,不能完成本次服务"),
SERVICE_ORDER_CANNOT_DISPATCH("订单未支付,不能派工或已派工"),
SERVICE_ORDER_CANNOT_REDISPATCH("订单未工,不能修改"),
SERVICE_ORDER_TIMEOUT_CANNOT_DISPATCH("已过维修时间,不能派维修工"),
SERVICE_ORDER_CANNOT_FINISH("订单未派单,不能完成服务或已完成"),
SERVICE_ORDER_STATUS_ERROR("请选择正确的订单状态"),
......
......@@ -18,7 +18,14 @@ aliyun:
batch-size: 500 # 批量发送个数
# 短信模板Code
template-code:
# change-info: SMS_161475524 # 信息变更验证码
change-phone: SMS_161475524 # 修改手机号短信验证码
payable: SMS_226520016 # 通知用户完成估价请支付 开发环境使用项目开盘替代
dispatched: SMS_226505027 # 通知用户已经派单 开发环境使用项目动态替代
redispatched: SMS_226505027 # 通知用户已经重新派单 开发环境使用项目动态替代
paid: SMS_226505027 # 通知业务人员客户已完成支付 开发环境使用优惠券发放替代
valuator: SMS_226505027 # 通知客户已派估价员 开发环境使用优惠券发放替代
revaluator: SMS_226505027 # 通知客户已重新指派估价员 开发环境使用优惠券发放替代
# 微信配置
......@@ -37,9 +44,9 @@ wx:
secret: d5e1aeae4fa4daa6328a6a02ddafb9ff #公众号的appsecret
token: OfficialAccounts2020 #接口配置里的Token值
aesKey: EBFO9I8JUrLLYZxSd1QqO08LyheQX1ABGLeNylv8LoW #接口配置里的EncodingAESKey值
# configs:
# - appId: wxceb5bea07decc398 #公众号的appid
# secret: d5e1aeae4fa4daa6328a6a02ddafb9ff #公众号的appsecret
# configs:
# - appId: wxceb5bea07decc398 #公众号的appid
# secret: d5e1aeae4fa4daa6328a6a02ddafb9ff #公众号的appsecret
# 微信支付
pay:
appId: wx2c8a98f02c1a4258 #微信公众号或者小程序等的appid
......
......@@ -43,8 +43,13 @@
parent_code,
icon,
name,
vr_name,
vr_path path,
show_order
show_order,
vr_redirect,
is_show,
is_cache,
vr_component_path component
from temp
order by show_order
</select>
......
package com.onsiteservice.miniapp.controller.order;
import com.onsiteservice.common.annotation.dict.Dict;
import com.onsiteservice.common.annotation.idempotent.ApiIdempotent;
import com.onsiteservice.common.annotation.user.CurrentUserId;
import com.onsiteservice.common.order.dto.DispatchServiceOrderDTO;
import com.onsiteservice.common.order.dto.FinishServiceOrderDTO;
......@@ -81,12 +82,14 @@ public class ServiceOrderController {
}
@ApiOperation(value = "订单估价")
@ApiIdempotent(interval = 3000L)
@PostMapping("valuation")
public Result valuation(@RequestBody @NonNull @Validated ValuationServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.valuation(dto, userId, ServiceOrderOpSourceEnum.MINI_APP) == 1 ? success() : fail("估价失败");
}
@ApiOperation(value = "修改估价")
@ApiIdempotent(interval = 3000L)
@PostMapping("revaluation")
public Result revaluation(@RequestBody @NonNull @Validated ValuationServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.revaluation(dto, userId, ServiceOrderOpSourceEnum.MINI_APP) == 1 ? success() : fail("修改估价失败");
......@@ -96,6 +99,7 @@ public class ServiceOrderController {
* 发送订单 已估价订单才能发送 <link>ServiceOrderStatusEnum</link>
*/
@ApiOperation(value = "发送订单")
@ApiIdempotent(interval = 3000L)
@PostMapping("send")
public Result valuation(@RequestBody @NonNull @Validated SendServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.sendOrder(dto, userId, ServiceOrderOpSourceEnum.MINI_APP) == 1 ? success() : fail("发送失败");
......@@ -103,12 +107,14 @@ public class ServiceOrderController {
@ApiOperation(value = "派单")
@ApiIdempotent(interval = 3000L)
@PostMapping("dispatch")
public Result dispatch(@RequestBody @NonNull @Validated DispatchServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.dispatch(dto, userId, ServiceOrderOpSourceEnum.MINI_APP) == 1 ? success() : fail("派单失败");
}
@ApiOperation(value = "修改派单")
@ApiIdempotent(interval = 3000L)
@PostMapping("redispatch")
public Result redispatch(@RequestBody @NonNull @Validated DispatchServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.redispatch(dto, userId, ServiceOrderOpSourceEnum.MINI_APP) == 1 ? success() : fail("修改派单失败");
......@@ -118,6 +124,7 @@ public class ServiceOrderController {
* 未派单之前不能完成,已申请退款的也可以点击完成
*/
@ApiOperation(value = "完成订单")
@ApiIdempotent(interval = 3000L)
@PostMapping("finish")
public Result finish(@RequestBody @NonNull @Validated FinishServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderService.finishOrder(dto, userId, ServiceOrderOpSourceEnum.MINI_APP) == 1 ? success() : fail("取消失败");
......@@ -137,6 +144,7 @@ public class ServiceOrderController {
*/
@ApiOperation(value = "取消订单")
@PostMapping("cancel")
@ApiIdempotent(interval = 3000L)
public Result cancel(@RequestBody @NonNull @Validated CancelServiceOrderDTO dto, @CurrentUserId Long userId) {
return serviceOrderBizService.cancelOrder(dto, userId, ServiceOrderOpSourceEnum.MINI_APP) == 1 ? success() : fail("取消失败");
}
......
......@@ -46,60 +46,53 @@ public class WechatNotifyController {
public void notify(HttpServletRequest request, HttpServletResponse response) throws Exception {
//WechatPayMyConfigMini config = new WechatPayMyConfigMini();
PrintWriter out = null;
try {
log.info("微信支付成功回调通知开始!");
StringBuffer sb = new StringBuffer();
InputStream is = request.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String s = "";
while ((s = br.readLine()) != null) {
sb.append(s);
}
log.info("微信支付成功回调通知内容:" + sb.toString());
if (StringUtils.isNotEmpty(sb.toString())) {
// 解析xml
Map<String, String> paramMap = ParseXmlUtil.parseXml2Map(sb.toString());
String returnCode = paramMap.get("return_code").toString();
log.info("微信支付成功返回result_code:" + returnCode);
String outTradeNo = paramMap.get("out_trade_no").toString();
log.info("微信支付成功回调通知开始!");
StringBuffer sb = new StringBuffer();
InputStream is = request.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String s = "";
while ((s = br.readLine()) != null) {
sb.append(s);
}
log.info("微信支付成功回调通知内容:" + sb.toString());
if (StringUtils.isNotEmpty(sb.toString())) {
// 解析xml
Map<String, String> paramMap = ParseXmlUtil.parseXml2Map(sb.toString());
String returnCode = paramMap.get("return_code").toString();
log.info("微信支付成功返回result_code:" + returnCode);
String outTradeNo = paramMap.get("out_trade_no").toString();
var payChannels = payChannelWechatMapper.selectAll();
if (payChannels.isEmpty()) {
throw new ServiceException("未配置商户信息");
}
var payChannel = payChannels.get(0);
String transactionId = paramMap.get("transaction_id").toString();
//支付响应记录日志
var payChannels = payChannelWechatMapper.selectAll();
if (payChannels.isEmpty()) {
throw new ServiceException("未配置商户信息");
}
var payChannel = payChannels.get(0);
String transactionId = paramMap.get("transaction_id").toString();
//支付响应记录日志
// savePayResponseLog(outTradeNo, transactionId, returnCode, sb.toString());
if (RETURN_CODE_SUCCESS.equals(returnCode)) {
if (validateSign(paramMap, payChannel.getWechatKey())) {
//更新支付凭证支付状态
orderBizService.paySuccess(outTradeNo, sb.toString());
out = response.getWriter();
// 通知微信,防止微信再通知
response.setContentType("application/xml");
out.write("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>");
out.flush();
out.close();
} else {
log.warn("微信支付成功回调通知签名校验失败,请检查!");
}
if (RETURN_CODE_SUCCESS.equals(returnCode)) {
if (validateSign(paramMap, payChannel.getWechatKey())) {
//更新支付凭证支付状态
orderBizService.paySuccess(outTradeNo, sb.toString());
out = response.getWriter();
// 通知微信,防止微信再通知
response.setContentType("application/xml");
out.write("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>");
out.flush();
out.close();
} else {
log.warn("微信支付成功回调通知返回码不成功(RETURN_CODE),请检查!");
log.warn("微信支付成功回调通知签名校验失败,请检查!");
}
} else {
log.warn("微信支付成功回调通知内容为空,请检查!");
log.warn("微信支付成功回调通知返回码不成功(RETURN_CODE),请检查!");
}
} catch (Exception e) {
log.error("notify() Exception exception:", e);
e.printStackTrace();
} else {
log.warn("微信支付成功回调通知内容为空,请检查!");
}
}
/**
* 微信通知签名校验
*
......
......@@ -2,11 +2,11 @@ package com.onsiteservice.miniapp.mapper.service;
/**
* @author 潘维吉
* @date 2022-07-11 16:07
* @description ServiceValuatorAssignBizMapper业务接口
*/
public interface ServiceValuatorAssignBizMapper {
int getTodoNum(Long valuatorId);
}
......@@ -6,7 +6,6 @@ import com.onsiteservice.entity.service.ServiceValuator;
import java.util.List;
/**
* @author 潘维吉
* @date 2022-07-11 16:07
* @description ServiceValuatorBizMapper业务接口
*/
......
......@@ -2,11 +2,9 @@ package com.onsiteservice.miniapp.mapper.service;
/**
* @author 潘维吉
* @date 2022-07-11 16:07
* @description ServiceWorkerAssignBizMapper业务接口
*/
public interface ServiceWorkerAssignBizMapper {
}
......@@ -17,7 +17,6 @@ public class OrderListener {
@Resource
private WeixinMessageService weixinMessageService;
/* TODO 给用户发送订单的新情况 */
@RabbitHandler
public void notice() {
weixinMessageService.sendMsg(null);
......
......@@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
import com.onsiteservice.common.order.vo.OrderPayVO;
import com.onsiteservice.common.order.vo.ServiceOrderLogVO;
import com.onsiteservice.common.order.vo.ServiceOrderVO;
import com.onsiteservice.common.service.CommonSmsService;
import com.onsiteservice.constant.constant.BizConstants;
import com.onsiteservice.constant.constant.SysConstants;
import com.onsiteservice.constant.constant.SysParamConstants;
......@@ -62,14 +63,11 @@ import java.util.stream.Collectors;
@Transactional(rollbackFor = Exception.class)
public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
/**
* 短信相关
*/
@Value("${aliyun.sms.sign}")
private String sign;
@Autowired
private SmsUtils smsUtils;
private CommonSmsService commonSmsService;
@Resource
private ServiceOrderMapper serviceOrderMapper;
......@@ -220,8 +218,6 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
recordComponent.recordServiceOrderImg(serviceOrder, dto.getUrls());
// TODO 发短信通知所有客服
// 记录流程
if (result == 1) {
recordComponent.recordProcess(serviceOrder.getId(), ServiceOrderStatusEnum.RESERVE.getStatus(), ServiceOrderStatusEnum.RESERVE.getMsg(), sourceEnum, null, null, null);
......@@ -230,18 +226,16 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
return result;
}
public void paySuccess(String outTradeNo, String orderNo) {
log.info("支付成功 outTradeNo: {}, orderNo: {}", outTradeNo, orderNo);
public void paySuccess(String orderNo, String info) {
log.info("支付成功 orderNo: {}, info: {}", orderNo, info);
var order = selectOneByProperty("orderNo", outTradeNo);
var order = selectOneByProperty("orderNo", orderNo);
order.setOrderStatus(ServiceOrderStatusEnum.PAY.getStatus());
int result = serviceOrderMapper.updateByPrimaryKeySelective(order);
if (result == 1) {
recordComponent.recordProcess(order.getId(), ServiceOrderStatusEnum.PAY.getStatus(), ServiceOrderStatusEnum.PAY.getMsg(), ServiceOrderOpSourceEnum.MINI_APP, null, null, null);
}
// 通知客服
var logCondition = new ServiceOrderLog();
logCondition.setOrderId(order.getId());
......@@ -252,7 +246,7 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
var sysUser = sysUserMapper.selectByPrimaryKey(orderLog.getHostId());
if (StringUtils.isNotEmpty(sysUser.getPhone())) {
try {
smsUtils.send("", "", "", sysUser.getPhone());
commonSmsService.paid(sysUser.getPhone());
amqpTemplate.convertAndSend(SysConstants.Queue.ADMIN_ORDER, Pair.of(sysUser.getId(), 1));
} catch (Exception e) {
e.printStackTrace();
......@@ -263,13 +257,16 @@ public class ServiceOrderBizService extends AbstractMapper<ServiceOrder> {
if (ServiceOrderOpSourceEnum.MINI_APP.getId().equals(orderLog.getSource())) {
var user = userMapper.selectByPrimaryKey(orderLog.getHostId());
try {
smsUtils.send("", "", "", user.getPhone());
commonSmsService.paid(user.getPhone());
} catch (Exception e) {
e.printStackTrace();
log.error("订单{} 支付成功短信发送失败", orderNo);
}
}
}
if (result == 1) {
recordComponent.recordProcess(order.getId(), ServiceOrderStatusEnum.PAY.getStatus(), ServiceOrderStatusEnum.PAY.getMsg(), ServiceOrderOpSourceEnum.MINI_APP, null, null, null);
}
}
......
......@@ -2,6 +2,7 @@ package com.onsiteservice.miniapp.service.user;
import com.alibaba.fastjson.JSON;
import com.onsiteservice.common.runner.InitDataRunner;
import com.onsiteservice.common.service.CommonSmsService;
import com.onsiteservice.constant.constant.Constants;
import com.onsiteservice.constant.constant.DictConstants;
import com.onsiteservice.constant.constant.RedisKeyConstants;
......@@ -29,6 +30,7 @@ import com.onsiteservice.miniapp.controller.user.dto.SendCodeDTO;
import com.onsiteservice.miniapp.controller.user.vo.UserInfoVO;
import com.onsiteservice.miniapp.controller.user.vo.UserOrderInfoVO;
import com.onsiteservice.miniapp.mapper.order.ServiceOrderBizMapper;
import com.onsiteservice.miniapp.mapper.service.ServiceValuatorAssignBizMapper;
import com.onsiteservice.util.RandomUtils;
import io.jsonwebtoken.Claims;
import lombok.AllArgsConstructor;
......@@ -58,7 +60,8 @@ public class UserService extends AbstractMapper<User> {
private UserConvert userConvert;
private ServiceOrderBizMapper serviceOrderBizMapper;
private ServiceOrderMapper serviceOrderMapper;
private ServiceValuatorAssignMapper serviceValuatorAssignMapper;
private ServiceValuatorAssignBizMapper serviceValuatorAssignBizMapper;
private CommonSmsService commonSmsService;
public Result<String> sendCode(SendCodeDTO dto) {
......@@ -81,7 +84,7 @@ public class UserService extends AbstractMapper<User> {
// 置入
redisTemplate.opsForValue().set(cacheKey, value, RedisKeyConstants.CODE_EXPIRED, TimeUnit.MILLISECONDS);
// TODO 发送短信
commonSmsService.sendChangePhone(code, dto.getTo());
return ResultGenerator.success();
}
......@@ -134,11 +137,7 @@ public class UserService extends AbstractMapper<User> {
vo.setTodo(num);
}
if (Objects.equals(user.getRoleType(), ServiceUserTypeEnum.VALUATOR.getId())) {
Condition condition = new Condition(ServiceValuatorAssign.class);
condition.createCriteria().andEqualTo("valuatorId", userId)
.andGreaterThan("assignTime", new Date());
int num = serviceValuatorAssignMapper.selectCountByCondition(condition);
vo.setTodo(num);
vo.setTodo(serviceValuatorAssignBizMapper.getTodoNum(userId));
}
// 获取订单状况
var numMap = serviceOrderBizMapper.getMyOrderNum(userId);
......@@ -146,7 +145,7 @@ public class UserService extends AbstractMapper<User> {
new UserOrderInfoVO("待支付", numMap.get("pay"), 1),
new UserOrderInfoVO("待受理", numMap.get("handle"), 3),
new UserOrderInfoVO("待派单", numMap.get("dispatch"), 4),
new UserOrderInfoVO("已完成", numMap.get("finished"), 6)
new UserOrderInfoVO("服务中", numMap.get("service"), 5)
));
return vo;
}
......
......@@ -3,4 +3,12 @@
<mapper namespace="com.onsiteservice.miniapp.mapper.service.ServiceValuatorAssignBizMapper">
<select id="getTodoNum" resultType="java.lang.Integer">
select count(1)
from service_valuator_assign t1
join service_order t2 on t1.order_id = t2.id
where t1.valuator_Id = #{valuatorId}
and t1.assign_time > current_timestamp
and t2.order_status = ${@com.onsiteservice.constant.enums.ServiceOrderStatusEnum@VALUATION.getStatus()}
</select>
</mapper>
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