Commit 8cf074a9 by wuwenlong

Merge branch 'dev' into test

parents 39500838 cb3069d8
......@@ -46,6 +46,11 @@ public class SConsumerController extends BaseController
return getDataTable(list);
}
@GetMapping("/query")
public AjaxResult query() {
return success(sConsumerService.selectSConsumerList(new SConsumer()));
}
/**
* 导出会员用户列表
*/
......
package share.web.controller.system;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
......@@ -7,6 +8,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
......@@ -21,10 +23,12 @@ import share.common.core.domain.AjaxResult;
import share.common.enums.BusinessType;
import share.common.enums.RoomType;
import share.common.enums.StoreType;
import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon;
import share.system.service.ISConsumerCouponService;
import share.common.utils.poi.ExcelUtil;
import share.common.core.page.TableDataInfo;
import share.system.service.SConsumerService;
/**
* 优惠券领取记录Controller
......@@ -39,6 +43,9 @@ public class SConsumerCouponController extends BaseController
@Autowired
private ISConsumerCouponService sConsumerCouponService;
@Autowired
private SConsumerService sConsumerService;
/**
* 查询优惠券领取记录列表
*/
......@@ -46,9 +53,26 @@ public class SConsumerCouponController extends BaseController
@GetMapping("/list")
public TableDataInfo list(SConsumerCoupon sConsumerCoupon)
{
List<SConsumer> list = sConsumerService.list();
startPage();
List<SConsumerCoupon> list = sConsumerCouponService.selectSConsumerCouponList(sConsumerCoupon);
return getDataTable(list);
if (share.common.utils.StringUtils.isNotBlank(sConsumerCoupon.getPhone())) {
SConsumer sConsumer = list.stream().filter(obj -> obj.getPhone().equals(sConsumerCoupon.getPhone())).findFirst().orElse(null);
if (!ObjectUtils.isEmpty(sConsumer)) {
sConsumerCoupon.setConsumerId(sConsumer.getId());
} else {
return getDataTable(new ArrayList<>());
}
}
if (share.common.utils.StringUtils.isNotBlank(sConsumerCoupon.getNickName())) {
SConsumer sConsumer = list.stream().filter(obj -> share.common.utils.StringUtils.isNotBlank(obj.getNickName()) && obj.getNickName().equals(sConsumerCoupon.getNickName())).findFirst().orElse(null);
if (!ObjectUtils.isEmpty(sConsumer)) {
sConsumerCoupon.setConsumerId(sConsumer.getId());
} else {
return getDataTable(new ArrayList<>());
}
}
List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponService.selectSConsumerCouponList(sConsumerCoupon);
return getDataTable(sConsumerCoupons);
}
......
package share.web.controller.system;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
......@@ -59,7 +60,7 @@ public class SCouponController extends BaseController
public TableDataInfo listDuration(SCoupon sCoupon) {
startPage();
sCoupon.setCouponType(CouponTypeEnum.DURATION.getCode());
List<SCoupon> list = sCouponService.selectSCouponList(sCoupon);
List<SCoupon> list = sCouponService.listDuration(sCoupon);
return getDataTable(list);
}
......@@ -132,4 +133,14 @@ public class SCouponController extends BaseController
{
return toAjax(sCouponService.deleteSCouponByIds(ids));
}
/**
* 查询美团所有优惠卷的适用门店
*/
@GetMapping("/queryshopdeal")
public AjaxResult queryShopDeal() {
return success(sCouponService.queryShopDeal());
}
}
......@@ -20,7 +20,7 @@ public class Constants
public final static Integer ROMM_LOCK_LAZY_MINUTE = 0;
public static final String CONFIG_KEY_SITE_URL = "https://www.coujio.com"; //域名
public static final String CONFIG_KEY_SITE_URL = "https://coujiao.pseer.com/"; //域名
public static final String CONFIG_KEY_API_URL = "https://www.coujio.com"; //admin接口地址
// 订单取消Key
public static final String ORDER_AUTO_CANCEL_KEY = "order_auto_cancel_key";
......
......@@ -5,6 +5,8 @@ public enum ConsumerCouponStatusEnum {
WECHAT("2", "微信回调"),
SERVICE("3", "SERVICE回调"),
ORDER("4", "订单下单"),
//任务
TASK("5", "任务"),
;
ConsumerCouponStatusEnum() {
......
package share.common.enums;
public enum StoreStatusEnum {
// 0:停业 1:正常营业
STOP("0", "停业"),
NORMAL("1", "正常营业"),
;
private String index;
private String value;
StoreStatusEnum() {
}
StoreStatusEnum(String index, String value) {
this.index = index;
this.value = value;
}
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
package share.common.enums;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @Author wwl
* @Date 2024/1/15 13:27
*/
public enum WeekEnum {
MONDAY(1,"周一"),
TUESDAY(2,"周二"),
WEDNESDAY(3,"周三"),
THURSDAY(4,"周四"),
FRIDAY(5,"周五"),
SATURDAY(6,"周六"),
SUNDAY(7,"周日");
private Integer code;
private String value;
WeekEnum(Integer code, String value) {
this.code = code;
this.value = value;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public static String getValueByCode(Integer code){
WeekEnum week = getEnumByCode(code);
if(Objects.nonNull(week)){
return week.value;
}
return "";
}
public static WeekEnum getEnumByCode(Integer code){
for (WeekEnum week : WeekEnum.values()) {
if (week.code.compareTo(code)==0) {
return week;
}
}
return null;
}
public static Boolean isSundays(ArrayList<Integer> weeks){
List<Integer> sundays = new ArrayList<Integer>(){{
add(SATURDAY.code);
add(SUNDAY.code);
}};
if(weeks.size()==2
&&sundays.contains(weeks.get(0))
&&sundays.contains(weeks.get(1))){
return true;
}
return false;
}
public static Boolean isAllWorkDays(ArrayList<Integer> weeks){
List<Integer> workDays = new ArrayList<Integer>(){{
add(MONDAY.code);
add(TUESDAY.code);
add(WEDNESDAY.code);
add(THURSDAY.code);
add(FRIDAY.code);
}};
if(weeks.size()==5
&&workDays.contains(weeks.get(0))
&&workDays.contains(weeks.get(1))
&&workDays.contains(weeks.get(2))
&&workDays.contains(weeks.get(3))
&&workDays.contains(weeks.get(4))){
return true;
}
return false;
}
}
......@@ -28,6 +28,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
public static String YYYY_MM_DD_HH= "yyyy-MM-dd HH";
public static String YYYY_MM_DD_HH_MM= "yyyy-MM-dd HH:mm";
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
......
......@@ -39,12 +39,14 @@ public class QPServiceImplAspect {
@Autowired
private ISStoreService sStoreService;
private static final Integer TRY_NUMBER = 3;
/**
* 切点函数,用于标识需要记录操作日志的方法。
* 切点表达式为:execution(* share.system.service.impl.QPServiceImpl.*(..)),表示匹配所有在share.system.service.impl.QPServiceImpl类中定义的方法。
*/
@Pointcut("execution(* share.system.service.impl.QPServiceImpl.*(..))")
@Pointcut("execution(* share.system.service.impl.QPServiceImpl.consume(..))")
public void operLogPoinCut() {
}
......@@ -53,7 +55,7 @@ public class QPServiceImplAspect {
public void beforMethod(JoinPoint point) {
}
@Pointcut("execution(* share.system.service.impl.QPServiceImpl.*(..))")
@Pointcut("execution(* share.system.service.impl.QPServiceImpl.consume(..))")
public void operExceptionLogPoinCut() {
}
......@@ -87,7 +89,6 @@ public class QPServiceImplAspect {
JSONObject jsonObject = JSON.parseObject(params);
//获得出参
String outParams = JSON.toJSONString(result);
// if(methodName.equals("consume")){
saveLog(couponLog, jsonObject);
couponLog.setStatus(YesNoEnum.yes.getDisplay_3());
couponLog.setMessage(outParams);
......@@ -112,6 +113,7 @@ public class QPServiceImplAspect {
*/
@AfterThrowing(pointcut = "operExceptionLogPoinCut()", throwing = "e")
public void saveExceptionLog(JoinPoint joinPoint, Throwable e) {
CouponLog couponLog = new CouponLog();
try {
// 从切面织入点处通过反射机制获取织入点处的方法
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
......@@ -119,18 +121,21 @@ public class QPServiceImplAspect {
Method method = signature.getMethod();
//获得方法名
String methodName = method.getName();
CouponLog couponLog = new CouponLog();
// 将入参转换成json // 请求参数
String[] paramNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames();
String params = argsArrayToString(paramNames, joinPoint.getArgs());
//转JSON
JSONObject jsonObject = JSON.parseObject(params);
// if(methodName.equals("consume")) {
saveLog(couponLog, jsonObject);
couponLog.setStatus(YesNoEnum.no.getDisplay_3());
couponLog.setMessage(stackTraceToString(e.getClass().getName(), e.getMessage(), e.getStackTrace()));
couponLog.setNumber(TRY_NUMBER);
couponLog.setCreateTime(new Date());
// 异步执行
couponLog.setMessage(e.getMessage());
} catch (Exception e2) {
e2.printStackTrace();
} finally {
CompletableFuture.supplyAsync(() -> {
int i = couponLogService.insertCouponLog(couponLog);
if (i > 0) {
......@@ -139,9 +144,6 @@ public class QPServiceImplAspect {
return false;
}
});
// }
} catch (Exception e2) {
e2.printStackTrace();
}
}
......
......@@ -46,15 +46,14 @@ public class DeviceController extends BaseController {
/**
* 开门、关门、取电、断电
*/
@Log(title = "设备信息", businessType = BusinessType.UPDATE)
@PostMapping(value = "/openOrClose")
public AjaxResult openOrClose(@RequestBody DeviceParamVo deviceParam) {
SConsumer user = consumerService.getInfo();
// 获取mqtt的topic、payload
MqttxVo mqttxVo = mqttxService.openOrCloseDevice(deviceParam.getDevId(),
SecurityUtils.getUsername(), deviceParam.getOpType());
user.getAccount(), deviceParam.getOpType());
// 发送mqtt消息
mqttGatewayComponent.sendToMqtt(mqttxVo.getTopic(), 0, mqttxVo.getPayload());
SConsumer user = consumerService.getInfo();
// 写日志记录
int result = deviceLogService.addDeviceLog(mqttxVo, user.getAccount());
return toAjax(result);
......
package share.web.controller.system;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import share.common.core.domain.AjaxResult;
import share.common.core.domain.R;
import share.system.service.ISOrderService;
import share.system.service.OpenInterfaceService;
@RestController
@RequestMapping("/openInterface")
public class OpenInterfaceController {
@Autowired
private OpenInterfaceService openInterfaceService;
@GetMapping("/order/info")
public AjaxResult orderInfo(@RequestParam("orderNo") String orderNo) {
return AjaxResult.success(openInterfaceService.orderInfo(orderNo));
}
@RequestMapping(value = "/open/door", method = RequestMethod.GET)
public R<String> openDoor(@RequestParam("orderNo") String orderNo) {
return R.ok(openInterfaceService.openDoor(orderNo));
}
}
......@@ -38,14 +38,8 @@ public class SConsumerCouponController extends BaseController {
// @PreAuthorize("@ss.hasPermi('system:coupon:list')")
@GetMapping("/list")
public TableDataInfo list( String useStatus) {
SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
if(StringUtils.isNotBlank(useStatus)){
sConsumerCoupon.setUseStatus(Integer.valueOf(useStatus));
}
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
sConsumerCoupon.setConsumerId(user.getId());
startPage();
List<SConsumerCoupon> list = sConsumerCouponService.selectSConsumerCouponList(sConsumerCoupon);
List<SConsumerCoupon> list = sConsumerCouponService.listByUseStatus(Integer.valueOf(useStatus));
return getDataTable(list);
}
......
......@@ -77,12 +77,6 @@ public class SCouponController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody SCoupon sCoupon)
{
if (StringUtils.isBlank(sCoupon.getRoomType())) {
sCoupon.setRoomType(RoomType.getCodeList());
}
if (StringUtils.isBlank(sCoupon.getStoreType())) {
sCoupon.setStoreType(StoreType.getCodeList());
}
return toAjax(sCouponService.insertSCoupon(sCoupon));
}
......
package share.quartz.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import share.common.enums.ConsumerCouponStatusEnum;
import share.common.enums.UserStatusEnum;
import share.common.enums.YesNoEnum;
import share.system.domain.CouponLog;
import share.system.domain.SConsumerCoupon;
import share.system.domain.SStore;
import share.system.service.CouponLogService;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISStoreService;
import share.system.service.QPService;
import share.system.service.impl.QPServiceImpl;
import java.util.*;
import java.util.stream.Collectors;
@Component("couponRetryTask")
public class CouponRetryTask {
@Autowired
private CouponLogService couponLogService;
@Autowired
private QPService qpService;
@Autowired
private ISStoreService sStoreService;
@Autowired
private ISConsumerCouponService sConsumerCouponService;
private static final Logger logger = LoggerFactory.getLogger(QPServiceImpl.class);
private static final Integer TRY_NUMBER = 3;
public void AuToRetryCoupon() {
LambdaQueryWrapper<SConsumerCoupon> consumerCouponWrapper = new LambdaQueryWrapper<>();
consumerCouponWrapper.eq(SConsumerCoupon::getUseStatus, UserStatusEnum.UNUSED.getCode());
List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponService.list(consumerCouponWrapper);
List<SConsumerCoupon> expiredSConsumerCounpons = Optional.ofNullable(sConsumerCoupons).orElse(new ArrayList<>()).stream().filter(item -> {
if (item.getEndDate().compareTo(new Date()) < 0) {
item.setUseStatus(UserStatusEnum.EXPIRED.getCode());
return true;
}
return false;
}).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(expiredSConsumerCounpons)) {
sConsumerCouponService.updateBatchById(expiredSConsumerCounpons);
}
LambdaQueryWrapper<CouponLog> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CouponLog::getStatus, YesNoEnum.no.getDisplay_3());
queryWrapper.eq(CouponLog::getNumber, TRY_NUMBER);
List<CouponLog> list = couponLogService.list(queryWrapper);
if (CollectionUtils.isEmpty(list)) {
return;
}
//根据code分组
Map<String, List<CouponLog>> collect = list.stream().collect(Collectors.groupingBy(CouponLog::getCode));
//门店id集合
List<Long> storeIds = list.stream().map(CouponLog::getStoreId).distinct().collect(Collectors.toList());
List<SStore> sStoreList = sStoreService.listByIds(storeIds);
//遍历Map
collect.forEach((k, v) -> {
CouponLog couponLog = v.get(0);
SStore sStore = sStoreList.stream().filter(s -> s.getId().equals(couponLog.getStoreId())).findFirst().get();
if (couponLog.getNumber().equals(TRY_NUMBER)) {
for (int i = 0; i < TRY_NUMBER; i++) {
try {
qpService.consume(couponLog.getCode(), 1, sStore.getOpenShopUuid(), ConsumerCouponStatusEnum.TASK.getCode());
} catch (Exception e) {
logger.error("验卷失败:{}", e.getMessage());
} finally {
couponLog.setNumber(couponLog.getNumber() - 1);
couponLogService.updateById(couponLog);
}
}
//根据code批量更新状态
LambdaUpdateWrapper<CouponLog> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(CouponLog::getCode, k);
//设置number为0
updateWrapper.set(CouponLog::getNumber, 0);
couponLogService.update(updateWrapper);
//更新优惠卷领取状态
SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
sConsumerCoupon.setId(couponLog.getCouponId());
sConsumerCoupon.setUseStatus(UserStatusEnum.EXPIRED.getCode());
sConsumerCouponService.updateById(sConsumerCoupon);
}
});
}
}
......@@ -215,9 +215,11 @@ public class OrderTask {
// 退优惠券
if (ObjectUtil.isNotNull(sOrder.getCouponId())) {
SConsumerCoupon couponUser = consumerCouponService.getById(sOrder.getCouponId());
if(Objects.nonNull(couponUser)) {
couponUser.setUseStatus(CouponStatusEnum.NORMAL.getValue());
consumerCouponService.updateById(couponUser);
}
}
return true;
});
} catch (Exception e) {
......@@ -240,6 +242,12 @@ public class OrderTask {
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
String orderNo = jsonObject.getStr("orderNo");
SOrder byOrderNo = orderService.getByOrderNo(String.valueOf(orderNo));
if (ObjectUtil.isEmpty(byOrderNo)) {
redisUtil.delete(o);
logger.info("订单号为:" + jsonObject.getStr("orderNo") + "的订单不存在");
return;
}
//时间到期前10分钟到9分
long expire = (expirationTime.getTime() - new Date().getTime()) / 1000;
// if (expire < TEN_MINUTES && expire > NINE_MINUTES) {
......@@ -248,14 +256,14 @@ public class OrderTask {
// }
//判断时间是否在15分钟到14分钟
if (expire < FIFTEEN_MINUTES && expire > FOURTEEN_MINUTES) {
SOrder byOrderNo = orderService.getByOrderNo(String.valueOf(orderNo));
SStore sStore = storeService.getById(byOrderNo.getStoreId());
SRoom sRoom = roomService.getById(byOrderNo.getRoomId());
smsService.sendSmsOrderStartRemind(byOrderNo.getConsumerPhone(), sStore, sRoom);
// SStore sStore = storeService.getById(byOrderNo.getStoreId());
// SRoom sRoom = roomService.getById(byOrderNo.getRoomId());
// smsService.sendSmsOrderStartRemind(byOrderNo.getConsumerPhone(), sStore, sRoom);
logger.info("订单号为:" + jsonObject.getStr("orderNo") + "的订单开始预定时间到15分钟");
return;
}
if (expirationTime.getTime() < new Date().getTime()) {
sOrders.add(orderService.getByOrderNo(String.valueOf(orderNo)));
sOrders.add(byOrderNo);
}
});
if (CollectionUtils.isEmpty(sOrders)) {
......
......@@ -209,6 +209,7 @@ public class RedisTask {
SOrder sOrder = sOrders.stream().filter(item -> item.getOrderNo().equals(jsonObject.getStr("orderNo"))).findFirst().orElse(null);
if (ObjectUtils.isEmpty(sOrder)) {
redisUtil.delete(o);
logger.info("订单号为:" + jsonObject.getStr("orderNo") + "的订单不存在");
throw new BaseException("订单不存在!");
}
long expire = (expirationTime.getTime() - new Date().getTime()) / 1000;
......@@ -218,18 +219,18 @@ public class RedisTask {
deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.RENEWAL_REMINDER1.getCode(),
DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
DateUtil.format(DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
logger.info("订单号为:" + sOrder.getOrderNo() + "的订单距离结束时间还有15分钟");
//从门店集合中判断门店id相同的门店对象
SStore sStore = sStoreList.stream().filter(item -> item.getId().equals(sOrder.getStoreId())).findFirst().orElse(null);
// SStore sStore = sStoreList.stream().filter(item -> item.getId().equals(sOrder.getStoreId())).findFirst().orElse(null);
//从房间集合中判断房间id相同的房间对象
SRoom sRoom = sRoomList.stream().filter(item -> item.getId().equals(sOrder.getRoomId())).findFirst().orElse(null);
// smsService.sendSmsCleanRecordsRemind15(byOrderNo.getConsumerPhone(), sStore, sRoom);
// SRoom sRoom = sRoomList.stream().filter(item -> item.getId().equals(sOrder.getRoomId())).findFirst().orElse(null);
//通知用户
smsService.sendSmsOrderEndRemind(sOrder.getConsumerPhone(), sStore, sRoom);
//通知保洁人员
sConsumerService.selectListByStoreId(sOrder.getStoreId()).stream().forEach(item -> {
// 循环发送短信提示门店保洁打扫卫生
smsService.sendSmsCleanRecordsRemind15(item.getPhone(), sStore, sRoom);
});
// smsService.sendSmsOrderEndRemind(sOrder.getConsumerPhone(), sStore, sRoom);
// //通知保洁人员
// sConsumerService.selectListByStoreId(sOrder.getStoreId()).stream().forEach(item -> {
// // 循环发送短信提示门店保洁打扫卫生
// smsService.sendSmsCleanRecordsRemind15(item.getPhone(), sStore, sRoom);
// });
return;
}
//判断时间是否在5分钟到4分钟
......@@ -238,6 +239,7 @@ public class RedisTask {
deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.RENEWAL_REMINDER2.getCode(),
DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
DateUtil.format(DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
logger.info("订单号为:" + sOrder.getOrderNo() + "的订单距离结束时间还有5分钟");
}
//判断是否过期
if (expirationTime.getTime() < new Date().getTime()) {
......@@ -268,7 +270,7 @@ public class RedisTask {
DateUtil.format(DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
//延时3分钟断电
deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(), OpTypeEnum.CUT_ELECTRIC.getCode(), true, THREE_MINUTES);
logger.info("订单号为:" + sOrder.getOrderNo() + "的订单已结束,更改订单状态为已使用");
}
});
......@@ -289,6 +291,7 @@ public class RedisTask {
//更改订单状态
sOrder.setStatus(OrderStatusEnum.USED.getCode());
isOrderService.updateById(sOrder);
logger.info("订单号为:" + sOrder.getOrderNo() + "的订单已有续单,更改订单状态为已使用");
return true;
}
return false;
......
......@@ -52,6 +52,12 @@ public class CouponLog extends BaseEntity {
private Long couponId;
/**
* 数量
*/
@Excel(name = "数量")
private Integer number;
/**
* 优惠券名称
*/
@Excel(name = "优惠券名称")
......@@ -81,25 +87,20 @@ public class CouponLog extends BaseEntity {
@Excel(name = "消息")
private String message;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("code", getCode())
.append("consumerId", getConsumerId())
.append("storeId", getStoreId())
.append("couponId", getCouponId())
.append("couponName", getCouponName())
.append("couponType", getCouponType())
.append("couponValue", getCouponValue())
.append("status", getStatus())
.append("message", getMessage())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
return "CouponLog{" +
"id=" + id +
", code='" + code + '\'' +
", consumerId=" + consumerId +
", storeId=" + storeId +
", couponId=" + couponId +
", number=" + number +
", couponName='" + couponName + '\'' +
", couponType='" + couponType + '\'' +
", couponValue=" + couponValue +
", status='" + status + '\'' +
", message='" + message + '\'' +
'}';
}
}
......@@ -48,6 +48,18 @@ public class SConsumerCoupon extends BaseEntity
@Excel(name = "套餐ID")
private Long dealId;
/**
* 团购ID
*/
@Excel(name = "团购ID")
private Long dealgroupId;
/**
* 适用门店id
*/
@Excel(name = "适用门店id")
private String storeIds;
/** 优惠券编码 */
@Excel(name = "优惠券编码")
private String couponCode;
......@@ -143,6 +155,12 @@ public class SConsumerCoupon extends BaseEntity
@TableField(select = false)
private Integer isDelete;
/**
* 适用星期列表(1:周一,2:周二,3:周三,4:周四,5:周五,6:周六,7:周日)
*/
@Excel(name = "适用星期列表")
private String weeks;
/** 更新者 */
@Excel(name = "更新者")
private String deleteBy;
......@@ -164,4 +182,16 @@ public class SConsumerCoupon extends BaseEntity
*/
@TableField(select = false)
private String reason;
/**
* 手机号
*/
@TableField(select = false)
private String phone;
/**
* 昵称
*/
@TableField(select = false)
private String nickName;
}
......@@ -95,11 +95,29 @@ public class SCoupon extends BaseEntity
@Excel(name = "绑定套餐ID")
private Long packageId;
/**
* 团购ID
*/
@Excel(name = "团购ID")
private Long dealgroupId;
/**
* 适用门店id
*/
@Excel(name = "适用门店id")
private String storeIds;
/** 是否可叠加使用(0:不可叠加,1:可叠加) */
@Excel(name = "是否可叠加使用(0:不可叠加,1:可叠加)")
private Integer isOverlay;
/**
* 适用星期列表(1:周一,2:周二,3:周三,4:周四,5:周五,6:周六,7:周日)
*/
@Excel(name = "适用星期列表")
private String weeks;
/**
* 第三方平台类型(1:自营,2:美团)
*/
@Excel(name = "第三方平台类型(1:自营,2:美团)")
......
package share.system.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
public class OrderVo {
/**
* 订单编号
*/
private String orderNo;
/**
* 支付类型(1:微信,2:支付宝)
*/
private Integer payType;
/**
* 支付时间
*/
private Date payTime;
/**
* 订单时长
*/
private String timeLong;
/**
* 预约开始时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private Date preStartDate;
/**
* 预约结束时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private Date preEndDate;
/**
* 开始时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private Date startDate;
/**
* 结束时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private Date endDate;
/**
* 门店名称
*/
private String storeName;
/**
* 房间名称
*/
private String roomName;
//房间图片
private String roomImages;
//房间类型
private String roomType;
//房间类型名称
private String roomTypeName;
/**
* 门店地址
*/
private String address;
/**
* 经度
*/
private String longitude;
/**
* 纬度
*/
private String latitude;
//是否可以申请退款
private Boolean isRefund;
//套餐名称
private String packName;
//优惠卷名称
private String couponName;
//订单状态
private Integer orderType;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
private Integer status;
}
......@@ -62,4 +62,10 @@ public interface SCouponMapper
List<SCoupon> selectSCouponByName(String dealTitle);
List<SCoupon> selectSCouponByIds(Long[] couponIds);
List<SCoupon> listDuration(SCoupon sCoupon);
List<SCoupon> selectSCouponByDealgroupId(Long dealgroupId);
SCoupon selectByDealgroupId(Long dealgroupId);
}
......@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import share.common.annotation.Excel;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
......@@ -29,6 +30,13 @@ public class CouponRequest {
@NotNull(message = "下单模式不能为空")
private Integer orderMode;
@ApiModelProperty(value = "下单类型(1:预定,2:续单)", required = true)
@NotNull(message = "下单类型不能为空")
private Integer orderType;
@ApiModelProperty(value = "套餐ID")
private Long packageId;
/**
* 预约开始时间
*/
......
......@@ -28,6 +28,13 @@ public interface ISConsumerCouponService extends IService<SConsumerCoupon>
* @return 优惠券领取记录集合
*/
public List<SConsumerCoupon> selectSConsumerCouponList(SConsumerCoupon sConsumerCoupon);
/**
* 查询优惠券领取记录列表
*
* @param useStatus 优惠券领取记录
* @return 优惠券领取记录集合
*/
public List<SConsumerCoupon> listByUseStatus(Integer useStatus);
/**
* 新增优惠券领取记录
......
......@@ -2,6 +2,7 @@ package share.system.service;
import java.util.List;
import share.system.domain.SConsumptionRecords;
import share.system.domain.SOrder;
import share.system.domain.vo.SConsumptionRecordsVo;
/**
......@@ -37,6 +38,13 @@ public interface ISConsumptionRecordsService
public int insertSConsumptionRecords(SConsumptionRecords sConsumptionRecords);
/**
* 新增消费记录
*
* @param sOrder 消费记录
* @return 结果
*/
public int insertSConsumptionRecords(SOrder sOrder);
/**
* 修改消费记录
*
* @param sConsumptionRecords 消费记录
......
......@@ -67,4 +67,10 @@ public interface ISCouponService
List<SCoupon> selectSCouponByName(String dealTitle);
List<SCoupon> selectSCouponByIds(Long[] couponIds);
List<SCoupon> queryShopDeal();
List<SCoupon> listDuration(SCoupon sCoupon);
List<SCoupon> selectSCouponByDealgroupId(Long dealgroupId);
}
......@@ -4,7 +4,9 @@ import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.SConsumerCoupon;
import share.system.domain.SOrder;
import share.system.domain.vo.OrderVo;
import share.system.domain.vo.SOrderVo;
import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest;
......@@ -171,4 +173,11 @@ public interface ISOrderService extends IService<SOrder>
* @return
*/
List<SOrder> payedUnrefundListByUserId(Long userId);
boolean isRefund(SOrderVo orderVo, SConsumerCoupon coupon);
boolean isRefund(SOrder order, SConsumerCoupon coupon);
}
package share.system.service;
import share.system.domain.vo.OrderVo;
public interface OpenInterfaceService {
OrderVo orderInfo(String orderNo);
String openDoor(String orderNo);
}
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.enums.DeviceType;
import share.common.enums.RoomType;
import share.common.exception.base.BaseException;
import share.common.utils.bean.BeanUtils;
import share.system.domain.*;
import share.system.domain.vo.OrderVo;
import share.system.domain.vo.SRoomVo;
import share.system.service.*;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class OpenInterfaceServiceImpl implements OpenInterfaceService {
@Autowired
private ISConsumerCouponService consumerCouponService;
@Autowired
private ISStoreService storeService;
@Autowired
private ISRoomService roomService;
@Autowired
private ISOrderService orderService;
@Autowired
private IPackService packService;
@Autowired
private DeviceService deviceService;
@Autowired
private DeviceOpService deviceOpService;
@Override
public OrderVo orderInfo(String orderNo) {
SOrder en = orderService.getByOrderNo(orderNo);
OrderVo vo = new OrderVo();
BeanUtils.copyProperties(en, vo);
SStore store = storeService.getById(en.getStoreId());
SRoom room = roomService.getById(en.getRoomId());
vo.setStoreName(store.getName());
vo.setAddress(store.getAddress());
vo.setRoomImages(room.getImages());
vo.setRoomName(room.getName());
vo.setRoomType(room.getRoomType());
vo.setRoomTypeName(RoomType.getNameByCode(room.getRoomType()));
vo.setLongitude(store.getLongitude());
vo.setLatitude(store.getLatitude());
if (ObjectUtil.isNotEmpty(en.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(en.getCouponId());
vo.setCouponName(consumerCoupon.getName());
// 判断是否可以退款
vo.setIsRefund(orderService.isRefund(en, consumerCoupon));
} else {
// 判断是否可以退款
vo.setIsRefund(orderService.isRefund(en, null));
}
if (ObjectUtil.isNotEmpty(en.getPackId())) {
SPack byId = packService.getById(en.getPackId());
vo.setPackName(byId.getName());
}
return vo;
}
@Override
public String openDoor(String orderNo) {
LambdaQueryWrapper<SOrder> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
orderLambdaQueryWrapper.eq(SOrder::getOrderNo, orderNo);
SOrder sOrder = orderService.getOne(orderLambdaQueryWrapper);
if (Objects.isNull(sOrder)) {
throw new BaseException("订单不存在!");
}
SRoomVo sRoomVo = roomService.selectSRoomById(sOrder.getRoomId());
if (Objects.isNull(sRoomVo)) {
throw new BaseException("房间不存在!");
}
LambdaQueryWrapper<Device> deviceLambdaQueryWrapper = new LambdaQueryWrapper<>();
deviceLambdaQueryWrapper.eq(Device::getRoomId, sOrder.getRoomId());
deviceLambdaQueryWrapper.in(Device::getDevType, DeviceType.DEVICE_CCEE.getCode(), DeviceType.DEVICE_0001.getCode());
List<Device> deviceList = deviceService.list(deviceLambdaQueryWrapper);
if (CollectionUtils.isEmpty(deviceList)) {
throw new BaseException("房间设备缺失!");
}
if (deviceList.stream().filter(device ->
device.getDevType().equals(DeviceType.DEVICE_CCEE.getCode())
).collect(Collectors.toList()).isEmpty()) {
throw new BaseException("房间门锁设备不存在!");
}
if (deviceList.stream().filter(item ->
item.getDevType().equals(DeviceType.DEVICE_0001.getCode())
).collect(Collectors.toList()).isEmpty()) {
throw new BaseException("房间取电设备不存在!");
}
deviceOpService.openDoor(sRoomVo.getId(), sOrder.getConsumerPhone());
return "开锁成功";
}
}
......@@ -81,13 +81,17 @@ public class QPServiceImpl implements QPService {
//默认门槛金额
private static final BigDecimal DEFAULT_MIN_PRICE = BigDecimal.valueOf(0.00);
private static final String ACCOUNT = "13888888888";
private static final String NAME = "管理人员";
/**
* 用户验卷接口
*/
@Override
public TuangouReceiptPrepareResponseEntityVo consumeByUser(String code, String openShopUuid, String status) {
//验券准备
TuangouReceiptPrepareResponseEntity prepare = prepare(code, openShopUuid, status);
TuangouReceiptPrepareResponseEntity prepare = prepare(code.trim(), openShopUuid, status);
//获取用户信息
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
//查询领取记录表
......@@ -99,6 +103,12 @@ public class QPServiceImpl implements QPService {
LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
sStoreLambdaQueryWrapper.eq(SStore::getOpenShopUuid, openShopUuid);
SStore sStore = storeService.getOne(sStoreLambdaQueryWrapper);
if (ObjectUtils.isEmpty(sStore)) {
throw new RuntimeException("门店不存在");
}
if (sStore.getStatus().equals(StoreStatusEnum.STOP.getIndex())) {
throw new RuntimeException("门店已停止");
}
if (ObjectUtils.isNotEmpty(couponTwo)) {
//判断是否本人领取过
if (couponTwo.getConsumerId().equals(user.getId())) {
......@@ -114,8 +124,8 @@ public class QPServiceImpl implements QPService {
TuangouReceiptPrepareResponseEntityVo response = new TuangouReceiptPrepareResponseEntityVo();
SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
sConsumerCoupon.setConsumerId(user.getId());
sConsumerCoupon.setStoreId(sStore.getId());
sConsumerCoupon.setDealId(prepare.getDeal_id());
sConsumerCoupon.setStoreId(sStore.getId());
sConsumerCoupon.setCouponCode(code);
sConsumerCoupon.setName(prepare.getDeal_title());
sConsumerCoupon.setSourceType(SourceTypeEnum.CHECK.getCode());
......@@ -141,10 +151,10 @@ public class QPServiceImpl implements QPService {
}
});
List<SCoupon> sCoupons = isCouponService.selectSCouponByName(prepare.getDeal_title());
List<SCoupon> sCoupons = isCouponService.selectSCouponByDealgroupId(prepare.getDealgroup_id());
SCoupon sCoupon = null;
if (!CollectionUtils.isEmpty(sCoupons)) {
sCoupon = isCouponService.selectSCouponByName(prepare.getDeal_title()).get(0);
sCoupon = sCoupons.get(0);
}
if (ObjectUtils.isEmpty(sCoupon)) {
sConsumerCoupon.setCouponType(CouponTypeEnum.CASH.getCode());
......@@ -169,7 +179,10 @@ public class QPServiceImpl implements QPService {
sConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime());
sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime());
sConsumerCoupon.setOrderType(sCoupon.getOrderType());
sConsumerCoupon.setDealgroupId(sCoupon.getDealgroupId());
sConsumerCoupon.setStoreIds(sCoupon.getStoreIds());
sConsumerCoupon.setPackageId(sCoupon.getPackageId());
sConsumerCoupon.setWeeks(sCoupon.getWeeks());
sConsumerCoupon.setRemark(sCoupon.getRemark());
}
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon);
......@@ -253,12 +266,19 @@ public class QPServiceImpl implements QPService {
String session = (String) sessionKey.get("access_token");
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
String requestid = UUID.randomUUID().toString();
TuangouReceiptConsumeRequest request = new TuangouReceiptConsumeRequest(APP_KEY, APP_SECRET, session,
TuangouReceiptConsumeRequest request = null;
if (ObjectUtils.isEmpty(user)) {
request = new TuangouReceiptConsumeRequest(APP_KEY, APP_SECRET, session,
requestid, code, count, "", ACCOUNT, NAME, openShopUuid);
} else {
request = new TuangouReceiptConsumeRequest(APP_KEY, APP_SECRET, session,
requestid, code, count, "", user.getAccount(), user.getNickName(), openShopUuid);
}
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouReceiptConsume tuangouReceiptConsume = new TuangouReceiptConsume(request);
TuangouReceiptConsumeResponse invoke = openAPIClient.invoke(tuangouReceiptConsume);
if (invoke.getCode() != 200) {
redisUtil.delete(ReceiptRdeisEnum.PREPARE.getValue() + code);
logger.error("验卷失败:{}", invoke.getMsg());
throw new RuntimeException(invoke.getMsg());
}
......@@ -339,8 +359,9 @@ public class QPServiceImpl implements QPService {
TuangouDealQueryShopDeal tuangouDealQueryShopDeal = new TuangouDealQueryShopDeal(request);
TuangouDealQueryShopDealResponse response = openAPIClient.invoke(tuangouDealQueryShopDeal);
if (response.getCode() != 200) {
throw new RuntimeException(response.getMsg());
logger.error("门店团购信息:{}", response.getMsg());
}
logger.error("门店团购信息:{}", response.getData());
return response.getData();
}
......@@ -386,10 +407,13 @@ public class QPServiceImpl implements QPService {
JSONObject sessionKey = new JSONObject(o);
String session = (String) sessionKey.get("access_token");
String bid = (String) sessionKey.get("bid");
// CustomerKeyShopScopeRequest request = new CustomerKeyShopScopeRequest(APP_KEY, APP_SECRET, "13ff8a38219075fafbbdeea6839450ed6bea1b9b","f1fd23c1c413862137b895bdcfc10ef8");
CustomerKeyShopScopeRequest request = new CustomerKeyShopScopeRequest(APP_KEY, APP_SECRET, session, bid);
CustomerKeyShopScopeQuery shopScopeQuery = new CustomerKeyShopScopeQuery(request);
CustomerKeyShopScopeResponse response = openAPIClient.invoke(shopScopeQuery);
if (response.getCode() != 200) {
logger.error("适用店铺查询接口:{}", response.getMsg());
throw new RuntimeException(response.getMsg());
}
return response.getData();
}
......
......@@ -87,47 +87,68 @@ public class RoomStatusServiceImpl implements RoomStatusService {
//设置时间段房间可预约状态(可预约:大于营业开始时间,小于营业结束时间,大于当前时间,当前时间没有订单)
private void setTimeHourStatus(RoomStatusVo vo,Date timeHourDate, SStore store, List<SOrder> orderList, String day, String finalNowTime, Boolean isToday, Integer orderType){
vo.setStatus(RoomStatusEnum.FREE.getValue());
checkTimeHourToSysDate(vo,timeHourDate,day,finalNowTime,isToday);
checkTimeHourToBusiness(vo,timeHourDate,store,day);
checkTimeHourToOrder(vo,timeHourDate,orderList,orderType);
}
private void changeEndHoldTime(RoomStatusVo vo, Date date){
if(Objects.isNull(vo.getEndHoldTime())||vo.getEndHoldTime().compareTo(date)<0){
vo.setEndHoldTime(date);
}
}
private void changeStartHoldTime(RoomStatusVo vo, Date date){
if(Objects.isNull(vo.getStartHoldTime())||vo.getStartHoldTime().compareTo(date)>0){
vo.setStartHoldTime(date);
}
}
private void checkTimeHourToBusiness(RoomStatusVo vo,Date timeHourDate, SStore store, String day){
//门店存在营业时间
if(StringUtils.isNotBlank(store.getOpenStartTime())) {
//当前时段小于营业开始时间
if (timeHourDate.compareTo(DateUtils.parseDate(day + " " + store.getOpenStartTime())) == -1) {
vo.setStatus(RoomStatusEnum.HOLD.getValue());
vo.setStartHoldTime(timeHourDate);
changeStartHoldTime(vo,timeHourDate);
//判断是否是同一个小时,如果是同一个小时,占用结束时间为营业开始时间
if (timeHourDate.compareTo(DateUtils.parseDate(day + " " + store.getOpenStartTime().split(":")[0])) == 0) {
vo.setEndHoldTime(DateUtils.parseDate(day + " " + store.getOpenStartTime()));
changeEndHoldTime(vo,DateUtils.parseDate(day + " " + store.getOpenStartTime()));
} else {
//占用结束时间为当前时段59分59秒
vo.setEndHoldTime(DateUtils.addSeconds(timeHourDate, 59 * 60 + 59));
changeEndHoldTime(vo,DateUtils.addSeconds(timeHourDate, 59 * 60 + 59));
}
}
//当前时段大于营业结束时间
if (timeHourDate.compareTo(DateUtils.parseDate(day + " " + store.getOpenEndTime())) == 1 && !StringUtils.equals(store.getOpenStartTime(),"00:00")) {
vo.setStatus(RoomStatusEnum.HOLD.getValue());
//占用结束时间为当前时段59分59秒
vo.setEndHoldTime(DateUtils.addSeconds(timeHourDate, 59 * 60 + 59));
changeEndHoldTime(vo,DateUtils.addSeconds(timeHourDate, 59 * 60 + 59));
//判断是否是同一个小时,如果是同一个小时,占用开始时间为营业结束时间
if (timeHourDate.compareTo(DateUtils.parseDate(day + " " + store.getOpenEndTime().split(":")[0])) == 0) {
vo.setStartHoldTime(DateUtils.parseDate(day + " " + store.getOpenEndTime()));
changeStartHoldTime(vo,DateUtils.parseDate(day + " " + store.getOpenEndTime()));
} else {
//占用开始时间为当前时段0分0秒
vo.setStartHoldTime(timeHourDate);
changeStartHoldTime(vo,timeHourDate);
}
}
}
}
private void checkTimeHourToSysDate(RoomStatusVo vo,Date timeHourDate, String day, String finalNowTime, Boolean isToday){
//当前时段小于当前时间
if(isToday && timeHourDate.compareTo(DateUtils.parseDate(day+" "+ finalNowTime))==-1){
vo.setStatus(RoomStatusEnum.HOLD.getValue());
vo.setStartHoldTime(timeHourDate);
changeStartHoldTime(vo,timeHourDate);
//判断是否是同一个小时,如果是同一个小时,占用结束时间为当前时间
if(timeHourDate.compareTo(DateUtils.parseDate(day+" "+finalNowTime.split(":")[0])) == 0){
vo.setEndHoldTime(DateUtils.parseDate(day+" "+finalNowTime));
changeEndHoldTime(vo,DateUtils.parseDate(day+" "+finalNowTime));
}else {
//占用结束时间为当前时段59分59秒
vo.setEndHoldTime(DateUtils.addSeconds(timeHourDate, 59 * 60 + 59));
changeEndHoldTime(vo,DateUtils.addSeconds(timeHourDate, 59 * 60 + 59));
}
}
checkTimeHourToOrder(vo,timeHourDate,orderList,orderType);
}
private void checkTimeHourToOrder(RoomStatusVo vo,Date timeHourDate, List<SOrder> orderList, Integer orderType){
......@@ -149,18 +170,18 @@ public class RoomStatusServiceImpl implements RoomStatusService {
//判断订单开始时间是否是同一个小时,如果是同一个小时,占用开始时间为订单开始时间
if(StringUtils.equals(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH,timeHourDate)
,DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH,orderStartDate))){
vo.setStartHoldTime(orderStartDate);
changeStartHoldTime(vo,orderStartDate);
}else {
//占用开始时间为当前时段0分0秒
vo.setStartHoldTime(timeHourDate);
changeStartHoldTime(vo,timeHourDate);
}
//判断订单结束时间是否是同一个小时,如果是同一个小时,占用结束时间为订单结束时间
if(StringUtils.equals(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH,timeHourDate)
,DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH,orderEndDate))){
vo.setEndHoldTime(orderEndDate);
changeEndHoldTime(vo,orderEndDate);
}else {
//占用结束时间为当前时段59分59秒
vo.setEndHoldTime(DateUtils.addSeconds(timeHourDate, 59 * 60 + 59));
changeEndHoldTime(vo,DateUtils.addSeconds(timeHourDate, 59 * 60 + 59));
}
}
});
......
......@@ -199,7 +199,7 @@ public class SCleanRecordsServiceImpl extends ServiceImpl<SCleanRecordsMapper,SC
public boolean finishCleanRecords() {
Date now = DateUtil.date();
LambdaQueryWrapper<SCleanRecords> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SCleanRecords::getStatus,0);
queryWrapper.in(SCleanRecords::getStatus, CleaningStatusEnum.UNCLEAN.getCode(), CleaningStatusEnum.CLEANING.getCode());
queryWrapper.le(SCleanRecords::getCreateTime, DateUtil.offsetMinute(now, -Constants.ROOM_LOCK_DELAY_MINUTE));
List<SCleanRecords> list = baseMapper.selectList(queryWrapper);
if (list.size() == 0) {
......
......@@ -2,11 +2,11 @@ package share.system.service.impl;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -16,14 +16,12 @@ import share.common.enums.*;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.utils.StringUtils;
import share.system.domain.*;
import share.system.domain.vo.FrontTokenComponent;
import share.system.mapper.SConsumerCouponMapper;
import share.system.request.CouponRequest;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISCouponService;
import share.system.service.ISRoomService;
import share.system.service.ISStoreService;
import share.system.service.*;
/**
* 优惠券领取记录Service业务层处理
......@@ -33,8 +31,6 @@ import share.system.service.ISStoreService;
*/
@Service
public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMapper, SConsumerCoupon> implements ISConsumerCouponService {
@Autowired
private SConsumerCouponMapper sConsumerCouponMapper;
@Autowired
private ISRoomService sRoomService;
......@@ -45,6 +41,13 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
@Autowired
private ISCouponService sCouponService;
@Autowired
private IPackService packService;
@Autowired
private SConsumerService sConsumerService;
private static final Integer ZERO = 0;
/**
......@@ -55,7 +58,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
*/
@Override
public SConsumerCoupon selectSConsumerCouponById(Long id) {
return sConsumerCouponMapper.selectSConsumerCouponById(id);
return baseMapper.selectSConsumerCouponById(id);
}
/**
......@@ -66,18 +69,36 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
*/
@Override
public List<SConsumerCoupon> selectSConsumerCouponList(SConsumerCoupon sConsumerCoupon) {
List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponMapper.selectSConsumerCouponList(sConsumerCoupon);
List<SConsumerCoupon> sConsumerCoupons = baseMapper.selectSConsumerCouponList(sConsumerCoupon);
sConsumerCoupons.forEach(item -> {
if (item.getUseStatus().equals(UserStatusEnum.UNUSED.getCode())) {
if (item.getEndDate().compareTo(new Date()) < 0) {
item.setUseStatus(UserStatusEnum.EXPIRED.getCode());
sConsumerCouponMapper.updateSConsumerCoupon(item);
List<SConsumer> list = sConsumerService.list();
if (list.stream().filter(obj -> obj.getId().equals(item.getConsumerId())).findFirst().isPresent()) {
item.setPhone(list.stream().filter(obj -> obj.getId().equals(item.getConsumerId())).findFirst().get().getPhone());
if (StringUtils.isNotBlank(list.stream().filter(obj -> obj.getId().equals(item.getConsumerId())).findFirst().get().getNickName())) {
item.setNickName(list.stream().filter(obj -> obj.getId().equals(item.getConsumerId())).findFirst().get().getNickName());
}
}
});
return sConsumerCoupons;
}
@Override
public List<SConsumerCoupon> listByUseStatus(Integer useStatus) {
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<SConsumerCoupon>();
queryWrapper.eq(SConsumerCoupon::getConsumerId,user.getId());
queryWrapper.eq(SConsumerCoupon::getUseStatus,useStatus);
if(UserStatusEnum.EXPIRED.getCode().compareTo(useStatus)==0){
//已过期查询3个月以内的
queryWrapper.gt(SConsumerCoupon::getEndDate,DateUtils.addMonths(new Date(),-3));
}
queryWrapper.orderByDesc(SConsumerCoupon::getCreateTime);
List<SConsumerCoupon> sConsumerCoupons = baseMapper.selectList(queryWrapper);
return sConsumerCoupons;
}
/**
* 新增优惠券领取记录
*
......@@ -88,7 +109,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
public int insertSConsumerCoupon(SConsumerCoupon sConsumerCoupon) {
sConsumerCoupon.setCreateTime(DateUtils.getNowDate());
sConsumerCoupon.setUseStatus(UserStatusEnum.UNUSED.getCode());
return sConsumerCouponMapper.insertSConsumerCoupon(sConsumerCoupon);
return baseMapper.insertSConsumerCoupon(sConsumerCoupon);
}
/**
......@@ -100,7 +121,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
@Override
public int updateSConsumerCoupon(SConsumerCoupon sConsumerCoupon) {
sConsumerCoupon.setUpdateTime(DateUtils.getNowDate());
return sConsumerCouponMapper.updateSConsumerCoupon(sConsumerCoupon);
return baseMapper.updateSConsumerCoupon(sConsumerCoupon);
}
/**
......@@ -113,7 +134,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
public int deleteSConsumerCouponByIds(Long[] ids) {
LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SConsumerCoupon::getId, ids);
List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponMapper.selectList(queryWrapper);
List<SConsumerCoupon> sConsumerCoupons = baseMapper.selectList(queryWrapper);
//获取sConsumerCoupons里的优惠券id
Long[] couponIds = sConsumerCoupons.stream().map(SConsumerCoupon::getCouponId).toArray(Long[]::new);
//根据优惠券id查询优惠券信息
......@@ -128,7 +149,7 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
}
});
return sConsumerCouponMapper.deleteSConsumerCouponByIds(ids);
return baseMapper.deleteSConsumerCouponByIds(ids);
}
/**
......@@ -139,12 +160,12 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
*/
@Override
public int deleteSConsumerCouponById(Long id) {
return sConsumerCouponMapper.deleteSConsumerCouponById(id);
return baseMapper.deleteSConsumerCouponById(id);
}
@Override
public int selectSConsumerCouponConut(SConsumerCoupon sConsumerCoupon) {
return sConsumerCouponMapper.selectSConsumerCouponConut(sConsumerCoupon);
return baseMapper.selectSConsumerCouponConut(sConsumerCoupon);
}
@Override
......@@ -154,9 +175,9 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
sConsumerCoupon.setUseStatus(ConsumerCouponUseStatusEnum.WAIT_USE.getCode());
sConsumerCoupon.setConsumerId(user.getId());
//查询用户未使用的优惠券
List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponMapper.querySConsumerCouponList(sConsumerCoupon);
List<SConsumerCoupon> sConsumerCoupons = baseMapper.querySConsumerCouponList(sConsumerCoupon);
//计算时长
BigDecimal bigDecimal = DateUtils.differentHour(couponRequest.getPreStartDate(), couponRequest.getPreEndDate());
BigDecimal timeLong = DateUtils.differentHour(couponRequest.getPreStartDate(), couponRequest.getPreEndDate());
if (CollectionUtils.isEmpty(sConsumerCoupons)) {
return sConsumerCoupons;
}
......@@ -164,45 +185,171 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
List<SStore> sStores = sStoreService.list();
//查询所有房间
List<SRoom> sRooms = sRoomService.list();
//查询所有的套餐
List<SPack> sPacks = packService.list();
//迭代
sConsumerCoupons.forEach(item -> {
if (item.getStartDate().compareTo(couponRequest.getPreStartDate()) <= 0 && item.getEndDate().compareTo(couponRequest.getPreEndDate()) >= 0) {
SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm");
String proStartTime = sdf1.format(couponRequest.getPreStartDate());
if (proStartTime.compareTo(item.getCouponTimeStart()) >= 0) {
checkCoupon(item,couponRequest,sStores,sRooms,sPacks,timeLong);
});
return sConsumerCoupons;
}
private Boolean checkCoupon(SConsumerCoupon item, CouponRequest couponRequest
, List<SStore> sStores, List<SRoom> sRooms, List<SPack> sPacks, BigDecimal timeLong){
item.setIsAvailable(AvailableEnum.AVAILABLE.getCode());
return checkAvailableDate(item,couponRequest)
&&checkCouponPeriod(item,couponRequest)
&&checkStore(item,couponRequest,sStores)
&&checkCouponType(item,couponRequest,sStores,sRooms,timeLong)
&&checkOrderType(item,couponRequest)
&&checkPack(item,couponRequest,sPacks)
&&chekcWeeks(item,couponRequest);
}
private Boolean chekcWeeks(SConsumerCoupon item, CouponRequest couponRequest) {
if(StringUtils.isNotBlank(item.getWeeks())) {
Integer startWeek = DateUtil.dayOfWeek(DateUtils.addDays(couponRequest.getPreStartDate(), -1));
Integer endWeek = DateUtil.dayOfWeek(DateUtils.addDays(couponRequest.getPreEndDate(), -1));
ArrayList<Integer> weeks = (ArrayList<Integer>) Arrays.stream(item.getWeeks().split(","))
.map(Integer::parseInt).collect(Collectors.toList());
if(!weeks.contains(startWeek)||!weeks.contains(endWeek)){
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
if(checkIfArrayIsContinuous(weeks.stream().mapToInt(i->i.intValue()).toArray())){
if(weeks.size()==1) {
item.setReason("优惠卷" + WeekEnum.getValueByCode(weeks.get(0)) + "可用");
}else if(WeekEnum.isSundays(weeks)){
item.setReason("优惠卷周末可用");
}else if(WeekEnum.isAllWorkDays(weeks)){
item.setReason("优惠卷周一至周五可用");
}else{
item.setReason("优惠卷" + WeekEnum.getValueByCode(weeks.get(0)) + "至" +WeekEnum.getValueByCode(weeks.get(weeks.size()-1))+ "可用");
}
}else{
StringBuffer buf = new StringBuffer("优惠券");
for(int index=0;index<weeks.size();index++){
buf.append(WeekEnum.getValueByCode(weeks.get(index)));
if (index < weeks.size()) {
buf.append("可用");
//最后一个不加逗号
if (index < weeks.size() - 1) {
buf.append(",");
}
}
}
item.setReason(buf.toString());
}
}
}
return item.getIsAvailable() == 0;
}
private static boolean checkIfArrayIsContinuous(int[] array) {
if (array == null || array.length < 2) {
return true; // 空数组或只有一个元素时认为是连续的
}
Arrays.sort(array); // 先对数组进行排序
for (int i = 0; i < array.length - 1; i++) {
if (array[i] != array[i+1]) {
return false; // 如果相邻两个元素之间存在跨度大于1的情况则返回false
}
}
return true; // 没有发现跨度大于1的情况则返回true
}
private Boolean checkPack(SConsumerCoupon item, CouponRequest couponRequest, List<SPack> sPacks){
if(Objects.nonNull(item.getPackageId())&&item.getPackageId().compareTo(couponRequest.getPackageId())!=0){
SPack pack = sPacks.stream().filter(obj -> obj.getId().compareTo(item.getPackageId())==0).findFirst().orElse(null);
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("优惠卷当前套餐不可用,【"+pack.getName()+"】套餐可用");
}
return item.getIsAvailable()==0;
}
private Boolean checkOrderType(SConsumerCoupon item, CouponRequest couponRequest){
if(Objects.nonNull(item.getOrderType())&&item.getOrderType().compareTo(couponRequest.getOrderType())!=0){
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("优惠卷"+OrderTypeEnum.getEnumByCode(item.getOrderType()).getName()+"可用");
}
return item.getIsAvailable()==0;
}
private Boolean checkAvailableDate(SConsumerCoupon item, CouponRequest couponRequest){
if ((Objects.nonNull(item.getStartDate())&&Objects.nonNull(item.getEndDate()))
&&(item.getStartDate().compareTo(couponRequest.getPreStartDate()) > 0
|| item.getEndDate().compareTo(couponRequest.getPreEndDate()) < 0)){
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("优惠卷未生效,优惠卷有效时间为" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, item.getStartDate())
+ "-" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, item.getEndDate()));
}
return item.getIsAvailable()==0;
}
private Boolean checkCouponPeriod(SConsumerCoupon item, CouponRequest couponRequest){
if(Objects.nonNull(item.getCouponTimeStart())&&Objects.nonNull(item.getCouponTimeEnd())
&& !StringUtils.equals(item.getCouponTimeStart(),"00:00")&&(!StringUtils.equals(item.getCouponTimeEnd(),"24:00")||!StringUtils.equals(item.getCouponTimeEnd(),"23:00"))){
String startStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,couponRequest.getPreStartDate());
//判断短是否跨日
if(DateUtils.parseDate(startStr+" "+item.getCouponTimeStart()).compareTo(DateUtils.parseDate(startStr+" "+item.getCouponTimeEnd()))>0){
if(DateUtils.parseDate(startStr+" "+item.getCouponTimeStart()).compareTo(couponRequest.getPreStartDate())>0
||DateUtils.addDays(DateUtils.parseDate(startStr+" "+item.getCouponTimeEnd()),1).compareTo(couponRequest.getPreEndDate())<0) {
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("优惠卷可用时段为" + item.getCouponTimeStart() + "-次日" + item.getCouponTimeEnd());
}
}else{
if(DateUtils.parseDate(startStr+" "+item.getCouponTimeStart()).compareTo(couponRequest.getPreStartDate())>0
||DateUtils.parseDate(startStr+" "+item.getCouponTimeEnd()).compareTo(couponRequest.getPreEndDate())<0) {
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("优惠卷可用时段为" + item.getCouponTimeStart() + "-" + item.getCouponTimeEnd());
}
}
}
return item.getIsAvailable()==0;
}
private Boolean checkCouponType(SConsumerCoupon item, CouponRequest couponRequest
, List<SStore> sStores, List<SRoom> sRooms, BigDecimal timeLong){
SStore sStore = sStores.stream().filter(store -> store.getId().equals(couponRequest.getStoreId())).findFirst().orElse(null);
SRoom byId = sRooms.stream().filter(room -> room.getId().equals(couponRequest.getRoomId())).findFirst().orElse(null);
BigDecimal subtract = new BigDecimal(item.getMinDuration());
if (item.getCouponType().equals(CouponTypeEnum.PACKAGE.getCode())) {
CouponTypeEnum couponTypeEnum = CouponTypeEnum.getTypeCode(item.getCouponType());
switch (couponTypeEnum){
case PACKAGE:
if (couponRequest.getOrderMode().equals(BuyTypeEnum.PACK.getCode())) {
//计算价格
extracted(item, bigDecimal, byId, subtract, sStore);
extracted(item, timeLong, byId, subtract, sStore);
} else {
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("仅支持套餐模式下单使用");
}
} else if (item.getCouponType().equals(CouponTypeEnum.DURATION.getCode())) {
break;
case DURATION:
//判断门槛时长
if (bigDecimal.compareTo(subtract) >= 0) {
if (timeLong.compareTo(subtract) >= 0) {
//判断门店类型
isStoreType(item, sStore, byId);
} else {
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("下单时长等于" + bigDecimal + "小时,不满足优惠券门槛时长");
item.setReason("下单时长等于" + timeLong + "小时,不满足优惠券门槛时长");
}
} else {
extracted(item, bigDecimal, byId, subtract, sStore);
break;
default:
extracted(item, timeLong, byId, subtract, sStore);
break;
}
} else {
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("优惠卷未生效,优惠卷有效时段为每天" + item.getCouponTimeStart() + "-" + item.getCouponTimeEnd());
return item.getIsAvailable()==0;
}
} else {
private Boolean checkStore(SConsumerCoupon item,CouponRequest couponRequest,List<SStore> sStores){
if (StringUtils.isNotBlank(item.getStoreIds())) {
List<Long> storeIds = Arrays.asList(item.getStoreIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
if (!storeIds.contains(couponRequest.getStoreId())) {
List<String> storeNames = sStores.stream().filter(store -> storeIds.contains(store.getId())).map(SStore::getName).collect(Collectors.toList());
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("优惠卷未生效,优惠卷有效时间为" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, item.getStartDate()) + "-" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, item.getEndDate()));
item.setReason("优惠卷当前门店不可用,适用门店:" + storeNames.toString());
}
});
return sConsumerCoupons;
}
return item.getIsAvailable()==0;
}
@Override
......@@ -230,17 +377,18 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
newSConsumerCoupon.setCouponType(sCoupon.getCouponType());
newSConsumerCoupon.setMinPrice(new BigDecimal(0.00));
newSConsumerCoupon.setSubPrice(sCoupon.getSubPrice());
newSConsumerCoupon.setWeeks(sCoupon.getWeeks());
newSConsumerCoupon.setMinDuration(sCoupon.getMinDuration());
newSConsumerCoupon.setMaxDuration(sCoupon.getMaxDuration());
newSConsumerCoupon.setDuration(sCoupon.getDuration());
newSConsumerCoupon.setOrderType(sCoupon.getOrderType());
newSConsumerCoupon.setPackageId(sCoupon.getPackageId());
newSConsumerCoupon.setSourceType(SourceTypeEnum.GIVE.getCode());
newSConsumerCoupon.setPlatformType(String.valueOf(sCoupon.getPlatformType()));
newSConsumerCoupon.setStartDate(sCoupon.getStartDate());
newSConsumerCoupon.setEndDate(sCoupon.getEndDate());
newSConsumerCoupon.setRemark(sCoupon.getRemark());
int insert = sConsumerCouponMapper.insert(newSConsumerCoupon);
int insert = baseMapper.insert(newSConsumerCoupon);
if (insert > 0) {
//优惠券数量减一
sCoupon.setNumber(sCoupon.getNumber() - 1);
......
......@@ -6,6 +6,9 @@ import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import share.common.enums.ConsumeNameEnum;
import share.common.enums.PayTypeEnum;
import share.common.enums.SignEnum;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -103,6 +106,19 @@ public class SConsumptionRecordsServiceImpl implements ISConsumptionRecordsServi
return sConsumptionRecordsMapper.insertSConsumptionRecords(sConsumptionRecords);
}
@Override
public int insertSConsumptionRecords(SOrder sOrder) {
SConsumptionRecords sConsumptionRecords = new SConsumptionRecords();
sConsumptionRecords.setConsumerId(sOrder.getConsumerId());
sConsumptionRecords.setOrderId(sOrder.getId());
sConsumptionRecords.setName(ConsumeNameEnum.CONSUME.getValue());
sConsumptionRecords.setPrice(sOrder.getPayPrice());
sConsumptionRecords.setPayType(PayTypeEnum.WECHAT.getName());
sConsumptionRecords.setSign(SignEnum.BURDEN.getValue());
sConsumptionRecords.setCreateTime(DateUtils.getNowDate());
return sConsumptionRecordsMapper.insertSConsumptionRecords(sConsumptionRecords);
}
/**
* 修改消费记录
*
......
package share.system.service.impl;
import java.math.BigDecimal;
import java.util.List;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dianping.openapi.sdk.api.tuangou.entity.TuangouDealQueryShopDealResponseEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import share.common.enums.CouponTypeEnum;
import share.common.enums.RoomType;
import share.common.enums.StoreType;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.system.domain.SStore;
import share.system.mapper.SCouponMapper;
import share.system.domain.SCoupon;
import share.system.service.ISCouponService;
import share.system.service.ISStoreService;
import share.system.service.QPService;
/**
* 优惠券Service业务层处理
......@@ -20,10 +31,13 @@ import share.system.service.ISCouponService;
* @date 2023-09-27
*/
@Service
public class SCouponServiceImpl implements ISCouponService
{
public class SCouponServiceImpl implements ISCouponService {
@Autowired
private SCouponMapper sCouponMapper;
@Autowired
private ISStoreService storeService;
@Autowired
private QPService qpService;
//默认时长
private static final String DEFAULT_DURATION = "0";
//默认折扣最大时长
......@@ -31,7 +45,9 @@ public class SCouponServiceImpl implements ISCouponService
//默认优惠开始(有效)时段
private static final String DEFAULT_START_TIME = "00:00";
//默认优惠结束(有效)时段
private static final String DEFAULT_END_TIME = "24:00";
private static final String DEFAULT_END_TIME = "23:00";
private static final String TWO = "2";
/**
......@@ -41,8 +57,7 @@ public class SCouponServiceImpl implements ISCouponService
* @return 优惠券
*/
@Override
public SCoupon selectSCouponById(Long id)
{
public SCoupon selectSCouponById(Long id) {
return sCouponMapper.selectSCouponById(id);
}
......@@ -53,8 +68,8 @@ public class SCouponServiceImpl implements ISCouponService
* @return 优惠券
*/
@Override
public List<SCoupon> selectSCouponList(SCoupon sCoupon)
{
public List<SCoupon> selectSCouponList(SCoupon sCoupon) {
return sCouponMapper.selectSCouponList(sCoupon);
}
......@@ -65,22 +80,29 @@ public class SCouponServiceImpl implements ISCouponService
* @return 结果
*/
@Override
public int insertSCoupon(SCoupon sCoupon)
{
public int insertSCoupon(SCoupon sCoupon) {
if (StringUtils.isBlank(sCoupon.getRoomType())) {
sCoupon.setRoomType(RoomType.getCodeList());
}
if (StringUtils.isBlank(sCoupon.getStoreType())) {
sCoupon.setStoreType(StoreType.getCodeList());
}
if (StringUtils.isBlank(sCoupon.getValidStartTime())) {
sCoupon.setValidStartTime(DEFAULT_START_TIME);
}
if (StringUtils.isBlank(sCoupon.getValidEndTime())) {
sCoupon.setValidEndTime(DEFAULT_END_TIME);
}
sCoupon.setMinDuration(DEFAULT_DURATION);
sCoupon.setMaxDuration(DEFAULT_MAX_DURATION);
sCoupon.setMinPrice(new BigDecimal("0.00"));
sCoupon.setCreateTime(DateUtils.getNowDate());
SCoupon sCouponList = sCouponMapper.selectByDealgroupId(sCoupon.getDealgroupId());
if (ObjectUtils.isEmpty(sCouponList)) {
return sCouponMapper.insertSCoupon(sCoupon);
} else {
throw new RuntimeException("该团购已存在");
}
}
/**
......@@ -90,10 +112,14 @@ public class SCouponServiceImpl implements ISCouponService
* @return 结果
*/
@Override
public int updateSCoupon(SCoupon sCoupon)
{
public int updateSCoupon(SCoupon sCoupon) {
sCoupon.setUpdateTime(DateUtils.getNowDate());
SCoupon sCouponList = sCouponMapper.selectByDealgroupId(sCoupon.getDealgroupId());
if (ObjectUtils.isEmpty(sCouponList) || sCouponList.getId().equals(sCoupon.getId())) {
return sCouponMapper.updateSCoupon(sCoupon);
} else {
throw new RuntimeException("该团购已存在");
}
}
/**
......@@ -103,8 +129,7 @@ public class SCouponServiceImpl implements ISCouponService
* @return 结果
*/
@Override
public int deleteSCouponByIds(Long[] ids)
{
public int deleteSCouponByIds(Long[] ids) {
return sCouponMapper.deleteSCouponByIds(ids);
}
......@@ -115,13 +140,13 @@ public class SCouponServiceImpl implements ISCouponService
* @return 结果
*/
@Override
public int deleteSCouponById(Long id)
{
public int deleteSCouponById(Long id) {
return sCouponMapper.deleteSCouponById(id);
}
/**
* 根据优惠券名称查询优惠券
*
* @param dealTitle
* @return
*/
......@@ -134,4 +159,65 @@ public class SCouponServiceImpl implements ISCouponService
public List<SCoupon> selectSCouponByIds(Long[] couponIds) {
return sCouponMapper.selectSCouponByIds(couponIds);
}
@Override
public List<SCoupon> queryShopDeal() {
//查询所有门店的shopId
List<SStore> sStores = storeService.list();
//获取所有的openShopUuid,去掉为空的
List<String> openShopUuids = sStores.stream().map(SStore::getOpenShopUuid).filter(StringUtils::isNotBlank).collect(Collectors.toList());
Map<Long, SCoupon> sCouponList = new LinkedHashMap<>();
openShopUuids.stream().forEach(openShopUuid -> {
List<TuangouDealQueryShopDealResponseEntity> queryshopdeal = qpService.queryshopdeal(openShopUuid);
if (!CollectionUtils.isEmpty(queryshopdeal)) {
queryshopdeal.stream().forEach(item -> {
if (TWO.equals(item.getSale_status())) {
SCoupon sCoupon1 = sCouponList.get(item.getDealgroup_id());
if (ObjectUtils.isEmpty(sCoupon1)) {
SCoupon sCoupon = new SCoupon();
//添加团购id
sCoupon.setDealgroupId(item.getDealgroup_id());
//套餐名称
sCoupon.setName(item.getTitle());
//套餐原价
sCoupon.setSubPrice(BigDecimal.valueOf(item.getMarketprice()));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
Date receiptEndDate = sdf.parse(item.getReceipt_end_date());
Date receiptBeginDate = sdf.parse(item.getReceipt_begin_date());
sCoupon.setStartDate(receiptBeginDate);
sCoupon.setEndDate(receiptEndDate);
} catch (ParseException e) {
throw new RuntimeException(e);
}
sCoupon.setRoomType(RoomType.getCodeList());
sCoupon.setStoreType(StoreType.getCodeList());
sCoupon.setValidStartTime(DEFAULT_START_TIME);
sCoupon.setValidEndTime(DEFAULT_END_TIME);
sCoupon.setMinDuration(DEFAULT_DURATION);
sCoupon.setMaxDuration(DEFAULT_MAX_DURATION);
sCoupon.setMinPrice(new BigDecimal("0.00"));
sCoupon.setCouponType(CouponTypeEnum.CASH.getCode());
sCouponList.put(item.getDealgroup_id(), sCoupon);
//从门店列表中获取门店id
sCoupon.setStoreIds(String.valueOf(sStores.stream().filter(store -> store.getOpenShopUuid().equals(openShopUuid)).findFirst().get().getId()));
} else {
sCoupon1.setStoreIds(sCoupon1.getStoreIds() + "," + sStores.stream().filter(store -> store.getOpenShopUuid().equals(openShopUuid)).findFirst().get().getId());
}
}
});
}
});
return new ArrayList<>(sCouponList.values());
}
@Override
public List<SCoupon> listDuration(SCoupon sCoupon) {
return sCouponMapper.listDuration(sCoupon);
}
@Override
public List<SCoupon> selectSCouponByDealgroupId(Long dealgroupId) {
return sCouponMapper.selectSCouponByDealgroupId(dealgroupId);
}
}
......@@ -100,7 +100,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
private SmsService smsService;
/**
* 查询订单
*
......@@ -134,10 +133,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Override
public List<SOrderVo> selectSOrderVoList(SOrder sOrder) {
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
if(Objects.nonNull(sOrder.getPayStatus())) {
if (Objects.nonNull(sOrder.getPayStatus())) {
queryWrapper.eq(SOrder::getPayStatus, sOrder.getPayStatus());
}
if(Objects.nonNull(sOrder.getConsumerId())){
if (Objects.nonNull(sOrder.getConsumerId())) {
queryWrapper.eq(SOrder::getConsumerId, sOrder.getConsumerId());
}
if (ObjectUtil.isNotEmpty(sOrder.getStatus())) {
......@@ -165,10 +164,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
public List<SOrderVo> selectPayedSOrderVoList(SOrder sOrder){
if(Objects.isNull(sOrder.getConsumerId())){
public List<SOrderVo> selectPayedSOrderVoList(SOrder sOrder) {
if (Objects.isNull(sOrder.getConsumerId())) {
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
if(Objects.isNull(user)){
if (Objects.isNull(user)) {
throw new BaseException("登陆过期!");
}
sOrder.setConsumerId(user.getId());
......@@ -178,21 +177,22 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
/**
* 验证是否可以申请退款
*
* @param orderVo 订单信息
* @param coupon 优惠券信息
* @return
*/
private boolean isRefund(SOrderVo orderVo, SConsumerCoupon coupon) {
@Override
public boolean isRefund(SOrderVo orderVo, SConsumerCoupon coupon) {
if (coupon != null && !PlatformTypeEnum.SELF.getCode().equals(coupon.getPlatformType())) {
return Boolean.FALSE;
} else if (orderVo != null && OrderStatusEnum.UNUSED.getCode().equals(orderVo.getStatus())
&& OrderTypeEnum.RESERVER.getCode().equals(orderVo.getOrderType())){
&& OrderTypeEnum.RESERVER.getCode().equals(orderVo.getOrderType())) {
Date startTime = orderVo.getPreStartDate();
Date nowTime = cn.hutool.core.date.DateUtil.date();
if (startTime.compareTo(nowTime) <=0) {
if (startTime.compareTo(nowTime) <= 0) {
return Boolean.FALSE;
}
long between = cn.hutool.core.date.DateUtil.between(nowTime,
......@@ -206,17 +206,19 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
/**
* 验证是否可以申请退款
*
* @param order 订单信息
* @param coupon 优惠券信息
* @return
*/
private boolean isRefund(SOrder order, SConsumerCoupon coupon) {
@Override
public boolean isRefund(SOrder order, SConsumerCoupon coupon) {
if (coupon != null && !PlatformTypeEnum.SELF.getCode().equals(coupon.getPlatformType())) {
return Boolean.FALSE;
} else if (order != null && OrderStatusEnum.UNUSED.getCode().equals(order.getStatus())){
} else if (order != null && OrderStatusEnum.UNUSED.getCode().equals(order.getStatus())) {
Date startTime = order.getPreStartDate();
Date nowTime = cn.hutool.core.date.DateUtil.date();
if (startTime.compareTo(nowTime) <=0) {
if (startTime.compareTo(nowTime) <= 0) {
return Boolean.FALSE;
}
long between = cn.hutool.core.date.DateUtil.between(nowTime,
......@@ -227,6 +229,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
return Boolean.FALSE;
}
/**
* 新增订单
*
......@@ -308,7 +311,22 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
//校验订单预约时间
checkOrderDate(request);
//校验订单套餐
checkOrderPack(request,user);
checkOrderPack(request, user);
SConsumerCoupon byId = null;
if (Objects.nonNull(request.getCouponId()) && request.getCouponId() != 0) {
byId = consumerCouponService.getById(request.getCouponId());
if (Objects.nonNull(byId)) {
if (byId.getUseStatus().equals(UserStatusEnum.UNUSED.getCode())) {
if (StringUtils.isNotEmpty(byId.getCouponCode())) {
qpService.prepare(byId.getCouponCode(), sStore.getOpenShopUuid(), ConsumerCouponStatusEnum.ORDER.getCode());
}
} else {
throw new BaseException("优惠券已使用!");
}
} else {
throw new BaseException("优惠券不存在!");
}
}
OrderPayResultResponse response = new OrderPayResultResponse();
if (request.getPayFee().compareTo(BigDecimal.ZERO) <= 0) {
response.setPayType(PayTypeEnum.WECHAT.getValue());
......@@ -325,35 +343,25 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
save(sOrder);
if (response.getStatus().equals(YesNoEnum.yes.getFlag())) {
if (Objects.nonNull(request.getCouponId()) && request.getCouponId() != 0) {
SConsumerCoupon byId = consumerCouponService.getById(request.getCouponId());
if (Objects.nonNull(byId)) {
if (StringUtils.isNotEmpty(byId.getCouponCode())) {
if (byId.getUseStatus().equals(UserStatusEnum.UNUSED.getCode())) {
//验劵
qpService.consume(byId.getCouponCode(), 1, sStore.getOpenShopUuid(), ConsumerCouponStatusEnum.ORDER.getCode());
} else {
throw new BaseException("优惠券已使用!");
}
}
SConsumerCoupon consumerCoupon = new SConsumerCoupon();
consumerCoupon.setId(request.getCouponId());
consumerCoupon.setUseStatus(UserStatusEnum.USED.getCode());
consumerCouponService.updateById(consumerCoupon);
}
SConsumptionRecords sConsumptionRecords = new SConsumptionRecords();
sConsumptionRecords.setConsumerId(sOrder.getConsumerId());
sConsumptionRecords.setOrderId(sOrder.getId());
sConsumptionRecords.setName(ConsumeNameEnum.CONSUME.getValue());
sConsumptionRecords.setPrice(sOrder.getPayPrice());
sConsumptionRecords.setPayType(PayTypeEnum.WECHAT.getName());
sConsumptionRecords.setSign(SignEnum.BURDEN.getValue());
sConsumptionRecordsService.insertSConsumptionRecords(sConsumptionRecords);
sConsumptionRecordsService.insertSConsumptionRecords(sOrder);
Map<String, String> map = new HashMap<>();
map.put("orderNo", sOrder.getOrderNo());
map.put("expirationTime", sOrder.getPreStartDate().toString());
JSONObject jsonObject = new JSONObject(map);
if (sOrder.getOrderType().equals(OrderTypeEnum.RESERVER.getCode())) {
redisUtils.set(ReceiptRdeisEnum.ORDER_NO.getValue() + sOrder.getOrderNo(), jsonObject.toString());
}
}
if (sOrder.getOrderType().equals(OrderTypeEnum.RENEW.getCode())) {
sOrder.setStartDate(sOrder.getPreStartDate());
sOrder.setEndDate(sOrder.getPreEndDate());
......@@ -366,7 +374,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.RENEWAL_SUCCESS.getCode(),
cn.hutool.core.date.DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
cn.hutool.core.date.DateUtil.format(cn.hutool.core.date.DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
SRoom sRoom = roomService.getById(sOrder.getRoomId());
// SRoom sRoom = roomService.getById(sOrder.getRoomId());
// //通知保洁人员
// sConsumerService.selectListByStoreId(sOrder.getStoreId()).stream().forEach(item -> {
// // 循环发送短信提示门店保洁打扫卫生
......@@ -379,27 +387,26 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
map.put("expirationTime", sOrder.getEndDate().toString());
JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + sOrder.getOrderNo(), jsonObject.toString());
redisUtils.delete(ReceiptRdeisEnum.ORDER_NO.getValue() + sOrder.getOrderNo());
}
return response;
}
private void checkOrderPack(CreateOrderRequest request, SConsumer user) {
if(Objects.nonNull(request.getPackId()) && request.getPackId()>0){
if (Objects.nonNull(request.getPackId()) && request.getPackId() > 0) {
//判断是否首次订单套餐
SPack pack = packService.getById(request.getPackId());
if(Objects.isNull(pack)||Objects.isNull(pack.getId())){
if (Objects.isNull(pack) || Objects.isNull(pack.getId())) {
throw new BaseException("下单套餐不存在!");
}
if(YesNoEnum.yes.getIndex().compareTo(pack.getFirstOrderAvailable())==0){
if (YesNoEnum.yes.getIndex().compareTo(pack.getFirstOrderAvailable()) == 0) {
List<SOrder> orderList = payedUnrefundListByUserId(user.getId());
if(CollectionUtils.isNotEmpty(orderList)){
if (CollectionUtils.isNotEmpty(orderList)) {
throw new BaseException("当前套餐仅首次下单可用!");
}
}
if(Objects.nonNull(pack.getPackaStartPeriod())&&Objects.nonNull(pack.getPackaEndPeriod())
&&(!StringUtils.equals(pack.getPackaStartPeriod(),"0")||!StringUtils.equals(pack.getPackaEndPeriod(),"23"))) {
if (Objects.nonNull(pack.getPackaStartPeriod()) && Objects.nonNull(pack.getPackaEndPeriod())
&& (!StringUtils.equals(pack.getPackaStartPeriod(), "0") || !StringUtils.equals(pack.getPackaEndPeriod(), "23"))) {
Integer preStartHour = Integer.parseInt(DateUtils.parseDateToStr("H", request.getPreStartDate()));
Integer preEndHour = Integer.parseInt(DateUtils.parseDateToStr("H", request.getPreEndDate()));
Integer packaStartPeriod = Integer.parseInt(pack.getPackaStartPeriod());
......@@ -411,7 +418,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
throw new BaseException("预约时段非套餐可用时段!");
}
//1 开始时段>结束时段,代表可用时段跨日,则应该预约开始时间<可用开始时间,预约结束时间>可用结束时间
}else{
} else {
if (packaStartPeriod.compareTo(preStartHour) < 0 || preEndHour.compareTo(packaEndPeriod) < 0) {
throw new BaseException("预约时段非套餐可用时段!");
}
......@@ -743,21 +750,14 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.RENEWAL_SUCCESS.getCode(),
cn.hutool.core.date.DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
cn.hutool.core.date.DateUtil.format(cn.hutool.core.date.DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
SRoom sRoom = roomService.getById(sOrder.getRoomId());
//通知保洁人员
// SRoom sRoom = roomService.getById(sOrder.getRoomId());
// //通知保洁人员
// sConsumerService.selectListByStoreId(sOrder.getStoreId()).stream().forEach(item -> {
// // 循环发送短信提示门店保洁打扫卫生
// smsService.sendSmsCleanRecordsStopRemind(item.getPhone(), sStore, sRoom);
// });
}
SConsumptionRecords sConsumptionRecords = new SConsumptionRecords();
sConsumptionRecords.setConsumerId(sOrder.getConsumerId());
sConsumptionRecords.setOrderId(sOrder.getId());
sConsumptionRecords.setName(ConsumeNameEnum.CONSUME.getValue());
sConsumptionRecords.setPrice(sOrder.getPayPrice());
sConsumptionRecords.setPayType(PayTypeEnum.WECHAT.getName());
sConsumptionRecords.setSign(SignEnum.BURDEN.getValue());
sConsumptionRecordsService.insertSConsumptionRecords(sConsumptionRecords);
sConsumptionRecordsService.insertSConsumptionRecords(sOrder);
}
@Override
......@@ -767,6 +767,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
/**
* 小程序申请退款
*
* @param request
* @return
*/
......@@ -812,28 +813,29 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
e.printStackTrace();
throw new BaseException("微信申请退款失败!");
}
}
}else {
//修改订单退款状态,退款成功
// sOrder.setStatus(OrderStatusEnum.CANCEL.getCode());
// sOrder.setRefundStatus(RefundStatusEnum.REFUNDED.getCode());
// sOrder.setRefundReasonTime(cn.hutool.core.date.DateUtil.date());
// sOrder.setRefundPrice(request.getAmount());
// Boolean execute = Boolean.FALSE;
// try {
// sOrder.setRefundReason(request.getRefundReason());
// updateById(sOrder);
// //微信退款
sOrder.setStatus(OrderStatusEnum.CANCEL.getCode());
sOrder.setRefundStatus(RefundStatusEnum.REFUNDED.getCode());
sOrder.setRefundReasonTime(cn.hutool.core.date.DateUtil.date());
sOrder.setRefundPrice(BigDecimal.ZERO);
Boolean execute = Boolean.FALSE;
try {
sOrder.setRefundReason(request.getRefundReason());
updateById(sOrder);
//微信退款
// if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getCode()) && request.getAmount().compareTo(BigDecimal.ZERO) == 0) {
// // 退款task, 定时任务退优惠券
// redisUtil.lPush(Constants.ORDER_TASK_REDIS_KEY_AFTER_REFUND_BY_USER, sOrder.getId());
// }
// execute = Boolean.TRUE;
// } catch (Exception e) {
// logger.error(e.toString());
// }
// if (!execute) {
// throw new BaseException("订单更新失败");
// 退款task, 定时任务退优惠券
redisUtil.lPush(Constants.ORDER_TASK_REDIS_KEY_AFTER_REFUND_BY_USER, sOrder.getId());
// }
execute = Boolean.TRUE;
} catch (Exception e) {
logger.error(e.toString());
}
if (!execute) {
throw new BaseException("订单更新失败");
}
}
return Boolean.TRUE;
}
......@@ -843,7 +845,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
queryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
queryWrapper.eq(SOrder::getConsumerId, userId);
queryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
queryWrapper.in(SOrder::getStatus, new ArrayList<Integer>(){{
queryWrapper.in(SOrder::getStatus, new ArrayList<Integer>() {{
add(OrderStatusEnum.UNUSED.getCode());
add(OrderStatusEnum.INUSE.getCode());
add(OrderStatusEnum.USED.getCode());
......@@ -885,7 +887,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
vo.setRoomTypeName(RoomType.getNameByCode(room.getRoomType()));
}
});
if(Objects.nonNull(vo.getCouponId())) {
if (Objects.nonNull(vo.getCouponId())) {
userCouponList.stream().forEach(userCoupon -> {
if (userCoupon.getId().equals(vo.getCouponId())) {
// 判断是否可以退款
......@@ -894,7 +896,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
});
}else{
} else {
// 判断是否可以退款
vo.setIsRefund(isRefund(o, null));
}
......@@ -942,14 +944,14 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
).collect(Collectors.toList()).isEmpty()) {
throw new BaseException("房间取电设备不存在!");
}
if (ObjectUtil.isNotEmpty(sOrder.getArrivalTime())) {
if (RoomStatusEnum.HOLD.getValue().compareTo(sRoomVo.getStatus())==0
||!checkOrderOpenDoor(sOrder)) {
if (sOrder.getStatus().equals(OrderStatusEnum.UNUSED.getCode())) {
if (RoomStatusEnum.HOLD.getValue().compareTo(sRoomVo.getStatus()) == 0
|| !checkOrderOpenDoor(sOrder)) {
throw new BaseException("房间当前时段已被占用不可开门!");
}
//判断预约时间是否到达,可提前一个小时开门
if (DateUtils.addHours(sOrder.getPreStartDate(), Constants.OPEN_DOOR_AHEAD_HOUR_MINUS).compareTo(new Date()) > 0) {
throw new BaseException("预约时间未到达,可提前"+Constants.OPEN_DOOR_AHEAD_HOUR+"小时进场,请耐心等候!");
throw new BaseException("预约时间未到达,可提前" + Constants.OPEN_DOOR_AHEAD_HOUR + "小时进场,请耐心等候!");
}
//更改订单状态,房间状态,开始时间,结束时间
sOrder.setStatus(OrderStatusEnum.INUSE.getCode());
......@@ -982,9 +984,17 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
cn.hutool.core.date.DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
cn.hutool.core.date.DateUtil.format(cn.hutool.core.date.DateUtil.offsetMinute(new Date(), 1),
DatePattern.NORM_DATETIME_PATTERN), "1", 10L);
} else {
deviceOpService.openDoor(sRoomVo.getId(), sOrder.getConsumerPhone());
if (ObjectUtil.isEmpty(sOrder.getArrivalTime())) {
//语音
deviceOpService.asyncActionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.OPEN.getCode(),
cn.hutool.core.date.DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
cn.hutool.core.date.DateUtil.format(cn.hutool.core.date.DateUtil.offsetMinute(new Date(), 1),
DatePattern.NORM_DATETIME_PATTERN), "1", 10L);
sOrder.setArrivalTime(new Date());
baseMapper.updateById(sOrder);
}
}
return "开锁成功";
}
......@@ -1012,9 +1022,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}});
//订单开始时间大于等于当前时间 并且 订单开始时间小于等于当前订单实际结束时间+30分钟保洁
BigDecimal bigDecimal = DateUtils.differentHour(order.getPreStartDate(), order.getPreEndDate());
Date orderEndDate = DateUtils.addMinutes(DateUtils.addHours(new Date(), bigDecimal.intValue()),Constants.ROOM_LOCK_DELAY_MINUTE);
Date orderEndDate = DateUtils.addMinutes(DateUtils.addHours(new Date(), bigDecimal.intValue()), Constants.ROOM_LOCK_DELAY_MINUTE);
queryWrapper.apply("IFNULL(start_date,pre_start_date) >= '" + DateUtils.getTime() + "' " +
" AND IFNULL(start_date,pre_start_date) <= '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,orderEndDate) + "'");
" AND IFNULL(start_date,pre_start_date) <= '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderEndDate) + "'");
return count(queryWrapper) == 0;
}
......@@ -1046,9 +1056,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setPayFee(payPrice);
} else {
// 判断优惠券是否可以使用
if(Objects.nonNull(user)&&Objects.nonNull(request.getCouponId())) {
if (Objects.nonNull(user) && Objects.nonNull(request.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(request.getCouponId());
computedCouponPrice(priceResponse, user, consumerCoupon);
computedCouponPrice(request, priceResponse, user, consumerCoupon);
}
}
return priceResponse;
......@@ -1065,7 +1075,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
/**
* 计算使用优惠券后的订单金额
*/
private void computedCouponPrice(ComputedOrderPriceResponse priceResponse, SConsumer user, SConsumerCoupon consumerCoupon) {
private void computedCouponPrice(OrderComputedPriceRequest request, ComputedOrderPriceResponse priceResponse
, SConsumer user, SConsumerCoupon consumerCoupon) {
if (ObjectUtil.isNull(consumerCoupon) || !consumerCoupon.getConsumerId().equals(user.getId())) {
throw new BaseException("优惠券领取记录不存在!");
}
......@@ -1085,7 +1096,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
case DISCOUNT://TODO 折扣券
break;
case PACKAGE://套餐券
case CASH://现金券
case CASH://现金券(团购券)
//判断优惠券最小使用金额
if (consumerCoupon.getMinPrice().compareTo(priceResponse.getTotalFee()) > 0) {
throw new BaseException("总金额小于优惠券最小使用金额");
......@@ -1099,7 +1110,20 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setPayFee(subtract);
}
break;
case DURATION://TODO 时长券
case DURATION://时长券
BigDecimal timeLong = DateUtils.differentHour(request.getPreStartDate(), request.getPreEndDate());
if (new BigDecimal(consumerCoupon.getMinDuration()).compareTo(timeLong) > 0) {
throw new BaseException("总时长小于优惠券最小使用时长");
}
BigDecimal duration = new BigDecimal(consumerCoupon.getDuration());
if (duration.compareTo(timeLong) >= 0) {
priceResponse.setPayFee(BigDecimal.ZERO);
priceResponse.setCouponFee(priceResponse.getTotalFee());
} else {
BigDecimal unitPrice = priceResponse.getTotalFee().divide(timeLong);
priceResponse.setPayFee(unitPrice.multiply(timeLong.subtract(duration)));
priceResponse.setCouponFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
}
break;
default:
break;
......
......@@ -405,6 +405,9 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme
}
//查询所有房间
List<SRoomVo> roomVoList = sRoomService.listByStoreIds(storeIds);
List<Long> roomIdList = Optional.ofNullable(roomVoList).orElse(new ArrayList<>()).stream().map(SRoomVo::getId).collect(Collectors.toList());
List<SCleanRecords> sCleanRecordsList = cleanRecordsService.unCleanedListByRoomIds(roomIdList);
Map<Long, List<SCleanRecords>> recordsMap = Optional.ofNullable(sCleanRecordsList).orElse(new ArrayList<>()).stream().collect(Collectors.groupingBy(SCleanRecords::getRoomId));
//查询所有设备
List<Device> deviceList = deviceService.list();
//遍历门店
......@@ -412,6 +415,11 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme
List<SRoomVo> roomVos = new ArrayList<>();
//遍历房间
roomVoList.stream().forEach(room -> {
if (CollectionUtils.isNotEmpty(recordsMap.get(room.getId()))) {
SCleanRecords records = recordsMap.get(room.getId()).get(0);
room.setRecordsStatus(records.getStatus());
room.setRecordsId(records.getId());
}
List<Device> devices = new ArrayList<>();
deviceList.stream().forEach(device -> {
if (room.getId().compareTo(device.getRoomId()) == 0) {
......
......@@ -14,6 +14,7 @@
<result property="couponType" column="coupon_type"/>
<result property="couponValue" column="coupon_value"/>
<result property="status" column="status"/>
<result property="number" column="number"/>
<result property="message" column="message"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
......@@ -31,6 +32,7 @@
coupon_name,
coupon_type,
coupon_value,
number,
status,
message,
create_by,
......@@ -50,6 +52,7 @@
<if test="couponId != null ">and coupon_id = #{couponId}</if>
<if test="couponName != null and couponName != ''">and coupon_name like concat('%', #{couponName}, '%')
</if>
<if test="number != null ">and number = #{number}</if>
<if test="couponType != null and couponType != ''">and coupon_type = #{couponType}</if>
<if test="couponValue != null ">and coupon_value = #{couponValue}</if>
<if test="status != null and status != ''">and status = #{status}</if>
......@@ -73,6 +76,7 @@
<if test="couponType != null and couponType != ''">coupon_type,</if>
<if test="couponValue != null">coupon_value,</if>
<if test="status != null and status != ''">status,</if>
<if test="number != null">number,</if>
<if test="message != null and message != ''">message,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
......@@ -89,6 +93,7 @@
<if test="couponType != null and couponType != ''">#{couponType},</if>
<if test="couponValue != null">#{couponValue},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="number != null">#{number},</if>
<if test="message != null and message != ''">#{message},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
......@@ -109,6 +114,7 @@
<if test="couponType != null and couponType != ''">coupon_type = #{couponType},</if>
<if test="couponValue != null">coupon_value = #{couponValue},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="number != null">number = #{number},</if>
<if test="message != null and message != ''">message = #{message},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
......
......@@ -10,6 +10,8 @@
<result property="couponId" column="coupon_id" />
<result property="storeId" column="store_id"/>
<result property="dealId" column="deal_id"/>
<result property="dealgroupId" column="dealgroup_id"/>
<result property="storeIds" column="store_ids"/>
<result property="couponCode" column="coupon_code" />
<result property="name" column="name" />
<result property="couponType" column="coupon_type" />
......@@ -31,6 +33,7 @@
<result property="useDate" column="use_date" />
<result property="useStatus" column="use_status" />
<result property="isDelete" column="is_delete" />
<result property="weeks" column="weeks"/>
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
......@@ -46,6 +49,8 @@
coupon_id,
store_id,
deal_id,
dealgroup_id,
store_ids,
coupon_code,
name,
coupon_type,
......@@ -63,6 +68,7 @@
use_date,
use_status,
is_delete,
weeks,
create_by,
create_time,
update_by,
......@@ -101,7 +107,8 @@
<if test="startDate != null "> and start_date = #{startDate}</if>
<if test="endDate != null "> and end_date = #{endDate}</if>
<if test="useDate != null "> and use_date = #{useDate}</if>
<if test="useStatus != null and useStatus != ''"> and use_status = #{useStatus}</if>
<if test="useStatus != null and useStatus != '' or useStatus==0">and use_status = #{useStatus}</if>
<if test="weeks != null and weeks != ''">and weeks = #{weeks}</if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
<if test="deleteBy != null and deleteBy != ''"> and delete_by = #{deleteBy}</if>
<if test="deleteTime != null "> and delete_time = #{deleteTime}</if>
......@@ -151,6 +158,7 @@
<if test="useDate != null">use_date,</if>
<if test="useStatus != null">use_status,</if>
<if test="isDelete != null">is_delete,</if>
<if test="weeks != null">weeks,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
......@@ -162,11 +170,13 @@
<if test="storeType != null">store_type,</if>
<if test="orderType != null">order_type,</if>
<if test="packageId != null">package_id,</if>
<if test="dealgroupId != null">dealgroup_id,</if>
<if test="storeIds != null">store_ids,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="consumerId != null">#{consumerId},</if>
<if test="couponId != null">#{couponId},</if>
<if test="storeId != null">#{storeId}</if>
<if test="storeId != null">#{storeId},</if>
<if test="dealId != null">#{dealId},</if>
<if test="couponCode != null and couponCode != ''">#{couponCode},</if>
<if test="name != null and name != ''">#{name},</if>
......@@ -185,6 +195,7 @@
<if test="useDate != null">#{useDate},</if>
<if test="useStatus != null">#{useStatus},</if>
<if test="isDelete != null">#{isDelete},</if>
<if test="weeks != null">#{weeks},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
......@@ -196,6 +207,8 @@
<if test="storeType != null">#{storeType},</if>
<if test="orderType != null">#{orderType},</if>
<if test="packageId != null">#{packageId},</if>
<if test="dealgroupId != null">#{dealgroupId},</if>
<if test="storeIds != null">#{storeIds},</if>
</trim>
</insert>
......@@ -223,6 +236,7 @@
<if test="useDate != null">use_date = #{useDate},</if>
<if test="useStatus != null">use_status = #{useStatus},</if>
<if test="isDelete != null">is_delete = #{isDelete},</if>
<if test="weeks != null">weeks = #{weeks},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
......@@ -234,6 +248,8 @@
<if test="storeType != null">store_type = #{storeType},</if>
<if test="orderType != null">order_type = #{orderType},</if>
<if test="packageId != null">package_id = #{packageId},</if>
<if test="dealgroupId != null">dealgroup_id = #{dealgroupId},</if>
<if test="storeIds != null">store_ids = #{storeIds},</if>
</trim>
where id = #{id}
</update>
......
......@@ -16,12 +16,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="couponType" column="coupon_type" />
<result property="orderType" column="order_type"/>
<result property="packageId" column="package_id"/>
<result property="dealgroupId" column="dealgroup_id"/>
<result property="storeIds" column="store_ids"/>
<result property="duration" column="duration" />
<result property="minDuration" column="min_duration" />
<result property="maxDuration" column="max_duration" />
<result property="minPrice" column="min_price" />
<result property="subPrice" column="sub_price" />
<result property="isOverlay" column="is_overlay" />
<result property="weeks" column="weeks"/>
<result property="platformType" column="platform_type" />
<result property="number" column="number" />
<result property="createBy" column="create_by" />
......@@ -39,6 +42,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
coupon_type,
order_type,
package_id,
dealgroup_id,
weeks,
store_ids,
duration,min_duration,max_duration,
min_price,sub_price,is_overlay,
platform_type,number,create_by,
......@@ -59,6 +65,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="couponType != null"> and coupon_type = #{couponType}</if>
<if test="orderType != null">and order_type = #{orderType}</if>
<if test="packageId != null">and package_id = #{packageId}</if>
<if test="dealgroupId != null">and dealgroup_id = #{dealgroupId}</if>
<if test="storeIds != null">and store_ids = #{storeIds}</if>
<if test="duration != null and duration != ''"> and duration = #{duration}</if>
<if test="minDuration != null and minDuration != ''"> and min_duration = #{minDuration}</if>
<if test="maxDuration != null and maxDuration != ''"> and max_duration = #{maxDuration}</if>
......@@ -66,6 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="subPrice != null and subPrice != ''"> and sub_price = #{subPrice}</if>
<if test="isOverlay != null"> and is_overlay = #{isOverlay}</if>
<if test="platformType != null"> and platform_type = #{platformType}</if>
<if test="weeks != null">and weeks = #{weeks}</if>
<if test="number != null"> and number = #{number}</if>
<if test="createBy != null"> and create_by = #{createBy}</if>
<if test="createTime != null"> and create_time = #{createTime}</if>
......@@ -89,6 +98,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</select>
<select id="listDuration" resultMap="SCouponResult">
<include refid="selectSCouponVo"/>
where 1=1 and coupon_type = #{couponType}
<if test="endDate != null">and end_date >= NOW()</if>
</select>
<select id="selectSCouponByDealgroupId" resultMap="SCouponResult">
<include refid="selectSCouponVo"/>
where dealgroup_id = #{dealgroupId}
</select>
<select id="selectByDealgroupId" resultMap="SCouponResult">
<include refid="selectSCouponVo"/>
where dealgroup_id = #{dealgroupId}
</select>
<insert id="insertSCoupon" parameterType="SCoupon" useGeneratedKeys="true" keyProperty="id">
insert into s_coupon
......@@ -107,6 +130,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="minPrice != null">min_price,</if>
<if test="subPrice != null">sub_price,</if>
<if test="isOverlay != null">is_overlay,</if>
<if test="weeks != null">weeks,</if>
<if test="platformType != null">platform_type,</if>
<if test="number != null">number,</if>
<if test="createBy != null">create_by,</if>
......@@ -114,6 +138,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">remark,</if>
<if test="orderType != null">order_type,</if>
<if test="packageId != null">package_id,</if>
<if test="dealgroupId != null">dealgroup_id,</if>
<if test="storeIds != null">store_ids,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if>
......@@ -130,6 +156,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="minPrice != null">#{minPrice},</if>
<if test="subPrice != null">#{subPrice},</if>
<if test="isOverlay != null">#{isOverlay},</if>
<if test="weeks != null">#{weeks},</if>
<if test="platformType != null">#{platformType},</if>
<if test="number != null">#{number},</if>
<if test="createBy != null">#{createBy},</if>
......@@ -137,6 +164,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">#{remark},</if>
<if test="orderType != null">#{orderType},</if>
<if test="packageId != null">#{packageId},</if>
<if test="dealgroupId != null">#{dealgroupId},</if>
<if test="storeIds != null">#{storeIds},</if>
</trim>
</insert>
......@@ -146,16 +175,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="name != null and name != ''">name = #{name},</if>
<if test="startDate != null">start_date = #{startDate},</if>
<if test="endDate != null">end_date = #{endDate},</if>
<if test="validStartTime != null">valid_start_time = #{validStartTime},</if>
<if test="validEndTime != null">valid_end_time = #{validEndTime},</if>
<if test="validStartTime != ''">valid_start_time = #{validStartTime},</if>
<if test="validEndTime != ''">valid_end_time = #{validEndTime},</if>
<if test="storeType != null">store_type = #{storeType},</if>
<if test="roomType != null">room_type = #{roomType},</if>
<if test="couponType != null">coupon_type = #{couponType},</if>
<if test="orderType != null">order_type = #{orderType},</if>
<if test="packageId != null">package_id = #{packageId},</if>
<if test="orderType != ''">order_type = #{orderType},</if>
<if test="packageId != ''">package_id = #{packageId},</if>
<if test="storeIds != null">store_ids = #{storeIds},</if>
<if test="dealgroupId != null">dealgroup_id = #{dealgroupId},</if>
<if test="duration != null and duration != ''">duration = #{duration},</if>
<if test="minDuration != null and minDuration != ''">min_duration = #{minDuration},</if>
<if test="maxDuration != null and maxDuration != ''">max_duration = #{maxDuration},</if>
<if test="weeks != null">weeks = #{weeks},</if>
<if test="minPrice != null and minPrice != ''">min_price = #{minPrice},</if>
<if test="subPrice != null and subPrice != ''">sub_price = #{subPrice},</if>
<if test="isOverlay != null">is_overlay = #{isOverlay},</if>
......
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