diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/annotation/MyLog.java b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/MyLog.java new file mode 100644 index 0000000..19c4391 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/MyLog.java @@ -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; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/aop/LogAop.java b/src/main/java/com/chaozhanggui/system/cashierservice/aop/LogAop.java new file mode 100644 index 0000000..579f673 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/aop/LogAop.java @@ -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 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 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 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; + } + } + + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/ActionType.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/ActionType.java new file mode 100644 index 0000000..71bf830 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/ActionType.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/GetKeyWith.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/GetKeyWith.java new file mode 100644 index 0000000..dcd1ee8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/GetKeyWith.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/LogTag.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/LogTag.java new file mode 100644 index 0000000..4543914 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/LogTag.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/LogType.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/LogType.java new file mode 100644 index 0000000..1bb599d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/LogType.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/OperationLogState.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/OperationLogState.java new file mode 100644 index 0000000..cec77e1 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/OperationLogState.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/OperationLogType.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/OperationLogType.java new file mode 100644 index 0000000..522bc70 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/OperationLogType.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/Plat.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/Plat.java new file mode 100644 index 0000000..e08f21e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/Plat.java @@ -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; + } + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/ShopWxMsgTypeEnum.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/ShopWxMsgTypeEnum.java new file mode 100644 index 0000000..56dad9d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/ShopWxMsgTypeEnum.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index 5b26a4c..215fb84 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -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, diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java index acd74f0..bc36128 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java @@ -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 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 selectByOrderId(@Param("orderId") String orderId,@Param("status") String status); -} \ No newline at end of file + + List selectActivateByQrcode(@Param("tableId") String tableId, @Param("shopId") Integer shopId); + + QueryCartPo selectProductNumByQrcode(@Param("qrcode") String qrcode, @Param("shopId") Integer shopId); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java index ad45837..19f7bc9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java @@ -52,4 +52,6 @@ public interface TbOrderInfoMapper { TbOrderInfo selectById(Integer id); + + List selectActivateOrder(@Param("shopId") String shopId, @Param("tableId") String qrcodeId); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java index bf63e68..5b0e08a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java @@ -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 selectByShopId(Integer integer); + + @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1);") + List selectStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java index 32a8954..2220724 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java @@ -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; } -} \ No newline at end of file +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CartVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CartVo.java index 119851f..a4e701c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CartVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CartVo.java @@ -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; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index f056e3e..9a40660 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -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 list = cashierCartMapper.selectALlByMasterId(masterId, "create"); - TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid); + List 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 shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId())); + List 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 list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId),"create",day); - if (list.size() < 1){ + + List 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 skuIds=new ArrayList<>(); skuIds.add(cashierCart.getSkuId()); - cashierCartMapper.deleteByCartId(masterId, cartId); + cashierCartMapper.deleteByCartIdOrTableId(masterId, cartId, qrcode); return Result.success(CodeEnum.SUCCESS); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ShopInfoService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ShopInfoService.java index 9dab6c6..ab60c20 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ShopInfoService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ShopInfoService.java @@ -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 list= tbShopAreaMapper.selectByShopId(shopId); @@ -48,6 +55,7 @@ public class ShopInfoService { PageHelperUtil.startPage(page, pageSize); List shopTables=tbShopTableMapper.selectByShopIdAndStatus(shopId,areaId,status); PageInfo pageInfo=new PageInfo(shopTables); + return Result.success(CodeEnum.SUCCESS,pageInfo); } diff --git a/src/main/resources/mapper/TbCashierCartMapper.xml b/src/main/resources/mapper/TbCashierCartMapper.xml index 73c8e41..a86be1a 100644 --- a/src/main/resources/mapper/TbCashierCartMapper.xml +++ b/src/main/resources/mapper/TbCashierCartMapper.xml @@ -59,6 +59,16 @@ and uuid = #{uuid} + + + + - \ No newline at end of file + + diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index 7b74a28..fbff1b4 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -627,5 +627,9 @@ select * from tb_order_info where trade_day = #{day} and table_id = #{masterId} + + diff --git a/src/main/resources/mapper/TbShopTableMapper.xml b/src/main/resources/mapper/TbShopTableMapper.xml index aee6013..17dceed 100644 --- a/src/main/resources/mapper/TbShopTableMapper.xml +++ b/src/main/resources/mapper/TbShopTableMapper.xml @@ -17,13 +17,14 @@ + - 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 - \ No newline at end of file +