Merge branch 'ww' into test

This commit is contained in:
wangw 2024-09-20 18:18:13 +08:00
commit 0abcbbec32
9 changed files with 217 additions and 69 deletions

View File

@ -53,6 +53,13 @@ public interface LogService {
@Async
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log,Integer shopId);
/**
* @param description 描述
* @param method 方法
* @param param 入参
*/
void save(String description,String method,String param);
/**
* 查询异常详情
* @param id 日志ID

View File

@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
@ -120,6 +121,24 @@ public class LogServiceImpl implements LogService {
logRepository.save(log);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(String description,String method,String param) {
Log log = new Log();
HttpServletRequest request = RequestHolder.getHttpServletRequest();
log.setUsername(SecurityUtils.getCurrentUsername());
log.setLogType("INFO");
log.setBrowser(StringUtils.getBrowser(request));
log.setRequestIp(StringUtils.getIp(request));
log.setAddress(StringUtils.getCityInfo(log.getRequestIp()));
log.setDescription(description);
log.setMethod(method);
log.setParams(param);
logRepository.save(log);
}
/**
* 根据方法和传入的参数获取请求参数
*/

View File

@ -1,25 +1,31 @@
package cn.ysk.cashier.cons.rest;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.ViewHandover;
import cn.ysk.cashier.cons.service.ViewHandoverService;
import cn.ysk.cashier.cons.service.dto.ViewHandoverQueryCriteria;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.utils.JSONUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.http.client.methods.CloseableHttpResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
/**
* @author admin
@ -40,18 +46,25 @@ public class ViewHandoverController {
@PostMapping("handoverData")
@Log("提交交班")
@ApiOperation("提交交班")
public ResponseEntity<Object> handoverData(@RequestBody ViewHandover resources){
if(Objects.isNull(resources.getShopId())) throw new BadRequestException("店铺信息不可为空");
HttpResponse response = HttpUtil.createGet(StrUtil.format(wxServiceHostname,"/cashierService/common/handoverData?shopId={}", resources.getShopId())).execute();
if (response.getStatus() >= 200 && response.getStatus() < 300) {
String body = response.body();
return new ResponseEntity<>(HttpStatus.OK);
} else {
// 请求失败获取状态码和错误信息
int statusCode = response.getStatus();
String errorMessage = response.body(); // 可以获取错误信息
log.error("交班提交失败:{}",errorMessage);
throw new BadRequestException("请求失败,状态码:"+statusCode);
public ResponseEntity<Object> handoverData(@RequestBody Map<String, Object> map) throws Exception {
if (CollectionUtils.isEmpty(map) || !map.containsKey("shopId") || !map.containsKey("isprintProduct")) {
throw new BadRequestException("参数缺失");
}
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost post = new HttpPost(wxServiceHostname + "/cashierService/common/handoverData");
String jsonString = JSONUtil.toJSONString(map);
StringEntity entity = new StringEntity(jsonString);
post.setEntity(entity);
post.setHeader("Content-Type", "application/json");
try (CloseableHttpResponse response = httpClient.execute(post)) {
if (response.getStatusLine().getStatusCode() == 200) {
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.valueOf(response.getStatusLine().getStatusCode()));
}
} finally {
httpClient.close();
}
}

View File

@ -2,10 +2,12 @@ package cn.ysk.cashier.controller.product;
import cn.hutool.core.util.StrUtil;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.dto.product.StockQueryDto;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.service.product.StockService;
import cn.ysk.cashier.utils.BeanUtil;
import cn.ysk.cashier.utils.JSONUtil;
import cn.ysk.cashier.vo.StockUpdateValueVO;
import cn.ysk.cashier.vo.StockUpdateWarnLineVO;
import cn.ysk.cashier.vo.StockV2Vo;
@ -16,11 +18,13 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@ -134,10 +138,12 @@ public class StockController {
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("商品库存 修改商品状态")
@PutMapping("productStatus")
public ResponseEntity<Object> updateProductStatus(@RequestBody StockUpdateValueVO updateValueVO) {
stockService.updateProductStatus(updateValueVO);
// @Log("商品库存 修改商品状态")
@PostMapping("updateProductData")
@AnonymousPostMapping
public ResponseEntity<Object> updateProductData(@Validated @RequestBody List<StockUpdateValueVO> updateValueVO) {
log.info(JSONUtil.toJSONString(updateValueVO));
// stockService.updateProductStatus(updateValueVO);
return new ResponseEntity<>("修改成功", HttpStatus.OK);
}

View File

@ -10,6 +10,7 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.util.List;
/**
@ -69,4 +70,8 @@ public interface TbProductRepository extends JpaRepository<TbProduct, Integer>,
@Query(value = "select * from tb_product as a where a.id=:skuId", nativeQuery = true)
TbProduct selectById(@Param("skuId") Integer skuId);
@Modifying
@Query("update TbProduct set lowPrice=:lowPrice where id=:id")
void upLowPrice(@Param("id") Integer id, @Param("lowPrice") BigDecimal lowPrice);
}

View File

@ -160,6 +160,10 @@ public interface TbProductSkuRepository extends JpaRepository<TbProductSku, Inte
List<StockVo> searchProStock(@Param("shopId") String shopId, @Param("proName") String proName, @Param("isStock")Integer isStock,@Param("num")Double num);
@Query(value = "SELECT min(sale_price) from tb_product_sku where product_id = ?1 and id != ?2", nativeQuery = true)
BigDecimal searchMinSalePrice(@Param("productId") Integer productId, @Param("skuId") Integer skuId);
@Transactional
@Modifying
@Query("update FROM TbProductSku sku set sku.costPrice=:costPrice,sku.coverImg =:coverImg, " +

View File

@ -15,6 +15,7 @@ import cn.ysk.cashier.repository.product.TbProductSkuRepository;
import cn.ysk.cashier.repository.product.TbProductStockDetailRepository;
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
import cn.ysk.cashier.repository.shop.TbShopUnitRepository;
import cn.ysk.cashier.service.LogService;
import cn.ysk.cashier.service.TbProductStockOperateService;
import cn.ysk.cashier.service.product.StockService;
import cn.ysk.cashier.service.product.TbProductService;
@ -61,6 +62,7 @@ public class StockServiceImpl implements StockService {
private final TbProductStockDetailRepository tbProductStockDetailRepository;
private final TbProductRepository tbProductRepository;
private final WxMsgUtils wxMsgUtils;
private final LogService logService;
@PersistenceContext
private EntityManager em;
@ -332,70 +334,153 @@ public class StockServiceImpl implements StockService {
@Override
@Transactional
public void updateProductStatus(StockUpdateValueVO updateValueVO) {
if (!"0".equals(updateValueVO.getUpdateValue()) && !"1".equals(updateValueVO.getUpdateValue())) {
throw new BadRequestException("无效值");
public void updateProductStatus(List<StockUpdateValueVO> updateValueVOs) {
TbProduct product = new TbProduct();
for (StockUpdateValueVO updateValueVO : updateValueVOs) {
if (!updateValueVO.isSku()) {
if (!updateValueVO.isSku()) {
if (product == null) {
product = tbProductRepository.getById(Integer.valueOf(updateValueVO.getId()));
}
productUp(updateValueVO, product);
} else {
if (product == null) {
product = tbProductRepository.selectBySkuId(Integer.valueOf(updateValueVO.getId()));
}
productSkuUp(updateValueVO, product);
}
}
}
if (StringUtils.isBlank(updateValueVO.getTargetId())) {
throw new BadRequestException("更新id不能为空");
}
public void productUp(StockUpdateValueVO updateValueVO,TbProduct product){
if(Objects.isNull(product)){
throw new BadRequestException("该商品不存在");
}
StringBuilder sqlQuery = new StringBuilder("update tb_product ");
switch (updateValueVO.getUpdateKey()) {
case "pauseSaleSku":
sqlQuery = new StringBuilder("update tb_product_sku set is_pause_sale = ").
append(updateValueVO.getUpdateValue()).
append(" where id = ").
append(updateValueVO.getTargetId()).
append(";");
Query nativeQuery = em.createNativeQuery(String.valueOf(sqlQuery));
nativeQuery.executeUpdate();
TbProduct product = tbProductRepository.selectBySkuId(Integer.valueOf(updateValueVO.getTargetId()));
TbProductSku tbProductSku = tbProductSkuRepository.findById(Integer.valueOf(updateValueVO.getTargetId())).orElse(null);
// 推送微信操作消息
if (product != null && tbProductSku != null) {
wxMsgUtils.aboardOperationMsg(("0".equals(updateValueVO.getUpdateValue()) ? "关闭售罄: " : "开启售罄: ") + product.getName() + "/"+ tbProductSku.getSpecSnap(), Integer.valueOf(updateValueVO.getShopId()));
}else {
log.warn("推送微信操作消息失败未查询到商品信息skuId: {}", updateValueVO.getTargetId());
StringBuilder description = new StringBuilder("商品" + product.getName());
switch (updateValueVO.getKey()) {
case "pauseSale"://商品 暂停销售
if (!"0".equals(updateValueVO.getValue()) && !"1".equals(updateValueVO.getValue())) {
throw new BadRequestException("无效值");
}
return;
case "stock":
sqlQuery.append(" set is_stock = ").append(updateValueVO.getUpdateValue());
sqlQuery.append(" set is_pause_sale = ").append(updateValueVO.getValue());
description.append(" 修改为" + ("0".equals(updateValueVO.getValue()) ? "非售罄" : "已售罄"));
break;
case "distribute":
sqlQuery.append(" set is_distribute = ").append(updateValueVO.getUpdateValue());
break;
case "pauseSale":
sqlQuery.append(" set is_pause_sale = ").append(updateValueVO.getUpdateValue());
TbProduct product1 = tbProductRepository.getById(Integer.valueOf(updateValueVO.getTargetId()));
// 推送微信操作消息
if (product1 != null) {
wxMsgUtils.aboardOperationMsg(("0".equals(updateValueVO.getUpdateValue()) ? "关闭售罄: " : "开启售罄: ") + product1.getName(), Integer.valueOf(updateValueVO.getShopId()));
}else {
log.warn("推送微信操作消息失败未查询到商品信息skuId: {}", updateValueVO.getTargetId());
case "grounding"://上下架
if (!"0".equals(updateValueVO.getValue()) && !"1".equals(updateValueVO.getValue())) {
throw new BadRequestException("无效值");
}
tbProductSkuRepository.updateGroundingByProId(product.getId().toString(), Integer.valueOf(updateValueVO.getValue()));
description.append("0".equals(updateValueVO.getValue()) ? "已下架" : "已上架");
sqlQuery.append(" set is_grounding = ").append(updateValueVO.getValue());
break;
case "stockNumber"://库存
description.append(" 库存数量修改为:"+updateValueVO.getValue()+" 原库存:"+product.getStockNumber());
sqlQuery.append(" set stock_number = ").append(updateValueVO.getValue());
break;
// case "stock"://库存开关
// if (!"0".equals(updateValueVO.getValue()) && !"1".equals(updateValueVO.getValue())) {
// throw new BadRequestException("无效值");
// }
// description.append("库存开关" + ("0".equals(updateValueVO.getValue()) ? "已关闭" : "已开启"));
// sqlQuery.append(" set is_stock = ").append(updateValueVO.getValue());
// break;
// case "distribute"://共享库存
// if (!"0".equals(updateValueVO.getValue()) && !"1".equals(updateValueVO.getValue())) {
// throw new BadRequestException("无效值");
// }
// description.append("库存共享 " + ("0".equals(updateValueVO.getValue()) ? "已关闭" : "已开启"));
// sqlQuery.append(" set is_distribute = ").append(updateValueVO.getValue());
// break;
default:
throw new BadRequestException("无效更新类型");
}
sqlQuery.append(" where ");
if (StringUtils.isNotBlank(updateValueVO.getShopId())) {
sqlQuery.append(" shop_id = ").append(updateValueVO.getShopId());
sqlQuery.append(" and ");
}
sqlQuery.append(" id = ").append(updateValueVO.getTargetId());
sqlQuery.append(" id = ").append(updateValueVO.getId());
sqlQuery.append(" ;");
Query nativeQuery = em.createNativeQuery(String.valueOf(sqlQuery));
nativeQuery.executeUpdate();
if("pauseSale".equals(updateValueVO.getKey())){
wxMsgUtils.aboardOperationMsg(("0".equals(updateValueVO.getValue()) ? "关闭售罄: " : "开启售罄: ") + product.getName(),
Integer.valueOf(updateValueVO.getShopId()));
}
logService.save(description.toString(),
"cn.ysk.cashier.controller.product.StockController.updateProductStatus()",
JSONUtil.toJSONString(updateValueVO));
}
public void productSkuUp(StockUpdateValueVO updateValueVO, TbProduct product) {
if (Objects.isNull(product)) {
throw new BadRequestException("该商品不存在");
}
TbProductSku tbProductSku = tbProductSkuRepository.findById(Integer.valueOf(updateValueVO.getId())).orElse(null);
if (Objects.isNull(tbProductSku)) {
throw new BadRequestException("该商品规格不存在");
}
StringBuilder sqlQuery = new StringBuilder("update tb_product_sku ");
StringBuilder description = new StringBuilder("商品" + product.getName()+" 规格:" + tbProductSku.getSpecSnap());
switch (updateValueVO.getKey()) {
case "pauseSale": //sku售罄
if (!"0".equals(updateValueVO.getValue()) && !"1".equals(updateValueVO.getValue())) {
throw new BadRequestException("无效值");
}
sqlQuery.append(" set is_pause_sale = ").append(updateValueVO.getValue());
description.append(" 修改为" + ("0".equals(updateValueVO.getValue()) ? "非售罄" : "已售罄"));
break;
case "grounding": //sku上下架
if (!"0".equals(updateValueVO.getValue()) && !"1".equals(updateValueVO.getValue())) {
throw new BadRequestException("无效值");
}
sqlQuery.append(" set is_grounding = ").append(updateValueVO.getValue());
description.append("0".equals(updateValueVO.getValue()) ? "已下架" : "已上架");
break;
case "salePrice"://价格
description.append("修改价格为" + updateValueVO.getValue());
sqlQuery.append(" set sale_price = ").append(updateValueVO.getValue());
if(("sku").equals(product.getTypeEnum())){
BigDecimal bigDecimal = tbProductSkuRepository.searchMinSalePrice(Integer.valueOf(tbProductSku.getProductId()),tbProductSku.getId());
if (bigDecimal.compareTo(new BigDecimal(updateValueVO.getValue())) < 0) {
tbProductRepository.upLowPrice(product.getId(),bigDecimal);
}else {
tbProductRepository.upLowPrice(product.getId(),new BigDecimal(updateValueVO.getValue()));
}
}else {
tbProductRepository.upLowPrice(product.getId(),new BigDecimal(updateValueVO.getValue()));
}
break;
default:
throw new BadRequestException("无效更新类型");
}
sqlQuery.append(" where ");
if (StringUtils.isNotBlank(updateValueVO.getShopId())) {
sqlQuery.append(" shop_id = ").append(updateValueVO.getShopId());
sqlQuery.append(" and ");
}
sqlQuery.append(" id = ").append(updateValueVO.getId());
sqlQuery.append(" ;");
Query nativeQuery = em.createNativeQuery(String.valueOf(sqlQuery));
nativeQuery.executeUpdate();
if("pauseSale".equals(updateValueVO.getKey())){
// 推送微信操作消息
wxMsgUtils.aboardOperationMsg(
("0".equals(updateValueVO.getValue()) ? "关闭售罄: " : "开启售罄: ") + product.getName() + "/" + tbProductSku.getSpecSnap(),
Integer.valueOf(updateValueVO.getShopId()));
}
logService.save(description.toString(),
"cn.ysk.cashier.controller.product.StockController.updateProductStatus()",
JSONUtil.toJSONString(updateValueVO));
}
@Override
public void updateProductWarnLine(StockUpdateWarnLineVO stockUpdateWarnLineVO) {
TbShopInfo shopInfo = tbShopInfoRepository.findById(Integer.valueOf(stockUpdateWarnLineVO.getShopId())).orElse(null);

View File

@ -37,7 +37,7 @@ public interface StockService {
void updateIsStock(Integer proId, String shopId,Integer isStock);
void updateProductStatus(StockUpdateValueVO updateValueVO);
void updateProductStatus(List<StockUpdateValueVO> updateValueVO);
/**
* 商品库存警戒线设置

View File

@ -2,13 +2,22 @@ package cn.ysk.cashier.vo;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author GYJ
*/
@Data
public class StockUpdateValueVO {
private String updateValue;
private String updateKey;
private String targetId;
@NotNull(message = "店铺Id不可为空")
private String shopId;
@NotNull
private boolean isSku;
@NotNull(message = "主键不可为空")
private String id;
@NotNull(message = "key不可为空")
private String key;
@NotNull(message = "value不可为空")
private String value;
}