Compare commits

...

6 Commits
master ... zs

33 changed files with 1019 additions and 65 deletions

View File

@ -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;
}

View File

@ -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();
//读取字符流的字符拼接在stringBufferStringBuffer在进行字符串处理时不生成新的对象在内存使用上要优于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;
}
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,7 +1,10 @@
package com.chaozhanggui.system.cashierservice.controller; package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; 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.OrderVo;
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo; import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
import com.chaozhanggui.system.cashierservice.service.OrderService; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.sql.Timestamp;
import java.util.Date;
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
@RestController @RestController
@Slf4j @Slf4j
@ -34,25 +34,34 @@ public class OrderController {
String userId = jsonObject.getString("accountId"); String userId = jsonObject.getString("accountId");
return orderService.createCart(cartVo.getMasterId(),cartVo.getProductId(),cartVo.getShopId(), return orderService.createCart(cartVo.getMasterId(),cartVo.getProductId(),cartVo.getShopId(),
cartVo.getSkuId(),cartVo.getNumber(),userId,clientType,cartVo.getCartId(),cartVo.getIsGift(), 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") @GetMapping("/queryCart")
public Result queryCart(@RequestHeader("token") String token, public Result queryCart(@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName, @RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType, @RequestHeader("clientType") String clientType,
@RequestParam("masterId") String masterId, @RequestParam(value = "masterId", required = false) String masterId,
@RequestParam(required = false) String tableId,
@RequestParam("shopId") String shopId @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") @GetMapping("/delCart")
public Result delCart(@RequestHeader("token") String token, public Result delCart(@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName, @RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType, @RequestHeader("clientType") String clientType,
@RequestParam("masterId") String masterId, @RequestParam(required = false) String tableId,
@RequestParam(value = "masterId", required = false) String masterId,
@RequestParam("cartId") Integer cartId @RequestParam("cartId") Integer cartId
){ ){
return orderService.delCart(masterId,cartId); return orderService.delCart(masterId,cartId, tableId);
} }
@GetMapping("/createCode") @GetMapping("/createCode")
public Result createCode(@RequestHeader("token") String token, public Result createCode(@RequestHeader("token") String token,

View File

@ -1,13 +1,17 @@
package com.chaozhanggui.system.cashierservice.controller; package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO;
import com.chaozhanggui.system.cashierservice.service.ProductService; import com.chaozhanggui.system.cashierservice.service.ProductService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Map; import java.util.Map;
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
@ -21,6 +25,23 @@ public class ProductController {
private ProductService productService; private ProductService productService;
@PutMapping("/productStatus")
public Result productStatus(
@Valid @RequestBody ProductStatusDTO productStatusDTO
) {
productService.updateState(productStatusDTO);
return Result.success(CodeEnum.SUCCESS);
}
@PutMapping("/productStock")
public Result productStock(
@Valid @RequestBody ProductStockDTO productStockDTO
) {
productService.updateStock(productStockDTO);
return Result.success(CodeEnum.SUCCESS);
}
@GetMapping(value = "queryCommodityInfo") @GetMapping(value = "queryCommodityInfo")
public Result queryCommodityInfo( public Result queryCommodityInfo(
@RequestHeader("token") String token, @RequestHeader("token") String token,

View File

@ -30,9 +30,12 @@ public interface TbCashierCartMapper {
TbCashierCart selectByDetail(@Param("masterId") String masterId, @Param("productId") String productId, 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); @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); 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); 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> 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);
}

View File

@ -52,4 +52,6 @@ public interface TbOrderInfoMapper {
TbOrderInfo selectById(Integer id); TbOrderInfo selectById(Integer id);
List<TbOrderInfo> selectActivateOrder(@Param("shopId") String shopId, @Param("tableId") String qrcodeId);
} }

View File

@ -5,6 +5,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbProductWithBLOBs;
import com.chaozhanggui.system.cashierservice.entity.po.ProConsSkuInfo; import com.chaozhanggui.system.cashierservice.entity.po.ProConsSkuInfo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -35,6 +36,7 @@ public interface TbProductMapper {
List<TbProductWithBLOBs> selectByShopIdAndShopType(@Param("shopId") String shopId, @Param("categoryId") String categoryId,@Param("commdityName") String commdityName); List<TbProductWithBLOBs> selectByShopIdAndShopType(@Param("shopId") String shopId, @Param("categoryId") String categoryId,@Param("commdityName") String commdityName);
List<TbProductWithBLOBs> selectByShopIdAndShopTypeCheckGrounding(@Param("shopId") String shopId, @Param("categoryId") String categoryId,@Param("commdityName") String commdityName); List<TbProductWithBLOBs> selectByShopIdAndShopTypeCheckGrounding(@Param("shopId") String shopId, @Param("categoryId") String categoryId,@Param("commdityName") String commdityName);
List<TbProductWithBLOBs> selectByShopIdAndShopTypeUnGrounding(@Param("shopId") String shopId,@Param("commdityName") String commdityName);
@ -53,4 +55,24 @@ public interface TbProductMapper {
@Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id}") @Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id}")
int decrStockUnCheck(String id, int num); int decrStockUnCheck(String id, int num);
@Select("select * from tb_product product where product.id=#{productId} and product.shop_id=#{shopId} and product.is_del=0")
TbProduct selectByShopIdAndId(@Param("productId") Integer productId, @Param("shopId") Integer shopId);
@Update("update tb_product_sku set is_grounding=#{isGrounding} where product_id=#{productId}")
int updateGroundingByProId(@Param("productId") Integer productId, @Param("isGrounding") int isGrounding);
@Update("update tb_product_sku set is_grounding=#{status} where id=#{skuId}")
int updateGrounding(@Param("skuId") Integer skuId, @Param("status") int status);
@Update("update tb_product set is_pause_sale=#{state} where id=#{id} and shop_id=#{shopId}")
int pauseSale(@Param("id") Integer id, @Param("shopId") Integer shopId, @Param("state") Integer state);
@Update("update tb_product_sku set is_pause_sale=#{state} where product_id=#{id} and shop_id=#{shopId}")
int pauseSkuSale(@Param("id") Integer proId, @Param("shopId") Integer shopId, @Param("state") Integer state);
@Update("update tb_product set stock_number=#{stock} where id=#{productId} and shop_id=#{shopId}")
int updateStock(@Param("shopId") Integer shopId, @Param("productId") Integer productId, @Param("stock") Integer stock);
} }

View File

@ -55,5 +55,11 @@ public interface TbProductSkuMapper {
List<TbProductSku> selectByProductCheckGrounding(@Param("id") Integer id); List<TbProductSku> selectByProductCheckGrounding(@Param("id") Integer id);
@Select("select * from tb_product_sku where is_grounding=1 and is_del=0 and product_id=#{id}") @Select("select * from tb_product_sku where is_grounding=1 and is_del=0 and product_id=#{id}")
List<TbProductSku> selectGroundingByProId(Integer id); List<TbProductSku> selectGroundingByProId(@Param("id") Integer id);
@Update("update tb_product_sku set is_pause_sale=#{state} where id=#{skuId} and shop_id=#{shopId}")
int pauseSale(@Param("skuId") Integer skuId, @Param("shopId") Integer shopId, @Param("state") Integer state);
@Update("update tb_product_sku set stock_number=#{stock} where product_id=#{skuId} and shop_id=#{shopId}")
int updateStock(@Param("shopId") Integer shopId, @Param("skuId") Integer skuId, @Param("stock") Integer stock);
} }

View File

@ -1,6 +1,7 @@
package com.chaozhanggui.system.cashierservice.dao; package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbShopOpenId; import com.chaozhanggui.system.cashierservice.entity.TbShopOpenId;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.List; 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") @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1")
List<TbShopOpenId> selectByShopId(Integer integer); 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);
} }

View File

@ -0,0 +1,176 @@
package com.chaozhanggui.system.cashierservice.entity;
import java.io.Serializable;
import java.util.Date;
/**
*
* @TableName tb_shop_msg_state
*/
public class TbShopMsgState implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private Integer shopId;
/**
*
*/
private Integer type;
/**
*
*/
private Integer state;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
private static final long serialVersionUID = 1L;
/**
*
*/
public Integer getId() {
return id;
}
/**
*
*/
public void setId(Integer id) {
this.id = id;
}
/**
*
*/
public Integer getShopId() {
return shopId;
}
/**
*
*/
public void setShopId(Integer shopId) {
this.shopId = shopId;
}
/**
*
*/
public Integer getType() {
return type;
}
/**
*
*/
public void setType(Integer type) {
this.type = type;
}
/**
*
*/
public Integer getState() {
return state;
}
/**
*
*/
public void setState(Integer state) {
this.state = state;
}
/**
*
*/
public Date getCreateTime() {
return createTime;
}
/**
*
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
*
*/
public Date getUpdateTime() {
return updateTime;
}
/**
*
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
TbShopMsgState other = (TbShopMsgState) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", shopId=").append(shopId);
sb.append(", type=").append(type);
sb.append(", state=").append(state);
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@ -34,6 +34,16 @@ public class TbShopTable implements Serializable {
private Long updatedAt; 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; private static final long serialVersionUID = 1L;
public Integer getId() { public Integer getId() {
@ -155,4 +165,4 @@ public class TbShopTable implements Serializable {
public void setUpdatedAt(Long updatedAt) { public void setUpdatedAt(Long updatedAt) {
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
} }

View File

@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotNull;
@Data
public class ProductStatusDTO {
@NotNull
private Integer productId;
@NotNull
private Integer shopId;
@NotNull
@Range(min = 0, max = 1)
private Integer state;
// 0上下架 1售罄
@Range(min = 0, max = 1)
@NotNull
private Integer type;
}

View File

@ -0,0 +1,18 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@Data
public class ProductStockDTO {
@NotNull
private Integer shopId;
@NotNull
private Integer productId;
@NotNull
@Min(0)
private Integer stock;
}

View File

@ -5,7 +5,10 @@ import lombok.Data;
@Data @Data
public class CartVo { public class CartVo {
private String productId; private String productId;
// orderId不为空为代客下单
private String masterId; private String masterId;
private String tableId;
private String shopId; private String shopId;
private Integer skuId; private Integer skuId;
private Integer number; private Integer number;

View File

@ -0,0 +1,29 @@
package com.chaozhanggui.system.cashierservice.mapper;
import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* @author Administrator
* @description 针对表tb_shop_msg_state的数据库操作Mapper
* @createDate 2024-08-12 14:27:26
* @Entity com.chaozhanggui.system.cashierservice.entity.TbShopMsgState
*/
public interface TbShopMsgStateMapper {
int deleteByPrimaryKey(Long id);
int insert(TbShopMsgState record);
int insertSelective(TbShopMsgState record);
TbShopMsgState selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(TbShopMsgState record);
int updateByPrimaryKey(TbShopMsgState record);
@Select("select * from tb_shop_msg_state where shop_id=#{shopId} and type=#{type};")
TbShopMsgState selectByType(@Param("type") Integer type, @Param("shopId") Integer shopId);
}

View File

@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.bean.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.util.*; import com.chaozhanggui.system.cashierservice.util.*;
@ -132,7 +133,7 @@ public class ConsMsgConsumer {
log.info("开始推送耗材模板消息rediskey{}", value); log.info("开始推送耗材模板消息rediskey{}", value);
if (Objects.isNull(value)) { if (Objects.isNull(value)) {
JSONObject jsonObject = wxAccountUtil.sendStockWarnMsg("耗材库存不足", tbConsInfo.getConName(), JSONObject jsonObject = wxAccountUtil.sendStockWarnMsg("耗材库存不足", tbConsInfo.getConName(),
tbConsInfo.getStockNumber().subtract(tbConsInfo.getStockConsume()).toBigInteger().intValue(), tbUserShopMsg.getOpenId()); tbConsInfo.getStockNumber().subtract(tbConsInfo.getStockConsume()).toBigInteger().intValue(), tbUserShopMsg.getOpenId(), ShopWxMsgTypeEnum.CONSUMABLES_MSG, shopId);
if (jsonObject != null) { if (jsonObject != null) {
log.info("写入redis:{}",key); log.info("写入redis:{}",key);
redisUtil.saveMessage(key, "1", 30 * 60); redisUtil.saveMessage(key, "1", 30 * 60);

View File

@ -1,12 +1,13 @@
package com.chaozhanggui.system.cashierservice.service; package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.bean.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.po.*; import com.chaozhanggui.system.cashierservice.entity.po.*;
@ -25,7 +26,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -92,7 +92,7 @@ public class OrderService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result createCart(String masterId, String productId, String shopId, Integer skuId, Integer number, 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) { if (Objects.isNull(number) || number < 0) {
return Result.fail(CodeEnum.NUMBER); return Result.fail(CodeEnum.NUMBER);
} }
@ -121,8 +121,6 @@ public class OrderService {
return Result.fail(CodeEnum.PRODUCTSKUERROR); return Result.fail(CodeEnum.PRODUCTSKUERROR);
} }
String exists = redisUtil.getMessage(RedisCst.ORDER_CART_EXISTS + cartId); 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()){ }else if (exists != null && skuWithBLOBs.getSuit() != null && skuWithBLOBs.getSuit() != 0 && number < skuWithBLOBs.getSuit()){
redisUtil.deleteByKey(RedisCst.ORDER_CART_EXISTS + cartId); redisUtil.deleteByKey(RedisCst.ORDER_CART_EXISTS + cartId);
delCart(masterId, cartId); delCart(masterId, cartId, qrcode);
return Result.success(CodeEnum.SUCCESS, masterId); 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); boolean flag = redisUtil.exists("SHOP:CODE:" + clientType + ":" + shopId);
if (flag) { if (flag) {
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId).toString(); String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId).toString();
@ -160,6 +158,8 @@ public class OrderService {
masterId = "#" + String.format("%03d", 1); masterId = "#" + String.format("%03d", 1);
} }
} }
TbCashierCart cart = cashierCartMapper.selectByPrimaryKey(cartId); TbCashierCart cart = cashierCartMapper.selectByPrimaryKey(cartId);
if (Objects.nonNull(cart)) { if (Objects.nonNull(cart)) {
cart.setSkuId(skuId.toString()); cart.setSkuId(skuId.toString());
@ -182,15 +182,23 @@ public class OrderService {
cashierCartMapper.updateByPrimaryKeySelective(cart); cashierCartMapper.updateByPrimaryKeySelective(cart);
} else { } else {
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create"); List<TbCashierCart> list = StrUtil.isNotBlank(masterId) ? cashierCartMapper.selectALlByMasterId(masterId, "create")
TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid); : 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 (number > 0) {
if (Objects.isNull(cashierCart)) { if (Objects.isNull(cashierCart)) {
cashierCart = new TbCashierCart(); cashierCart = new TbCashierCart();
cashierCart.setCoverImg(product.getCoverImg()); cashierCart.setCoverImg(product.getCoverImg());
cashierCart.setCreatedAt(System.currentTimeMillis()); cashierCart.setCreatedAt(System.currentTimeMillis());
cashierCart.setIsSku(product.getTypeEnum()); cashierCart.setIsSku(product.getTypeEnum());
cashierCart.setMasterId(masterId); if (qrcode != null) {
cashierCart.setTableId(qrcode);
}else {
cashierCart.setMasterId(masterId);
}
cashierCart.setUuid(uuid); cashierCart.setUuid(uuid);
cashierCart.setMerchantId(userId); cashierCart.setMerchantId(userId);
cashierCart.setName(product.getName()); cashierCart.setName(product.getName());
@ -252,7 +260,9 @@ public class OrderService {
skuWithBLOBs.setUpdatedAt(System.currentTimeMillis()); skuWithBLOBs.setUpdatedAt(System.currentTimeMillis());
tbProductSkuMapper.updateByPrimaryKey(skuWithBLOBs); 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,24 +295,30 @@ public class OrderService {
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine()) (product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && productSku.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 -> { shopOpenIds.forEach(item -> {
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber()-num : (int) (productSku.getStockNumber() - num), item.getOpenId()); product.getIsDistribute() == 1 ? product.getStockNumber()-num : (int) (productSku.getStockNumber() - num), item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopId);
}); });
} }
} }
public Result queryCart(String masterId, String shopId) { public Result queryCart(String masterId, String shopId, String qrcode) {
if (StringUtils.isEmpty(shopId)) { if (StringUtils.isEmpty(shopId)) {
return Result.fail(CodeEnum.SHOPINFONOEXIST); return Result.fail(CodeEnum.SHOPINFONOEXIST);
} }
String day = DateUtils.getDay(); 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); list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId), "refund",day);
if (list.size() > 0){ if (!list.isEmpty()){
if (list.size() < 1) { if (list.isEmpty()) {
return Result.fail(CodeEnum.CARTJH); return Result.fail(CodeEnum.CARTJH);
} }
int orderId = 0; int orderId = 0;
@ -344,7 +360,13 @@ public class OrderService {
} }
// TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPr imaryKey(Integer.valueOf(cashierCart.getProductId())); // 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.setPackAmount(packAmount);
queryCartPo.setTotalAmount(totalAmount); queryCartPo.setTotalAmount(totalAmount);
// queryCartPo.setTotalAmount(totalAmount.add(packAmount)); // queryCartPo.setTotalAmount(totalAmount.add(packAmount));
@ -355,7 +377,7 @@ public class OrderService {
} }
@Transactional(rollbackFor = Exception.class) @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); TbCashierCart cashierCart=cashierCartMapper.selectByPrimaryKey(cartId);
@ -387,7 +409,7 @@ public class OrderService {
List<String> skuIds=new ArrayList<>(); List<String> skuIds=new ArrayList<>();
skuIds.add(cashierCart.getSkuId()); skuIds.add(cashierCart.getSkuId());
cashierCartMapper.deleteByCartId(masterId, cartId); cashierCartMapper.deleteByCartIdOrTableId(masterId, cartId, qrcode);
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }

View File

@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo; import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect; import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect;
@ -106,7 +108,11 @@ public class ProductService {
if(ObjectUtil.isEmpty(categoryId)){ if(ObjectUtil.isEmpty(categoryId)){
tbProductWithBLOBs=tbProductMapper.selectByShopIdAndCheckGrounding(shopId,commdityName); tbProductWithBLOBs=tbProductMapper.selectByShopIdAndCheckGrounding(shopId,commdityName);
}else { }else {
tbProductWithBLOBs=tbProductMapper.selectByShopIdAndShopTypeCheckGrounding(shopId,categoryId,commdityName); if (Integer.valueOf(categoryId).equals(-1)) {
tbProductWithBLOBs = tbProductMapper.selectByShopIdAndShopTypeUnGrounding(shopId,commdityName);
}else {
tbProductWithBLOBs=tbProductMapper.selectByShopIdAndShopTypeCheckGrounding(shopId,categoryId,commdityName);
}
} }
String day = DateUtils.getDay(); String day = DateUtils.getDay();
@ -222,4 +228,29 @@ public class ProductService {
} }
} }
} }
public void updateState(ProductStatusDTO productStatusDTO) {
TbProduct product = tbProductMapper.selectByShopIdAndId(productStatusDTO.getProductId(), productStatusDTO.getShopId());
if (productStatusDTO.getType().equals(0)) {
tbProductMapper.updateGroundingByProId(product.getId(), productStatusDTO.getState());
}else {
tbProductMapper.pauseSale(productStatusDTO.getProductId(), productStatusDTO.getShopId(), productStatusDTO.getState());
tbProductMapper.pauseSkuSale(productStatusDTO.getProductId(), productStatusDTO.getShopId(), productStatusDTO.getState());
}
}
public void updateStock(ProductStockDTO productStockDTO) {
TbProduct product = tbProductMapper.selectByShopIdAndId(productStockDTO.getProductId(), productStockDTO.getShopId());
if (product == null) {
throw new MsgException("商品不存在");
}
if (product.getIsDistribute() != 1 && product.getTypeEnum().equals("sku")) {
throw new MsgException("多规格非共享商品暂不支持修改库存");
}else {
tbProductMapper.updateStock(productStockDTO.getShopId(), productStockDTO.getProductId(), productStockDTO.getStock());
tbProductSkuMapper.updateStock(productStockDTO.getShopId(), productStockDTO.getProductId(), productStockDTO.getStock());
}
}
} }

View File

@ -1,6 +1,8 @@
package com.chaozhanggui.system.cashierservice.service; package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
@ -33,6 +35,11 @@ public class ShopInfoService {
ShopUserDutyMapper shopUserDutyMapper; ShopUserDutyMapper shopUserDutyMapper;
@Autowired @Autowired
ShopUserDutyDetailMapper shopUserDutyDetailMapper; ShopUserDutyDetailMapper shopUserDutyDetailMapper;
private final TbOrderInfoMapper orderInfoMapper;
public ShopInfoService(TbOrderInfoMapper orderInfoMapper) {
this.orderInfoMapper = orderInfoMapper;
}
public Result queryShopArea(String shopId){ public Result queryShopArea(String shopId){
List<TbShopArea> list= tbShopAreaMapper.selectByShopId(shopId); List<TbShopArea> list= tbShopAreaMapper.selectByShopId(shopId);
@ -48,6 +55,7 @@ public class ShopInfoService {
PageHelperUtil.startPage(page, pageSize); PageHelperUtil.startPage(page, pageSize);
List<TbShopTable> shopTables=tbShopTableMapper.selectByShopIdAndStatus(shopId,areaId,status); List<TbShopTable> shopTables=tbShopTableMapper.selectByShopIdAndStatus(shopId,areaId,status);
PageInfo pageInfo=new PageInfo(shopTables); PageInfo pageInfo=new PageInfo(shopTables);
return Result.success(CodeEnum.SUCCESS,pageInfo); return Result.success(CodeEnum.SUCCESS,pageInfo);
} }

View File

@ -5,7 +5,10 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.bean.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.TbShopMsgStateMapper;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -25,7 +28,7 @@ public class WxAccountUtil {
private static String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0"; private static String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0";
@Value("${wx.ysk.warnMsgTmpId}") @Value("${wx.ysk.warnMsgTmpId}")
private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0"; private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0";
private final TbShopMsgStateMapper shopMsgStateMapper;
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>(); static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
static { static {
@ -97,7 +100,12 @@ public class WxAccountUtil {
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
} }
public JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId) { public JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId, ShopWxMsgTypeEnum typeEnum, Integer shopId) {
TbShopMsgState shopMsgState = shopMsgStateMapper.selectByType(typeEnum.getType(), shopId);
if (shopMsgState == null || shopMsgState.getState().equals(0)) {
log.info("店铺未开启推送:{}", shopMsgState);
return null;
}
stock = stock < 0 ? 0 : stock; stock = stock < 0 ? 0 : stock;
Integer finalStock = stock; Integer finalStock = stock;
Map<String, Object> data = new HashMap<String, Object>() {{ Map<String, Object> data = new HashMap<String, Object>() {{

View File

@ -59,6 +59,16 @@
and uuid = #{uuid} and uuid = #{uuid}
</if> </if>
</select> </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 id="selectByMaskerId" resultType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart">
select * select *
from tb_cashier_cart where master_id = #{masterId} and shop_id = #{shopId} and status = #{status} and trade_day = #{day} order by id desc 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 delete from tb_cashier_cart
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<delete id="deleteByCartId"> <delete id="deleteByCartIdOrTableId">
delete from tb_cashier_cart where id = #{cartId} and master_id = #{masterId} 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>
<delete id="deleteBymasterId"> <delete id="deleteBymasterId">
delete from tb_cashier_cart where master_id = #{masterId} and shop_id = #{shopId} delete from tb_cashier_cart where master_id = #{masterId} and shop_id = #{shopId}
@ -103,22 +120,22 @@
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart" useGeneratedKeys="true" keyProperty="id"> <insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart" useGeneratedKeys="true" keyProperty="id">
insert into tb_cashier_cart (id, master_id, order_id, insert into tb_cashier_cart (id, master_id, order_id,
ref_order_id, total_amount, product_id, ref_order_id, total_amount, product_id,
cover_img, is_sku, sku_id, cover_img, is_sku, sku_id,
name, sale_price, number, name, sale_price, number,
total_number, refund_number, category_id, total_number, refund_number, category_id,
status, type, merchant_id, status, type, merchant_id,
shop_id, created_at, updated_at, pack_fee,trade_day,is_pack,is_gift,uuid 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}, values (#{id,jdbcType=INTEGER}, #{masterId,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR},
#{refOrderId,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL}, #{productId,jdbcType=VARCHAR}, #{refOrderId,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL}, #{productId,jdbcType=VARCHAR},
#{coverImg,jdbcType=VARCHAR}, #{isSku,jdbcType=TINYINT}, #{skuId,jdbcType=VARCHAR}, #{coverImg,jdbcType=VARCHAR}, #{isSku,jdbcType=TINYINT}, #{skuId,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR}, #{salePrice,jdbcType=DECIMAL}, #{number,jdbcType=REAL}, #{name,jdbcType=VARCHAR}, #{salePrice,jdbcType=DECIMAL}, #{number,jdbcType=REAL},
#{totalNumber,jdbcType=REAL}, #{refundNumber,jdbcType=REAL}, #{categoryId,jdbcType=VARCHAR}, #{totalNumber,jdbcType=REAL}, #{refundNumber,jdbcType=REAL}, #{categoryId,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{merchantId,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{merchantId,jdbcType=VARCHAR},
#{shopId,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{packFee,jdbcType=DECIMAL} #{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>
<insert id="insertSelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbCashierCart"> <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 * from tb_cashier_cart where master_id = #{masterId} and trade_day = #{day} and shop_id = #{shopId} and status = 'create'
</select> </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>

View File

@ -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> </select>
</mapper> </mapper>

View File

@ -938,6 +938,18 @@
</if> </if>
and b.is_grounding=1 GROUP BY a.id ORDER BY a.`sort` and b.is_grounding=1 GROUP BY a.id ORDER BY a.`sort`
</select>
<select id="selectByShopIdAndShopTypeUnGrounding" resultMap="ResultMapWithBLOBs">
select a.* from tb_product as a
left join tb_product_sku as b on a.id = b.product_id
where a.shop_id=#{shopId} and a.status=1 and a.is_show_cash = 1 and a.type_enum in ('normal','sku','currentPrice','weight')
<if test="commdityName != null and commdityName!='' ">
and a.name like CONCAT('%',#{commdityName},'%')
</if>
and b.is_grounding=0 GROUP BY a.id ORDER BY a.`sort`
</select> </select>
<select id="countOrderByshopIdAndProductId" resultType="INTEGER"> <select id="countOrderByshopIdAndProductId" resultType="INTEGER">

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.chaozhanggui.system.cashierservice.mapper.TbShopMsgStateMapper">
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="type" column="type" jdbcType="INTEGER"/>
<result property="state" column="state" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,shop_id,type,
state,create_time,update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tb_shop_msg_state
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from tb_shop_msg_state
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState" useGeneratedKeys="true">
insert into tb_shop_msg_state
( id,shop_id,type
,state,create_time,update_time
)
values (#{id,jdbcType=INTEGER},#{shopId,jdbcType=INTEGER},#{type,jdbcType=INTEGER}
,#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState" useGeneratedKeys="true">
insert into tb_shop_msg_state
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="shopId != null">shop_id,</if>
<if test="type != null">type,</if>
<if test="state != null">state,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id,jdbcType=INTEGER},</if>
<if test="shopId != null">#{shopId,jdbcType=INTEGER},</if>
<if test="type != null">#{type,jdbcType=INTEGER},</if>
<if test="state != null">#{state,jdbcType=INTEGER},</if>
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
<if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
update tb_shop_msg_state
<set>
<if test="shopId != null">
shop_id = #{shopId,jdbcType=INTEGER},
</if>
<if test="type != null">
type = #{type,jdbcType=INTEGER},
</if>
<if test="state != null">
state = #{state,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
update tb_shop_msg_state
set
shop_id = #{shopId,jdbcType=INTEGER},
type = #{type,jdbcType=INTEGER},
state = #{state,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>

View File

@ -17,13 +17,14 @@
<result column="view" jdbcType="VARCHAR" property="view" /> <result column="view" jdbcType="VARCHAR" property="view" />
<result column="created_at" jdbcType="BIGINT" property="createdAt" /> <result column="created_at" jdbcType="BIGINT" property="createdAt" />
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" /> <result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
<result column="qrcode" jdbcType="VARCHAR" property="qrcode" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <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 type, amount, perhour, view, created_at, updated_at
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from tb_shop_table from tb_shop_table
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
@ -33,16 +34,16 @@
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopTable"> <insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopTable">
insert into tb_shop_table (id, name, shop_id, insert into tb_shop_table (id, name, shop_id,
max_capacity, sort, area_id, max_capacity, sort, area_id,
is_predate, predate_amount, status, is_predate, predate_amount, status,
type, amount, perhour, type, amount, perhour,
view, created_at, updated_at view, created_at, updated_at
) )
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{shopId,jdbcType=INTEGER}, values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{shopId,jdbcType=INTEGER},
#{maxCapacity,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER}, #{areaId,jdbcType=INTEGER}, #{maxCapacity,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER}, #{areaId,jdbcType=INTEGER},
#{isPredate,jdbcType=TINYINT}, #{predateAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}, #{isPredate,jdbcType=TINYINT}, #{predateAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR},
#{type,jdbcType=TINYINT}, #{amount,jdbcType=DECIMAL}, #{perhour,jdbcType=DECIMAL}, #{type,jdbcType=TINYINT}, #{amount,jdbcType=DECIMAL}, #{perhour,jdbcType=DECIMAL},
#{view,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT} #{view,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}
) )
</insert> </insert>
@ -227,4 +228,4 @@
</select> </select>
</mapper> </mapper>