1.代客下单相关接口
This commit is contained in:
parent
c300f61def
commit
86df7addd6
|
|
@ -0,0 +1,26 @@
|
|||
package com.chaozhanggui.system.cashierservice.annotation;
|
||||
|
||||
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.bean.*;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 日志注解
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface MyLog {
|
||||
String value() default "未命名日志";
|
||||
LogTag tag();
|
||||
OperationLogType operationLogType() default OperationLogType.NULL;
|
||||
boolean write() default false;
|
||||
GetKeyWith getKeyWith() default GetKeyWith.WITH_NULL;
|
||||
String keyName() default "";
|
||||
OperationLogState operationLogstate() default OperationLogState.UN_HTTP_STATE;
|
||||
ActionType actionType() default ActionType.SELECT;
|
||||
LogType type() default LogType.INFO;
|
||||
boolean showBody() default false;
|
||||
}
|
||||
|
|
@ -0,0 +1,201 @@
|
|||
package com.chaozhanggui.system.cashierservice.aop;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.annotation.MyLog;
|
||||
import com.chaozhanggui.system.cashierservice.bean.GetKeyWith;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Aspect
|
||||
@Order
|
||||
@Component
|
||||
@Log4j2
|
||||
public class LogAop {
|
||||
|
||||
|
||||
@Pointcut("@annotation(com.chaozhanggui.system.cashierservice.annotation.MyLog)")
|
||||
private void getLogPointCut() {
|
||||
}
|
||||
|
||||
private String getRequestBodyInfo(HttpServletRequest request) {
|
||||
try {
|
||||
//利用InputStreamReader将字节流转换为字符流
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(request.getInputStream()));
|
||||
String string;
|
||||
StringBuilder stringBuffer=new StringBuilder();
|
||||
//读取字符流的字符拼接在stringBuffer,StringBuffer在进行字符串处理时,不生成新的对象,在内存使用上要优于String类
|
||||
while((string=bufferedReader.readLine())!=null){
|
||||
stringBuffer.append(string);
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}catch (Exception e) {
|
||||
log.error(e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@Async
|
||||
public void writeLog(String remoteAddr, String url, MyLog logAnnotation, Map<String, String[]> parameterMap, String bodyInfo, Object resp, long duration) {
|
||||
if (!logAnnotation.write()) return;
|
||||
// 系统操作日志, 异步事件
|
||||
String keyVal = null;
|
||||
JSONObject jsonObject = JSON.parseObject(bodyInfo);
|
||||
if (logAnnotation.keyName() != null && jsonObject != null) {
|
||||
if (GetKeyWith.WITH_POST.equals(logAnnotation.getKeyWith())) {
|
||||
keyVal = jsonObject.getString(logAnnotation.keyName());
|
||||
}else if (GetKeyWith.WITH_GET.equals(logAnnotation.getKeyWith())) {
|
||||
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
||||
if (entry.getKey().equals(logAnnotation.keyName())) {
|
||||
keyVal = entry.getValue()[0];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SystemOperationLog operationLog = new SystemOperationLog();
|
||||
// operationLog.setMsg(logAnnotation.tag().getValue() + " " + logAnnotation.value())
|
||||
// .setKeyValue(keyVal)
|
||||
// .setKeyName(logAnnotation.keyName())
|
||||
// .setState(logAnnotation.operationLogstate())
|
||||
// .setType(logAnnotation.operationLogType())
|
||||
// .setRespData(resp)
|
||||
// .setDuration(duration)
|
||||
// .setIp(remoteAddr)
|
||||
// .setUrl(url)
|
||||
// .setReqData(jsonObject);
|
||||
// Utils.publishEvent(operationLog, OperationLogEvent.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置环绕通知,使用在方法logPointcut()上注册的切入点
|
||||
*
|
||||
* @param joinPoint join point for advice
|
||||
*/
|
||||
@Around("getLogPointCut()")
|
||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
String logInfo = "\033[34m请求地址: {}, 请求ip: {}, 请求方式: {}, GET参数: {}, POST参数: {}\033[0m";
|
||||
String logStr = "";
|
||||
String bodyInfo = "";
|
||||
|
||||
Map<String, String[]> parameterMap = new HashMap<>();
|
||||
HttpServletRequest request = null;
|
||||
String remoteAddr = "";
|
||||
if (attributes != null) {
|
||||
request = attributes.getRequest();
|
||||
if (request.getHeader("X-Forwarded-For") != null) {
|
||||
remoteAddr = request.getHeader("X-Forwarded-For").split(",")[0];
|
||||
} else {
|
||||
remoteAddr = request.getRemoteAddr();
|
||||
}
|
||||
parameterMap = request.getParameterMap();
|
||||
bodyInfo = getRequestBodyInfo(request);
|
||||
logStr = StrFormatter.format(logInfo,
|
||||
request.getRequestURI(), remoteAddr, request.getMethod(), request.getQueryString(), bodyInfo);
|
||||
log.info(logStr);
|
||||
}
|
||||
|
||||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = methodSignature.getMethod();
|
||||
MyLog logAnnotation = method.getAnnotation(MyLog.class);
|
||||
|
||||
|
||||
// 开始时间
|
||||
long startTime = DateUtil.current(false);
|
||||
Object result = null;
|
||||
Exception error = null;
|
||||
try {
|
||||
result = joinPoint.proceed();
|
||||
return result;
|
||||
}catch (Exception e) {
|
||||
error = e;
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
long endTime = DateUtil.current(false);
|
||||
|
||||
writeLog(remoteAddr, request != null ? request.getRequestURI() : "", logAnnotation, parameterMap, bodyInfo, result == null ? Objects.requireNonNull(error).getCause() + error.getMessage(): result, endTime - startTime);
|
||||
|
||||
// 异步记录日志
|
||||
if (logAnnotation.showBody()) {
|
||||
logInfo = "\033[32;4m包名: {}, 方法名: {}, 描述: {}, 操作类型: {}, 执行结果: {}, 执行时间: {}ms\033[0m";
|
||||
}else {
|
||||
logInfo = "\033[32;4m包名: {}, 方法名: {}, 描述: {}, 操作类型: {}, 执行时间: {}ms\033[0m";
|
||||
}
|
||||
switch (logAnnotation.type()) {
|
||||
case INFO:
|
||||
if (logAnnotation.showBody()) {
|
||||
log.info(logInfo,
|
||||
joinPoint.getTarget().getClass().getPackage().getName(),
|
||||
method.getName(), logAnnotation.value(), logAnnotation.actionType().getType(), result, endTime - startTime);
|
||||
}else {
|
||||
log.info(logInfo,
|
||||
joinPoint.getTarget().getClass().getPackage().getName(),
|
||||
method.getName(), logAnnotation.tag() + logAnnotation.value(), logAnnotation.actionType().getType(), endTime - startTime);
|
||||
}
|
||||
|
||||
break;
|
||||
case ERROR:
|
||||
if (logAnnotation.showBody()) {
|
||||
log.error(logInfo,
|
||||
joinPoint.getTarget().getClass().getPackage().getName(),
|
||||
method.getName(), logAnnotation.value(), logAnnotation.actionType().getType(), result, endTime - startTime);
|
||||
}else {
|
||||
log.error(logInfo,
|
||||
joinPoint.getTarget().getClass().getPackage().getName(),
|
||||
method.getName(), logAnnotation.tag() + logAnnotation.value(), logAnnotation.actionType().getType(), endTime - startTime);
|
||||
}
|
||||
break;
|
||||
case WARN:
|
||||
if (logAnnotation.showBody()) {
|
||||
log.warn(logInfo,
|
||||
joinPoint.getTarget().getClass().getPackage().getName(),
|
||||
method.getName(), logAnnotation.value(), logAnnotation.actionType().getType(), result, endTime - startTime);
|
||||
}else {
|
||||
log.warn(logInfo,
|
||||
joinPoint.getTarget().getClass().getPackage().getName(),
|
||||
method.getName(), logAnnotation.tag() + logAnnotation.value(), logAnnotation.actionType().getType(), endTime - startTime);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (logAnnotation.showBody()) {
|
||||
log.debug(logInfo,
|
||||
joinPoint.getTarget().getClass().getPackage().getName(),
|
||||
method.getName(), logAnnotation.value(), logAnnotation.actionType().getType(), result, endTime - startTime);
|
||||
}else {
|
||||
log.debug(logInfo,
|
||||
joinPoint.getTarget().getClass().getPackage().getName(),
|
||||
method.getName(), logAnnotation.tag() + logAnnotation.value(), logAnnotation.actionType().getType(), endTime - startTime);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.chaozhanggui.system.cashierservice.bean;
|
||||
|
||||
|
||||
/**
|
||||
* 日志操作活动枚举
|
||||
*/
|
||||
public enum ActionType {
|
||||
SELECT("查询操作"),
|
||||
UPDATE("修改操作"),
|
||||
DELETE("删除操作"),
|
||||
ADD("新增操作");
|
||||
private String type;
|
||||
|
||||
ActionType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.chaozhanggui.system.cashierservice.bean;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author: ZhangSong
|
||||
* @create: 2024-05-15 17:01
|
||||
*/
|
||||
@Getter
|
||||
public enum GetKeyWith {
|
||||
WITH_GET(0),
|
||||
WITH_POST(1),
|
||||
WITH_NULL(-1);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
GetKeyWith(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.chaozhanggui.system.cashierservice.bean;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 日志标签
|
||||
* @author: ZhangSong
|
||||
* @create: 2024-05-15 16:32
|
||||
*/
|
||||
@Getter
|
||||
public enum LogTag {
|
||||
JPUSH("极光"), CLIENT("安卓"),
|
||||
LOGIN("登录"), SYSTEM("系统"), CART("订单购物车");
|
||||
private final String value;
|
||||
|
||||
LogTag(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.chaozhanggui.system.cashierservice.bean;
|
||||
|
||||
public enum LogType {
|
||||
INFO("INFO"),
|
||||
ERROR("ERROR"),
|
||||
WARN("WARN"),
|
||||
DEBUG("DEBUG");
|
||||
private String value;
|
||||
|
||||
LogType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.chaozhanggui.system.cashierservice.bean;
|
||||
|
||||
/**
|
||||
* 操作日志所有状态
|
||||
* @author: ZhangSong
|
||||
* @create: 2024-04-28 11:06
|
||||
*/
|
||||
public enum OperationLogState {
|
||||
UN_HTTP_STATE(-1),
|
||||
HTTP_FAIL_STATE(0),
|
||||
HTTP_SUCCESS_STATE(1),
|
||||
SQL_EXE_FAIL_STATE(2),
|
||||
SQL_EXE_SUCCESS_STATE(3);
|
||||
|
||||
private Integer state;
|
||||
|
||||
OperationLogState(Integer state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Integer getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.chaozhanggui.system.cashierservice.bean;
|
||||
|
||||
/**
|
||||
* 操作日志所有操作类型
|
||||
* @author: ZhangSong
|
||||
* @create: 2024-04-28 11:04
|
||||
*/
|
||||
public enum OperationLogType {
|
||||
UM_API_QUERY_CITY_CALL(1000),
|
||||
UM_API_UPDATE_ORDER_PHONE(1010),
|
||||
UM_API_QUERY_DRIVER_LOCATION(1020),
|
||||
UM_API_CANCEL_ORDER(1030),
|
||||
UM_API_CANCEL_ORDER_SUCCESS(1040),
|
||||
UM_API_PAY_ORDER_CALL(1050),
|
||||
UM_API_CREATE_INVOICE_CALL(1060),
|
||||
UM_API_QUERY_INVOICE_CALL(1070),
|
||||
UM_API_RED_REVERSE_CALL(1080),
|
||||
UM_API_RED_REVERSE_CALL_SUCCESS(1081),
|
||||
UM_API_PUSH_ORDER_STATE_CALL(1090),
|
||||
UM_API_PUSH_ORDER_STATE_CALL_GET_HL_STATE_FAIL(1091),
|
||||
UM_API_PUSH_DRIVER_CALL(1100),
|
||||
UM_API_PUSH_DRIVER_CALL_API_FAIL(1101),
|
||||
UM_API_QUERY_PRICE_CALL(1110),
|
||||
UM_API_CREATE_ORDER_CALL(1120),
|
||||
UM_API_QUERY_ORDER_DETAIL_CALL(1130),
|
||||
JPUSH_API_CALL(1140),
|
||||
UM_CONTROLLER_MAKE_INVOICE_CALL(1150), UM_API_PUSH_TEMP_DRIVER_CALL(1160),
|
||||
ENUOYUN_INVOICE_CALL(1170),
|
||||
UM_API_CALL_UM_CHANGE_ORDER_STATE(1180),
|
||||
API_CHARGEBACK_CALL(1190),
|
||||
API_REDISTRIBUTE_CALL(1200), API_DRIVER_LOGIN_CALL(1210), NULL(-1),
|
||||
API_CHANGXING_HANGLV_CHONGXIN_SHANGCHUAN(1220),
|
||||
API_CHANGXING_HANGLV_FAPIAO_ZUOFEI(1230);
|
||||
private final Integer value;
|
||||
|
||||
OperationLogType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.chaozhanggui.system.cashierservice.bean;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author: ZhangSong
|
||||
* @create: 2024-05-23 19:01
|
||||
*/
|
||||
@Getter
|
||||
public enum Plat {
|
||||
TT(1),
|
||||
CX(2),
|
||||
RZ(3),
|
||||
JS(5),
|
||||
UNDEFINED(-1);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
Plat(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.chaozhanggui.system.cashierservice.bean;
|
||||
|
||||
public enum ShopWxMsgTypeEnum {
|
||||
ALL_MSG(-1),
|
||||
STOCK_MSG(0),
|
||||
CONSUMABLES_MSG(1),
|
||||
OPERATION_MSG(2);
|
||||
private final Integer type;
|
||||
|
||||
ShopWxMsgTypeEnum(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.annotation.MyLog;
|
||||
import com.chaozhanggui.system.cashierservice.bean.LogTag;
|
||||
import com.chaozhanggui.system.cashierservice.entity.OrderVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
|
||||
import com.chaozhanggui.system.cashierservice.service.OrderService;
|
||||
|
|
@ -11,9 +14,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@CrossOrigin(origins = "*")
|
||||
@RestController
|
||||
@Slf4j
|
||||
|
|
@ -34,25 +34,34 @@ public class OrderController {
|
|||
String userId = jsonObject.getString("accountId");
|
||||
return orderService.createCart(cartVo.getMasterId(),cartVo.getProductId(),cartVo.getShopId(),
|
||||
cartVo.getSkuId(),cartVo.getNumber(),userId,clientType,cartVo.getCartId(),cartVo.getIsGift(),
|
||||
cartVo.getIsPack(),cartVo.getUuid(),cartVo.getType());
|
||||
cartVo.getIsPack(),cartVo.getUuid(),cartVo.getType(), cartVo.getTableId());
|
||||
}
|
||||
|
||||
@MyLog(value = "查询购物车信息", tag = LogTag.CART)
|
||||
@GetMapping("/queryCart")
|
||||
public Result queryCart(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("masterId") String masterId,
|
||||
@RequestParam(value = "masterId", required = false) String masterId,
|
||||
@RequestParam(required = false) String tableId,
|
||||
@RequestParam("shopId") String shopId
|
||||
){
|
||||
return orderService.queryCart(masterId,shopId);
|
||||
if (tableId == null && StrUtil.isBlank(masterId)) {
|
||||
return Result.fail("masterId和tableId不能同时为空");
|
||||
}
|
||||
return orderService.queryCart(masterId,shopId, tableId);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/delCart")
|
||||
public Result delCart(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("masterId") String masterId,
|
||||
@RequestParam(required = false) String tableId,
|
||||
@RequestParam(value = "masterId", required = false) String masterId,
|
||||
@RequestParam("cartId") Integer cartId
|
||||
){
|
||||
return orderService.delCart(masterId,cartId);
|
||||
return orderService.delCart(masterId,cartId, tableId);
|
||||
}
|
||||
@GetMapping("/createCode")
|
||||
public Result createCode(@RequestHeader("token") String token,
|
||||
|
|
|
|||
|
|
@ -30,9 +30,12 @@ public interface TbCashierCartMapper {
|
|||
TbCashierCart selectByDetail(@Param("masterId") String masterId, @Param("productId") String productId,
|
||||
@Param("shopId") String shopId, @Param("skuId") String skuId, @Param("day") String day,@Param("uuid") String uuid);
|
||||
|
||||
TbCashierCart selectDetailByQrcode(@Param("tableId") String tableId, @Param("productId") String productId,
|
||||
@Param("shopId") String shopId, @Param("skuId") String skuId, @Param("uuid") String uuid);
|
||||
|
||||
List<TbCashierCart> selectByMaskerId(@Param("masterId")String masterId, @Param("shopId")Integer shopId,@Param("status") String status,@Param("day") String day);
|
||||
|
||||
void deleteByCartId(@Param("masterId") String masterId, @Param("cartId")Integer cartId);
|
||||
void deleteByCartIdOrTableId(@Param("masterId") String masterId, @Param("cartId")Integer cartId, @Param("qrcode") String qrcode);
|
||||
|
||||
void updateStatus(@Param("masterId") Integer id,@Param("status") String status);
|
||||
|
||||
|
|
@ -60,4 +63,8 @@ public interface TbCashierCartMapper {
|
|||
|
||||
|
||||
List<TbCashierCart> selectByOrderId(@Param("orderId") String orderId,@Param("status") String status);
|
||||
}
|
||||
|
||||
List<TbCashierCart> selectActivateByQrcode(@Param("tableId") String tableId, @Param("shopId") Integer shopId);
|
||||
|
||||
QueryCartPo selectProductNumByQrcode(@Param("qrcode") String qrcode, @Param("shopId") Integer shopId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,4 +52,6 @@ public interface TbOrderInfoMapper {
|
|||
|
||||
|
||||
TbOrderInfo selectById(Integer id);
|
||||
|
||||
List<TbOrderInfo> selectActivateOrder(@Param("shopId") String shopId, @Param("tableId") String qrcodeId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.chaozhanggui.system.cashierservice.dao;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopOpenId;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -27,4 +28,7 @@ public interface TbShopOpenIdMapper {
|
|||
|
||||
@Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1")
|
||||
List<TbShopOpenId> selectByShopId(Integer integer);
|
||||
|
||||
@Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1);")
|
||||
List<TbShopOpenId> selectStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,16 @@ public class TbShopTable implements Serializable {
|
|||
|
||||
private Long updatedAt;
|
||||
|
||||
private String qrcode;
|
||||
|
||||
public String getQrcode() {
|
||||
return qrcode;
|
||||
}
|
||||
|
||||
public void setQrcode(String qrcode) {
|
||||
this.qrcode = qrcode;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public Integer getId() {
|
||||
|
|
@ -155,4 +165,4 @@ public class TbShopTable implements Serializable {
|
|||
public void setUpdatedAt(Long updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ import lombok.Data;
|
|||
@Data
|
||||
public class CartVo {
|
||||
private String productId;
|
||||
|
||||
// orderId不为空为代客下单
|
||||
private String masterId;
|
||||
private String tableId;
|
||||
private String shopId;
|
||||
private Integer skuId;
|
||||
private Integer number;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.bean.ShopWxMsgTypeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.*;
|
||||
|
|
@ -25,7 +26,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -92,7 +92,7 @@ public class OrderService {
|
|||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result createCart(String masterId, String productId, String shopId, Integer skuId, Integer number,
|
||||
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type) {
|
||||
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type, String qrcode) {
|
||||
if (Objects.isNull(number) || number < 0) {
|
||||
return Result.fail(CodeEnum.NUMBER);
|
||||
}
|
||||
|
|
@ -121,8 +121,6 @@ public class OrderService {
|
|||
return Result.fail(CodeEnum.PRODUCTSKUERROR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
String exists = redisUtil.getMessage(RedisCst.ORDER_CART_EXISTS + cartId);
|
||||
|
||||
// 首次加入购物车,并且拥有起售数,设置为起售数
|
||||
|
|
@ -131,7 +129,7 @@ public class OrderService {
|
|||
// 低于起售,删除商品
|
||||
}else if (exists != null && skuWithBLOBs.getSuit() != null && skuWithBLOBs.getSuit() != 0 && number < skuWithBLOBs.getSuit()){
|
||||
redisUtil.deleteByKey(RedisCst.ORDER_CART_EXISTS + cartId);
|
||||
delCart(masterId, cartId);
|
||||
delCart(masterId, cartId, qrcode);
|
||||
return Result.success(CodeEnum.SUCCESS, masterId);
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +145,7 @@ public class OrderService {
|
|||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(masterId)) {
|
||||
if (qrcode == null && StringUtils.isEmpty(masterId)) {
|
||||
boolean flag = redisUtil.exists("SHOP:CODE:" + clientType + ":" + shopId);
|
||||
if (flag) {
|
||||
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId).toString();
|
||||
|
|
@ -160,6 +158,8 @@ public class OrderService {
|
|||
masterId = "#" + String.format("%03d", 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TbCashierCart cart = cashierCartMapper.selectByPrimaryKey(cartId);
|
||||
if (Objects.nonNull(cart)) {
|
||||
cart.setSkuId(skuId.toString());
|
||||
|
|
@ -182,15 +182,23 @@ public class OrderService {
|
|||
cashierCartMapper.updateByPrimaryKeySelective(cart);
|
||||
|
||||
} else {
|
||||
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
|
||||
TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid);
|
||||
List<TbCashierCart> list = StrUtil.isNotBlank(masterId) ? cashierCartMapper.selectALlByMasterId(masterId, "create")
|
||||
: cashierCartMapper.selectActivateByQrcode(qrcode, Integer.valueOf(shopId));
|
||||
|
||||
TbCashierCart cashierCart = StrUtil.isNotBlank(masterId) ? cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid)
|
||||
: cashierCartMapper.selectDetailByQrcode(qrcode, productId, shopId, skuId.toString(), uuid);
|
||||
|
||||
if (number > 0) {
|
||||
if (Objects.isNull(cashierCart)) {
|
||||
cashierCart = new TbCashierCart();
|
||||
cashierCart.setCoverImg(product.getCoverImg());
|
||||
cashierCart.setCreatedAt(System.currentTimeMillis());
|
||||
cashierCart.setIsSku(product.getTypeEnum());
|
||||
cashierCart.setMasterId(masterId);
|
||||
if (qrcode != null) {
|
||||
cashierCart.setTableId(qrcode);
|
||||
}else {
|
||||
cashierCart.setMasterId(masterId);
|
||||
}
|
||||
cashierCart.setUuid(uuid);
|
||||
cashierCart.setMerchantId(userId);
|
||||
cashierCart.setName(product.getName());
|
||||
|
|
@ -252,7 +260,9 @@ public class OrderService {
|
|||
skuWithBLOBs.setUpdatedAt(System.currentTimeMillis());
|
||||
tbProductSkuMapper.updateByPrimaryKey(skuWithBLOBs);
|
||||
|
||||
redisUtil.saveMessage("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + DateUtils.getDay(),masterId.substring(1,masterId.length()));
|
||||
if (StrUtil.isNotBlank(masterId)) {
|
||||
redisUtil.saveMessage("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + DateUtils.getDay(), masterId.substring(1,masterId.length()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -285,7 +295,7 @@ public class OrderService {
|
|||
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|
||||
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
|
||||
) {
|
||||
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId()));
|
||||
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
|
||||
shopOpenIds.forEach(item -> {
|
||||
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
|
||||
product.getIsDistribute() == 1 ? product.getStockNumber()-num : (int) (productSku.getStockNumber() - num), item.getOpenId());
|
||||
|
|
@ -293,16 +303,22 @@ public class OrderService {
|
|||
}
|
||||
}
|
||||
|
||||
public Result queryCart(String masterId, String shopId) {
|
||||
public Result queryCart(String masterId, String shopId, String qrcode) {
|
||||
if (StringUtils.isEmpty(shopId)) {
|
||||
return Result.fail(CodeEnum.SHOPINFONOEXIST);
|
||||
}
|
||||
String day = DateUtils.getDay();
|
||||
List<TbCashierCart> list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId),"create",day);
|
||||
if (list.size() < 1){
|
||||
|
||||
List<TbCashierCart> list;
|
||||
if (StrUtil.isBlank(masterId)) {
|
||||
list = cashierCartMapper.selectActivateByQrcode(qrcode, Integer.valueOf(shopId));
|
||||
}else {
|
||||
list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId),"create",day);
|
||||
}
|
||||
if (StrUtil.isNotBlank(masterId) && list.isEmpty()){
|
||||
list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId), "refund",day);
|
||||
if (list.size() > 0){
|
||||
if (list.size() < 1) {
|
||||
if (!list.isEmpty()){
|
||||
if (list.isEmpty()) {
|
||||
return Result.fail(CodeEnum.CARTJH);
|
||||
}
|
||||
int orderId = 0;
|
||||
|
|
@ -344,7 +360,13 @@ public class OrderService {
|
|||
}
|
||||
// TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPr imaryKey(Integer.valueOf(cashierCart.getProductId()));
|
||||
}
|
||||
QueryCartPo queryCartPo = cashierCartMapper.selectProductNumByMarketId(day, shopId, masterId);
|
||||
|
||||
QueryCartPo queryCartPo;
|
||||
if (StrUtil.isNotBlank(masterId)) {
|
||||
queryCartPo = cashierCartMapper.selectProductNumByMarketId(day, shopId, masterId);
|
||||
}else {
|
||||
queryCartPo = cashierCartMapper.selectProductNumByQrcode(qrcode, Integer.valueOf(shopId));
|
||||
}
|
||||
queryCartPo.setPackAmount(packAmount);
|
||||
queryCartPo.setTotalAmount(totalAmount);
|
||||
// queryCartPo.setTotalAmount(totalAmount.add(packAmount));
|
||||
|
|
@ -355,7 +377,7 @@ public class OrderService {
|
|||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result delCart(String masterId, Integer cartId) {
|
||||
public Result delCart(String masterId, Integer cartId, String qrcode) {
|
||||
|
||||
|
||||
TbCashierCart cashierCart=cashierCartMapper.selectByPrimaryKey(cartId);
|
||||
|
|
@ -387,7 +409,7 @@ public class OrderService {
|
|||
List<String> skuIds=new ArrayList<>();
|
||||
skuIds.add(cashierCart.getSkuId());
|
||||
|
||||
cashierCartMapper.deleteByCartId(masterId, cartId);
|
||||
cashierCartMapper.deleteByCartIdOrTableId(masterId, cartId, qrcode);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
|
|
@ -33,6 +35,11 @@ public class ShopInfoService {
|
|||
ShopUserDutyMapper shopUserDutyMapper;
|
||||
@Autowired
|
||||
ShopUserDutyDetailMapper shopUserDutyDetailMapper;
|
||||
private final TbOrderInfoMapper orderInfoMapper;
|
||||
|
||||
public ShopInfoService(TbOrderInfoMapper orderInfoMapper) {
|
||||
this.orderInfoMapper = orderInfoMapper;
|
||||
}
|
||||
|
||||
public Result queryShopArea(String shopId){
|
||||
List<TbShopArea> list= tbShopAreaMapper.selectByShopId(shopId);
|
||||
|
|
@ -48,6 +55,7 @@ public class ShopInfoService {
|
|||
PageHelperUtil.startPage(page, pageSize);
|
||||
List<TbShopTable> shopTables=tbShopTableMapper.selectByShopIdAndStatus(shopId,areaId,status);
|
||||
PageInfo pageInfo=new PageInfo(shopTables);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS,pageInfo);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,16 @@
|
|||
and uuid = #{uuid}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectDetailByQrcode" resultType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from tb_cashier_cart where table_id = #{tableId} and product_id = #{productId} and shop_id = #{shopId} and
|
||||
sku_id = #{skuId}
|
||||
<if test="uuid != null">
|
||||
and uuid = #{uuid}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByMaskerId" resultType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart">
|
||||
select *
|
||||
from tb_cashier_cart where master_id = #{masterId} and shop_id = #{shopId} and status = #{status} and trade_day = #{day} order by id desc
|
||||
|
|
@ -92,8 +102,15 @@
|
|||
delete from tb_cashier_cart
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<delete id="deleteByCartId">
|
||||
delete from tb_cashier_cart where id = #{cartId} and master_id = #{masterId}
|
||||
<delete id="deleteByCartIdOrTableId">
|
||||
delete from tb_cashier_cart where id = #{cartId} and
|
||||
<if test="masterId != null">
|
||||
master_id = #{masterId}
|
||||
</if>
|
||||
|
||||
<if test="qrcode != null">
|
||||
table_id =#{qrcode}
|
||||
</if>
|
||||
</delete>
|
||||
<delete id="deleteBymasterId">
|
||||
delete from tb_cashier_cart where master_id = #{masterId} and shop_id = #{shopId}
|
||||
|
|
@ -103,22 +120,22 @@
|
|||
</if>
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into tb_cashier_cart (id, master_id, order_id,
|
||||
ref_order_id, total_amount, product_id,
|
||||
cover_img, is_sku, sku_id,
|
||||
name, sale_price, number,
|
||||
total_number, refund_number, category_id,
|
||||
status, type, merchant_id,
|
||||
shop_id, created_at, updated_at, pack_fee,trade_day,is_pack,is_gift,uuid
|
||||
insert into tb_cashier_cart (id, master_id, order_id,
|
||||
ref_order_id, total_amount, product_id,
|
||||
cover_img, is_sku, sku_id,
|
||||
name, sale_price, number,
|
||||
total_number, refund_number, category_id,
|
||||
status, type, merchant_id,
|
||||
shop_id, created_at, updated_at, pack_fee,trade_day,is_pack,is_gift,uuid, table_id
|
||||
)
|
||||
values (#{id,jdbcType=INTEGER}, #{masterId,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR},
|
||||
#{refOrderId,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL}, #{productId,jdbcType=VARCHAR},
|
||||
#{coverImg,jdbcType=VARCHAR}, #{isSku,jdbcType=TINYINT}, #{skuId,jdbcType=VARCHAR},
|
||||
#{name,jdbcType=VARCHAR}, #{salePrice,jdbcType=DECIMAL}, #{number,jdbcType=REAL},
|
||||
#{totalNumber,jdbcType=REAL}, #{refundNumber,jdbcType=REAL}, #{categoryId,jdbcType=VARCHAR},
|
||||
#{status,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{merchantId,jdbcType=VARCHAR},
|
||||
values (#{id,jdbcType=INTEGER}, #{masterId,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR},
|
||||
#{refOrderId,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL}, #{productId,jdbcType=VARCHAR},
|
||||
#{coverImg,jdbcType=VARCHAR}, #{isSku,jdbcType=TINYINT}, #{skuId,jdbcType=VARCHAR},
|
||||
#{name,jdbcType=VARCHAR}, #{salePrice,jdbcType=DECIMAL}, #{number,jdbcType=REAL},
|
||||
#{totalNumber,jdbcType=REAL}, #{refundNumber,jdbcType=REAL}, #{categoryId,jdbcType=VARCHAR},
|
||||
#{status,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{merchantId,jdbcType=VARCHAR},
|
||||
#{shopId,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{packFee,jdbcType=DECIMAL}
|
||||
, #{tradeDay,jdbcType=VARCHAR}, #{isPack,jdbcType=VARCHAR}, #{isGift,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}
|
||||
, #{tradeDay,jdbcType=VARCHAR}, #{isPack,jdbcType=VARCHAR}, #{isGift,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR},#{tableId,jdbcType=VARCHAR}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart">
|
||||
|
|
@ -389,5 +406,16 @@
|
|||
select * from tb_cashier_cart where master_id = #{masterId} and trade_day = #{day} and shop_id = #{shopId} and status = 'create'
|
||||
</select>
|
||||
|
||||
<select id="selectActivateByQrcode"
|
||||
resultType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart">
|
||||
select * from tb_cashier_cart where table_id = #{tableId} and shop_id = #{shopId} and status = 'create'
|
||||
</select>
|
||||
<select id="selectProductNumByQrcode"
|
||||
resultType="com.chaozhanggui.system.cashierservice.entity.po.QueryCartPo">
|
||||
select ifnull(count(*),0) as productNum,ifnull(sum(number),0)as productSum
|
||||
from (select count(*),number
|
||||
from tb_cashier_cart where table_id = #{qrcode} and shop_id = #{shopId} group by product_id ) a
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -627,5 +627,9 @@ select * from tb_order_info where trade_day = #{day} and table_id = #{masterId}
|
|||
|
||||
|
||||
|
||||
</select>
|
||||
<select id="selectActivateOrder" resultType="com.chaozhanggui.system.cashierservice.entity.TbOrderInfo">
|
||||
SELECT * FROM `tb_order_info` where shop_id=#{shopId} and
|
||||
table_id=#{tableId} and order_type != 'return' and `status` not in ('closed', 'refund', 'merge')
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -17,13 +17,14 @@
|
|||
<result column="view" jdbcType="VARCHAR" property="view" />
|
||||
<result column="created_at" jdbcType="BIGINT" property="createdAt" />
|
||||
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
|
||||
<result column="qrcode" jdbcType="VARCHAR" property="qrcode" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, name, shop_id, max_capacity, sort, area_id, is_predate, predate_amount, status,
|
||||
id, name, shop_id, max_capacity, sort, area_id, is_predate, predate_amount, status,
|
||||
type, amount, perhour, view, created_at, updated_at
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from tb_shop_table
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
|
|
@ -33,16 +34,16 @@
|
|||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopTable">
|
||||
insert into tb_shop_table (id, name, shop_id,
|
||||
max_capacity, sort, area_id,
|
||||
is_predate, predate_amount, status,
|
||||
type, amount, perhour,
|
||||
insert into tb_shop_table (id, name, shop_id,
|
||||
max_capacity, sort, area_id,
|
||||
is_predate, predate_amount, status,
|
||||
type, amount, perhour,
|
||||
view, created_at, updated_at
|
||||
)
|
||||
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{shopId,jdbcType=INTEGER},
|
||||
#{maxCapacity,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER}, #{areaId,jdbcType=INTEGER},
|
||||
#{isPredate,jdbcType=TINYINT}, #{predateAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR},
|
||||
#{type,jdbcType=TINYINT}, #{amount,jdbcType=DECIMAL}, #{perhour,jdbcType=DECIMAL},
|
||||
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{shopId,jdbcType=INTEGER},
|
||||
#{maxCapacity,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER}, #{areaId,jdbcType=INTEGER},
|
||||
#{isPredate,jdbcType=TINYINT}, #{predateAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR},
|
||||
#{type,jdbcType=TINYINT}, #{amount,jdbcType=DECIMAL}, #{perhour,jdbcType=DECIMAL},
|
||||
#{view,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}
|
||||
)
|
||||
</insert>
|
||||
|
|
@ -227,4 +228,4 @@
|
|||
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue