From 4f7a38734988e8dd56c50b87d483a54768ec3a39 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 1 Aug 2024 16:07:29 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=E9=94=80=E9=87=8F=E5=AF=BC=E5=87=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/utils/FileUtil.java | 34 ++++++++++++ .../order/TbOrderDetailRepository.java | 17 ++++++ .../service/impl/SummaryServiceImpl.java | 54 +++++++++++++------ .../cashier/vo/TbOrderSalesCountByDayVo.java | 18 +++++++ 4 files changed, 106 insertions(+), 17 deletions(-) diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java index 0f2fcacc..74b22ffa 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java @@ -32,9 +32,11 @@ import java.io.*; import java.security.MessageDigest; import java.text.DecimalFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentLinkedQueue; /** * File工具类,扩展 hutool 工具包 @@ -231,6 +233,36 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { IoUtil.close(out); } + public static void downloadExcelAndMerge(ConcurrentLinkedQueue> list, int colSize, HttpServletResponse response, ArrayList mergeRowIndex) throws IOException { + String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; + File file = new File(tempPath); + BigExcelWriter writer = ExcelUtil.getBigWriter(file); + + // 合并单元格后的标题行,使用默认标题样式. + for (int i = 0; i < mergeRowIndex.size(); i++) { + for (int i1 = 0; i1 < colSize; i1++) { + writer.merge(i == 0 ? 0 : mergeRowIndex.get(i - 1) + 1, mergeRowIndex.get(i), i1, i1, "", true); + } + } + // 一次性写出内容,使用默认样式,强制输出标题 + writer.write(list, true); + SXSSFSheet sheet = (SXSSFSheet)writer.getSheet(); + //上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法 + sheet.trackAllColumnsForAutoSizing(); + //列宽自适应 + writer.autoSizeColumnAll(); + //response为HttpServletResponse对象 + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); + //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 + response.setHeader("Content-Disposition", "attachment;filename=file.xlsx"); + ServletOutputStream out = response.getOutputStream(); + // 终止后删除临时文件 + file.deleteOnExit(); + writer.flush(out, true); + //此处记得关闭输出Servlet流 + IoUtil.close(out); + } + public static String getFileType(String type) { String documents = "txt doc pdf ppt pps xlsx xls docx"; String music = "mp3 wav wma mpa ram ra aac aif m4a"; @@ -353,4 +385,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { public static String getMd5(File file) { return getMd5(getByte(file)); } + + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java index e8cdda21..6de46a4b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java @@ -3,6 +3,7 @@ package cn.ysk.cashier.repository.order; import cn.ysk.cashier.dto.product.StockCountDTO; import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.vo.TbOrderPayCountVo; +import cn.ysk.cashier.vo.TbOrderSaleVO; import cn.ysk.cashier.vo.TbOrderSalesCountByDayVo; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Page; @@ -77,6 +78,7 @@ public interface TbOrderDetailRepository extends JpaRepository findOrderIdsByProductNameLike(@Param("productName") String productName, @Param("shop_id") String shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + @Query(value = "SELECT\n" + + "od.num,\n" + + "od.price AS price,\n" + + "od.status, oi.orderNo \n" + + "FROM\n" + + "TbOrderInfo oi\n" + + "LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" + + "WHERE\n" + + "od.shopId = :shopId \n" + + "AND ( od.status = 'closed' OR od.status = 'refund' ) \n" + + "AND oi.createdAt > :startTime \n" + + "AND oi.createdAt < :endTime \n" + + "AND od.productId = :productId\n" + + "AND od.productSkuId = :productSkuId") + List querySaleOrderInfo(Date startTime, Date endTime, Integer productId, Integer productSkuId, String shopId); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index a8bf5b37..6588408b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -37,6 +37,7 @@ import java.time.Instant; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.ConcurrentLinkedQueue; @Service @RequiredArgsConstructor @@ -403,10 +404,13 @@ public class SummaryServiceImpl implements SummaryService { @Override public void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); +// List> list = new ArrayList<>(); + ConcurrentLinkedQueue> list = new ConcurrentLinkedQueue(); if(StringUtils.isBlank(summaryDto.getCateId())){ summaryDto.setCateId(null); } + + ArrayList mergeRowIndex = new ArrayList<>(); if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额 Long start = 1704038400000L; Long end = Instant.now().toEpochMilli(); @@ -430,23 +434,39 @@ public class SummaryServiceImpl implements SummaryService { summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L))); summaryDto.setEndTime(new Date()); } - List tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime()); - for (TbOrderSalesCountByDayVo all : tbOrderSalesCountByDayVos) { - Map map = new LinkedHashMap<>(); - map.put("商品分类", all.getCateName()); - map.put("商品名称", all.getProductName()); - map.put("单 位", all.getUnitName()); - map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName()); - map.put("销 售 额", all.getSalesAmount()); - map.put("销 量", all.getSalesNum()); - map.put("单 价", all.getPrice()); - map.put("退 单 量", all.getRefNum()); - map.put("退 单 额", all.getRefAmount().compareTo(BigDecimal.ZERO)==0?all.getRefAmount():"-"+all.getRefAmount()); - map.put("总 量", all.getNum()-all.getRefNum()); - list.add(map); - } + List tbOrderSalesCountByDayVos = detailRepository + .queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime()); + tbOrderSalesCountByDayVos.stream().parallel().forEach(all -> { + List tbOrderSaleVOS = detailRepository.querySaleOrderInfo(summaryDto.getStartTime(), + summaryDto.getEndTime(), all.getProductId(), all.getProductSkuId(), summaryDto.getShopId()); + for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) { + Map map = new LinkedHashMap<>(); + map.put("商品分类", all.getCateName()); + map.put("商品名称", all.getProductName()); + map.put("单 位", all.getUnitName()); + map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName()); + map.put("销 售 额", all.getSalesAmount()); + map.put("销 量", all.getSalesNum()); + map.put("单 价", all.getPrice()); + map.put("退 单 量", all.getRefNum()); + map.put("退 单 额", all.getRefAmount().compareTo(BigDecimal.ZERO)==0?all.getRefAmount():"-"+all.getRefAmount()); + map.put("总 量", all.getNum()-all.getRefNum()); + map.put("订单编号", tbOrderSaleVO.getOrderNo()); + map.put("售出数量", tbOrderSaleVO.getNum()); + list.add(map); + } + if (!tbOrderSaleVOS.isEmpty()) { + if (mergeRowIndex.isEmpty()) { + mergeRowIndex.add(tbOrderSaleVOS.size()); + }else { + mergeRowIndex.add(mergeRowIndex.get(mergeRowIndex.size() - 1) + tbOrderSaleVOS.size()); + } + } + + }); + } - FileUtil.downloadExcel(list, response); + FileUtil.downloadExcelAndMerge(list, 12, response, mergeRowIndex); } @Override diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java index f2644496..b48d86c7 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java @@ -14,6 +14,24 @@ public class TbOrderSalesCountByDayVo { private BigDecimal salesAmount; private BigDecimal refAmount; private Long num; + private Integer productId; + private Integer productSkuId; + + public Integer getProductId() { + return productId; + } + + public void setProductId(Integer productId) { + this.productId = productId; + } + + public Integer getProductSkuId() { + return productSkuId; + } + + public void setProductSkuId(Integer productSkuId) { + this.productSkuId = productSkuId; + } public String getProductName() { return productName; From 556b0338de5c7df3c1064e4ed1676119a7ce40a7 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 1 Aug 2024 17:15:40 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=E9=94=80=E9=87=8F=E5=AF=BC=E5=87=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/utils/FileUtil.java | 4 +- eladmin-system/pom.xml | 6 +++ .../order/TbOrderDetailRepository.java | 37 ++++++++++--------- .../service/impl/SummaryServiceImpl.java | 11 +++--- .../cashier/vo/TbOrderSalesCountByDayVo.java | 19 ++++++++++ pom.xml | 2 + 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java index 74b22ffa..36c88ff1 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java @@ -36,7 +36,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentLinkedQueue; /** * File工具类,扩展 hutool 工具包 @@ -233,13 +232,14 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { IoUtil.close(out); } - public static void downloadExcelAndMerge(ConcurrentLinkedQueue> list, int colSize, HttpServletResponse response, ArrayList mergeRowIndex) throws IOException { + public static void downloadExcelAndMerge(List> list, int colSize, HttpServletResponse response, ArrayList mergeRowIndex) throws IOException { String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; File file = new File(tempPath); BigExcelWriter writer = ExcelUtil.getBigWriter(file); // 合并单元格后的标题行,使用默认标题样式. for (int i = 0; i < mergeRowIndex.size(); i++) { + System.out.println(i); for (int i1 = 0; i1 < colSize; i1++) { writer.merge(i == 0 ? 0 : mergeRowIndex.get(i - 1) + 1, mergeRowIndex.get(i), i1, i1, "", true); } diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index 8984287d..1acadac4 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -19,6 +19,7 @@ + cn.ysk.cashier @@ -39,6 +40,11 @@ 2.6 + + org.apache.poi + poi + 5.2.1 + org.springframework.boot diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java index 6de46a4b..dc5a9597 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java @@ -15,6 +15,8 @@ import org.springframework.data.jpa.repository.Query; import javax.persistence.Tuple; +import java.sql.Time; +import java.sql.Timestamp; import java.util.Date; import java.util.List; @@ -78,13 +80,14 @@ public interface TbOrderDetailRepository extends JpaRepository queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + @Query(value = "SELECT " + + "new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status)\n" + + "FROM\n" + + "TbOrderInfo oi\n" + + "LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" + + "WHERE\n" + + "od.shopId = :shopId \n" + + "AND ( od.status = 'closed' OR od.status = 'refund' ) \n" + + "AND od.createTime > :startTime \n" + + "AND od.createTime < :endTime \n" + + "AND (:productId is null or od.productId = :productId)\n" + + "AND (:productId is null or od.productSkuId = :productSkuId)") + List querySaleOrderInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("productId") Integer productId, @Param("productSkuId") Integer productSkuId, @Param("shopId") Integer shopId); + @Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" + "COALESCE(CAST(SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END) as long),0), " + "COALESCE(CAST(SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END) as long),0))" + @@ -147,19 +164,5 @@ public interface TbOrderDetailRepository extends JpaRepository findOrderIdsByProductNameLike(@Param("productName") String productName, @Param("shop_id") String shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); - @Query(value = "SELECT\n" + - "od.num,\n" + - "od.price AS price,\n" + - "od.status, oi.orderNo \n" + - "FROM\n" + - "TbOrderInfo oi\n" + - "LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" + - "WHERE\n" + - "od.shopId = :shopId \n" + - "AND ( od.status = 'closed' OR od.status = 'refund' ) \n" + - "AND oi.createdAt > :startTime \n" + - "AND oi.createdAt < :endTime \n" + - "AND od.productId = :productId\n" + - "AND od.productSkuId = :productSkuId") - List querySaleOrderInfo(Date startTime, Date endTime, Integer productId, Integer productSkuId, String shopId); + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index 6588408b..d7b4ff6f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; +import java.sql.Timestamp; import java.time.Instant; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @@ -404,8 +405,8 @@ public class SummaryServiceImpl implements SummaryService { @Override public void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException { -// List> list = new ArrayList<>(); - ConcurrentLinkedQueue> list = new ConcurrentLinkedQueue(); + List> list = new ArrayList<>(); +// ConcurrentLinkedQueue> list = new ConcurrentLinkedQueue(); if(StringUtils.isBlank(summaryDto.getCateId())){ summaryDto.setCateId(null); } @@ -436,9 +437,9 @@ public class SummaryServiceImpl implements SummaryService { } List tbOrderSalesCountByDayVos = detailRepository .queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime()); - tbOrderSalesCountByDayVos.stream().parallel().forEach(all -> { - List tbOrderSaleVOS = detailRepository.querySaleOrderInfo(summaryDto.getStartTime(), - summaryDto.getEndTime(), all.getProductId(), all.getProductSkuId(), summaryDto.getShopId()); + tbOrderSalesCountByDayVos.forEach(all -> { + List tbOrderSaleVOS = detailRepository.querySaleOrderInfo(new Timestamp(summaryDto.getStartTime().getTime()), + new Timestamp(summaryDto.getEndTime().getTime()), all.getProductId(), all.getProductSkuId(), Integer.valueOf(summaryDto.getShopId())); for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) { Map map = new LinkedHashMap<>(); map.put("商品分类", all.getCateName()); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java index b48d86c7..c35b2dbe 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java @@ -134,6 +134,25 @@ public class TbOrderSalesCountByDayVo { count(); } + public TbOrderSalesCountByDayVo(String productName, String productSkuName, String cateName,String unitName,BigDecimal price, + Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount, Integer productId, Integer productSkuId) { + this.productName = productName; + this.productSkuName = productSkuName; + this.cateName = cateName; + this.unitName = unitName; + this.price = price; + this.salesNum = salesNum; + this.refNum = refNum; + this.salesAmount = salesAmount; + this.refAmount = refAmount; + this.num = num; + this.productId = productId; + this.productSkuId = productSkuId; + count(); + } + + + public void count(){ salesNum=salesNum-refNum; salesAmount=salesAmount.subtract(refAmount); diff --git a/pom.xml b/pom.xml index dc2e1007..4e5d59af 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,8 @@ + + org.springframework.boot From 49ec7ab65d8b91b0aa404669032a2712c0947a31 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 2 Aug 2024 16:11:23 +0800 Subject: [PATCH 03/15] =?UTF-8?q?1.=E6=95=B0=E6=8D=AE=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=E9=94=80=E9=87=8F=E5=AF=BC=E5=87=BA=E4=BF=AE=E6=94=B9=202.?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=85=B3=E9=97=AD=E5=BA=93=E5=AD=98=E5=88=86?= =?UTF-8?q?=E7=BB=84=E5=BE=AE=E4=BF=A1=E6=8F=90=E9=86=92=203.=E7=9B=98?= =?UTF-8?q?=E7=82=B9=E5=87=BA=E5=85=A5=E5=BA=93=E5=B1=95=E7=A4=BA=E8=A7=84?= =?UTF-8?q?=E6=A0=BC=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/utils/FileUtil.java | 69 ++++++++-- .../controller/product/StockController.java | 7 - .../cashier/mybatis/entity/TbShopOpenId.java | 59 ++++++++ .../mybatis/mapper/TbShopOpenIdMapper.java | 18 +++ .../mybatis/service/TbShopOpenIdService.java | 13 ++ .../service/impl/TbShopOpenIdServiceImpl.java | 22 +++ .../product/TbProductRepository.java | 2 + .../service/impl/SummaryServiceImpl.java | 2 +- .../impl/productimpl/StockServiceImpl.java | 25 +++- .../TbProductGroupServiceImpl.java | 6 +- .../TbProductStocktakinServiceImpl.java | 1 + .../cn/ysk/cashier/utils/WxAccountUtil.java | 126 ++++++++++++++++++ .../java/cn/ysk/cashier/utils/WxMsgUtils.java | 58 ++++++++ .../java/cn/ysk/cashier/vo/TbOrderSaleVO.java | 17 +++ .../src/main/resources/config/application.yml | 6 + .../resources/mapper/TbShopOpenIdMapper.xml | 22 +++ 16 files changed, 429 insertions(+), 24 deletions(-) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopOpenId.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopOpenIdMapper.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopOpenIdService.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopOpenIdServiceImpl.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMsgUtils.java create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSaleVO.java create mode 100644 eladmin-system/src/main/resources/mapper/TbShopOpenIdMapper.xml diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java index 36c88ff1..ae33d9f2 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java @@ -17,14 +17,19 @@ package cn.ysk.cashier.utils; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.poi.excel.BigExcelWriter; import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; import cn.ysk.cashier.exception.BadRequestException; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.streaming.SXSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFSheet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.multipart.MultipartFile; + import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -154,7 +159,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { /** * inputStream 转 File */ - static File inputStreamToFile(InputStream ins, String name){ + static File inputStreamToFile(InputStream ins, String name) { File file = new File(SYS_TEM_DIR + name); if (file.exists()) { return file; @@ -215,7 +220,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { BigExcelWriter writer = ExcelUtil.getBigWriter(file); // 一次性写出内容,使用默认样式,强制输出标题 writer.write(list, true); - SXSSFSheet sheet = (SXSSFSheet)writer.getSheet(); + SXSSFSheet sheet = (SXSSFSheet) writer.getSheet(); //上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法 sheet.trackAllColumnsForAutoSizing(); //列宽自适应 @@ -232,29 +237,71 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { IoUtil.close(out); } + /** + * 输入标题到excel + * + * @param writer excel对象 + * @param column 当前列位置 + * @param cellValue 标题内容 + * @param requiredFlag 是否标红 + */ + private static void writeCell(ExcelWriter writer, int column, int row, String cellValue, boolean requiredFlag) { + // 根据x,y轴设置单元格内容 + if (StrUtil.isNotBlank(cellValue)) { + writer.writeCellValue(column, row, cellValue); + } + Font font = writer.createFont(); + font.setColor(Font.COLOR_RED); + if (requiredFlag) { + // 根据x,y轴获取当前单元格样式 + CellStyle cellStyle = writer.createCellStyle(column, row); + // 内容水平居中 + cellStyle.setAlignment(HorizontalAlignment.CENTER); + // 内容垂直居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + // 设置边框 + cellStyle.setBorderBottom(BorderStyle.THIN); + cellStyle.setBorderLeft(BorderStyle.THIN); + cellStyle.setBorderRight(BorderStyle.THIN); + // 字体颜色标红 +// cellStyle.setFont(font); + cellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + } + public static void downloadExcelAndMerge(List> list, int colSize, HttpServletResponse response, ArrayList mergeRowIndex) throws IOException { String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; File file = new File(tempPath); - BigExcelWriter writer = ExcelUtil.getBigWriter(file); - - // 合并单元格后的标题行,使用默认标题样式. + ExcelWriter writer = ExcelUtil.getWriter(file); for (int i = 0; i < mergeRowIndex.size(); i++) { - System.out.println(i); + + int start = i == 0 ? 1 : mergeRowIndex.get(i - 1) + 1; for (int i1 = 0; i1 < colSize; i1++) { - writer.merge(i == 0 ? 0 : mergeRowIndex.get(i - 1) + 1, mergeRowIndex.get(i), i1, i1, "", true); + + if (start != mergeRowIndex.get(i)) { + writer.merge(i == 0 ? 1 : mergeRowIndex.get(i - 1) + 1, mergeRowIndex.get(i), i1, i1, "", true); + } } } + // 一次性写出内容,使用默认样式,强制输出标题 writer.write(list, true); - SXSSFSheet sheet = (SXSSFSheet)writer.getSheet(); + + XSSFSheet sheet = (XSSFSheet) writer.getSheet(); + // 设置列宽 + for (int i = 0; i < colSize + 2; i++) { + sheet.setColumnWidth(i, 4000); // 200个字符宽度 + } //上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法 - sheet.trackAllColumnsForAutoSizing(); +// sheet.trackAllColumnsForAutoSizing(); //列宽自适应 - writer.autoSizeColumnAll(); +// writer.autoSizeColumnAll(); //response为HttpServletResponse对象 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 response.setHeader("Content-Disposition", "attachment;filename=file.xlsx"); + // 将写入的Excel作为文件流写出到response ServletOutputStream out = response.getOutputStream(); // 终止后删除临时文件 file.deleteOnExit(); @@ -295,7 +342,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { public static boolean check(File file1, File file2) { String img1Md5 = getMd5(file1); String img2Md5 = getMd5(file2); - if(img1Md5 != null){ + if (img1Md5 != null) { return img1Md5.equals(img2Md5); } return false; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/StockController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/StockController.java index 8326bb57..a41c8e77 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/StockController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/StockController.java @@ -1,15 +1,11 @@ package cn.ysk.cashier.controller.product; import cn.hutool.core.util.StrUtil; -import cn.ysk.cashier.annotation.AnonymousAccess; 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.SecurityUtils; -import cn.ysk.cashier.vo.StockPageImpl; import cn.ysk.cashier.vo.StockUpdateValueVO; import cn.ysk.cashier.vo.StockUpdateWarnLineVO; import cn.ysk.cashier.vo.StockV2Vo; @@ -18,15 +14,12 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; 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 javax.validation.Valid; import java.io.IOException; import java.util.Map; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopOpenId.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopOpenId.java new file mode 100644 index 00000000..72c687f3 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopOpenId.java @@ -0,0 +1,59 @@ +package cn.ysk.cashier.mybatis.entity; + +import java.io.Serializable; +import java.time.LocalDateTime; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 商家openid信息表 + * @TableName tb_shop_open_id + */ +@Table(name="tb_shop_open_id") +@Data +@EqualsAndHashCode +public class TbShopOpenId implements Serializable { + /** + * + */ + @Id + private Integer id; + + /** + * 店铺id + */ + private Integer shopId; + + /** + * 已经订阅消息的商家微信号 + */ + private String openId; + + /** + * + */ + private Integer status; + + /** + * + */ + private LocalDateTime createTime; + + /** + * + */ + private LocalDateTime updateTime; + + /** + * 类型 -1 任意消息 0库存预警 + */ + private Integer type; + + private static final long serialVersionUID = 1L; + + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopOpenIdMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopOpenIdMapper.java new file mode 100644 index 00000000..3e088ed0 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopOpenIdMapper.java @@ -0,0 +1,18 @@ +package cn.ysk.cashier.mybatis.mapper; + +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author Administrator +* @description 针对表【tb_shop_open_id(商家openid信息表)】的数据库操作Mapper +* @createDate 2024-08-02 10:00:27 +* @Entity cn.ysk.cashier.mybatis.entity.TbShopOpenId +*/ +public interface TbShopOpenIdMapper extends BaseMapper { + +} + + + + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopOpenIdService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopOpenIdService.java new file mode 100644 index 00000000..554107d5 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopOpenIdService.java @@ -0,0 +1,13 @@ +package cn.ysk.cashier.mybatis.service; + +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author Administrator +* @description 针对表【tb_shop_open_id(商家openid信息表)】的数据库操作Service +* @createDate 2024-08-02 10:00:27 +*/ +public interface TbShopOpenIdService extends IService { + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopOpenIdServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopOpenIdServiceImpl.java new file mode 100644 index 00000000..bf99c448 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopOpenIdServiceImpl.java @@ -0,0 +1,22 @@ +package cn.ysk.cashier.mybatis.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import cn.ysk.cashier.mybatis.service.TbShopOpenIdService; +import cn.ysk.cashier.mybatis.mapper.TbShopOpenIdMapper; +import org.springframework.stereotype.Service; + +/** +* @author Administrator +* @description 针对表【tb_shop_open_id(商家openid信息表)】的数据库操作Service实现 +* @createDate 2024-08-02 10:00:27 +*/ +@Service +public class TbShopOpenIdServiceImpl extends ServiceImpl + implements TbShopOpenIdService{ + +} + + + + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java index 01e2ae64..86bc5ffc 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java @@ -62,4 +62,6 @@ public interface TbProductRepository extends JpaRepository, @Query("select product from TbProduct product where product.shopId=:shopId") List selectByShopId(String shopId); + @Query(value = "select b.* from tb_product_sku as a left join tb_product as b on a.product_id=b.id where a.id=:skuId", nativeQuery = true) + TbProduct selectBySkuId(@Param("skuId") Integer skuId); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index d7b4ff6f..15c158ca 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -467,7 +467,7 @@ public class SummaryServiceImpl implements SummaryService { }); } - FileUtil.downloadExcelAndMerge(list, 12, response, mergeRowIndex); + FileUtil.downloadExcelAndMerge(list, 10, response, mergeRowIndex); } @Override diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/StockServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/StockServiceImpl.java index 25363231..4511db70 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/StockServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/StockServiceImpl.java @@ -17,10 +17,7 @@ import cn.ysk.cashier.repository.shop.TbShopUnitRepository; import cn.ysk.cashier.service.TbProductStockOperateService; import cn.ysk.cashier.service.product.StockService; import cn.ysk.cashier.service.product.TbProductService; -import cn.ysk.cashier.utils.CacheKey; -import cn.ysk.cashier.utils.FileUtil; -import cn.ysk.cashier.utils.RedisUtils; -import cn.ysk.cashier.utils.StringUtils; +import cn.ysk.cashier.utils.*; import cn.ysk.cashier.vo.StockUpdateValueVO; import cn.ysk.cashier.vo.StockUpdateWarnLineVO; import cn.ysk.cashier.vo.StockV2Vo; @@ -62,6 +59,7 @@ public class StockServiceImpl implements StockService { private final TbShopUnitRepository shopUnitRepository; private final TbProductStockDetailRepository tbProductStockDetailRepository; private final TbProductRepository tbProductRepository; + private final WxMsgUtils wxMsgUtils; @PersistenceContext private EntityManager em; @@ -349,6 +347,15 @@ public class StockServiceImpl implements StockService { 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()) ? "关闭sku售罄: " : "开启sku售罄: ") + product.getName() + "/"+ tbProductSku.getSpecSnap()); + }else { + log.warn("推送微信操作消息失败,未查询到商品信息,skuId: {}", updateValueVO.getTargetId()); + } return; case "stock": sqlQuery.append(" set is_stock = ").append(updateValueVO.getUpdateValue()); @@ -358,6 +365,13 @@ public class StockServiceImpl implements StockService { break; case "pauseSale": sqlQuery.append(" set is_pause_sale = ").append(updateValueVO.getUpdateValue()); + TbProduct product1 = tbProductRepository.selectBySkuId(Integer.valueOf(updateValueVO.getTargetId())); + // 推送微信操作消息 + if (product1 != null) { + wxMsgUtils.aboardOperationMsg(("0".equals(updateValueVO.getUpdateValue()) ? "关闭售罄: " : "开启售罄: ") + product1.getName()); + }else { + log.warn("推送微信操作消息失败,未查询到商品信息,skuId: {}", updateValueVO.getTargetId()); + } break; default: throw new BadRequestException("无效更新类型"); @@ -393,7 +407,10 @@ public class StockServiceImpl implements StockService { if (tbProductSku == null) { throw new BadRequestException("商品不存在,skuId: " + skuId); } + TbProduct product = tbProductRepository.selectByShopIdAndId(Integer.parseInt(tbProductSku.getProductId()), String.valueOf(shopId)); + // 推送微信操作消息 + wxMsgUtils.aboardOperationMsg((isGrounding ? "上架商品: " : "下架商品: ") + product.getName()); // 共享库存下架所有sku if (product.getIsDistribute().equals(1)) { tbProductSkuRepository.updateGroundingByProId(product.getId().toString(), isGrounding ? 1 : 0); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java index 89bbc6cc..bb84510a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java @@ -46,6 +46,7 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { private final TbProductGroupRepository tbProductGroupRepository; private final TbProductGroupMapper tbProductGroupMapper; private final TbProductRepository tbProductRepository; + private final WxMsgUtils wxMsgUtils; @Resource private OnlineUserService onlineUserService; @@ -104,6 +105,9 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { ValidationUtil.isNull( tbProductGroup.getId(),"TbProductGroup","id",resources.getId()); tbProductGroup.copy(resources); tbProductGroupRepository.save(tbProductGroup); + + // 推送微信操作消息 + wxMsgUtils.aboardOperationMsg((resources.getIsShow() == 0 ? "关闭分组: " : "开启分组: ") + tbProductGroup.getName()); } @Transactional(rollbackFor = Exception.class) @@ -224,4 +228,4 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { -} \ No newline at end of file +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductStocktakinServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductStocktakinServiceImpl.java index 2f953ab9..ed5c51ce 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductStocktakinServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductStocktakinServiceImpl.java @@ -160,6 +160,7 @@ public class TbProductStocktakinServiceImpl implements TbProductStocktakinServic round = (int) Math.floor( productSku.getStockNumber()); + productStockDetail.setSpecSnap(productSku.getSpecSnap()); productStockDetail.setSubType(productStocktakinDTO.getStocktakinNum() > productSku.getStockNumber() ? 1 : -1); stockOperate.setType(productStocktakinDTO.getStocktakinNum() > productSku.getStockNumber() ? "盘点入库" : "盘点出库"); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java new file mode 100644 index 00000000..409d60ed --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java @@ -0,0 +1,126 @@ +package cn.ysk.cashier.utils; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpUtil; +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Data +@Slf4j +@Component +public class WxAccountUtil { + @Value("${wx.ysk.appId}") + private String appId = "wx212769170d2c6b2a"; + @Value("${wx.ysk.secrete}") + private String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0"; + @Value("${wx.ysk.operationMsgTmpId}") + private String operationMsgTmpId ; + + static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); + + static { + + linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); + linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40037","不合法的 template_id"); + linkedHashMap.put("43101","用户未订阅消息"); + linkedHashMap.put("43107","订阅消息能力封禁"); + linkedHashMap.put("43108","并发下发消息给同一个粉丝"); + linkedHashMap.put("45168","命中敏感词"); + linkedHashMap.put("47003","参数错误"); + + } + + public static void main(String[] args) { +// sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI"); + } + + public String getRadarQrCode(Integer shopId) { + HashMap req = new HashMap<>(); + req.put("expire_seconds", 300); + req.put("action_name", "QR_STR_SCENE"); + HashMap actionInfo = new HashMap<>(); + HashMap scene = new HashMap<>(); + scene.put("scene_str", "msg" + shopId); + actionInfo.put("scene", scene); + req.put("action_info", actionInfo); + log.info("开始获取公众号二维码, 请求数据: {}", req); + String resp = HttpUtil.post("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getAccessToken(), JSONObject.toJSONString(req)); + JSONObject respInfo = JSONObject.parseObject(resp); + log.warn("获取微信公众号二维码结束,响应: {}", resp); + if (!respInfo.containsKey("url")) { + log.warn("获取微信公众号二维码失败,响应: {}", resp); + throw new RuntimeException(resp); + } + return respInfo.getString("url"); + } + + + public String getAccessToken() { + String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete)); + JSONObject respInfo = JSONObject.parseObject(resp); + if (!respInfo.containsKey("access_token")) { + log.warn("公众号获取token失败, 响应内容: {}", resp); + throw new RuntimeException(resp); + } + return respInfo.getString("access_token"); + } + + public JSONObject sendTemplateMsg(String templateId, String toUserOpenId, Map data) { + log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); + String accessToken = getAccessToken(); + + JSONObject object1=new JSONObject(); + + object1.put("template_id", templateId); + object1.put("touser", toUserOpenId); + object1.put("data",data); + + String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); + log.info("微信模板消息发送成功,响应内容:{}",response); + JSONObject resObj=JSONObject.parseObject(response); + if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ + return resObj; + } + + throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); + } + + @Async + public void sendOperationMsg(List openIds, String userName, String operationDesc) { + openIds.forEach(item -> { + Map data = new HashMap() {{ + put("thing19", new HashMap(){{ + put("value", userName); + }}); + put("thing8", new HashMap(){{ + put("value", operationDesc); + }}); + put("time21", new HashMap(){{ + put("value", DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss")); + }}); + }}; + log.info("开始发送敏感操作消息, 接收用户openId: {}, 操作用户: {}, 操作描述: {}", item.getOpenId(), userName, operationDesc); + try { + sendTemplateMsg(operationMsgTmpId, item.getOpenId(), data); + }catch (Exception e) { + log.error("发送失败, openId: {}, 响应: {}", item.getOpenId(), e.getMessage()); + } + }); + + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMsgUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMsgUtils.java new file mode 100644 index 00000000..79d74135 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMsgUtils.java @@ -0,0 +1,58 @@ +package cn.ysk.cashier.utils; + +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import cn.ysk.cashier.mybatis.service.TbShopOpenIdService; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@Component +@Slf4j +public class WxMsgUtils { + + private final TbShopOpenIdService tbShopOpenIdService; + + private final RedisUtils redisUtils; + + private final WxAccountUtil wxAccountUtil; + + public WxMsgUtils(TbShopOpenIdService tbShopOpenIdService, RedisUtils redisUtils, WxAccountUtil wxAccountUtil) { + this.tbShopOpenIdService = tbShopOpenIdService; + this.redisUtils = redisUtils; + this.wxAccountUtil = wxAccountUtil; + } + + public void aboardOperationMsg(String operationDesc) { + HttpServletRequest request = RequestHolder.getHttpServletRequest(); + + Object o = redisUtils.get("online-token-"+getToken(request)); + JSONObject jsonObject; + Integer shopId; + String nickName; + if (o != null) { + String jsonString = JSON.toJSONString(o); + jsonObject = JSONObject.parseObject(jsonString); + shopId = (Integer) jsonObject.get("shopId"); + nickName = jsonObject.get("nickName") == null ? "" : jsonObject.get("nickName").toString(); + List openIds = tbShopOpenIdService.lambdaQuery().eq(TbShopOpenId::getShopId, shopId).list(); + log.info("即将开始推送敏感操作消息, 接收推送openId列表: {}", openIds); + String finalNickName = nickName; + wxAccountUtil.sendOperationMsg(openIds, finalNickName, operationDesc); + }else { + log.warn("发送敏感操作预警失败,未获取到登录信息"); + } + } + + public String getToken(HttpServletRequest request) { + final String requestHeader = request.getHeader("Authorization"); + if (requestHeader != null && requestHeader.startsWith("Bearer")) { + return requestHeader.substring(7); + } + return null; + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSaleVO.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSaleVO.java new file mode 100644 index 00000000..667e3ebe --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSaleVO.java @@ -0,0 +1,17 @@ +package cn.ysk.cashier.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TbOrderSaleVO { + private String orderNo; + private Integer num; + private BigDecimal price; + private String status; +} diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index 79bfa777..752a7fc8 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -78,3 +78,9 @@ aliyun: oss: bucketname: cashier-oss endpoint: oss-cn-beijing.aliyuncs.com + +wx: + ysk: + appId: wx212769170d2c6b2a + secrete: 8492a7e8d55bbb1b57f5c8276ea1add0 + operationMsgTmpId: wFdoUG-dUT7bDRHq8bMJD9CF5TjyH9x_uJQgQByZqHg diff --git a/eladmin-system/src/main/resources/mapper/TbShopOpenIdMapper.xml b/eladmin-system/src/main/resources/mapper/TbShopOpenIdMapper.xml new file mode 100644 index 00000000..131b90c7 --- /dev/null +++ b/eladmin-system/src/main/resources/mapper/TbShopOpenIdMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + id,shop_id,open_id, + status,create_time,update_time, + type + + From 48488daad8154d532d33bc55af009735b2616f8b Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 2 Aug 2024 16:43:46 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E5=91=98=E5=B7=A5=E5=88=A0=E9=99=A4=20?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AF=86=E7=A0=81=20=E5=95=86=E5=93=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=83=AD=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/utils/CacheKey.java | 2 + .../product/TbProductController.java | 4 +- .../shop/TbPlussShopStaffController.java | 27 +++++------ .../controller/shop/TbShopInfoController.java | 2 +- .../product/TbProductRepository.java | 4 +- .../shop/TbPlussShopStaffRepository.java | 21 ++------ .../productimpl/TbProductServiceImpl.java | 5 +- .../shopimpl/TbPlussShopStaffServiceImpl.java | 2 +- .../service/product/TbProductService.java | 2 +- .../cashier/system/domain/vo/UserPassVo.java | 18 ++----- .../cashier/system/rest/UserController.java | 48 +++++++++++-------- 11 files changed, 56 insertions(+), 79 deletions(-) diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java index 2abfebf2..78af6b89 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java @@ -22,6 +22,8 @@ package cn.ysk.cashier.utils; */ public interface CacheKey { + String ONLINE_ADMIN = "ONLINE_ADMIN:"; + /** * 激活码 */ diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java index 5e78001a..134e1799 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java @@ -39,8 +39,8 @@ public class TbProductController { } @GetMapping("/isHot") - public ResponseEntity updateIsHot(@RequestParam String shopId, @RequestParam Integer id){ - tbProductService.updateIsHot(id,shopId); + public ResponseEntity updateIsHot(@RequestParam Integer isHot, @RequestParam Integer id){ + tbProductService.updateIsHot(id,isHot); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java index 6607c755..480ff91c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java @@ -1,25 +1,9 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ package cn.ysk.cashier.controller.shop; import cn.ysk.cashier.annotation.Log; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; import cn.ysk.cashier.service.shop.TbPlussShopStaffService; import cn.ysk.cashier.dto.shop.TbPlussShopStaffQueryCriteria; -import io.swagger.models.auth.In; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -91,4 +75,15 @@ public class TbPlussShopStaffController { tbPlussShopStaffService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); } + +// @ApiOperation("修改个人密码") +// @PostMapping(value = "/upPass") +// @AnonymousPostMapping +// public ResponseEntity upshopStaffPass(HttpServletRequest request, @RequestBody Map map){ +// tbShopInfoService.upShopPass(map.get("username"),map.get("password")); +// //根据token踢出用户 +// onlineUserService.logout(tokenProvider.getToken(request)); +// log.info("修改商户密码成功。"); +// return new ResponseEntity<>(HttpStatus.OK); +// } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java index 48a51f9b..a6980d50 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java @@ -72,7 +72,7 @@ public class TbShopInfoController { public ResponseEntity upShopPass(HttpServletRequest request, @RequestBody Map map) throws Exception { tbShopInfoService.upShopPass(map.get("username"),map.get("password")); //根据token踢出用户 -// onlineUserService.logout(tokenProvider.getToken(request)); + onlineUserService.logout(tokenProvider.getToken(request)); log.info("修改商户密码成功。"); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java index 01e2ae64..0bbc2a16 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java @@ -25,9 +25,9 @@ public interface TbProductRepository extends JpaRepository, @Query(value = "update tb_product set status = -1 where id in :productIds",nativeQuery = true) @Modifying void updateByStatus(List productIds); - @Query(value = "update tb_product set is_hot=1 where id = :id",nativeQuery = true) + @Query(value = "update tb_product set is_hot=:isHot where id = :id",nativeQuery = true) @Modifying - void updateIsHot(@Param("id") Integer id); + void updateIsHot(@Param("id") Integer id,@Param("isHot")Integer isHot); @Query(value = "update tb_product set is_stock=:isStock where id = :proId and shop_id=:shopId",nativeQuery = true) @Modifying diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java index f8429d07..00876641 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java @@ -1,18 +1,3 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ package cn.ysk.cashier.repository.shop; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; @@ -21,8 +6,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; -import java.util.List; - /** * @website https://eladmin.vip * @author lyf @@ -42,6 +25,10 @@ public interface TbPlussShopStaffRepository extends JpaRepository sysUserIds=new HashSet<>(); for (Integer id : ids) { TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffRepository.findById(id).get(); - User sysUser = userRepository.findByUsername(tbPlussShopStaff.getAccount()); + User sysUser = userRepository.findByUsername(tbPlussShopStaff.getShopId()+"@"+tbPlussShopStaff.getAccount()); tbPlussShopStaffRepository.deleteById(id); sysUserIds.add(sysUser.getId()); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java index d9e55502..3ee7c092 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java @@ -85,7 +85,7 @@ public interface TbProductService { */ void download(List all, HttpServletResponse response) throws IOException; - void updateIsHot(Integer id, String shopId); + void updateIsHot(Integer id,Integer isStock); void updateIsStock(Integer proId, String shopId, Integer isStock); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java index 625c0271..31bdb4aa 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java @@ -1,18 +1,3 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package cn.ysk.cashier.system.domain.vo; import lombok.Data; @@ -25,6 +10,9 @@ import lombok.Data; @Data public class UserPassVo { + //staff + private String loginType; + private String oldPass; private String newPass; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java b/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java index f54b9107..bc462c86 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java @@ -1,26 +1,15 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package cn.ysk.cashier.system.rest; import cn.hutool.core.collection.CollectionUtil; +import cn.ysk.cashier.config.security.security.TokenProvider; +import cn.ysk.cashier.config.security.service.OnlineUserService; +import cn.ysk.cashier.repository.shop.TbPlussShopStaffRepository; import cn.ysk.cashier.system.domain.Dept; import cn.ysk.cashier.system.domain.User; import cn.ysk.cashier.system.domain.vo.UserPassVo; import cn.ysk.cashier.system.service.dto.UserDto; import cn.ysk.cashier.system.service.dto.UserQueryCriteria; +import cn.ysk.cashier.utils.MD5Utils; import cn.ysk.cashier.utils.PageUtil; import cn.ysk.cashier.utils.RsaUtils; import cn.ysk.cashier.utils.SecurityUtils; @@ -37,16 +26,20 @@ import cn.ysk.cashier.system.service.dto.RoleSmallDto; import cn.ysk.cashier.system.service.VerifyService; import cn.ysk.cashier.system.service.UserService; import cn.ysk.cashier.utils.enums.CodeEnum; +import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; @@ -68,6 +61,9 @@ public class UserController { private final DeptService deptService; private final RoleService roleService; private final VerifyService verificationCodeService; + private final OnlineUserService onlineUserService; + private final TbPlussShopStaffRepository shopStaffRepository; + private final TokenProvider tokenProvider; @ApiOperation("导出用户数据") @GetMapping(value = "/download") @@ -155,17 +151,27 @@ public class UserController { @ApiOperation("修改密码") @PostMapping(value = "/updatePass") - public ResponseEntity updateUserPass(@RequestBody UserPassVo passVo) throws Exception { - String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getOldPass()); - String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getNewPass()); - UserDto user = userService.findByName(SecurityUtils.getCurrentUsername()); - if(!passwordEncoder.matches(oldPass, user.getPassword())){ + @Transactional + public ResponseEntity updateUserPass(HttpServletRequest request, @RequestBody UserPassVo passVo) throws Exception { + String currentUsername = SecurityUtils.getCurrentUsername(); + UserDto user = userService.findByName(currentUsername); + String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, passVo.getOldPass()); + String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, passVo.getNewPass()); + if (!passwordEncoder.matches(oldPass, user.getPassword())) { throw new BadRequestException("修改失败,旧密码错误"); } - if(passwordEncoder.matches(newPass, user.getPassword())){ + if (passwordEncoder.matches(newPass, user.getPassword())) { throw new BadRequestException("新密码不能与旧密码相同"); } + String encPass = MD5Utils.encrypt( passVo.getNewPass()); + if (StringUtils.isNotBlank(passVo.getLoginType()) && passVo.getLoginType().equals("staff")) { + String[] split = currentUsername.split("@"); + shopStaffRepository.updatePassAndShopId(split[1],split[0],encPass,System.currentTimeMillis()); + }else { + shopStaffRepository.updatePass(currentUsername,encPass,System.currentTimeMillis()); + } userService.updatePass(user.getUsername(),passwordEncoder.encode(newPass)); + onlineUserService.logout(tokenProvider.getToken(request)); return new ResponseEntity<>(HttpStatus.OK); } From 96b9d5008872480f0731ba4ef907097840064817 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sat, 3 Aug 2024 09:54:29 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E5=A4=9A=E8=A7=84=E6=A0=BC=E5=95=86?= =?UTF-8?q?=E5=93=81=EF=BC=8C=E4=B8=8D=E5=85=B1=E4=BA=AB=E5=BA=93=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E4=B8=80=E4=B8=AA=E8=A7=84=E6=A0=BC=E4=B8=BA=E4=B8=8A?= =?UTF-8?q?=E6=9E=B6=E7=8A=B6=E6=80=81=EF=BC=8C=E5=85=B6=E4=BB=96=E8=A7=84?= =?UTF-8?q?=E6=A0=BC=E4=B8=BA=E4=B8=8B=E6=9E=B6=E7=8A=B6=E6=80=81=EF=BC=8C?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=85=B1=E4=BA=AB=E5=BA=93=E5=AD=98=EF=BC=8C?= =?UTF-8?q?=E5=85=B1=E4=BA=AB=E5=BA=93=E5=AD=98=E4=B8=BA=E4=B8=8B=E6=9E=B6?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/repository/product/TbProductSkuRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductSkuRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductSkuRepository.java index 7cf13c48..7996d6a6 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductSkuRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductSkuRepository.java @@ -63,7 +63,7 @@ public interface TbProductSkuRepository extends JpaRepository 0 THEN true ELSE false END as isGrounding) " + "from " + "TbProduct pro " + "LEFT JOIN TbProductSku sku on pro.id = sku.productId " + From b70c00667ac9a6df9571eb315a5ebeddbec533fd Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 3 Aug 2024 14:43:30 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E5=95=86=E5=93=81=E5=87=BA=E5=85=A5?= =?UTF-8?q?=E5=BA=93=20=E5=92=8C=20=E8=80=97=E6=9D=90=E5=87=BA=E5=85=A5?= =?UTF-8?q?=E5=BA=93=20=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=20=E6=98=8E?= =?UTF-8?q?=E7=A1=AE=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/service/impl/LogServiceImpl.java | 20 +++++++++++++++++++ .../cons/rest/TbConsInfoController.java | 2 +- .../TbProductStockOperateController.java | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/eladmin-logging/src/main/java/cn/ysk/cashier/service/impl/LogServiceImpl.java b/eladmin-logging/src/main/java/cn/ysk/cashier/service/impl/LogServiceImpl.java index 7e6e2f1d..32095301 100644 --- a/eladmin-logging/src/main/java/cn/ysk/cashier/service/impl/LogServiceImpl.java +++ b/eladmin-logging/src/main/java/cn/ysk/cashier/service/impl/LogServiceImpl.java @@ -96,6 +96,26 @@ public class LogServiceImpl implements LogService { String value = SpelUtil.generateKeyBySpEL(split[1], joinPoint); // 描述 log.setDescription(split[0] + ":" + value); + } + if (split.length == 3) { +// String v1 = SpelUtil.generateKeyBySpEL(split[1], joinPoint); + String v2 = SpelUtil.generateKeyBySpEL(split[2], joinPoint); + if (methodName.contains("createOutAndONOperate")) { + //subType 1入库 -1出库 + if ("purchase".equals(v2) || "purveyor".equals(v2)) { + v2 = "入库"; + } else { + v2 = "出库"; + } + }else if(methodName.contains("stockInOut")){ + if (("in".equals(v2) || "purveyor".equals(v2))) { + v2 = "入库"; + } else { + v2 = "出库"; + } + } + // 描述 + log.setDescription(split[0] + ":" + v2 ); }else { log.setDescription(split[0]); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java index 7c50ba9a..bcff3be2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java @@ -71,7 +71,7 @@ public class TbConsInfoController { } @PostMapping(value = "stockInOut") - @Log("耗材出入库") + @Log("耗材出入库::#resources.type") @ApiOperation("耗材出入库") public ResponseEntity stockInOut(@Validated @RequestBody SuppFlow resources) throws Exception { diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java index 3e222c74..86890fcb 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java @@ -61,7 +61,7 @@ public class TbProductStockOperateController { @PostMapping("/outAndOn") @ApiOperation("新增/product/StockOperate") - @Log("出入库") + @Log("商品出入库::#outAndOnDto.type") // @PreAuthorize("@el.check('tbProductStockOperate:add')") public ResponseEntity createOutAndONOperate(@RequestBody OutAndOnDto outAndOnDto){ return new ResponseEntity<>(tbProductStockOperateService.createOutAndONOperate(outAndOnDto),HttpStatus.CREATED); From cf2ac9755fed0ca6dcf6f0efd6d657b065433d3f Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 3 Aug 2024 14:44:33 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E5=95=86=E5=93=81=E5=87=BA=E5=85=A5?= =?UTF-8?q?=E5=BA=93=20=E5=92=8C=20=E8=80=97=E6=9D=90=E5=87=BA=E5=85=A5?= =?UTF-8?q?=E5=BA=93=20=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=20=E6=98=8E?= =?UTF-8?q?=E7=A1=AE=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/cons/rest/TbConsInfoController.java | 2 +- .../controller/product/TbProductStockOperateController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java index bcff3be2..e9928425 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java @@ -71,7 +71,7 @@ public class TbConsInfoController { } @PostMapping(value = "stockInOut") - @Log("耗材出入库::#resources.type") + @Log("耗材::#resources.type") @ApiOperation("耗材出入库") public ResponseEntity stockInOut(@Validated @RequestBody SuppFlow resources) throws Exception { diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java index 86890fcb..b8ea5c2d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java @@ -61,7 +61,7 @@ public class TbProductStockOperateController { @PostMapping("/outAndOn") @ApiOperation("新增/product/StockOperate") - @Log("商品出入库::#outAndOnDto.type") + @Log("商品::#outAndOnDto.type") // @PreAuthorize("@el.check('tbProductStockOperate:add')") public ResponseEntity createOutAndONOperate(@RequestBody OutAndOnDto outAndOnDto){ return new ResponseEntity<>(tbProductStockOperateService.createOutAndONOperate(outAndOnDto),HttpStatus.CREATED); From a1ebe64c20d38f54695a553c21781a840c213ba4 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 3 Aug 2024 15:29:41 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=9B=9E=E4=BC=A0=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/config/security/rest/AuthorizationController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java index fc8f93f5..c321ea7f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java @@ -150,6 +150,7 @@ public class AuthorizationController { put("user", jwtUserDto); if (byAccount != null) { put("shopId", byAccount.getId()); + put("loginType", org.apache.commons.lang3.StringUtils.isNotBlank(authUser.getLoginType())?"merchant":authUser.getLoginType()); put("shopName", byAccount.getShopName()); put("logo", byAccount.getLogo()); } From db15b53826b8ead7807bbdff40aef9da894798ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=8F=89=E9=97=AA=E9=97=AA?= <18322780655@163.com> Date: Sat, 3 Aug 2024 15:32:44 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E4=B8=BA=E9=9D=9E=E5=BF=85=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TbConsInfoServiceImpl.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java index acdb3836..191c0188 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java @@ -185,12 +185,17 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { throw new Exception("店铺信息不存在"); } TbShopPurveyor purveyor = tbShopPurveyorRepository.getById(resources.getSupplierId()); + TbProductStockOperate stockOperate = new TbProductStockOperate(); if (Objects.isNull(purveyor)) { - throw new Exception("不存在的供应商"); + stockOperate.setPurveyorId(null); + stockOperate.setPurveyorName(null); + }else { + stockOperate.setPurveyorId(resources.getSupplierId().toString()); + stockOperate.setPurveyorName(purveyor.getPurveyorName()); } - TbProductStockOperate stockOperate = new TbProductStockOperate(); + stockOperate.setShopId(tbShopInfo.getId().toString()); stockOperate.setStockSnap(""); stockOperate.setType(resources.getType().equals("in")?"cons_in":"cons_out"); @@ -204,8 +209,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { stockOperate.setCreatedAt(System.currentTimeMillis()); stockOperate.setUpdatedAt(System.currentTimeMillis()); stockOperate.setStatus("normal"); - stockOperate.setPurveyorId(resources.getSupplierId().toString()); - stockOperate.setPurveyorName(purveyor.getPurveyorName()); + JSONArray array=new JSONArray(); @@ -224,9 +228,9 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { TbShopPurveyorTransact purveyorTransact = new TbShopPurveyorTransact(); purveyorTransact.setShopId(tbShopInfo.getId().toString()); - purveyorTransact.setPurveyorName(purveyor.getPurveyorName()); - purveyorTransact.setPurveyorId(purveyor.getId().toString()); - purveyorTransact.setRemark(""); + purveyorTransact.setPurveyorName(Objects.isNull(purveyor)?"":purveyor.getPurveyorName()); + purveyorTransact.setPurveyorId(Objects.isNull(purveyor)?"":purveyor.getId().toString()); + purveyorTransact.setRemark(resources.getRemark()); purveyorTransact.setCreatedAt(System.currentTimeMillis()); purveyorTransact.setUpdatedAt(System.currentTimeMillis()); From f18769abd5315cd013b97883ce2e4bc99dc362ef Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 3 Aug 2024 15:39:39 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=9B=9E=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/config/security/rest/AuthorizationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java index c321ea7f..250da238 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java @@ -150,7 +150,7 @@ public class AuthorizationController { put("user", jwtUserDto); if (byAccount != null) { put("shopId", byAccount.getId()); - put("loginType", org.apache.commons.lang3.StringUtils.isNotBlank(authUser.getLoginType())?"merchant":authUser.getLoginType()); + put("loginType", org.apache.commons.lang3.StringUtils.isNotBlank(authUser.getLoginType())?authUser.getLoginType():"merchant"); put("shopName", byAccount.getShopName()); put("logo", byAccount.getLogo()); } From cd8ccb9a8efc4b3c2108ddb2ac01b378e3ae6a86 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 3 Aug 2024 15:41:46 +0800 Subject: [PATCH 11/15] =?UTF-8?q?git=E6=8F=90=E4=BA=A4=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 28fb35fc..b8080da1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ */*.iml /.gradle/ /application.pid -*.log \ No newline at end of file +*.log +logs/* \ No newline at end of file From 60cdf33b7bede041b03c76f5b395780dd51505cb Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 3 Aug 2024 17:35:28 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E7=94=A8=E6=88=B7=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/system/rest/UserController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java b/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java index bc462c86..208f1418 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java @@ -156,11 +156,11 @@ public class UserController { String currentUsername = SecurityUtils.getCurrentUsername(); UserDto user = userService.findByName(currentUsername); String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, passVo.getOldPass()); - String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, passVo.getNewPass()); if (!passwordEncoder.matches(oldPass, user.getPassword())) { throw new BadRequestException("修改失败,旧密码错误"); } - if (passwordEncoder.matches(newPass, user.getPassword())) { + System.out.println(oldPass); + if (passwordEncoder.matches(passVo.getNewPass(), user.getPassword())) { throw new BadRequestException("新密码不能与旧密码相同"); } String encPass = MD5Utils.encrypt( passVo.getNewPass()); @@ -170,7 +170,7 @@ public class UserController { }else { shopStaffRepository.updatePass(currentUsername,encPass,System.currentTimeMillis()); } - userService.updatePass(user.getUsername(),passwordEncoder.encode(newPass)); + userService.updatePass(user.getUsername(),passwordEncoder.encode(passVo.getNewPass())); onlineUserService.logout(tokenProvider.getToken(request)); return new ResponseEntity<>(HttpStatus.OK); } From 443df8faa38d9985f68bd205721881aae4266b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=8F=89=E9=97=AA=E9=97=AA?= <18322780655@163.com> Date: Sat, 3 Aug 2024 18:22:36 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E4=B8=BA=E9=9D=9E=E5=BF=85=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TbConCheckServiceImpl.java | 8 ++++---- .../service/impl/TbConsInfoServiceImpl.java | 17 ++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java index a5c50c38..44236cb4 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java @@ -66,9 +66,9 @@ public class TbConCheckServiceImpl implements TbConCheckService { throw new Exception("耗材信息不存在"); } - BigDecimal stonum=consInfo.getStockNumber().subtract(consInfo.getStockConsume()); - consInfo.setStockConsume(consInfo.getStockConsume().add(resources.getLpNum().negate())); + consInfo.setStockConsume(BigDecimal.ZERO); + consInfo.setStockNumber(resources.getStockNumber()); consInfo.setUpdateTime(new Timestamp(System.currentTimeMillis())); tbConsInfoRepository.save(consInfo); @@ -77,8 +77,8 @@ public class TbConCheckServiceImpl implements TbConCheckService { conCheck.setConInfoId(consInfo.getId()); conCheck.setConName(consInfo.getConName()); conCheck.setPrice(consInfo.getPrice()); - conCheck.setAcStockNumber(consInfo.getStockNumber().subtract(consInfo.getStockConsume())); - conCheck.setStockNumber(stonum); + conCheck.setAcStockNumber(resources.getStockNumber()); + conCheck.setStockNumber(resources.getStockNumber()); conCheck.setLpNum(resources.getLpNum()); conCheck.setLpAmount(consInfo.getPrice().multiply(resources.getLpNum())); conCheck.setCreateTime(new Timestamp(System.currentTimeMillis())); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java index 191c0188..c7ba1027 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java @@ -184,18 +184,17 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { if (Objects.isNull(tbShopInfo)) { throw new Exception("店铺信息不存在"); } - TbShopPurveyor purveyor = tbShopPurveyorRepository.getById(resources.getSupplierId()); + + TbShopPurveyor purveyor=null; TbProductStockOperate stockOperate = new TbProductStockOperate(); - if (Objects.isNull(purveyor)) { - stockOperate.setPurveyorId(null); - stockOperate.setPurveyorName(null); - }else { - stockOperate.setPurveyorId(resources.getSupplierId().toString()); - stockOperate.setPurveyorName(purveyor.getPurveyorName()); + if(Objects.nonNull(resources.getSupplierId())){ + purveyor = tbShopPurveyorRepository.getById(resources.getSupplierId()); + if (Objects.nonNull(purveyor)) { + stockOperate.setPurveyorId(resources.getSupplierId().toString()); + stockOperate.setPurveyorName(purveyor.getPurveyorName()); + } } - - stockOperate.setShopId(tbShopInfo.getId().toString()); stockOperate.setStockSnap(""); stockOperate.setType(resources.getType().equals("in")?"cons_in":"cons_out"); From e9b0301eb95529fe5034df1b677cd3ab395efe73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=8F=89=E9=97=AA=E9=97=AA?= <18322780655@163.com> Date: Sat, 3 Aug 2024 18:28:25 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E4=B8=BA=E9=9D=9E=E5=BF=85=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java index 69eb8171..a8f6aa8e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java @@ -60,7 +60,6 @@ public class TbConsSuppFlow implements Serializable { private Integer productId; @Column(name = "`supplier_id`",nullable = false) - @NotNull @ApiModelProperty(value = "supplierId") private Integer supplierId; From 9de0c594cd3b099eeae8133cff59a5e61768b44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=8F=89=E9=97=AA=E9=97=AA?= <18322780655@163.com> Date: Mon, 5 Aug 2024 10:18:34 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E4=B8=BA=E9=9D=9E=E5=BF=85=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/cons/domain/TbConsSuppFlow.java | 2 +- .../service/impl/TbConCheckServiceImpl.java | 30 +++++++++++++++++++ .../service/impl/TbConsInfoServiceImpl.java | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java index a8f6aa8e..20105559 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java @@ -59,7 +59,7 @@ public class TbConsSuppFlow implements Serializable { @ApiModelProperty(value = "productId") private Integer productId; - @Column(name = "`supplier_id`",nullable = false) + @Column(name = "`supplier_id`") @ApiModelProperty(value = "supplierId") private Integer supplierId; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java index 44236cb4..4ced9a06 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java @@ -2,6 +2,8 @@ package cn.ysk.cashier.cons.service.impl; import cn.ysk.cashier.cons.domain.TbConCheck; import cn.ysk.cashier.cons.domain.TbConsInfo; +import cn.ysk.cashier.cons.domain.TbConsInfoFlow; +import cn.ysk.cashier.cons.repository.TbConsInfoFlowRepository; import cn.ysk.cashier.cons.repository.TbConsInfoRepository; import cn.ysk.cashier.utils.FileUtil; import cn.ysk.cashier.utils.PageUtil; @@ -39,6 +41,8 @@ public class TbConCheckServiceImpl implements TbConCheckService { private final TbConsInfoRepository tbConsInfoRepository; + public final TbConsInfoFlowRepository tbConsInfoFlowRepository; + @Override public Map queryAll(TbConCheckQueryCriteria criteria, Pageable pageable){ Page page = tbConCheckRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); @@ -65,6 +69,17 @@ public class TbConCheckServiceImpl implements TbConCheckService { if(Objects.isNull(consInfo)){ throw new Exception("耗材信息不存在"); } + TbConsInfoFlow flow=new TbConsInfoFlow(); + + if(consInfo.getStockNumber().compareTo(resources.getStockNumber())>=0){ + flow.setBizCode("checkStockOut"); + flow.setBizName("盘点出库"); + flow.setBizType("-"); + }else { + flow.setBizCode("checkStockIn"); + flow.setBizName("盘点入库"); + flow.setBizType("+"); + } consInfo.setStockConsume(BigDecimal.ZERO); @@ -72,6 +87,21 @@ public class TbConCheckServiceImpl implements TbConCheckService { consInfo.setUpdateTime(new Timestamp(System.currentTimeMillis())); tbConsInfoRepository.save(consInfo); + + + + + flow.setConsId(consInfo.getId()); + flow.setShopId(consInfo.getShopId()); + flow.setConName(consInfo.getConName()); + flow.setAmount(consInfo.getStockNumber()); + flow.setBalance(consInfo.getStockNumber()); + + flow.setCreateTime(new Timestamp(System.currentTimeMillis())); + tbConsInfoFlowRepository.save(flow); + + + TbConCheck conCheck=new TbConCheck(); conCheck.setConInfoId(consInfo.getId()); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java index c7ba1027..5a9b7e8c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java @@ -235,7 +235,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { suppFlow.setConInfoId(info.getConTypeId()); suppFlow.setShopId(resources.getShopId()); - suppFlow.setSupplierId(resources.getSupplierId()); + suppFlow.setSupplierId(Objects.isNull(resources.getSupplierId())?0: resources.getSupplierId()); suppFlow.setType(resources.getType()); suppFlow.setStockNumber(conInfos.getStockNumber());