Browse Source

采购退货

其他问题优化;
dev
wangfukang 2 years ago
parent
commit
42cf6f27de
  1. 16
      hiver-admin/test-output/test-report.html
  2. 4
      hiver-core/src/main/java/cc/hiver/core/common/constant/DealingsRecordConstant.java
  3. 5
      hiver-core/src/main/java/cc/hiver/core/common/constant/SaleConstant.java
  4. 2
      hiver-core/src/main/java/cc/hiver/core/config/properties/HiverTokenProperties.java
  5. 56
      hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/AuthController.java
  6. 10
      hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java
  7. 143
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/service/impl/BillServiceImpl.java
  8. 6
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/ArrearsVo.java
  9. 6
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/CustomerBillDataVo.java
  10. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/CustomerBillSaleVo.java
  11. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/SupplierBillDataVo.java
  12. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/SupplierBillPurchaseVo.java
  13. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/checkstock/service/impl/CheckStockServiceImpl.java
  14. 2
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/common/constant/StockConstant.java
  15. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/common/constant/StockLogConstant.java
  16. 22
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ProductController.java
  17. 94
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/SaleController.java
  18. 12
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopController.java
  19. 7
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/StockController.java
  20. 2
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/ShopUserDao.java
  21. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/PurchaseDetailMapper.java
  22. 6
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/SaleDetailMapper.java
  23. 53
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/SaleMapper.java
  24. 2
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/StockMapper.java
  25. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/service/DebtService.java
  26. 61
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/service/impl/DebtServiceImpl.java
  27. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleDetailQueryDTO.java
  28. 6
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java
  29. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductPageVO.java
  30. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/SaleAllVO.java
  31. 25
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/TotalAmountDetailByCustomerVo.java
  32. 28
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/TotalAmountDetailByProductVo.java
  33. 9
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchaseocr/service/impl/PurchaseOcrPictureServiceImpl.java
  34. 7
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/constant/PurchaseReturnConstant.java
  35. 92
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/controller/PurchaseReturnController.java
  36. 26
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/controller/PurchaseReturnDetailController.java
  37. 76
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/entity/PurchaseReturn.java
  38. 117
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/entity/PurchaseReturnDetail.java
  39. 28
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/mapper/PurchaseReturnDetailMapper.java
  40. 30
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/mapper/PurchaseReturnMapper.java
  41. 36
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/service/PurchaseReturnDetailService.java
  42. 45
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/service/PurchaseReturnService.java
  43. 51
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/service/impl/PurchaseReturnDetailServiceImpl.java
  44. 234
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/service/impl/PurchaseReturnServiceImpl.java
  45. 29
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/vo/PurchaseReturnDataVo.java
  46. 18
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/vo/PurchaseReturnQueryVo.java
  47. 29
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/vo/PurchaseReturnVo.java
  48. 1
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopUserService.java
  49. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/PurchaseDetailService.java
  50. 15
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/SaleDetailService.java
  51. 20
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/SaleService.java
  52. 11
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/StockService.java
  53. 1
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java
  54. 27
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesCalculateServiceImpl.java
  55. 5
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopUserServiceImpl.java
  56. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/StockAndLogServiceImpl.java
  57. 182
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/ProductServiceImpl.java
  58. 6
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseDetailServiceImpl.java
  59. 88
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/ReturnSaleServiceImpl.java
  60. 12
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/SaleDetailServiceImpl.java
  61. 94
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/SaleServiceImpl.java
  62. 421
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockServiceImpl.java
  63. 13
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/AliOcrUtil.java
  64. 2
      hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml
  65. 35
      hiver-modules/hiver-mall/src/main/resources/mapper/DealingsRecordMapper.xml
  66. 27
      hiver-modules/hiver-mall/src/main/resources/mapper/ProductMapper.xml
  67. 24
      hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseDetailMapper.xml
  68. 239
      hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseReturnDetailMapper.xml
  69. 73
      hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseReturnMapper.xml
  70. 3
      hiver-modules/hiver-mall/src/main/resources/mapper/ReturnSaleMapper.xml
  71. 55
      hiver-modules/hiver-mall/src/main/resources/mapper/SaleDetailMapper.xml
  72. 140
      hiver-modules/hiver-mall/src/main/resources/mapper/SaleMapper.xml
  73. 6
      hiver-modules/hiver-mall/src/main/resources/mapper/StockMapper.xml

16
hiver-admin/test-output/test-report.html

@ -35,7 +35,7 @@
<a href="#"><span class="badge badge-primary">Hiver</span></a>
</li>
<li class="m-r-10">
<a href="#"><span class="badge badge-primary">八月 12, 2024 09:47:24</span></a>
<a href="#"><span class="badge badge-primary">八月 24, 2024 11:36:29</span></a>
</li>
</ul>
</div>
@ -84,7 +84,7 @@
<div class="test-detail">
<span class="meta text-white badge badge-sm"></span>
<p class="name">passTest</p>
<p class="text-sm"><span>09:47:25 上午</span> / <span>0.017 secs</span></p>
<p class="text-sm"><span>11:36:29 上午</span> / <span>0.019 secs</span></p>
</div>
<div class="test-contents d-none">
<div class="detail-head">
@ -92,9 +92,9 @@
<div class="info">
<div class='float-right'><span class='badge badge-default'>#test-id=1</span></div>
<h5 class="test-status text-pass">passTest</h5>
<span class='badge badge-success'>08.12.2024 09:47:25</span>
<span class='badge badge-danger'>08.12.2024 09:47:25</span>
<span class='badge badge-default'>0.017 secs</span>
<span class='badge badge-success'>08.24.2024 11:36:29</span>
<span class='badge badge-danger'>08.24.2024 11:36:29</span>
<span class='badge badge-default'>0.019 secs</span>
</div>
<div class="m-t-10 m-l-5"></div>
</div>
@ -104,7 +104,7 @@
<tbody>
<tr class="event-row">
<td><span class="badge log pass-bg">Pass</span></td>
<td>9:47:25</td>
<td>11:36:29</td>
<td>
Test passed
</td>
@ -128,13 +128,13 @@
<div class="col-md-3">
<div class="card"><div class="card-body">
<p class="m-b-0">Started</p>
<h3>八月 12, 2024 09:47:24</h3>
<h3>八月 24, 2024 11:36:29</h3>
</div></div>
</div>
<div class="col-md-3">
<div class="card"><div class="card-body">
<p class="m-b-0">Ended</p>
<h3>八月 12, 2024 09:47:25</h3>
<h3>八月 24, 2024 11:36:29</h3>
</div></div>
</div>
<div class="col-md-3">

4
hiver-core/src/main/java/cc/hiver/core/common/constant/DealingsRecordConstant.java

@ -13,8 +13,8 @@ public interface DealingsRecordConstant {
Integer[] TYPE = {0, 1};
/**
* 交易类型0:开单1退货(应该是没用到)2回款3新增客户/供应商欠款4充值5追加欠款;6:撤销订单;7:入库8删除交易记录
* 交易类型0:开单1退货(应该是没用到)2回款3新增客户/供应商欠款4充值5追加欠款;6:撤销订单;7:入库8删除交易记录; 9:入库退货10撤销入库退货
*/
Integer[] DEALINGS_TYPE = {0, 1, 2, 3, 4, 5, 6, 7, 8};
Integer[] DEALINGS_TYPE = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
}

5
hiver-core/src/main/java/cc/hiver/core/common/constant/SaleConstant.java

@ -49,4 +49,9 @@ public interface SaleConstant {
* 是否是AI的标识0不是AI1AI未识别, 2AI识别成功3AI识别失败
*/
int[] AI_FLAG = {0, 1, 2, 3};
/**
* 是否购买过0没买过1买过
*/
int[] IS_PURCHASED_BEFORE = {0, 1};
}

2
hiver-core/src/main/java/cc/hiver/core/config/properties/HiverTokenProperties.java

@ -36,7 +36,7 @@ public class HiverTokenProperties {
/**
* 用户选择保存登录状态对应token过期时间
*/
private Integer saveLoginTime = 7;
private Integer saveLoginTime = 365;
/**
* 限制用户登陆错误次数

56
hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/AuthController.java

@ -176,24 +176,19 @@ public class AuthController {
if (UserConstant.USER_TYPE_NORMAL.equals(type)) {
// 获取
final List<ShopUser> shopUsers = shopUserService.selectByUserId(user.getId());
if(shopUsers != null && !shopUsers.isEmpty()){
if (shopUsers != null && !shopUsers.isEmpty()) {
// 获取店主手机号
final Shop shop = shopService.findById(shopUsers.get(0).getShopId());
if(shop != null && shop.getShopOwnerId() != null && StringUtils.isNotEmpty(shop.getShopOwnerId())){
final User shopOwner = userService.get(shop.getShopOwnerId());
for (ShopUser shopUser : shopUsers) {
shopUser.setShopOwnerName(shopOwner.getNickname());
shopUser.setShopOwnerPhone(shopOwner.getMobile());
for (ShopUser shopUser : shopUsers) {
final Shop shop = shopService.findById(shopUser.getShopId());
if (shop != null && shop.getShopOwnerId() != null && StringUtils.isNotEmpty(shop.getShopOwnerId())) {
final User shopOwner = userService.findById(shop.getShopOwnerId());
if(shopOwner != null){
shopUser.setShopOwnerName(shopOwner.getNickname());
shopUser.setShopOwnerPhone(shopOwner.getMobile());
}
}
}
}
if (!shopUsers.isEmpty()) {
/*if (shopUsers.size() == 1) {
// 如果只有一个商铺,直接放到缓存中取
final ShopUser shopUser = shopUsers.get(0);
final Shop shop = shopService.get(shopUser.getShopId());
securityUtil.chooseShop(shopUser.getShopId(), shop.getRegionId(), accessToken);
}*/
result.put("shopList", shopUsers);
} else {
return ResultUtil.error("店铺未开通!");
@ -227,12 +222,17 @@ public class AuthController {
// 获取
final List<ShopUser> shopUsers = shopUserService.selectByUserId(user.getId());
if (!shopUsers.isEmpty()) {
/*if (shopUsers.size() == 1) {
// 如果只有一个商铺,直接放到缓存中取
final ShopUser shopUser = shopUsers.get(0);
final Shop shop = shopService.get(shopUser.getShopId());
securityUtil.chooseShop(shopUser.getShopId(), shop.getRegionId(), accessToken);
}*/
// 获取店主手机号
for (ShopUser shopUser : shopUsers) {
final Shop shop = shopService.findById(shopUser.getShopId());
if (shop != null && shop.getShopOwnerId() != null && StringUtils.isNotEmpty(shop.getShopOwnerId())) {
final User shopOwner = userService.findById(shop.getShopOwnerId());
if(shopOwner != null){
shopUser.setShopOwnerName(shopOwner.getNickname());
shopUser.setShopOwnerPhone(shopOwner.getMobile());
}
}
}
result.put("shopList", shopUsers);
} else {
return ResultUtil.error("店铺未开通!");
@ -517,12 +517,14 @@ public class AuthController {
final List<ShopUser> shopUsers = shopUserService.selectByUserId(u.getId());
if(shopUsers != null && !shopUsers.isEmpty()){
// 获取店主手机号
final Shop shop = shopService.findById(shopUsers.get(0).getShopId());
if(shop != null && shop.getShopOwnerId() != null && StringUtils.isNotEmpty(shop.getShopOwnerId())){
final User user = userService.get(shop.getShopOwnerId());
for (ShopUser shopUser : shopUsers) {
shopUser.setShopOwnerName(user.getNickname());
shopUser.setShopOwnerPhone(user.getMobile());
for (ShopUser shopUser : shopUsers) {
final Shop shop = shopService.findById(shopUser.getShopId());
if (shop != null && shop.getShopOwnerId() != null && StringUtils.isNotEmpty(shop.getShopOwnerId())) {
final User shopOwner = userService.findById(shop.getShopOwnerId());
if(shopOwner != null){
shopUser.setShopOwnerName(shopOwner.getNickname());
shopUser.setShopOwnerPhone(shopOwner.getMobile());
}
}
}
}

10
hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java

@ -141,12 +141,16 @@ public class UserController {
@ApiParam("手机号") @RequestParam String mobile,
@ApiParam("旧密码") @RequestParam String password,
@ApiParam("新密码") @RequestParam String newPass) {
if(StringUtils.isEmpty(mobile) && StringUtils.isEmpty(newPass)){
return ResultUtil.error("未修改任何信息!");
}
final User user = userService.findById(userId);
// 修改了密码
if (StringUtils.isNotEmpty(password) && StringUtils.isNotEmpty(newPass)) {
if (!new BCryptPasswordEncoder().matches(password, user.getPassword())) {
if (StringUtils.isNotEmpty(newPass)) {
// 20240819 修改位不校验旧密码,直接更新为新密码
/*if (!new BCryptPasswordEncoder().matches(password, user.getPassword())) {
return ResultUtil.error("旧密码不正确");
}
}*/
final String newEncryptPass = new BCryptPasswordEncoder().encode(newPass);
user.setPassword(newEncryptPass);
}

143
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/service/impl/BillServiceImpl.java

@ -6,6 +6,8 @@ import cc.hiver.mall.bill.vo.*;
import cc.hiver.mall.debt.entity.Debt;
import cc.hiver.mall.debt.service.DebtService;
import cc.hiver.mall.entity.*;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail;
import cc.hiver.mall.purchasereturn.service.PurchaseReturnDetailService;
import cc.hiver.mall.service.SupplierService;
import cc.hiver.mall.service.mybatis.*;
import cc.hiver.mall.utils.DateUtil;
@ -38,6 +40,9 @@ public class BillServiceImpl implements BillService {
@Autowired
private PurchaseDetailService purchaseDetailService;
@Autowired
private PurchaseReturnDetailService purchaseReturnDetailService;
@Autowired
private StockLogService stockLogService;
@ -81,9 +86,11 @@ public class BillServiceImpl implements BillService {
if (saleArrearsVo != null) {
customerBillDataVo.setArrears(saleArrearsVo.getArrears());
customerBillDataVo.setTotalSale(saleArrearsVo.getTotalSale());
customerBillDataVo.setSaleProductCount(saleArrearsVo.getSaleProductCount());
} else {
customerBillDataVo.setArrears(BigDecimal.ZERO);
customerBillDataVo.setTotalSale(BigDecimal.ZERO);
customerBillDataVo.setSaleProductCount(0);
}
// 获取退货总金额
@ -301,6 +308,9 @@ public class BillServiceImpl implements BillService {
supplierBillDataVo.setArrears(BigDecimal.ZERO);
supplierBillDataVo.setTotalSale(BigDecimal.ZERO);
}
// 获取进货总件数
final Integer purchasingCount = purchaseDetailService.queryPurchasingCount(supplierBillQueryVo);
supplierBillDataVo.setPurchasingCount(purchasingCount);
// 根据客户id及日期范围对账单明细
final Page<SupplierBillPurchaseVo> dealingRecordPage = dealingsRecordService.getDealingsRecordPageBySupplierId(supplierBillQueryVo);
@ -368,6 +378,20 @@ public class BillServiceImpl implements BillService {
purchaseDetailMap.put(purchaseId, purchaseDetailArrayList);
}
}
// 获取入库退货单商品明细
final List<PurchaseReturnDetail> purchaseReturnDetails = purchaseReturnDetailService.getPurchaseReturnDetails(purchaseIdList);
final Map<String, List<PurchaseReturnDetail>> purchaseReturnDetailMap = new HashMap<>();
for (PurchaseReturnDetail purchaseReturnDetail : purchaseReturnDetails) {
final String purchaseId = purchaseReturnDetail.getPurchaseId();
if (purchaseReturnDetailMap.containsKey(purchaseId)) {
final List<PurchaseReturnDetail> purchaseReturnDetailList = purchaseReturnDetailMap.get(purchaseId);
purchaseReturnDetailList.add(purchaseReturnDetail);
} else {
final List<PurchaseReturnDetail> purchaseReturnDetailArrayList = new ArrayList<>();
purchaseReturnDetailArrayList.add(purchaseReturnDetail);
purchaseReturnDetailMap.put(purchaseId, purchaseReturnDetailArrayList);
}
}
// 获取入库单规格明细
final List<StockLog> stockLogList = stockLogService.getPurchaseDetails(purchaseIdList);
final Map<String, List<StockLog>> stockLogMap = new HashMap<>();
@ -386,48 +410,95 @@ public class BillServiceImpl implements BillService {
// 开始封装数据
for (SupplierBillPurchaseVo supplierBillPurchaseVo : records) {
final String purchaseId = supplierBillPurchaseVo.getPurchaseId();
// 封装销售单信息
final List<PurchaseDetail> purchaseDetailList = purchaseDetailMap.get(purchaseId);
// 根据商品id分类
final Map<String, List<PurchaseDetail>> purchaseDetailMapOfSale = new HashMap<>();
if (purchaseDetailList != null && !purchaseDetailList.isEmpty()) {
for (PurchaseDetail purchaseDetail : purchaseDetailList) {
final String productId = purchaseDetail.getProductId();
if (purchaseDetailMapOfSale.containsKey(productId)) {
final List<PurchaseDetail> purchaseDetailsOfMap = purchaseDetailMapOfSale.get(productId);
purchaseDetailsOfMap.add(purchaseDetail);
} else {
final List<PurchaseDetail> purchaseDetailArrayList = new ArrayList<>();
purchaseDetailArrayList.add(purchaseDetail);
purchaseDetailMapOfSale.put(productId, purchaseDetailArrayList);
if(purchaseDetailMap.containsKey(purchaseId)){
// 封装入库单信息
final List<PurchaseDetail> purchaseDetailList = purchaseDetailMap.get(purchaseId);
// 根据商品id分类
final Map<String, List<PurchaseDetail>> purchaseDetailMapOfSale = new HashMap<>();
if (purchaseDetailList != null && !purchaseDetailList.isEmpty()) {
for (PurchaseDetail purchaseDetail : purchaseDetailList) {
final String productId = purchaseDetail.getProductId();
if (purchaseDetailMapOfSale.containsKey(productId)) {
final List<PurchaseDetail> purchaseDetailsOfMap = purchaseDetailMapOfSale.get(productId);
purchaseDetailsOfMap.add(purchaseDetail);
} else {
final List<PurchaseDetail> purchaseDetailArrayList = new ArrayList<>();
purchaseDetailArrayList.add(purchaseDetail);
purchaseDetailMapOfSale.put(productId, purchaseDetailArrayList);
}
}
final List<BillProductDetailVo> billSaleDetailVos = new ArrayList<>();
for (Map.Entry<String, List<PurchaseDetail>> stringListEntry : purchaseDetailMapOfSale.entrySet()) {
final List<PurchaseDetail> value = stringListEntry.getValue();
final BillProductDetailVo billProductDetailVo = new BillProductDetailVo();
// 同一款商品,不同规格,商品信息只取第一个
billProductDetailVo.setProductSn(value.get(0).getProductSn());
billProductDetailVo.setProductName(value.get(0).getProductName());
final List<BillAttributeListVo> billAttributeListVos = new ArrayList<>();
final List<StockLog> stockLogList1 = stockLogMap.get(value.get(0).getId());
if (stockLogList1 != null && !stockLogList1.isEmpty()) {
for (StockLog stockLog : stockLogList1) {
final BillAttributeListVo billAttributeListVo = new BillAttributeListVo();
billAttributeListVo.setAttributeList(stockLog.getAttributeList());
billAttributeListVo.setProductCount(stockLog.getProductCount());
billAttributeListVos.add(billAttributeListVo);
}
}
billProductDetailVo.setProductCount(value.get(0).getProductCount());
final BigDecimal purchasePrice = value.get(0).getPurchasePrice() == null ? BigDecimal.ZERO : value.get(0).getPurchasePrice();
final BigDecimal productCount = value.get(0).getProductCount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(value.get(0).getProductCount());
billProductDetailVo.setTotalAmount(purchasePrice.multiply(productCount));
billProductDetailVo.setBillAttributeListVos(billAttributeListVos);
billSaleDetailVos.add(billProductDetailVo);
}
supplierBillPurchaseVo.setBillSaleDetailVos(billSaleDetailVos);
}
final List<BillProductDetailVo> billSaleDetailVos = new ArrayList<>();
for (Map.Entry<String, List<PurchaseDetail>> stringListEntry : purchaseDetailMapOfSale.entrySet()) {
final List<PurchaseDetail> value = stringListEntry.getValue();
final BillProductDetailVo billProductDetailVo = new BillProductDetailVo();
// 同一款商品,不同规格,商品信息值几钱取第一个
billProductDetailVo.setProductSn(value.get(0).getProductSn());
billProductDetailVo.setProductName(value.get(0).getProductName());
final List<BillAttributeListVo> billAttributeListVos = new ArrayList<>();
final List<StockLog> stockLogList1 = stockLogMap.get(value.get(0).getId());
if (stockLogList1 != null && !stockLogList1.isEmpty()) {
for (StockLog stockLog : stockLogList1) {
final BillAttributeListVo billAttributeListVo = new BillAttributeListVo();
billAttributeListVo.setAttributeList(stockLog.getAttributeList());
billAttributeListVo.setProductCount(stockLog.getProductCount());
billAttributeListVos.add(billAttributeListVo);
}
if(purchaseReturnDetailMap.containsKey(purchaseId)){
// 封装入库单信息
final List<PurchaseReturnDetail> purchaseReturnDetailList = purchaseReturnDetailMap.get(purchaseId);
// 根据商品id分类
final Map<String, List<PurchaseReturnDetail>> purchaseDetailMapOfSale = new HashMap<>();
if (purchaseReturnDetailList != null && !purchaseReturnDetailList.isEmpty()) {
for (PurchaseReturnDetail purchaseReturnDetail : purchaseReturnDetailList) {
final String productId = purchaseReturnDetail.getProductId();
if (purchaseDetailMapOfSale.containsKey(productId)) {
final List<PurchaseReturnDetail> purchaseDetailsOfMap = purchaseDetailMapOfSale.get(productId);
purchaseDetailsOfMap.add(purchaseReturnDetail);
} else {
final List<PurchaseReturnDetail> purchaseDetailArrayList = new ArrayList<>();
purchaseDetailArrayList.add(purchaseReturnDetail);
purchaseDetailMapOfSale.put(productId, purchaseDetailArrayList);
}
}
billProductDetailVo.setProductCount(value.get(0).getProductCount());
final BigDecimal purchasePrice = value.get(0).getPurchasePrice() == null ? BigDecimal.ZERO : value.get(0).getPurchasePrice();
final BigDecimal productCount = value.get(0).getProductCount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(value.get(0).getProductCount());
billProductDetailVo.setTotalAmount(purchasePrice.multiply(productCount));
billProductDetailVo.setBillAttributeListVos(billAttributeListVos);
billSaleDetailVos.add(billProductDetailVo);
final List<BillProductDetailVo> billSaleDetailVos = new ArrayList<>();
for (Map.Entry<String, List<PurchaseReturnDetail>> stringListEntry : purchaseDetailMapOfSale.entrySet()) {
final List<PurchaseReturnDetail> value = stringListEntry.getValue();
final BillProductDetailVo billProductDetailVo = new BillProductDetailVo();
// 同一款商品,不同规格,商品信息只取第一个
billProductDetailVo.setProductSn(value.get(0).getProductSn());
billProductDetailVo.setProductName(value.get(0).getProductName());
final List<BillAttributeListVo> billAttributeListVos = new ArrayList<>();
final List<StockLog> stockLogList1 = stockLogMap.get(value.get(0).getId());
if (stockLogList1 != null && !stockLogList1.isEmpty()) {
for (StockLog stockLog : stockLogList1) {
final BillAttributeListVo billAttributeListVo = new BillAttributeListVo();
billAttributeListVo.setAttributeList(stockLog.getAttributeList());
billAttributeListVo.setProductCount(stockLog.getProductCount());
billAttributeListVos.add(billAttributeListVo);
}
}
billProductDetailVo.setProductCount(value.get(0).getProductCount());
final BigDecimal purchasePrice = value.get(0).getPurchasePrice() == null ? BigDecimal.ZERO : value.get(0).getPurchasePrice();
final BigDecimal productCount = value.get(0).getProductCount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(value.get(0).getProductCount());
billProductDetailVo.setTotalAmount(purchasePrice.multiply(productCount));
billProductDetailVo.setBillAttributeListVos(billAttributeListVos);
billSaleDetailVos.add(billProductDetailVo);
}
supplierBillPurchaseVo.setBillSaleDetailVos(billSaleDetailVos);
}
supplierBillPurchaseVo.setBillSaleDetailVos(billSaleDetailVos);
}
}
}
// 将销售信息存放到对账单中

6
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/ArrearsVo.java

@ -13,6 +13,12 @@ public class ArrearsVo {
@ApiModelProperty(value = "拿货总金额")
private BigDecimal totalSale;
@ApiModelProperty(value = "拿货数量")
private Integer saleProductCount;
@ApiModelProperty(value = "退货总金额")
private BigDecimal totalReturn;
@ApiModelProperty(value = "退货总数量")
private Integer returnProductCount;
}

6
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/CustomerBillDataVo.java

@ -35,9 +35,15 @@ public class CustomerBillDataVo {
@ApiModelProperty(value = "拿货总金额")
private BigDecimal totalSale;
@ApiModelProperty(value = "拿货总数量")
private Integer saleProductCount;
@ApiModelProperty(value = "退货总金额")
private BigDecimal totalReturn;
@ApiModelProperty(value = "退货总数量")
private Integer returnProductCount;
@ApiModelProperty(value = "销售单明细")
private Page<CustomerBillSaleVo> customerBillSaleVos;

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/CustomerBillSaleVo.java

@ -62,6 +62,9 @@ public class CustomerBillSaleVo {
@ApiModelProperty(value = "删除标识")
private Integer delFlag;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "销售明细")
private List<BillProductDetailVo> billSaleDetailVos;

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/SupplierBillDataVo.java

@ -35,6 +35,9 @@ public class SupplierBillDataVo {
@ApiModelProperty(value = "拿货总金额")
private BigDecimal totalSale;
@ApiModelProperty(value = "拿货总数量")
private Integer purchasingCount;
@ApiModelProperty(value = "入库单明细")
private Page<SupplierBillPurchaseVo> supplierBillSaleVos;

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/bill/vo/SupplierBillPurchaseVo.java

@ -53,6 +53,9 @@ public class SupplierBillPurchaseVo {
@ApiModelProperty(value = "删除标识")
private Integer delFlag;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "销售明细")
private List<BillProductDetailVo> billSaleDetailVos;

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/checkstock/service/impl/CheckStockServiceImpl.java

@ -12,6 +12,7 @@ import cc.hiver.mall.checkstock.vo.CheckStockAttributeVo;
import cc.hiver.mall.checkstock.vo.CheckStockDetailVo;
import cc.hiver.mall.checkstock.vo.CheckStockPageVo;
import cc.hiver.mall.checkstock.vo.CheckStockVo;
import cc.hiver.mall.common.constant.StockLogConstant;
import cc.hiver.mall.entity.Shop;
import cc.hiver.mall.entity.Stock;
import cc.hiver.mall.entity.StockLog;
@ -150,7 +151,7 @@ public class CheckStockServiceImpl extends ServiceImpl<CheckStockMapper, CheckSt
// 记录库存变动历史
final StockLog stockLog = new StockLog();
// 盘点出库
stockLog.setChangeType("2");
stockLog.setChangeType(StockLogConstant.CHANGE_TYPE[2]);
stockLog.setOrderId(checkStockId);
stockLog.setProductId(productId);
stockLog.setAttributeList(attributeList);

2
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/common/constant/StockConstant.java

@ -10,6 +10,6 @@ public interface StockConstant {
/**
* 入库状态 0待入库1已入库
*/
Integer[] IN_STORAGE_STATUS = {0,1};
Integer[] IN_STORAGE_STATUS = {0, 1};
}

4
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/common/constant/StockLogConstant.java

@ -8,8 +8,8 @@ package cc.hiver.mall.common.constant;
public interface StockLogConstant {
/**
* 出入库类型0-入库1-出库
* 出入库类型0-入库1-出库;2-盘点
*/
String[] CHANGE_TYPE = {"0","1"};
String[] CHANGE_TYPE = {"0","1","2"};
}

22
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ProductController.java

@ -29,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@Slf4j
@RestController
@ -51,6 +52,14 @@ public class ProductController {
@RequestMapping(value = "/save", method = RequestMethod.POST)
@ApiOperation("新增货品")
public Result save(@RequestBody ProductVo productVo) {
// 20240824 增加修改的商品货号不能重复
// 根据货号查询商品是否存在
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
final CopyOnWriteArrayList<Product> oldProductListBySn = productService.getByProductSn(productVo.getProductSn(), shopId);
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) {
return ResultUtil.error("您已有货号"+productVo.getProductSn()+"的商品,请更换货号");
}
final Product product = new Product();
BeanUtils.copyBeanProp(product, productVo);
// 新增商品专属分类信息
@ -65,8 +74,6 @@ public class ProductController {
} else {
return ResultUtil.error("添加分类信息失败");
}
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
product.setShopId(shopId);
// 新增的默认为已上架
product.setDelFlag(CommonConstant.DEL_FLAG_TRUE);
@ -89,6 +96,17 @@ public class ProductController {
@RequestMapping(value = "/edit", method = RequestMethod.POST)
@ApiOperation("根据货品id修改货品")
public Result edit(@RequestBody ProductVo productVo) {
// 20240824 增加修改的商品货号不能重复
// 根据货号查询商品是否存在
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
final CopyOnWriteArrayList<Product> oldProductListBySn = productService.getByProductSn(productVo.getProductSn(), shopId);
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) {
// 如果旧商品id不等于前台传递的商品id,则返回信息
if (!productVo.getId().equals(oldProductListBySn.get(0).getId())) {
return ResultUtil.error("您已有货号"+productVo.getProductSn()+"的商品,请更换货号");
}
}
final Product product = new Product();
BeanUtils.copyBeanProp(product, productVo);
// 删除商品专属分类信息

94
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/SaleController.java

@ -40,10 +40,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
@Slf4j
@RestController
@ -146,9 +143,9 @@ public class SaleController {
saleQueryDTO.getSale().setShopId(shopId);
saleQueryDTO.getSale().setShopName(shop.getShopName());
// 根据该客户的欠款信息
String userId = saleQueryDTO.getSale().getUserId();
Debt debt = debtService.selectByUserId(shopId, userId);
BigDecimal amountOwed = debt.getAmountOwed();
final String userId = saleQueryDTO.getSale().getUserId();
final Debt debt = debtService.selectByUserId(shopId, userId);
final BigDecimal amountOwed = debt.getAmountOwed();
// 20240616 开单可能值包含退货单
Sale sale = saleQueryDTO.getSale();
sale.setLastDebtAmount(amountOwed);
@ -452,6 +449,34 @@ public class SaleController {
.eq("sale_id", id)
.groupBy("product_id");
final List<String> list = saleDetailService.selectByCondition1(queryWrapper);
// 查询客户除本单外其他拿货信息
// 客户id
// 封装为商品id+规格值为key的map
final Map<String, List<SaleDetail>> historySaleDetailMap = new HashMap<>();
if (list != null && !list.isEmpty()) {
final List<SaleDetail> historySaleDetailList = saleDetailService.selectDetailListByProductIds(list, sale);
for (SaleDetail saleDetail : historySaleDetailList) {
final String productId = StringUtils.isEmpty(saleDetail.getProductId()) ? "" : saleDetail.getProductId();
final String attributeList = StringUtils.isEmpty(saleDetail.getAttributeList()) ? "" : saleDetail.getAttributeList();
final String key = productId + attributeList;
if (historySaleDetailMap.containsKey(key)) {
historySaleDetailMap.get(key).add(saleDetail);
} else {
final List<SaleDetail> saleDetailList = new ArrayList<>();
saleDetailList.add(saleDetail);
historySaleDetailMap.put(key, saleDetailList);
}
}
}
//
final Map<String, Product> productMap = new HashMap<>();
if(list != null && !list.isEmpty()){
final List<Product> productList = productService.getProductList(list);
for (Product product : productList) {
productMap.putIfAbsent(product.getId(), product);
}
}
final List<SaleDetailDTO> saleDetailDTOS = new ArrayList<>();
for (String productId : list) {
final QueryWrapper<SaleDetail> queryPWrapper = new QueryWrapper<>();
@ -468,7 +493,14 @@ public class SaleController {
saleDetailDTO.setSaleId(saleDetail.getSaleId());
saleDetailDTO.setPrice(saleDetail.getPrice());
saleDetailDTO.setWholesalePrice(saleDetail.getWholesalePrice());
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
// 商品有采购价就使用商品的采购价
if (productMap.containsKey(productId)) {
final BigDecimal purchasePrice = productMap.get(productId).getPurchasePrice() == null ? BigDecimal.ZERO : productMap.get(productId).getPurchasePrice();
saleDetailDTO.setPurchasePrice(purchasePrice);
} else {
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
}
saleDetailDTO.setDiscount(saleDetail.getDiscount());
saleDetailDTO.setDiscountAmount(saleDetail.getDiscountAmount());
saleDetailDTO.setRealPrice(saleDetail.getRealPrice());
@ -477,6 +509,12 @@ public class SaleController {
final SaleDetailQueryDTO saleDetailQueryDTO = new SaleDetailQueryDTO();
saleDetailQueryDTO.setAttributeList(saleDetail.getAttributeList());
saleDetailQueryDTO.setProductCount(saleDetail.getProductCount());
// 判断之前是否拿过货
if (historySaleDetailMap.containsKey(productId + saleDetail.getAttributeList())) {
saleDetailQueryDTO.setIsPurchasedBefore(SaleConstant.IS_PURCHASED_BEFORE[1]);
} else {
saleDetailQueryDTO.setIsPurchasedBefore(SaleConstant.IS_PURCHASED_BEFORE[0]);
}
saleDetailQueryDTOS.add(saleDetailQueryDTO);
}
saleDetailDTO.setStockLogList1(saleDetailQueryDTOS);
@ -611,6 +649,8 @@ public class SaleController {
// 进货成本
final BigDecimal purchasingCost = purchaseService.getPurchasingCost(shopId, startTime, endTime);
saleAllVO.setPurchasingCost(purchasingCost);
} catch (Exception e) {
log.error(e.getMessage(), e);
return ResultUtil.error(500, e.getMessage());
@ -1157,6 +1197,44 @@ public class SaleController {
}
}
/**
* 利润明细-按客户
*
* @param salePageQuery
* @return Result
* @author 王富康
* @date 2024/8/18
*/
@PostMapping("/totalAmountDetailByCustomer")
public Result totalAmountDetailByCustomer(@RequestBody SalePageQuery salePageQuery) {
try {
final Page<TotalAmountDetailByCustomerVo> totalAmountDetailByCustomer = saleService.totalAmountDetailByCustomer(salePageQuery);
return new ResultUtil<>().setData(totalAmountDetailByCustomer);
} catch (Exception e) {
log.info(e.getMessage(), e);
return ResultUtil.error("查询失败");
}
}
/**
* 利润明细-按商品
*
* @param salePageQuery
* @return Result
* @author 王富康
* @date 2024/8/18
*/
@PostMapping("/totalAmountDetailByProduct")
public Result totalAmountDetailByProduct(@RequestBody SalePageQuery salePageQuery) {
try {
final Page<TotalAmountDetailByProductVo> totalAmountDetailByProduct = saleService.totalAmountDetailByProduct(salePageQuery);
return new ResultUtil<>().setData(totalAmountDetailByProduct);
} catch (Exception e) {
log.info(e.getMessage(), e);
return ResultUtil.error("查询失败");
}
}
/**
* 实收金额明细
*

12
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/ShopController.java

@ -130,6 +130,8 @@ public class ShopController {
@ResponseBody
@ApiOperation("编辑")
public Result<Object> edit(Shop shop) {
// 获取旧店铺信息
Shop oldShop = shopService.get(shop.getId());
if (CharSequenceUtil.isNotBlank(shop.getShopArea())) {
final ShopArea d = shopAreaService.get(shop.getShopArea());
if (d != null) {
@ -147,10 +149,12 @@ public class ShopController {
}
shopService.update(shop);
// 删除店铺用户
shopUserService.deleteAllByShopId(shop.getId());
//重新添加店长
if (shop.getShopMangerId() != null) {
//如果更换店主,那么就重新设置店主及店员信息
if (shop.getShopMangerId() != null && oldShop.getShopOwnerId().equals(shop.getShopMangerId())) {
// 删除原店主关联关系
shopUserService.deleteAllByShopIdAndUserId(oldShop.getId(),oldShop.getShopOwnerId());
// 添加角色
final List<ShopUser> shopUsers = Collections.singletonList(shop.getShopMangerId()).stream().map(e -> {
return new ShopUser().setShopId(shop.getId()).setShopName(shop.getShopName()).setUserId(e).setType(ShopUserConstant.SHOP_ADMIN_COST[0]);

7
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/StockController.java

@ -9,6 +9,7 @@ import cc.hiver.mall.pojo.vo.ProductCategoryStockVo;
import cc.hiver.mall.pojo.vo.PurchaseVo;
import cc.hiver.mall.pojo.vo.ShopStockVo;
import cc.hiver.mall.pojo.vo.StockProductVo;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnVo;
import cc.hiver.mall.service.mybatis.StockService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
@ -79,6 +80,12 @@ public class StockController {
return stockService.putInPrice(purchaseVo);
}
@RequestMapping(value = "/putOutPrice", method = RequestMethod.POST)
@ApiOperation("采购单退货")
public Result putOutPrice(@RequestBody PurchaseReturnVo purchaseReturnVo) {
return stockService.putOutPrice(purchaseReturnVo);
}
@RequestMapping(value = "/putInPriceOfAi", method = RequestMethod.POST)
@ApiOperation("AI确认入库")
@Transactional

2
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/ShopUserDao.java

@ -23,4 +23,6 @@ public interface ShopUserDao extends HiverBaseDao<ShopUser, String> {
* @return List<ShopUser>
*/
List<ShopUser> findByShopId(String shopId);
void deleteAllByShopIdAndUserId(String shopId, String shopOwnerId);
}

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/PurchaseDetailMapper.java

@ -1,5 +1,6 @@
package cc.hiver.mall.dao.mapper;
import cc.hiver.mall.bill.vo.SupplierBillQueryVo;
import cc.hiver.mall.entity.PurchaseDetail;
import cc.hiver.mall.entity.PurchaseDetailExample;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -56,4 +57,6 @@ public interface PurchaseDetailMapper extends BaseMapper<PurchaseDetail> {
List<PurchaseDetail> getPurchaseDetailListByProductIds(@Param("productIdList") List<String> productIdList,@Param("id") String id);
void realDeleteByPurchaseId(@Param("purchaseId") String purchaseId);
int queryPurchasingCount(@Param("supplierBillQueryVo") SupplierBillQueryVo supplierBillQueryVo);
}

6
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/SaleDetailMapper.java

@ -1,12 +1,14 @@
package cc.hiver.mall.dao.mapper;
import cc.hiver.mall.entity.PurchaseDetail;
import cc.hiver.mall.entity.Sale;
import cc.hiver.mall.entity.SaleDetail;
import cc.hiver.mall.entity.SaleDetailExample;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
import java.util.List;
@Repository
public interface SaleDetailMapper extends BaseMapper<SaleDetail> {
@ -45,4 +47,8 @@ public interface SaleDetailMapper extends BaseMapper<SaleDetail> {
List<SaleDetail> getSaleDetails(@Param("saleIdList") List<String> saleIdList);
List<SaleDetail> getSaleDetailListByProductIds(@Param("productIdList") List<String> productIdList);
List<SaleDetail> selectDetailListByProductIds(@Param("productIdList")List<String> productIdList,@Param("sale") Sale sale);
BigDecimal getTotalProfit(@Param("shopId") String shopId,@Param("startDate") String startDate,@Param("endDate") String endDate);
}

53
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/SaleMapper.java

@ -65,7 +65,7 @@ public interface SaleMapper extends BaseMapper<Sale> {
Page<CustomerBuyProductLogVo> getCustomerBuyProductLog(Page<CustomerBuyProductLogVo> page, @Param("salePageQuery") SalePageQuery salePageQuery);
List<CustomerBuyProductDetailLogVo> getCustomerBuyProductLogDetailLog(@Param("userId") String userId, @Param("shopId") String shopId, @Param("productIds") List<String> productIds,@Param("startTime") String startTime, @Param("endTime") String endTime);
List<CustomerBuyProductDetailLogVo> getCustomerBuyProductLogDetailLog(@Param("userId") String userId, @Param("shopId") String shopId, @Param("productIds") List<String> productIds, @Param("startTime") String startTime, @Param("endTime") String endTime);
BigDecimal queryTotalAlreadyEarn(@Param("shopId") String shopId, @Param("startTime") String startTime, @Param("endTime") String endTime);
@ -75,44 +75,69 @@ public interface SaleMapper extends BaseMapper<Sale> {
List<SupplierBuyProductDetailLogVo> getSupplierBuyProductLogDetailLog(@Param("supplierId") String supplierId, @Param("shopId") String shopId, @Param("productIds") List<String> productIds);
Page<SupplierBuyProductLogVo> getSupplierBuyProductLog(Page<SupplierBuyProductLogVo> page,@Param("salePageQuery") SalePageQuery salePageQuery);
Page<SupplierBuyProductLogVo> getSupplierBuyProductLog(Page<SupplierBuyProductLogVo> page, @Param("salePageQuery") SalePageQuery salePageQuery);
Page<SaleNoWorkerVO> getSaleByCompanyId(Page<SaleNoWorkerVO> page, @Param("salePageQuery") SalePageQuery salePageQuery);
void companyGetSale(@Param("saleId")String saleId);
void companyGetSale(@Param("saleId") String saleId);
void updateAiMsg(@Param("aiMsg") String aiMsg,@Param("saleId") String saleId);
void updateAiMsg(@Param("aiMsg") String aiMsg, @Param("saleId") String saleId);
void updateAiFlag(@Param("id")String id, @Param("status") Integer status);
void updateStatus(@Param("id")String id, @Param("status") Integer status);
void updateAiFlag(@Param("id") String id, @Param("status") Integer status);
List<TotalAlreadyEarnDetailVo> queryTotalAlreadyEarnDetail(@Param("shopId") String shopId,@Param("startTime") String startTime,@Param("endTime") String endTime);
void updateStatus(@Param("id") String id, @Param("status") Integer status);
List<TotalAlreadyEarnDetailVo> queryTotalAlreadyEarnDetail(@Param("shopId") String shopId, @Param("startTime") String startTime, @Param("endTime") String endTime);
List<CustomerBillSaleVo> getCustomerBill(@Param("customerBillQueryVo") CustomerBillQueryVo customerBillQueryVo);
ArrearsVo getArrearsAndTotalSale( @Param("customerBillQueryVo") CustomerBillQueryVo customerBillQueryVo);
ArrearsVo getArrearsAndTotalSale(@Param("customerBillQueryVo") CustomerBillQueryVo customerBillQueryVo);
Page<TotalAmountDetailVo> totalAmountDetail(Page<TotalAmountDetailVo> page, @Param("salePageQuery") SalePageQuery salePageQuery);
/**
* 实收金额明细
* @author 王富康
* @date 2024/6/29
*
* @param page
* @param salePageQuery
* @return List<TotalAlreadyEarnDetailDayVo>
* @author 王富康
* @date 2024/6/29
*/
Page<TotalAlreadyEarnDetailDayVo> totalAlreadyEarnDetail(Page<TotalAlreadyEarnDetailDayVo> page,@Param("salePageQuery") SalePageQuery salePageQuery);
Page<TotalAlreadyEarnDetailDayVo> totalAlreadyEarnDetail(Page<TotalAlreadyEarnDetailDayVo> page, @Param("salePageQuery") SalePageQuery salePageQuery);
/**
* 客户拿货统计
*
* @param page
* @param salePageQuery
* @return Page<CustomerSaleDetailVo>
* @author 王富康
* @date 2024/6/29
*/
Page<CustomerSaleDetailVo> customerSaleDetail(Page<CustomerSaleDetailVo> page, @Param("salePageQuery") SalePageQuery salePageQuery);
int queryTotalJCount(@Param("shopId") String shopId, @Param("startTime") String startTime, @Param("endTime") String endTime);
/**
* 利润明细-按客户
*
* @param page
* @param salePageQuery
* @return Page<CustomerSaleDetailVo>
* @return Page<TotalAmountDetailByCustomerVo>
* @author 王富康
* @date 2024/8/18
*/
Page<CustomerSaleDetailVo> customerSaleDetail(Page<CustomerSaleDetailVo> page,@Param("salePageQuery") SalePageQuery salePageQuery);
Page<TotalAmountDetailByCustomerVo> totalAmountDetailByCustomer(Page<TotalAmountDetailByCustomerVo> page, @Param("salePageQuery") SalePageQuery salePageQuery);
int queryTotalJCount(@Param("shopId") String shopId,@Param("startTime") String startTime, @Param("endTime") String endTime);
/**
* 利润明细-按商品
*
* @param page
* @param salePageQuery
* @return Page<TotalAmountDetailByProductVo>
* @author 王富康
* @date 2024/8/18
*/
Page<TotalAmountDetailByProductVo> totalAmountDetailByProduct(Page<TotalAmountDetailByProductVo> page, @Param("salePageQuery") SalePageQuery salePageQuery);
}

2
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/StockMapper.java

@ -58,4 +58,6 @@ public interface StockMapper extends BaseMapper<Stock> {
void batchReduceStockByLog(@Param("stockLogList") List<StockLog> stockLogList);
List<Stock> getDefaultStockCount(@Param("productIdList") List<String> productIdList);
void batchIncreaseStockByLog(@Param("stockLogList") List<StockLog> stockLogList);
}

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/service/DebtService.java

@ -5,6 +5,7 @@ import cc.hiver.mall.debt.vo.DebtOfShopVo;
import cc.hiver.mall.debt.vo.QueryDebtVo;
import cc.hiver.mall.entity.Purchase;
import cc.hiver.mall.pojo.dto.SaleQueryDTO;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
@ -81,4 +82,6 @@ public interface DebtService extends IService<Debt> {
Debt recharge(Debt debt);
DebtOfShopVo getAllDebtByShopId(QueryDebtVo queryDebtVo);
void purchaseReturnToDebt(PurchaseReturn putOutPurchase, String type);
}

61
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/debt/service/impl/DebtServiceImpl.java

@ -1,6 +1,7 @@
package cc.hiver.mall.debt.service.impl;
import cc.hiver.core.common.constant.DealingsRecordConstant;
import cc.hiver.core.common.exception.HiverException;
import cc.hiver.core.common.utils.SecurityUtil;
import cc.hiver.core.entity.User;
import cc.hiver.mall.debt.constant.DebtConstant;
@ -14,6 +15,8 @@ import cc.hiver.mall.entity.DealingsRecord;
import cc.hiver.mall.entity.Purchase;
import cc.hiver.mall.entity.Supplier;
import cc.hiver.mall.pojo.dto.SaleQueryDTO;
import cc.hiver.mall.purchasereturn.constant.PurchaseReturnConstant;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import cc.hiver.mall.service.SupplierService;
import cc.hiver.mall.service.mybatis.CustomerService;
import cc.hiver.mall.service.mybatis.DealingsRecordService;
@ -236,6 +239,9 @@ public class DebtServiceImpl extends ServiceImpl<DebtMapper, Debt> implements De
public void purchaseToDebt(Purchase purchase) {
final String shopId = securityUtil.getShopId();
final Debt oldDebt = debtMapper.selectByUserId(shopId, purchase.getSupplierId());
if (oldDebt == null) {
throw new HiverException("供应商不存在!");
}
BigDecimal lastDebtAmount = BigDecimal.ZERO;
BigDecimal newDebtAmount;
// 本单欠款
@ -334,4 +340,59 @@ public class DebtServiceImpl extends ServiceImpl<DebtMapper, Debt> implements De
public DebtOfShopVo getAllDebtByShopId(QueryDebtVo queryDebtVo) {
return debtMapper.getAllDebtByShopId(queryDebtVo);
}
@Override
public void purchaseReturnToDebt(PurchaseReturn putOutPurchase, String type) {
final String shopId = securityUtil.getShopId();
final Debt oldDebt = debtMapper.selectByUserId(shopId, putOutPurchase.getSupplierId());
if (oldDebt == null) {
throw new HiverException("供应商不存在!");
}
BigDecimal lastDebtAmount = BigDecimal.ZERO;
BigDecimal newDebtAmount;
// 本单欠款
BigDecimal alreadyPay = putOutPurchase.getAlreadyPay() == null ? BigDecimal.ZERO : putOutPurchase.getAlreadyPay();
// 上次欠款
lastDebtAmount = oldDebt.getAmountOwed() == null ? BigDecimal.ZERO : oldDebt.getAmountOwed();
// 计算欠款
if (PurchaseReturnConstant.TYPE[0].equals(type)) {
newDebtAmount = oldDebt.getAmountOwed().subtract(alreadyPay);
} else {
newDebtAmount = oldDebt.getAmountOwed().add(alreadyPay);
}
oldDebt.setAmountOwed(newDebtAmount);
debtMapper.updateById(oldDebt);
// 2. 新增欠款记录
final DealingsRecord dealingsRecord = new DealingsRecord();
// 创建人
final User user = securityUtil.getCurrUser();
dealingsRecord.setCreateBy(user.getId());
dealingsRecord.setCreateByName(user.getNickname());
dealingsRecord.setCreateTime(new Date());
dealingsRecord.setSaleId(putOutPurchase.getId());
dealingsRecord.setDealingsUserId(putOutPurchase.getSupplierId());
dealingsRecord.setDealingsUserName(putOutPurchase.getSupplierName());
dealingsRecord.setUserType(DealingsRecordConstant.TYPE[0]);
if (PurchaseReturnConstant.TYPE[0].equals(type)) {
dealingsRecord.setDealingsWay("入库退货");
} else {
dealingsRecord.setDealingsWay("撤销入库退货");
}
dealingsRecord.setShopId(shopId);
// 上次欠款
dealingsRecord.setLastDebtAmount(lastDebtAmount);
// 最新欠款
dealingsRecord.setBalanceDue(newDebtAmount);
// 本次欠款
dealingsRecord.setAmount(alreadyPay);
if (PurchaseReturnConstant.TYPE[0].equals(type)) {
dealingsRecord.setDealingsType(DealingsRecordConstant.DEALINGS_TYPE[9]);
} else {
dealingsRecord.setDealingsType(DealingsRecordConstant.DEALINGS_TYPE[10]);
}
dealingsRecordService.save(dealingsRecord);
}
}

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/SaleDetailQueryDTO.java

@ -19,5 +19,8 @@ public class SaleDetailQueryDTO implements Serializable {
@ApiModelProperty(value = "库存数量")
private Integer stockCount;
@ApiModelProperty(value = "之前是否购买过:0:没买过:1:买过")
private Integer isPurchasedBefore;
private static final long serialVersionUID = 1L;
}

6
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java

@ -66,4 +66,10 @@ public class ProductPageQuery extends HiverBasePageQuery {
@ApiModelProperty("查询条件")
private String searchStr;
@ApiModelProperty("开始时间")
private String startDate;
@ApiModelProperty("结束时间")
private String endDate;
}

4
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/ProductPageVO.java

@ -109,4 +109,8 @@ public class ProductPageVO {
@ApiModelProperty(value = "商品均色均码总库存")
private Integer defaultStockCount;
@ApiModelProperty(value = "商品总销量")
private Integer totalSold;
}

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/SaleAllVO.java

@ -59,4 +59,7 @@ public class SaleAllVO implements Serializable {
@ApiModelProperty(value = "进货成本")
private BigDecimal purchasingCost;
@ApiModelProperty(value = "进货总件数")
private int purchasingCount;
}

25
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/TotalAmountDetailByCustomerVo.java

@ -0,0 +1,25 @@
package cc.hiver.mall.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class TotalAmountDetailByCustomerVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = " 客户id")
private String userId;
@ApiModelProperty(value = " 客户名称")
private String userName;
@ApiModelProperty(value = "利润")
private BigDecimal profit;
@ApiModelProperty(value = "利润占比")
private BigDecimal profitProportion;
}

28
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/TotalAmountDetailByProductVo.java

@ -0,0 +1,28 @@
package cc.hiver.mall.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class TotalAmountDetailByProductVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = " 商品id")
private String productId;
@ApiModelProperty(value = " 商品名称")
private String productName;
@ApiModelProperty(value = " 商品货号")
private String productSn;
@ApiModelProperty(value = "利润")
private BigDecimal profit;
@ApiModelProperty(value = "利润占比")
private BigDecimal profitProportion;
}

9
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchaseocr/service/impl/PurchaseOcrPictureServiceImpl.java

@ -409,9 +409,12 @@ public class PurchaseOcrPictureServiceImpl implements PurchaseOcrPictureService
final List<StockLog> stockLogList = new ArrayList<>();
for (int j = 0; j < attributeListJsonArray.size(); j++) {
final JSONObject attributeListObject = attributeListJsonArray.getJSONObject(j);
String color = attributeListObject.getString("color").toUpperCase();
String size = attributeListObject.getString("size").toUpperCase();
final String productCount1 = attributeListObject.getString("productCount");
String color = attributeListObject.getString("color");
color = StringUtils.isEmpty(color) ? "均色" :color.toUpperCase();
String size = attributeListObject.getString("size");
size = StringUtils.isEmpty(size) ? "均码" :size.toUpperCase();
String productCount1 = attributeListObject.getString("productCount");
productCount1 = StringUtils.isEmpty(productCount1) ? "0" : productCount1;
final Matcher countMatchered = COMPILE.matcher(productCount1);
String replaced = "";
if (countMatchered.find()) {

7
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/constant/PurchaseReturnConstant.java

@ -0,0 +1,7 @@
package cc.hiver.mall.purchasereturn.constant;
public interface PurchaseReturnConstant {
// 订单类型:0:新增入库退货; 1:撤销入库退货
String[] TYPE = {"0","1"};
}

92
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/controller/PurchaseReturnController.java

@ -0,0 +1,92 @@
package cc.hiver.mall.purchasereturn.controller;
import cc.hiver.core.common.utils.ResultUtil;
import cc.hiver.core.common.vo.Result;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import cc.hiver.mall.purchasereturn.service.PurchaseReturnService;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnDataVo;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* 采购退货接口
*
* @author 王富康
* @date 2024/8/17
*/
@Slf4j
@RestController
@Api(tags = "采购退货接口")
@RequestMapping("/hiver/app/purchaseReturn/")
@Transactional
public class PurchaseReturnController {
@Autowired
private PurchaseReturnService purchaseReturnService;
/**
* 分页获取采购退货列表
*
* @param purchaseReturnQueryVo
* @return Result<IPage < PurchaseReturn>>
* @author 王富康
* @date 2024/8/17
*/
@RequestMapping(value = "/getPurchaseReturnList", method = RequestMethod.POST)
@ApiOperation(value = "分页获取采购退货列表")
public Result<IPage<PurchaseReturn>> getPurchaseReturnList(@RequestBody PurchaseReturnQueryVo purchaseReturnQueryVo) {
final IPage<PurchaseReturn> result = purchaseReturnService.getPurchaseReturnList(purchaseReturnQueryVo);
return new ResultUtil<IPage<PurchaseReturn>>().setData(result);
}
/**
* 根据id获取采购退货
*
* @param id
* @return Result<PurchaseReturnDataVo>
* @author 王富康
* @date 2024/8/17
*/
@RequestMapping(value = "/getPurchaseReturnById", method = RequestMethod.POST)
@ApiOperation(value = "根据id获取采购退货")
public Result<PurchaseReturnDataVo> getPurchaseReturnById(String id) {
if (StringUtils.isEmpty(id)) {
return ResultUtil.error("id不能为空");
}
final PurchaseReturnDataVo result = purchaseReturnService.getPurchaseReturnById(id);
return new ResultUtil<PurchaseReturnDataVo>().setData(result);
}
/**
* 撤销采购单退货
*
* @param id
* @return Result<String>
* @author 王富康
* @date 2024/8/17
*/
@RequestMapping(value = "/cancelPurchaseReturn", method = RequestMethod.POST)
@ApiOperation(value = "撤销采购单退货")
public Result<String> cancelPurchaseReturn(String id) {
if (StringUtils.isEmpty(id)) {
return ResultUtil.error("id不能为空");
}
try {
purchaseReturnService.cancelPurchaseReturn(id);
return ResultUtil.success("撤销采购单退货成功");
} catch (Exception e) {
log.error("撤销采购单退货失败", e);
return ResultUtil.error("撤销采购单退货失败");
}
}
}

26
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/controller/PurchaseReturnDetailController.java

@ -0,0 +1,26 @@
package cc.hiver.mall.purchasereturn.controller;
import cc.hiver.mall.purchasereturn.service.PurchaseReturnDetailService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 采购退货明细接口
*
* @author 王富康
* @date 2024/8/17
*/
@Slf4j
@RestController
@Api(tags = "采购退货明细接口")
@RequestMapping("/hiver/app/purchaseReturnDetail/")
@Transactional
public class PurchaseReturnDetailController {
@Autowired
private PurchaseReturnDetailService purchaseReturnDetailService;
}

76
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/entity/PurchaseReturn.java

@ -0,0 +1,76 @@
package cc.hiver.mall.purchasereturn.entity;
import cc.hiver.core.base.HiverBaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 采购退货表
*
* @author 王富康
* @date 2024/8/17
*/
@Data
@ApiModel(value = "采购退货")
@TableName(value = "t_purchase_return", autoResultMap = true)
public class PurchaseReturn extends HiverBaseEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "供应商ID")
private String createByName;
@ApiModelProperty(value = "供应商ID")
private String supplierId;
@ApiModelProperty(value = "供应商名称")
private String supplierName;
@ApiModelProperty(value = "店铺ID")
private String shopId;
@ApiModelProperty(value = "订单金额")
private BigDecimal totalAmount;
@ApiModelProperty(value = "应付")
private BigDecimal shouldPay;
@ApiModelProperty(value = "已付")
private BigDecimal alreadyPay;
@ApiModelProperty(value = "未付")
private BigDecimal noPay;
@ApiModelProperty(value = "其他费用")
private BigDecimal otherPay;
@ApiModelProperty(value = "入库状态:0:待入库(未维护对应的采购价信息);1:已入库;")
private Integer inStorageStatus;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "余额抵扣")
private BigDecimal balanceDeductionAmount;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty(value = "入库时间,20240727重新定义为入库单的创建时间,createTime为前台传递的入库单")
private Date purchaseTime;
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "退货单详情")
private List<PurchaseReturnDetail> purchaseReturnDetails;
}

117
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/entity/PurchaseReturnDetail.java

@ -0,0 +1,117 @@
package cc.hiver.mall.purchasereturn.entity;
import cc.hiver.core.base.HiverBaseEntity;
import cc.hiver.mall.entity.StockLog;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 采购退货详情表
*
* @author 王富康
* @date 2024/8/17
*/
@Data
@ApiModel(value = "采购退货详情")
@TableName(value = "t_purchase_return_detail", autoResultMap = true)
public class PurchaseReturnDetail extends HiverBaseEntity {
@ApiModelProperty(value = "采购单ID")
private String purchaseId;
@ApiModelProperty(value = "商品ID")
private String productId;
@ApiModelProperty(value = "商品名称")
private String productName;
@ApiModelProperty(value = "单位")
private String unit;
@ApiModelProperty(value = "店铺ID")
private String shopId;
@ApiModelProperty(value = "商品分类")
private String categoryId;
@ApiModelProperty(value = "商品分类")
private String attrId;
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "分类名称")
private String categoryName;
@ApiModelProperty(value = "商品属性列表")
private String attributeList;
@ApiModelProperty(value = "供应商")
private String supplierId;
@ApiModelProperty(value = "供应商名称")
private String supplierName;
@ApiModelProperty(value = "货号")
private String productSn;
@ApiModelProperty(value = "条码")
private String barcode;
@ApiModelProperty(value = "零售价")
private BigDecimal price;
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "零售价(单纯用于接收前台传参)")
private BigDecimal lsPrice;
@ApiModelProperty(value = "采购价")
private BigDecimal purchasePrice;
@ApiModelProperty(value = "批发价")
private BigDecimal wholesalePrice;
@ApiModelProperty(value = "货品图片")
private String productPicture;
@ApiModelProperty(value = "货品视频")
private String productVideo;
@ApiModelProperty(value = "货品简介")
private String productIntro;
@ApiModelProperty(value = "销售周期")
private Date salesWeek;
@ApiModelProperty(value = "尾货预警")
private Integer tailWarn;
@ApiModelProperty(value = "打印条码(自己制作的)")
private String printBarcode;
@ApiModelProperty(value = "采购数量")
private Integer productCount;
@ApiModelProperty(value = "识别图片id")
private String ocrPicturePath;
@ApiModelProperty(value = "排序")
private Integer sort;
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "入库商品规格明细表")
private List<StockLog> stockLogList1;
private static final long serialVersionUID = 1L;
}

28
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/mapper/PurchaseReturnDetailMapper.java

@ -0,0 +1,28 @@
package cc.hiver.mall.purchasereturn.mapper;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 采购退货明细Mapper
*
* @author 王富康
* @date 2024/8/17
*/
public interface PurchaseReturnDetailMapper extends BaseMapper<PurchaseReturnDetail> {
List<PurchaseReturnDetail> getByPurchaseReturnId(@Param("id") String id);
/**
* 撤销入库明细
* @author 王富康
* @date 2024/8/17
* @param purchaseId
*/
void cancelByPurchaseReturnId(@Param("purchaseId") String purchaseId);
List<PurchaseReturnDetail> getPurchaseReturnDetails(@Param("purchaseIdList") List<String> purchaseIdList);
}

30
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/mapper/PurchaseReturnMapper.java

@ -0,0 +1,30 @@
package cc.hiver.mall.purchasereturn.mapper;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnQueryVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
/**
* 采购退货Mapper
*
* @author 王富康
* @date 2024/8/17
*/
public interface PurchaseReturnMapper extends BaseMapper<PurchaseReturn> {
/**
* 分页获取采购退货列表
* @author 王富康
* @date 2024/8/17
* @param page
* @param purchaseReturnQueryVo
* @return IPage<PurchaseReturn>
*/
IPage<PurchaseReturn> getPurchaseReturnList(Page<PurchaseReturn> page, @Param("queryParams") PurchaseReturnQueryVo purchaseReturnQueryVo);
void cancelPurchaseReturnById(@Param("id") String id);
}

36
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/service/PurchaseReturnDetailService.java

@ -0,0 +1,36 @@
package cc.hiver.mall.purchasereturn.service;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* 采购退货明细 Service
*
* @author 王富康
* @date 2024/8/17
*/
public interface PurchaseReturnDetailService extends IService<PurchaseReturnDetail> {
/**
* 根据入库退货id获取商品信息
*
* @param id
* @return List<PurchaseReturnDetail>
* @author 王富康
* @date 2024/8/17
*/
List<PurchaseReturnDetail> getByPurchaseReturnId(String id);
/**
* 撤销入库明细
*
* @param id
* @author 王富康
* @date 2024/8/17
*/
void cancelByPurchaseReturnId(String id);
List<PurchaseReturnDetail> getPurchaseReturnDetails(List<String> purchaseIdList);
}

45
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/service/PurchaseReturnService.java

@ -0,0 +1,45 @@
package cc.hiver.mall.purchasereturn.service;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnDataVo;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* 采购退货 Service
*
* @author 王富康
* @date 2024/8/17
*/
public interface PurchaseReturnService extends IService<PurchaseReturn> {
/**
* 分页获取采购退货列表
*
* @param purchaseReturnQueryVo
* @return IPage<PurchaseReturn>
* @author 王富康
* @date 2024/8/17
*/
IPage<PurchaseReturn> getPurchaseReturnList(PurchaseReturnQueryVo purchaseReturnQueryVo);
/**
* 根据id获取采购退货
*
* @param id
* @return PurchaseReturnDataVo
* @author 王富康
* @date 2024/8/17
*/
PurchaseReturnDataVo getPurchaseReturnById(String id);
/**
* 撤销采购单退货
*
* @param id
* @author 王富康
* @date 2024/8/17
*/
void cancelPurchaseReturn(String id);
}

51
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/service/impl/PurchaseReturnDetailServiceImpl.java

@ -0,0 +1,51 @@
package cc.hiver.mall.purchasereturn.service.impl;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail;
import cc.hiver.mall.purchasereturn.mapper.PurchaseReturnDetailMapper;
import cc.hiver.mall.purchasereturn.service.PurchaseReturnDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 采购退货明细服务实现类
*
* @author 王富康
* @date 2024/8/17
*/
@Service
public class PurchaseReturnDetailServiceImpl extends ServiceImpl<PurchaseReturnDetailMapper, PurchaseReturnDetail> implements PurchaseReturnDetailService {
@Autowired
private PurchaseReturnDetailMapper purchaseReturnDetailMapper;
/**
* 根据入库退货id获取商品信息
* @author 王富康
* @date 2024/8/17
* @param id
* @return List<PurchaseReturnDetail>
*/
@Override
public List<PurchaseReturnDetail> getByPurchaseReturnId(String id) {
return purchaseReturnDetailMapper.getByPurchaseReturnId(id);
}
/**
* 撤销入库明细
* @author 王富康
* @date 2024/8/17
* @param purchaseId
*/
@Override
public void cancelByPurchaseReturnId(String purchaseId) {
purchaseReturnDetailMapper.cancelByPurchaseReturnId(purchaseId);
}
@Override
public List<PurchaseReturnDetail> getPurchaseReturnDetails(List<String> purchaseIdList) {
return purchaseReturnDetailMapper.getPurchaseReturnDetails(purchaseIdList);
}
}

234
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/service/impl/PurchaseReturnServiceImpl.java

@ -0,0 +1,234 @@
package cc.hiver.mall.purchasereturn.service.impl;
import cc.hiver.core.common.exception.HiverException;
import cc.hiver.core.common.utils.SecurityUtil;
import cc.hiver.mall.common.constant.StockLogConstant;
import cc.hiver.mall.debt.service.DebtService;
import cc.hiver.mall.entity.Product;
import cc.hiver.mall.entity.Stock;
import cc.hiver.mall.entity.StockLog;
import cc.hiver.mall.entity.Supplier;
import cc.hiver.mall.purchasereturn.constant.PurchaseReturnConstant;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail;
import cc.hiver.mall.purchasereturn.mapper.PurchaseReturnMapper;
import cc.hiver.mall.purchasereturn.service.PurchaseReturnDetailService;
import cc.hiver.mall.purchasereturn.service.PurchaseReturnService;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnDataVo;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnQueryVo;
import cc.hiver.mall.service.SupplierService;
import cc.hiver.mall.service.mybatis.DealingsRecordService;
import cc.hiver.mall.service.mybatis.ProductService;
import cc.hiver.mall.service.mybatis.StockLogService;
import cc.hiver.mall.service.mybatis.StockService;
import cc.hiver.mall.utils.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 采购退货 服务实现类
*
* @author 王富康
* @date 2024/8/17
*/
@Service
public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper, PurchaseReturn> implements PurchaseReturnService {
@Autowired
private PurchaseReturnMapper purchaseReturnMapper;
@Autowired
private SupplierService supplierService;
@Autowired
private PurchaseReturnDetailService purchaseReturnDetailService;
@Autowired
private StockLogService stockLogService;
@Autowired
ProductService productService;
@Autowired
private DealingsRecordService dealingsRecordService;
@Autowired
private StockService stockService;
@Autowired
private SecurityUtil securityUtil;
@Autowired
private DebtService debtService;
/**
* 分页获取采购退货列表
*
* @param purchaseReturnQueryVo
* @return IPage<PurchaseReturn>
* @author 王富康
* @date 2024/8/17
*/
@Override
public IPage<PurchaseReturn> getPurchaseReturnList(PurchaseReturnQueryVo purchaseReturnQueryVo) {
//解释时间加1天
if (StringUtils.isNotEmpty(purchaseReturnQueryVo.getEndDate())) {
purchaseReturnQueryVo.setEndDate(DateUtil.addDay(purchaseReturnQueryVo.getEndDate(), 1));
}
final String shopId = securityUtil.getShopId();
purchaseReturnQueryVo.setShopId(shopId);
final Page<PurchaseReturn> page = new Page<>(purchaseReturnQueryVo.getPageNum(), purchaseReturnQueryVo.getPageSize());
return purchaseReturnMapper.getPurchaseReturnList(page, purchaseReturnQueryVo);
}
/**
* 根据id获取采购退货
*
* @param id
* @return PurchaseReturnDataVo
* @author 王富康
* @date 2024/8/17
*/
@Override
public PurchaseReturnDataVo getPurchaseReturnById(String id) {
final PurchaseReturnDataVo purchaseReturnDataVo = new PurchaseReturnDataVo();
// 获取采购单信息
final PurchaseReturn purchaseReturn = purchaseReturnMapper.selectById(id);
purchaseReturnDataVo.setPurchaseReturn(purchaseReturn);
// 获取供应商信息
final String supplierId = purchaseReturn.getSupplierId();
if (StringUtils.isNotEmpty(supplierId)) {
final Supplier supplier = supplierService.findById(supplierId);
purchaseReturnDataVo.setSupplier(supplier);
}
// 获取商品信息
final List<PurchaseReturnDetail> purchaseReturnDetails = purchaseReturnDetailService.getByPurchaseReturnId(id);
// 获取规格信息
final List<StockLog> stockLogList = stockLogService.getByPurchaseId(id);
final Map<String, List<StockLog>> stockLogMap = new HashMap<>();
// 封装规格属性
for (StockLog stockLog : stockLogList) {
final String productId = stockLog.getProductId();
if (stockLogMap.containsKey(productId)) {
stockLogMap.get(productId).add(stockLog);
} else {
final List<StockLog> stockLogs = new ArrayList<>();
stockLogs.add(stockLog);
stockLogMap.put(productId, stockLogs);
}
}
final List<String> productIdList = new ArrayList<>();
for (PurchaseReturnDetail returnDetail : purchaseReturnDetails) {
final String productId = returnDetail.getProductId();
returnDetail.setStockLogList1(stockLogMap.get(productId));
productIdList.add(productId);
}
if (!productIdList.isEmpty()) {
// 20240602 将商品的采购价、零售价、批发价回填回来
// 获取商品
final List<Product> productList = productService.getProductList(productIdList);
// 将商品封装为map,key为商品id,value为商品信息
final Map<String, Product> productMap = productList.stream().collect(Collectors.toMap(Product::getId, product -> product));
for (PurchaseReturnDetail purchaseReturnDetail : purchaseReturnDetails) {
final String productId = purchaseReturnDetail.getProductId();
if (productMap.containsKey(productId)) {
final Product product = productMap.get(productId);
purchaseReturnDetail.setPrice(product.getPrice());
purchaseReturnDetail.setWholesalePrice(product.getWholesalePrice());
purchaseReturnDetail.setPurchasePrice(product.getPurchasePrice());
}
}
purchaseReturnDataVo.setPurchaseReturnDetails(purchaseReturnDetails);
}
// 获取该入库单的欠款更新记录
purchaseReturnDataVo.setDealingsRecords(dealingsRecordService.getDealingsRecordList(id));
return purchaseReturnDataVo;
}
/**
* 撤销采购单退货
*
* @param id
* @author 王富康
* @date 2024/8/17
*/
@Override
public void cancelPurchaseReturn(String id) {
PurchaseReturnDataVo purchaseReturnById = getPurchaseReturnById(id);
// 1. 删除入库单主表信息
purchaseReturnMapper.cancelPurchaseReturnById(id);
// 2. 删除退货明细
purchaseReturnDetailService.cancelByPurchaseReturnId(id);
// 需要新增的履历集合
final List<StockLog> stockLogAddList = new ArrayList<>();
// 2. 回退库存
// 获取前台入库商品信息
final List<PurchaseReturnDetail> purchaseReturnDetails = purchaseReturnById.getPurchaseReturnDetails();
// 需要修改的商品信息集合,商品中的平均采购价需要计算
final List<String> productIdList = new ArrayList<>();
for (PurchaseReturnDetail purchaseReturnDetail : purchaseReturnDetails) {
productIdList.add(purchaseReturnDetail.getProductId());
}
// 根据商品id集合获取库存信息
final List<Stock> productStock = stockService.getProductStock(productIdList);
// 封装为商品id+商品属性为key ,Stock为value的map
final Map<String, Stock> stockMap = new HashMap<>();
for (Stock stock : productStock) {
stockMap.put(stock.getProductId() + stock.getAttributeList(), stock);
}
for (PurchaseReturnDetail purchaseReturnDetail : purchaseReturnDetails) {
final List<StockLog> changeStockLogs = purchaseReturnDetail.getStockLogList1();
for (StockLog changeStockLog : changeStockLogs) {
StockLog returnStockLog = new StockLog();
// 获取商品id+商品属性为key ,Stock为value的map
final String changeProductId = changeStockLog.getProductId();
final String changeAttributeList = changeStockLog.getAttributeList();
final String getKey = changeProductId + changeAttributeList;
if (stockMap.containsKey(getKey)) {
final Stock stock = stockMap.get(getKey);
//撤销前数量
returnStockLog.setStock(stock.getStockCount());
} else {
// 不存在库存?应该没有吧
throw new HiverException("商品id为" + changeProductId + "的商品属性为" + changeAttributeList + "的商品库存不存在");
}
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
// 整理入库商品规格明细表数据
// 记录库存履历
returnStockLog.setProductId(changeProductId);
returnStockLog.setOrderId(id);
returnStockLog.setDetailId(purchaseReturnDetail.getId());
//入库
returnStockLog.setChangeType(StockLogConstant.CHANGE_TYPE[0]);
returnStockLog.setShopId(shopId);
returnStockLog.setPurchasePrice(purchaseReturnDetail.getPurchasePrice());
returnStockLog.setProductCount(changeStockLog.getProductCount());
returnStockLog.setAttributeList(changeStockLog.getAttributeList());
stockLogAddList.add(returnStockLog);
}
}
// 批量更新库存数
stockService.batchIncreaseStockByLog(stockLogAddList);
// 库存记录
stockLogService.saveBatch(stockLogAddList);
// 3. 回退供应商欠款
// 异步更新供应商欠款信息机欠款记录
debtService.purchaseReturnToDebt(purchaseReturnById.getPurchaseReturn(), PurchaseReturnConstant.TYPE[1]);
// 作废当前订单的欠款记录
dealingsRecordService.cancelRecord(id);
}
}

29
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/vo/PurchaseReturnDataVo.java

@ -0,0 +1,29 @@
package cc.hiver.mall.purchasereturn.vo;
import cc.hiver.mall.entity.DealingsRecord;
import cc.hiver.mall.entity.Supplier;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
public class PurchaseReturnDataVo {
@ApiModelProperty(value = "供应商信息")
private Supplier supplier;
@ApiModelProperty(value = "采购单主表")
private PurchaseReturn purchaseReturn;
@ApiModelProperty(value = "采购单子表")
private List<PurchaseReturnDetail> purchaseReturnDetails;
@ApiModelProperty(value = "欠款信息")
private List<DealingsRecord> dealingsRecords;
}

18
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/vo/PurchaseReturnQueryVo.java

@ -0,0 +1,18 @@
package cc.hiver.mall.purchasereturn.vo;
import cc.hiver.core.base.HiverBasePageQuery;
import lombok.Data;
import java.io.Serializable;
@Data
public class PurchaseReturnQueryVo extends HiverBasePageQuery implements Serializable {
private String shopId;
private String queryStr;
private String startDate;
private String endDate;
}

29
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/purchasereturn/vo/PurchaseReturnVo.java

@ -0,0 +1,29 @@
package cc.hiver.mall.purchasereturn.vo;
import cc.hiver.mall.entity.DealingsRecord;
import cc.hiver.mall.entity.Supplier;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
public class PurchaseReturnVo {
@ApiModelProperty(value = "供应商信息")
private Supplier supplier;
@ApiModelProperty(value = "采购单退货主表")
private PurchaseReturn purchase;
@ApiModelProperty(value = "采购单退货子表")
private List<PurchaseReturnDetail> purchaseDetails;
@ApiModelProperty(value = "欠款信息")
private List<DealingsRecord> dealingsRecords;
}

1
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/ShopUserService.java

@ -23,4 +23,5 @@ public interface ShopUserService extends HiverBaseService<ShopUser, String> {
*/
List<ShopUser> findByShopId(String shopId);
void deleteAllByShopIdAndUserId(String shopId, String shopOwnerId);
}

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/PurchaseDetailService.java

@ -1,5 +1,6 @@
package cc.hiver.mall.service.mybatis;
import cc.hiver.mall.bill.vo.SupplierBillQueryVo;
import cc.hiver.mall.entity.PurchaseDetail;
import com.baomidou.mybatisplus.extension.service.IService;
@ -34,4 +35,6 @@ public interface PurchaseDetailService extends IService<PurchaseDetail> {
* @return List<PurchaseDetail>
*/
List<PurchaseDetail> getPurchaseDetailListByProductIds(List<String> productIdList, String id);
Integer queryPurchasingCount(SupplierBillQueryVo supplierBillQueryVo);
}

15
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/SaleDetailService.java

@ -1,11 +1,13 @@
package cc.hiver.mall.service.mybatis;
import cc.hiver.mall.entity.PurchaseDetail;
import cc.hiver.mall.entity.Sale;
import cc.hiver.mall.entity.SaleDetail;
import cc.hiver.mall.entity.SaleDetailExample;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import java.math.BigDecimal;
import java.util.List;
public interface SaleDetailService extends IService<SaleDetail> {
@ -38,4 +40,17 @@ public interface SaleDetailService extends IService<SaleDetail> {
* @return List<SaleDetail>
*/
List<SaleDetail> getSaleDetailListByProductIds(List<String> productIdList);
List<SaleDetail> selectDetailListByProductIds(List<String> list, Sale sale);
/**
* 获取利润
* @author 王富康
* @date 2024/8/18
* @param shopId
* @param startTime
* @param endTime
* @return BigDecimal
*/
BigDecimal getTotalProfit(String shopId, String startTime, String endTime);
}

20
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/SaleService.java

@ -128,4 +128,24 @@ public interface SaleService extends IService<Sale> {
* @date 2024/7/26
*/
void temporarySaveSale(SaleQueryDTO saleQueryDTO);
/**
* 利润明细-按客户
*
* @param salePageQuery
* @return Page<TotalAmountDetailByCustomerVo>
* @author 王富康
* @date 2024/8/18
*/
Page<TotalAmountDetailByCustomerVo> totalAmountDetailByCustomer(SalePageQuery salePageQuery);
/**
* 利润明细-按商品
*
* @param salePageQuery
* @return Page<TotalAmountDetailByProductVo>
* @author 王富康
* @date 2024/8/18
*/
Page<TotalAmountDetailByProductVo> totalAmountDetailByProduct(SalePageQuery salePageQuery);
}

11
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/StockService.java

@ -8,6 +8,7 @@ import cc.hiver.mall.pojo.vo.ProductCategoryStockVo;
import cc.hiver.mall.pojo.vo.PurchaseVo;
import cc.hiver.mall.pojo.vo.ShopStockVo;
import cc.hiver.mall.pojo.vo.StockProductVo;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnVo;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -95,6 +96,14 @@ public interface StockService extends IService<Stock> {
*/
void batchReduceStockByLog(List<StockLog> stockLogList);
/**
* 根据入库记录增加库存数
* @author 王富康
* @date 2024/8/19
* @param stockLogList
*/
void batchIncreaseStockByLog(List<StockLog> stockLogList);
/**
* 获取某些商品均色均码的库存数
*
@ -113,4 +122,6 @@ public interface StockService extends IService<Stock> {
* @date 2024/8/8
*/
void deleteStockById(String id);
Result putOutPrice(PurchaseReturnVo purchaseReturnVo);
}

1
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java

@ -307,6 +307,7 @@ public class SalesAndDetailsServiceImpl implements SalesAndDetailsService {
BeanUtils.copyBeanProp(saleDetail, saleDetailDTO);
saleDetail.setCreateTime(sale.getCreateTime());
saleDetail.setCreateBy(sale.getCreateBy());
saleDetail.setDelFlag(CommonConstant.DEL_FLAG_FALSE);
saleDetailList2.add(saleDetail);
}
}

27
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesCalculateServiceImpl.java

@ -3,11 +3,12 @@ package cc.hiver.mall.serviceimpl;
import cc.hiver.core.common.constant.CommonConstant;
import cc.hiver.core.common.constant.SaleConstant;
import cc.hiver.core.common.utils.SecurityUtil;
import cc.hiver.mall.bill.vo.SupplierBillQueryVo;
import cc.hiver.mall.dao.mapper.PurchaseDetailMapper;
import cc.hiver.mall.dao.mapper.ReturnSaleMapper;
import cc.hiver.mall.dao.mapper.SaleMapper;
import cc.hiver.mall.entity.ReturnSaleExample;
import cc.hiver.mall.entity.Sale;
import cc.hiver.mall.entity.SaleDetail;
import cc.hiver.mall.entity.SaleExample;
import cc.hiver.mall.pojo.vo.SaleAllVO;
import cc.hiver.mall.pojo.vo.TotalAlreadyEarnDetailVo;
@ -52,6 +53,9 @@ public class SalesCalculateServiceImpl implements SalesCalculateService {
@Autowired
private SecurityUtil securityUtil;
@Autowired
private PurchaseDetailMapper purchaseDetailMapper;
@Override
public SaleAllVO calculateService(String startTime, String endTime){
@ -113,7 +117,7 @@ public class SalesCalculateServiceImpl implements SalesCalculateService {
//
saleAllVO.setReturnTotalAmount(totalAmount2);
saleAllVO.setReturnTotalCount(totalCount2);
saleAllVO.setReturnTotalCount(totalJCount2);
// 总件数暂时没用着
// saleAllVO.setTotalJCount(totalJCount1 - totalJCount2);
@ -133,13 +137,13 @@ public class SalesCalculateServiceImpl implements SalesCalculateService {
}*/
//获取当日门店利润(当日总营收-当日总成本+(退货总营收-退货总成本))
BigDecimal totalPurchasePrice = new BigDecimal("0.0");
/*BigDecimal totalPurchasePrice = new BigDecimal("0.0");
final List<SaleDetail> list = saleDetailService.listOfShopAll(shopId,startTime,endTime);
for (SaleDetail saleDetail : list) {
final BigDecimal purchasePrice = saleDetail.getPurchasePrice() == null ? BigDecimal.ZERO :saleDetail.getPurchasePrice();
final int productCount = saleDetail.getProductCount() == null ? 0 : saleDetail.getProductCount();
totalPurchasePrice = totalPurchasePrice.add(purchasePrice.multiply(new BigDecimal(productCount)));
}
}*/
/*final QueryWrapper<ReturnDetail> returnDetailQueryWrapper = new QueryWrapper<>();
returnDetailQueryWrapper.eq("shop_id", shopId)
.between("create_time", startDate, endDate);
@ -150,8 +154,9 @@ public class SalesCalculateServiceImpl implements SalesCalculateService {
final int productCount = returnDetail.getProductCount();
totalReturnPurchasePrice = totalReturnPurchasePrice.add(purchasePrice.multiply(new BigDecimal(productCount)));
}*/
// 利润= 销售总金额-成本
saleAllVO.setTotalProfit(saleAllVO.getTotalAmount().subtract(totalPurchasePrice));
// 利润
BigDecimal totalPurchasePrice = saleDetailService.getTotalProfit(shopId,startTime,endTime);
saleAllVO.setTotalProfit(totalPurchasePrice);
//获取当日门店下单客户数
final QueryWrapper<Sale> querySaleWrapper = new QueryWrapper<>();
@ -181,9 +186,17 @@ public class SalesCalculateServiceImpl implements SalesCalculateService {
// 20240805 增加需要加一个今日销售总件数:查sale表的prodect_count总和 状态delflag=0;status=4的
//获取今日实收
//获取销售总件数
final int totalJCount = saleMapper.queryTotalJCount(shopId,startTime,endTime);
saleAllVO.setTotalJCount(totalJCount);
//获取进货总件数
SupplierBillQueryVo supplierBillQueryVo = new SupplierBillQueryVo();
supplierBillQueryVo.setShopId(shopId);
supplierBillQueryVo.setStartDate(startTime);
supplierBillQueryVo.setEndDate(endTime);
final int purchasingCount = purchaseDetailMapper.queryPurchasingCount(supplierBillQueryVo);
saleAllVO.setPurchasingCount(purchasingCount);
return saleAllVO;
}

5
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/ShopUserServiceImpl.java

@ -50,4 +50,9 @@ public class ShopUserServiceImpl implements ShopUserService {
public List<ShopUser> findByShopId(String shopId){
return shopUserDao.findByShopId(shopId);
}
@Override
public void deleteAllByShopIdAndUserId(String shopId, String shopOwnerId) {
shopUserDao.deleteAllByShopIdAndUserId(shopId, shopOwnerId);
}
}

4
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/StockAndLogServiceImpl.java

@ -53,7 +53,7 @@ public class StockAndLogServiceImpl implements StockAndLogService {
//2.记录库存履历
final StockLog stockLog = new StockLog();
stockLog.setChangeType("1");//出库
stockLog.setChangeType(StockLogConstant.CHANGE_TYPE[1]);//出库
stockLog.setProductId(saleDetail.getProductId());
stockLog.setAttributeList(saleDetail.getAttributeList());
stockLog.setStock(stockCount);//出库前数量
@ -84,7 +84,7 @@ public class StockAndLogServiceImpl implements StockAndLogService {
//2.记录库存履历
final StockLog stockLog = new StockLog();
stockLog.setChangeType("0");//退货-入库
stockLog.setChangeType(StockLogConstant.CHANGE_TYPE[0]);//退货-入库
stockLog.setProductId(saleDetail.getProductId());
stockLog.setAttributeList(saleDetail.getAttributeList());
stockLog.setStock(stockCount);//退货-入库前数量

182
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/ProductServiceImpl.java

@ -183,96 +183,118 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
// shopId从缓存中设置
// 判断是否新的商品,新的商品进行新增
final String productId = saleDetailDTO.getProductId();
if (StringUtils.isEmpty(productId)) {
// 新增商品
final Product product = new Product();
product.setCreateBy(user.getId());
product.setCreateTime(new Date());
product.setProductName(saleDetailDTO.getProductName());
product.setShopId(shopId);
// 默认为已上架的
product.setDelFlag(ProductConstant.DEL_FLAG[1]);
product.setCategoryId(saleDetailDTO.getCategoryId());
product.setSupplierName(saleDetailDTO.getSupplierName());
product.setProductSn(saleDetailDTO.getProductSn());
// 零售价
product.setPrice(saleDetailDTO.getPrice());
// 采购价
product.setPurchasePrice(saleDetailDTO.getPurchasePrice());
// 批发价
product.setWholesalePrice(saleDetailDTO.getWholesalePrice());
product.setProductPicture(saleDetailDTO.getProductPicture());
product.setInStorageStatus(PurchaseConstant.IN_STORAGE_STATUS[1]);
if (StringUtils.isEmpty(productId) ) {
// 货号或者商品名称都为空的时候不新增,其他时候新增商品
if (StringUtils.isEmpty(saleDetailDTO.getProductSn()) && StringUtils.isEmpty(saleDetailDTO.getProductName())) {
continue;
}
// 根据货号查询商品是否存在
CopyOnWriteArrayList<Product> oldProductListBySn = getByProductSn(saleDetailDTO.getProductSn(), shopId);
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) {
// 旧商品,赋值商品id
saleDetailDTO.setProductId(oldProductListBySn.get(0).getId());
}else{
// 新增商品
final Product product = new Product();
product.setCreateBy(user.getId());
product.setCreateTime(new Date());
product.setProductName(saleDetailDTO.getProductName());
product.setShopId(shopId);
// 默认为已上架的
product.setDelFlag(ProductConstant.DEL_FLAG[1]);
product.setCategoryId(saleDetailDTO.getCategoryId());
product.setSupplierName(saleDetailDTO.getSupplierName());
product.setProductSn(saleDetailDTO.getProductSn());
// 零售价
product.setPrice(saleDetailDTO.getPrice());
// 采购价
product.setPurchasePrice(saleDetailDTO.getPurchasePrice());
// 批发价
product.setWholesalePrice(saleDetailDTO.getWholesalePrice());
product.setProductPicture(saleDetailDTO.getProductPicture());
product.setInStorageStatus(PurchaseConstant.IN_STORAGE_STATUS[1]);
// 放到要查询的id中
// 填充前台传过来的数据
saleDetailDTO.setProductId(product.getId());
if (saleDetailDTO.getProductPictures() != null) {
// 新增商品图片子图
for (ProductPicture productPicture : saleDetailDTO.getProductPictures()) {
productPicture.setProductId(product.getId());
// 放到要查询的id中
// 填充前台传过来的数据
saleDetailDTO.setProductId(product.getId());
if (saleDetailDTO.getProductPictures() != null) {
// 新增商品图片子图
for (ProductPicture productPicture : saleDetailDTO.getProductPictures()) {
productPicture.setProductId(product.getId());
}
addProductPictureList.addAll(saleDetailDTO.getProductPictures());
}
addProductPictureList.addAll(saleDetailDTO.getProductPictures());
}
// 将规格及规格下的规格值提取出来
final List<SaleDetailQueryDTO> stockLogList1 = saleDetailDTO.getStockLogList1();
for (SaleDetailQueryDTO saleDetailQueryDTO : stockLogList1) {
final String attributeList = saleDetailQueryDTO.getAttributeList();
final JSONObject jsonObject = JSONUtil.parseObj(attributeList);
for (Map.Entry<String, Object> stringObjectEntry : jsonObject.entrySet()) {
final String key = stringObjectEntry.getKey();
String value = String.valueOf(stringObjectEntry.getValue());
// 根据规格id规格是颜色、还是尺码。
if ("颜色".equals(key)) {
if (!value.contains("色")) {
value += '色';
}
} else if ("尺码".equals(key)) {
final String valueUpperCase = value.toUpperCase();
if (value.contains("码")) {
value = valueUpperCase;
// 将规格及规格下的规格值提取出来
final List<SaleDetailQueryDTO> stockLogList1 = saleDetailDTO.getStockLogList1();
for (SaleDetailQueryDTO saleDetailQueryDTO : stockLogList1) {
final String attributeList = saleDetailQueryDTO.getAttributeList();
final StringBuilder newAttributeList = new StringBuilder();
newAttributeList.append("{");
StringBuilder colorStr = new StringBuilder("\"颜色\":");
StringBuilder sizeStr = new StringBuilder("\"尺码\":");
final JSONObject jsonObject = JSONUtil.parseObj(attributeList);
for (Map.Entry<String, Object> stringObjectEntry : jsonObject.entrySet()) {
final String key = stringObjectEntry.getKey();
String value = String.valueOf(stringObjectEntry.getValue());
// 根据规格id规格是颜色、还是尺码。
if ("颜色".equals(key)) {
if (!value.contains("色")) {
value += '色';
}
colorStr.append('"' +value+ '"');
} else if ("尺码".equals(key)) {
final String valueUpperCase = value.toUpperCase();
if (value.contains("码")) {
value = valueUpperCase;
} else {
value = valueUpperCase + '码';
}
sizeStr.append('"' +value+ '"');
} else {
value = valueUpperCase + '码';
// 暂不支持其他规格
}
} else {
// 暂不支持其他规格
}
if (attributeValueMap.containsKey(key)) {
final List<String> strings = attributeValueMap.get(key);
if (!strings.contains(value)) {
strings.add(value);
if (attributeValueMap.containsKey(key)) {
final List<String> strings = attributeValueMap.get(key);
if (!strings.contains(value)) {
strings.add(value);
}
} else {
final List<String> valueList = new ArrayList<>();
valueList.add(value);
attributeValueMap.put(key, valueList);
}
} else {
final List<String> valueList = new ArrayList<>();
valueList.add(value);
attributeValueMap.put(key, valueList);
}
newAttributeList.append(colorStr);
newAttributeList.append(',');
newAttributeList.append(sizeStr);
newAttributeList.append('}');
saleDetailQueryDTO.setAttributeList(newAttributeList.toString());
}
}
final CopyOnWriteArrayList<ProductAttributeOfAddVo> productAttributeOfAddVos = new CopyOnWriteArrayList<>();
for (Map.Entry<String, List<String>> stringListEntry : attributeValueMap.entrySet()) {
final String key = stringListEntry.getKey();
final List<String> entryValue = stringListEntry.getValue();
final ProductAttributeOfAddVo productAttributeOfAddVo = new ProductAttributeOfAddVo();
productAttributeOfAddVo.setAttributeName(key);
final CopyOnWriteArrayList<ProductAttributeValueVo> productAttributeValueVoList = new CopyOnWriteArrayList<>();
for (String s : entryValue) {
final ProductAttributeValueVo productAttributeValueVo = new ProductAttributeValueVo();
productAttributeValueVo.setValue(s);
productAttributeValueVoList.add(productAttributeValueVo);
final CopyOnWriteArrayList<ProductAttributeOfAddVo> productAttributeOfAddVos = new CopyOnWriteArrayList<>();
for (Map.Entry<String, List<String>> stringListEntry : attributeValueMap.entrySet()) {
final String key = stringListEntry.getKey();
final List<String> entryValue = stringListEntry.getValue();
final ProductAttributeOfAddVo productAttributeOfAddVo = new ProductAttributeOfAddVo();
productAttributeOfAddVo.setAttributeName(key);
final CopyOnWriteArrayList<ProductAttributeValueVo> productAttributeValueVoList = new CopyOnWriteArrayList<>();
for (String s : entryValue) {
final ProductAttributeValueVo productAttributeValueVo = new ProductAttributeValueVo();
productAttributeValueVo.setValue(s);
productAttributeValueVoList.add(productAttributeValueVo);
}
productAttributeOfAddVo.setProductAttributeValueVoList(productAttributeValueVoList);
productAttributeOfAddVos.add(productAttributeOfAddVo);
}
productAttributeOfAddVo.setProductAttributeValueVoList(productAttributeValueVoList);
productAttributeOfAddVos.add(productAttributeOfAddVo);
productCategoryVo.setProductAttributeOfAddVos(productAttributeOfAddVos);
// 批量去新增,并拿到分类id,回填商品
// 维护该商品专属分类
final String s = productCategoryService.batchSaveCategoryAndAttribute(productCategoryVo);
// 维护该店铺的专属分类
productCategoryService.batchSaveCategoryOfShop(productCategoryVo);
product.setAttrId(s);
addProductList.add(product);
}
productCategoryVo.setProductAttributeOfAddVos(productAttributeOfAddVos);
// 批量去新增,并拿到分类id,回填商品
// 维护该商品专属分类
final String s = productCategoryService.batchSaveCategoryAndAttribute(productCategoryVo);
// 维护该店铺的专属分类
productCategoryService.batchSaveCategoryOfShop(productCategoryVo);
product.setAttrId(s);
addProductList.add(product);
}
}
if (!addProductList.isEmpty()) {

6
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseDetailServiceImpl.java

@ -1,5 +1,6 @@
package cc.hiver.mall.serviceimpl.mybatis;
import cc.hiver.mall.bill.vo.SupplierBillQueryVo;
import cc.hiver.mall.dao.mapper.PurchaseDetailMapper;
import cc.hiver.mall.entity.PurchaseDetail;
import cc.hiver.mall.entity.StockLog;
@ -104,4 +105,9 @@ public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailMapper,
public List<PurchaseDetail> getPurchaseDetailListByProductIds(List<String> productIdList, String id) {
return purchaseDetailMapper.getPurchaseDetailListByProductIds(productIdList, id);
}
@Override
public Integer queryPurchasingCount(SupplierBillQueryVo supplierBillQueryVo) {
return purchaseDetailMapper.queryPurchasingCount(supplierBillQueryVo);
}
}

88
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/ReturnSaleServiceImpl.java

@ -4,6 +4,7 @@ import cc.hiver.core.common.utils.SecurityUtil;
import cc.hiver.mall.bill.vo.ArrearsVo;
import cc.hiver.mall.bill.vo.CustomerBillQueryVo;
import cc.hiver.mall.dao.mapper.ReturnSaleMapper;
import cc.hiver.mall.entity.Product;
import cc.hiver.mall.entity.ReturnDetail;
import cc.hiver.mall.entity.ReturnSale;
import cc.hiver.mall.pojo.dto.ReturnSaleDetailDTO;
@ -11,6 +12,7 @@ import cc.hiver.mall.pojo.dto.SaleDetailQueryDTO;
import cc.hiver.mall.pojo.query.ReturnSalePageQuery;
import cc.hiver.mall.pojo.vo.ReturnSaleVo;
import cc.hiver.mall.pojo.vo.ReturnTotalAmountDetailVo;
import cc.hiver.mall.service.mybatis.ProductService;
import cc.hiver.mall.service.mybatis.ReturnDetailService;
import cc.hiver.mall.service.mybatis.ReturnSaleService;
import cc.hiver.mall.utils.DateUtil;
@ -21,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -38,6 +41,9 @@ public class ReturnSaleServiceImpl extends ServiceImpl<ReturnSaleMapper, ReturnS
@Autowired
private SecurityUtil securityUtil;
@Autowired
private ProductService productService;
@Override
public ReturnSale getBySaleId(String id) {
return returnSaleMapper.getBySaleId(id);
@ -93,6 +99,14 @@ public class ReturnSaleServiceImpl extends ServiceImpl<ReturnSaleMapper, ReturnS
returnSaleMap.put(returnSaleId, returnDetailList);
}
}
// 获取商品信息
final String productId = returnSalePageQuery.getProductId();
BigDecimal purchasePrice = BigDecimal.ZERO;
if(StringUtils.isNotEmpty(productId)){
final Product product = productService.getById(productId);
purchasePrice = product.getPurchasePrice() == null ? BigDecimal.ZERO : product.getPurchasePrice();
}
// 将详细信息封装到返回结果中去
for (ReturnSaleVo returnSaleVo : returnSaleList) {
final String id = returnSaleVo.getId();
@ -109,7 +123,8 @@ public class ReturnSaleServiceImpl extends ServiceImpl<ReturnSaleMapper, ReturnS
returnSaleDetailDTO.setProductName(returnDetail.getProductName());
returnSaleDetailDTO.setProductCount(returnDetail.getProductCount());
returnSaleDetailDTO.setRealPrice(returnDetail.getRealPrice());
returnSaleDetailDTO.setPurchasePrice(returnDetail.getPurchasePrice());
returnSaleDetailDTO.setPurchasePrice(purchasePrice);
returnSaleDetailDTO.setDiscountAmount(returnDetail.getDiscountAmount());
// 详细规格
final SaleDetailQueryDTO saleDetailQueryDTO = new SaleDetailQueryDTO();
saleDetailQueryDTO.setAttributeList(returnDetail.getAttributeList());
@ -163,7 +178,7 @@ public class ReturnSaleServiceImpl extends ServiceImpl<ReturnSaleMapper, ReturnS
final Page<ReturnSaleVo> returnSalePage = returnSaleMapper.getReturnSaleListByUserId(page, returnSalePageQuery);
final List<ReturnSaleVo> returnSaleList = returnSalePage.getRecords();
// 根据商品id获取退货详细信息
List<String> returnSaleIdList = new ArrayList<>();
final List<String> returnSaleIdList = new ArrayList<>();
for (ReturnSaleVo returnSaleVo : returnSaleList) {
returnSaleIdList.add(returnSaleVo.getId());
}
@ -172,6 +187,7 @@ public class ReturnSaleServiceImpl extends ServiceImpl<ReturnSaleMapper, ReturnS
final List<ReturnDetail> returnDetails = returnDetailService.getReturnDetailsByReturnId(returnSaleIdList);
// 将returnDetails 放到以return_sale_id 为key ReturnDetail为value的map中去
final Map<String, List<ReturnDetail>> returnSaleMap = new HashMap<>();
final List<String> productIdList = new ArrayList<>();
for (ReturnDetail returnDetail : returnDetails) {
final String returnSaleId = returnDetail.getReturnSaleId();
if (returnSaleMap.containsKey(returnSaleId)) {
@ -183,34 +199,68 @@ public class ReturnSaleServiceImpl extends ServiceImpl<ReturnSaleMapper, ReturnS
returnDetailList.add(returnDetail);
returnSaleMap.put(returnSaleId, returnDetailList);
}
productIdList.add(returnDetail.getProductId());
}
final List<Product> productList = productService.getProductList(productIdList);
// 封装为map
final Map<String, Product> productMap = new HashMap<>();
for (Product product : productList) {
productMap.putIfAbsent(product.getId(), product);
}
// 将详细信息封装到返回结果中去
for (ReturnSaleVo returnSaleVo : returnSaleList) {
final String id = returnSaleVo.getId();
// 从returnSaleMap获取,并封装
if (returnSaleMap.containsKey(id)) {
// 这是是根据退商品id查询的,所以肯定是同一件商品,并且在同一个订单中采购价等也是一样
// 所以商品信息循环覆盖即可,每一个详情相当于一种规格
final List<ReturnSaleDetailDTO> returnSaleDetailList = new ArrayList<>();
final ReturnSaleDetailDTO returnSaleDetailDTO = new ReturnSaleDetailDTO();
final List<ReturnDetail> returnDetailList = returnSaleMap.get(id);
final List<SaleDetailQueryDTO> stockLogList1 = new ArrayList<>();
// 根据productId 分组为map
final Map<String, List<ReturnDetail>> returnDetailMap = new HashMap<>();
for (ReturnDetail returnDetail : returnDetailList) {
returnSaleDetailDTO.setProductId(returnDetail.getProductId());
returnSaleDetailDTO.setProductName(returnDetail.getProductName());
returnSaleDetailDTO.setProductCount(returnDetail.getProductCount());
returnSaleDetailDTO.setRealPrice(returnDetail.getRealPrice());
returnSaleDetailDTO.setProductSn(returnDetail.getProductSn());
returnSaleDetailDTO.setPurchasePrice(returnDetail.getPurchasePrice());
returnSaleDetailDTO.setDiscountAmount(returnDetail.getDiscountAmount());
if (returnDetailMap.containsKey(returnDetail.getProductId())){
returnDetailMap.get(returnDetail.getProductId()).add(returnDetail);
}else{
final List<ReturnDetail> thisProductReturnDetailList = new ArrayList<>();
thisProductReturnDetailList.add(returnDetail);
returnDetailMap.put(returnDetail.getProductId(),thisProductReturnDetailList);
}
}
for (Map.Entry<String, List<ReturnDetail>> entry : returnDetailMap.entrySet()) {
final List<ReturnDetail> thisProductReturnDetailList = entry.getValue();
// 同一款商品区第一个即可,规格不同而已
final ReturnDetail firstReturnDetail = thisProductReturnDetailList.get(0);
final ReturnSaleDetailDTO returnSaleDetailDTO = new ReturnSaleDetailDTO();
final List<SaleDetailQueryDTO> stockLogList1 = new ArrayList<>();
returnSaleDetailDTO.setProductId(firstReturnDetail.getProductId());
returnSaleDetailDTO.setProductName(firstReturnDetail.getProductName());
returnSaleDetailDTO.setProductCount(firstReturnDetail.getProductCount());
returnSaleDetailDTO.setRealPrice(firstReturnDetail.getRealPrice());
returnSaleDetailDTO.setProductSn(firstReturnDetail.getProductSn());
if(productMap.containsKey(firstReturnDetail.getProductId())){
final Product product = productMap.get(firstReturnDetail.getProductId());
final BigDecimal purchasePrice = product.getPurchasePrice() == null ? BigDecimal.ZERO : product.getPurchasePrice();
returnSaleDetailDTO.setPurchasePrice(purchasePrice);
}else{
returnSaleDetailDTO.setPurchasePrice(firstReturnDetail.getPurchasePrice());
}
returnSaleDetailDTO.setPurchasePrice(firstReturnDetail.getPurchasePrice());
returnSaleDetailDTO.setDiscountAmount(firstReturnDetail.getDiscountAmount());
// 详细规格
final SaleDetailQueryDTO saleDetailQueryDTO = new SaleDetailQueryDTO();
saleDetailQueryDTO.setAttributeList(returnDetail.getAttributeList());
saleDetailQueryDTO.setProductCount(returnDetail.getProductCount());
stockLogList1.add(saleDetailQueryDTO);
for (ReturnDetail returnDetail : thisProductReturnDetailList) {
final SaleDetailQueryDTO saleDetailQueryDTO = new SaleDetailQueryDTO();
saleDetailQueryDTO.setAttributeList(returnDetail.getAttributeList());
saleDetailQueryDTO.setProductCount(returnDetail.getProductCount());
stockLogList1.add(saleDetailQueryDTO);
}
returnSaleDetailDTO.setStockLogList1(stockLogList1);
returnSaleDetailList.add(returnSaleDetailDTO);
}
returnSaleDetailDTO.setStockLogList1(stockLogList1);
returnSaleDetailList.add(returnSaleDetailDTO);
returnSaleVo.setReturnSaleDetailList(returnSaleDetailList);
}
}

12
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/SaleDetailServiceImpl.java

@ -5,6 +5,7 @@ import cc.hiver.mall.dao.mapper.SaleDetailMapper;
import cc.hiver.mall.dao.mapper.StockLogMapper;
import cc.hiver.mall.dao.mapper.StockMapper;
import cc.hiver.mall.entity.PurchaseDetail;
import cc.hiver.mall.entity.Sale;
import cc.hiver.mall.entity.SaleDetail;
import cc.hiver.mall.entity.SaleDetailExample;
import cc.hiver.mall.service.mybatis.SaleDetailService;
@ -13,6 +14,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
@Service
@ -81,4 +83,14 @@ public class SaleDetailServiceImpl extends ServiceImpl<SaleDetailMapper, SaleDet
public List<SaleDetail> getSaleDetailListByProductIds(List<String> productIdList) {
return saleDetailMapper.getSaleDetailListByProductIds(productIdList);
}
@Override
public List<SaleDetail> selectDetailListByProductIds(List<String> productIdList, Sale sale) {
return saleDetailMapper.selectDetailListByProductIds(productIdList,sale);
}
@Override
public BigDecimal getTotalProfit(String shopId, String startTime, String endTime) {
return saleDetailMapper.getTotalProfit(shopId, startTime, endTime);
}
}

94
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/SaleServiceImpl.java

@ -213,14 +213,18 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa
saleDetailDTO.setSaleId(saleDetail.getSaleId());
saleDetailDTO.setPrice(saleDetail.getPrice());
saleDetailDTO.setWholesalePrice(saleDetail.getWholesalePrice());
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
saleDetailDTO.setDiscount(saleDetail.getDiscount());
saleDetailDTO.setDiscountAmount(saleDetail.getDiscountAmount());
saleDetailDTO.setRealPrice(saleDetail.getRealPrice());
// 回填商品的的图片及货号
if (productMap.containsKey(productId)) {
BigDecimal purchasePrice = productMap.get(productId).getPurchasePrice() == null ? BigDecimal.ZERO : productMap.get(productId).getPurchasePrice();
saleDetailDTO.setPurchasePrice(purchasePrice);
saleDetailDTO.setProductPicture(productMap.get(productId).getProductPicture());
saleDetailDTO.setProductSn(productMap.get(productId).getProductSn());
}else{
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
}
final SaleDetailQueryDTO saleDetailQueryDTO = new SaleDetailQueryDTO();
@ -298,7 +302,18 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa
queryPWrapper.eq("product_id", salePageQuery.getProductId());
queryPWrapper.in("sale_id", saleIdList);
final List<SaleDetail> saleDetailList = saleDetailService.list(queryPWrapper);
// 获取商品id
List<String> productIdList = new ArrayList<>();
for (SaleDetail saleDetail : saleDetailList) {
productIdList.add(saleDetail.getProductId());
}
// 根据商品id结合获取商品信息
final List<Product> productList = productService.getProductList(productIdList);
// 将商品信息转为map ,方便获取
final Map<String, Product> productMap = new HashMap<>();
for (Product product : productList) {
productMap.putIfAbsent(product.getId(), product);
}
// 转换为SaleDetailDTO
final List<SaleDetailDTO> saleDetailDTOS = new ArrayList<>();
for (SaleDetail saleDetail : saleDetailList) {
@ -311,7 +326,15 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa
saleDetailDTO.setSaleId(saleDetail.getSaleId());
saleDetailDTO.setPrice(saleDetail.getPrice());
saleDetailDTO.setWholesalePrice(saleDetail.getWholesalePrice());
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
// 取商品的采购价
if(productMap.containsKey(saleDetail.getProductId())){
Product product = productMap.get(saleDetail.getProductId());
BigDecimal purchasePrice = product.getPurchasePrice() == null ? BigDecimal.ZERO : product.getPurchasePrice();
saleDetailDTO.setPurchasePrice(purchasePrice);
}else{
saleDetailDTO.setPurchasePrice(saleDetail.getPurchasePrice());
}
saleDetailDTO.setDiscount(saleDetail.getDiscount());
saleDetailDTO.setDiscountAmount(saleDetail.getDiscountAmount());
saleDetailDTO.setRealPrice(saleDetail.getRealPrice());
@ -635,6 +658,16 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa
// 尝试从货号中提取正确的货号,因为货号可能包含颜色等信息
productSn = CommonUtil.getProductSn(productSn);
final String attributeList = object.getString("attributeList");
String wholesalePriceStr = object.getString("wholesalePrice");
BigDecimal wholesalePrice = BigDecimal.ZERO;
// 使用正则表达式提取数字部分
final Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?");
final Matcher matcher = pattern.matcher(wholesalePriceStr);
if (matcher.find()) {
// 获取匹配到的数字字符串并转换为BigDecimal
final String numericPart = matcher.group();
wholesalePrice = new BigDecimal(numericPart);
}
final JSONArray attributeListJsonArray = JSON.parseArray(attributeList);
// 定义一个map,货号为key,purchaseDetail 为value
final Map<String, PurchaseDetail> purchaseDetailMap = new HashMap<>();
@ -659,7 +692,13 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa
saleDetailDTO.setCategoryId(categoryId);
saleDetailDTO.setPrice(product.getPrice());
saleDetailDTO.setPurchasePrice(product.getPurchasePrice());
saleDetailDTO.setWholesalePrice(product.getWholesalePrice());
// 如果通义千问返回了批发价,那么就使用通义千问返回的批发价
if (wholesalePrice.compareTo(BigDecimal.ZERO) > 0) {
saleDetailDTO.setWholesalePrice(wholesalePrice);
} else {
saleDetailDTO.setWholesalePrice(product.getWholesalePrice());
}
saleDetailDTO.setProductPicture(product.getProductPicture());
saleDetailDTO.setProductSn(product.getProductSn());
saleDetailDTO.setProductCount(0);
@ -770,6 +809,7 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa
// 没查到,封装数据,货号为id
final SaleDetailDTO saleDetailDTO = new SaleDetailDTO();
saleDetailDTO.setProductSn(productSn);
saleDetailDTO.setWholesalePrice(wholesalePrice);
saleDetailDTO.setProductCount(0);
// 获取默认分类
final ProductCategoryVo defaultCategory = productCategoryService.getDefaultCategory(shopId);
@ -1162,6 +1202,52 @@ public class SaleServiceImpl extends ServiceImpl<SaleMapper, Sale> implements Sa
}
}
/**
* 利润明细-按客户
*
* @param salePageQuery
* @return Page<TotalAmountDetailByCustomerVo>
* @author 王富康
* @date 2024/8/18
*/
@Override
public Page<TotalAmountDetailByCustomerVo> totalAmountDetailByCustomer(SalePageQuery salePageQuery) {
//结束时间+1天
if (StringUtils.isNotEmpty(salePageQuery.getEndDate())) {
final String endDate = DateUtil.addDay(salePageQuery.getEndDate(), 1);
salePageQuery.setEndDate(endDate);
}
final Page<TotalAmountDetailByCustomerVo> page = new Page<>(salePageQuery.getPageNum(), salePageQuery.getPageSize());
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
salePageQuery.setShopId(shopId);
Page<TotalAmountDetailByCustomerVo> totalAmountDetailByCustomerVoPage = saleMapper.totalAmountDetailByCustomer(page, salePageQuery);
return totalAmountDetailByCustomerVoPage;
}
/**
* 利润明细-按商品
*
* @param salePageQuery
* @return Page<TotalAmountDetailByProductVo>
* @author 王富康
* @date 2024/8/18
*/
@Override
public Page<TotalAmountDetailByProductVo> totalAmountDetailByProduct(SalePageQuery salePageQuery) {
//结束时间+1天
if (StringUtils.isNotEmpty(salePageQuery.getEndDate())) {
final String endDate = DateUtil.addDay(salePageQuery.getEndDate(), 1);
salePageQuery.setEndDate(endDate);
}
final Page<TotalAmountDetailByProductVo> page = new Page<>(salePageQuery.getPageNum(), salePageQuery.getPageSize());
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
salePageQuery.setShopId(shopId);
Page<TotalAmountDetailByProductVo> totalAmountDetailByProductVoPage = saleMapper.totalAmountDetailByProduct(page, salePageQuery);
return totalAmountDetailByProductVoPage;
}
/**
* 使用正则表达式替换输入字符串中连续的字符为相应数量的X字符
*

421
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/StockServiceImpl.java

@ -2,6 +2,8 @@ package cc.hiver.mall.serviceimpl.mybatis;
import cc.hiver.core.common.constant.CommonConstant;
import cc.hiver.core.common.constant.ProductConstant;
import cc.hiver.core.common.constant.UserConstant;
import cc.hiver.core.common.exception.HiverException;
import cc.hiver.core.common.utils.ResultUtil;
import cc.hiver.core.common.utils.SecurityUtil;
import cc.hiver.core.common.utils.SnowFlakeUtil;
@ -10,6 +12,7 @@ import cc.hiver.core.common.vo.Result;
import cc.hiver.core.entity.User;
import cc.hiver.mall.common.constant.PurchaseConstant;
import cc.hiver.mall.common.constant.StockConstant;
import cc.hiver.mall.common.constant.StockLogConstant;
import cc.hiver.mall.dao.mapper.StockMapper;
import cc.hiver.mall.debt.service.DebtService;
import cc.hiver.mall.entity.*;
@ -17,6 +20,12 @@ import cc.hiver.mall.pojo.query.StockPageQuery;
import cc.hiver.mall.pojo.vo.*;
import cc.hiver.mall.productpicture.entity.ProductPicture;
import cc.hiver.mall.productpicture.service.ProductPictureService;
import cc.hiver.mall.purchasereturn.constant.PurchaseReturnConstant;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturn;
import cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail;
import cc.hiver.mall.purchasereturn.service.PurchaseReturnDetailService;
import cc.hiver.mall.purchasereturn.service.PurchaseReturnService;
import cc.hiver.mall.purchasereturn.vo.PurchaseReturnVo;
import cc.hiver.mall.service.mybatis.*;
import cc.hiver.mall.utils.DateUtil;
import com.alibaba.fastjson.JSON;
@ -68,6 +77,12 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
@Autowired
private DebtService debtService;
@Autowired
private PurchaseReturnService purchaseReturnService;
@Autowired
private PurchaseReturnDetailService purchaseReturnDetailService;
@Transactional
@Override
public Result putIn(PurchaseVo purchaseVo) {
@ -332,7 +347,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
stockLog.setProductId(purchaseDetail.getProductId());
stockLog.setOrderId(purchase.getId());
//入库
stockLog.setChangeType("0");
stockLog.setChangeType(StockLogConstant.CHANGE_TYPE[0]);
//入库前数量
stockLog.setStock(stockCount);
stockLog.setShopId(shopId);
@ -459,7 +474,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
// 与之前相等,不变
} else {
for (Stock stock : productStockList) {
final int oldStockCount = stock.getStockCount();
final int oldStockCount = stock.getStockCount() == null ? 0 : stock.getStockCount();
if (oldStockCount <= 0) {
// 如果库存为负数,那么就需要以新入库的采购价计算成本。
newProductCount += Math.abs(oldStockCount);
@ -541,7 +556,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
if (purchaseDetailService.saveOrUpdateBatch(purchaseDetails)) {
// 更新商品信息
productService.saveOrUpdateBatch(updateProductList);
// 异步更新供应商欠款信息机欠款记录
// 更新供应商欠款信息机欠款记录
debtService.purchaseToDebt(purchase);
return ResultUtil.success("添加成功");
} else {
@ -604,7 +619,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
final Integer tailWarn = product.getTailWarn();
//平均采购价
final BigDecimal purchasePrice = product.getPurchasePrice() == null ? new BigDecimal(0) : product.getPurchasePrice();
final Integer thisStockCount = stock.getStockCount()==null?0:stock.getStockCount();
final Integer thisStockCount = stock.getStockCount() == null ? 0 : stock.getStockCount();
// 计算成本,负数按0计算
if (thisStockCount > 0) {
final BigDecimal thisStockCost = purchasePrice.multiply(BigDecimal.valueOf(thisStockCount));
@ -759,103 +774,124 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
// 需要新增的
final Map<String, List<String>> attributeValueMap = new HashMap<>();
if (StringUtils.isEmpty(productId)) {
// 新增商品
final Product product = new Product();
product.setCreateBy(user.getId());
product.setCreateTime(new Date());
product.setProductName(purchaseDetail.getProductName());
product.setShopId(shopId);
// 默认为已上架的
product.setDelFlag(ProductConstant.DEL_FLAG[1]);
product.setCategoryId(purchaseDetail.getCategoryId());
// 新商品的专属分类id使用商品id
// product.setAttrId(product.getId());
product.setSupplierId(purchaseDetail.getSupplierId());
product.setSupplierName(purchaseDetail.getSupplierName());
product.setProductSn(purchaseDetail.getProductSn());
product.setBarcode(purchaseDetail.getBarcode());
// 零售价
product.setPrice(purchaseDetail.getPrice());
// 采购价
product.setPurchasePrice(purchaseDetail.getPurchasePrice());
// 批发价
product.setWholesalePrice(purchaseDetail.getWholesalePrice());
product.setProductPicture(purchaseDetail.getProductPicture());
product.setProductIntro(purchaseDetail.getProductIntro());
product.setSalesWeek(purchaseDetail.getSalesWeek());
product.setPrintBarcode(purchaseDetail.getPrintBarcode());
product.setTailWarn(purchaseDetail.getTailWarn());
product.setInStorageStatus(PurchaseConstant.IN_STORAGE_STATUS[1]);
addProductList.add(product);
// 放到要查询的id中
productIdList.add(product.getId());
// 填充前台传过来的数据
purchaseDetail.setProductId(product.getId());
// 新增商品图片子图
if (purchaseDetail.getProductPictures() != null) {
for (ProductPicture productPicture : purchaseDetail.getProductPictures()) {
productPicture.setProductId(product.getId());
// 20240824 增加货号判断是否为旧商品
// 根据货号查询商品是否存在
CopyOnWriteArrayList<Product> oldProductListBySn = productService.getByProductSn(purchaseDetail.getProductSn(), shopId);
if (oldProductListBySn != null && !oldProductListBySn.isEmpty()) {
// 旧商品,赋值商品id
purchaseDetail.setProductId(oldProductListBySn.get(0).getId());
// 旧商品
productIdList.add(productId);
}else{
// 新增商品
final Product product = new Product();
product.setCreateBy(user.getId());
product.setCreateTime(new Date());
product.setProductName(purchaseDetail.getProductName());
product.setShopId(shopId);
// 默认为已上架的
product.setDelFlag(ProductConstant.DEL_FLAG[1]);
product.setCategoryId(purchaseDetail.getCategoryId());
// 新商品的专属分类id使用商品id
// product.setAttrId(product.getId());
product.setSupplierId(purchaseDetail.getSupplierId());
product.setSupplierName(purchaseDetail.getSupplierName());
product.setProductSn(purchaseDetail.getProductSn());
product.setBarcode(purchaseDetail.getBarcode());
// 零售价
product.setPrice(purchaseDetail.getPrice());
// 采购价
product.setPurchasePrice(purchaseDetail.getPurchasePrice());
// 批发价
product.setWholesalePrice(purchaseDetail.getWholesalePrice());
product.setProductPicture(purchaseDetail.getProductPicture());
product.setProductIntro(purchaseDetail.getProductIntro());
product.setSalesWeek(purchaseDetail.getSalesWeek());
product.setPrintBarcode(purchaseDetail.getPrintBarcode());
product.setTailWarn(purchaseDetail.getTailWarn());
product.setInStorageStatus(PurchaseConstant.IN_STORAGE_STATUS[1]);
addProductList.add(product);
// 放到要查询的id中
productIdList.add(product.getId());
// 填充前台传过来的数据
purchaseDetail.setProductId(product.getId());
// 新增商品图片子图
if (purchaseDetail.getProductPictures() != null) {
for (ProductPicture productPicture : purchaseDetail.getProductPictures()) {
productPicture.setProductId(product.getId());
}
addProductPictureList.addAll(purchaseDetail.getProductPictures());
}
addProductPictureList.addAll(purchaseDetail.getProductPictures());
}
// 将规格及规格下的规格值提取出来
final List<StockLog> stockLogList1 = purchaseDetail.getStockLogList1();
for (StockLog stockLog : stockLogList1) {
final String attributeList = stockLog.getAttributeList();
final JSONObject jsonObject = JSON.parseObject(attributeList);
for (Map.Entry<String, Object> stringObjectEntry : jsonObject.entrySet()) {
final String key = stringObjectEntry.getKey();
String value = String.valueOf(stringObjectEntry.getValue());
// 根据规格id规格是颜色、还是尺码。
if ("颜色".equals(key)) {
if (!value.contains("色")) {
value += '色';
}
} else if ("尺码".equals(key)) {
final String valueUpperCase = value.toUpperCase();
if (value.contains("码")) {
value = valueUpperCase;
// 将规格及规格下的规格值提取出来
final List<StockLog> stockLogList1 = purchaseDetail.getStockLogList1();
for (StockLog stockLog : stockLogList1) {
final String attributeList = stockLog.getAttributeList();
final StringBuilder newAttributeList = new StringBuilder();
newAttributeList.append("{");
StringBuilder colorStr = new StringBuilder("\"颜色\":");
StringBuilder sizeStr = new StringBuilder("\"尺码\":");
final JSONObject jsonObject = JSON.parseObject(attributeList);
for (Map.Entry<String, Object> stringObjectEntry : jsonObject.entrySet()) {
final String key = stringObjectEntry.getKey();
String value = String.valueOf(stringObjectEntry.getValue());
// 根据规格id规格是颜色、还是尺码。
if ("颜色".equals(key)) {
if (!value.contains("色")) {
value += '色';
}
colorStr.append('"' +value+ '"');
} else if ("尺码".equals(key)) {
final String valueUpperCase = value.toUpperCase();
if (value.contains("码")) {
value = valueUpperCase;
} else {
value = valueUpperCase + '码';
}
sizeStr.append('"' +value+ '"');
} else {
value = valueUpperCase + '码';
// 暂不支持其他规格
}
} else {
// 暂不支持其他规格
}
if (attributeValueMap.containsKey(key)) {
final List<String> strings = attributeValueMap.get(key);
if (!strings.contains(value)) {
strings.add(value);
if (attributeValueMap.containsKey(key)) {
final List<String> strings = attributeValueMap.get(key);
if (!strings.contains(value)) {
strings.add(value);
}
} else {
final List<String> valueList = new ArrayList<>();
valueList.add(value);
attributeValueMap.put(key, valueList);
}
} else {
final List<String> valueList = new ArrayList<>();
valueList.add(value);
attributeValueMap.put(key, valueList);
}
newAttributeList.append(colorStr);
newAttributeList.append(',');
newAttributeList.append(sizeStr);
newAttributeList.append('}');
stockLog.setAttributeList(newAttributeList.toString());
}
}
final CopyOnWriteArrayList<ProductAttributeOfAddVo> productAttributeOfAddVos = new CopyOnWriteArrayList<>();
for (Map.Entry<String, List<String>> stringListEntry : attributeValueMap.entrySet()) {
final String key = stringListEntry.getKey();
final List<String> entryValue = stringListEntry.getValue();
final ProductAttributeOfAddVo productAttributeOfAddVo = new ProductAttributeOfAddVo();
productAttributeOfAddVo.setAttributeName(key);
final CopyOnWriteArrayList<ProductAttributeValueVo> productAttributeValueVoList = new CopyOnWriteArrayList<>();
for (String s : entryValue) {
final ProductAttributeValueVo productAttributeValueVo = new ProductAttributeValueVo();
productAttributeValueVo.setValue(s);
productAttributeValueVoList.add(productAttributeValueVo);
final CopyOnWriteArrayList<ProductAttributeOfAddVo> productAttributeOfAddVos = new CopyOnWriteArrayList<>();
for (Map.Entry<String, List<String>> stringListEntry : attributeValueMap.entrySet()) {
final String key = stringListEntry.getKey();
final List<String> entryValue = stringListEntry.getValue();
final ProductAttributeOfAddVo productAttributeOfAddVo = new ProductAttributeOfAddVo();
productAttributeOfAddVo.setAttributeName(key);
final CopyOnWriteArrayList<ProductAttributeValueVo> productAttributeValueVoList = new CopyOnWriteArrayList<>();
for (String s : entryValue) {
final ProductAttributeValueVo productAttributeValueVo = new ProductAttributeValueVo();
productAttributeValueVo.setValue(s);
productAttributeValueVoList.add(productAttributeValueVo);
}
productAttributeOfAddVo.setProductAttributeValueVoList(productAttributeValueVoList);
productAttributeOfAddVos.add(productAttributeOfAddVo);
}
productAttributeOfAddVo.setProductAttributeValueVoList(productAttributeValueVoList);
productAttributeOfAddVos.add(productAttributeOfAddVo);
productCategoryVo.setProductAttributeOfAddVos(productAttributeOfAddVos);
// 批量去新增,并拿到分类id,回填商品
// 维护该商品专属分类
final String s = productCategoryService.batchSaveCategoryAndAttribute(productCategoryVo);
// 维护该店铺的专属分类
// productCategoryService.batchSaveCategoryOfShop(productCategoryVo);
product.setAttrId(s);
}
productCategoryVo.setProductAttributeOfAddVos(productAttributeOfAddVos);
// 批量去新增,并拿到分类id,回填商品
// 维护该商品专属分类
final String s = productCategoryService.batchSaveCategoryAndAttribute(productCategoryVo);
// 维护该店铺的专属分类
// productCategoryService.batchSaveCategoryOfShop(productCategoryVo);
product.setAttrId(s);
} else {
// 旧商品,更新批发价和零售价
productIdList.add(productId);
@ -905,7 +941,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
stockQueryWrapper.eq("shop_id", shopId);
final List<Stock> productStockList = list(stockQueryWrapper);
if (purchaseDetail.getPurchasePrice() == null) {
if (purchaseDetail.getPurchasePrice() == null && user.getType().equals(UserConstant.USER_TYPE_NORMAL)) {
// 未维护采购价,设置订单状态为待入库,这里是循环的,前端要控制有就全部都要有,没有就全部没有。
// 设置为未入库,商品不计算平均采购价
purchase.setInStorageStatus(StockConstant.IN_STORAGE_STATUS[0]);
@ -916,7 +952,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
product.setInStorageStatus(StockConstant.IN_STORAGE_STATUS[1]);
if (!productStockList.isEmpty()) {
// 有库存
final BigDecimal newPurchasePrice = purchaseDetail.getPurchasePrice();
final BigDecimal newPurchasePrice = purchaseDetail.getPurchasePrice() == null ? BigDecimal.ZERO : purchaseDetail.getPurchasePrice();
int newProductCount = purchaseDetail.getProductCount();
int oldProductCount = 0;
final BigDecimal oldPurchasePrice = product.getPurchasePrice();
@ -973,6 +1009,65 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
// 更新库存数
final String categoryId = purchaseDetail.getCategoryId();
final String attrId = purchaseDetail.getAttrId();
for (StockLog stockLog : stockLogList) {
final String attributeList = stockLog.getAttributeList();
final StringBuilder newAttributeList = new StringBuilder();
newAttributeList.append("{");
StringBuilder colorStr = new StringBuilder("\"颜色\":");
StringBuilder sizeStr = new StringBuilder("\"尺码\":");
// Ai入库只能识别颜色和尺码,所以这里可以直接写死
final JSONObject jsonObject = JSON.parseObject(attributeList);
// 通过 keySet() 方法获取所有 key 值并遍历
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
// 根据 key 值获取相应的 value
String value = (String) entry.getValue();
// 对value 进行解析
final String key = entry.getKey();
// 20240330 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
// 根据规格id规格是颜色、还是尺码。
if ("颜色".equals(key)) {
if (!value.contains("色")) {
value += '色';
}
colorStr.append('"' +value+ '"');
} else if ("尺码".equals(key)) {
final String valueUpperCase = value.toUpperCase();
if (value.contains("码")) {
value = valueUpperCase;
} else {
value = valueUpperCase + '码';
}
sizeStr.append('"' +value+ '"');
} else {
// 暂不支持其他规格
}
if (stringListMap.containsKey(attrId)) {
final Map<String, List<String>> stringListMap1 = stringListMap.get(attrId);
if (stringListMap1.containsKey(key)) {
final List<String> stringList = stringListMap1.get(key);
if (!stringList.contains(value)) {
stringList.add(value);
}
} else {
final List<String> stringList = new ArrayList<>();
stringList.add(value);
stringListMap1.put(key, stringList);
}
} else {
final Map<String, List<String>> attributeListMap = new HashMap<>();
final List<String> stringList = new ArrayList<>();
stringList.add(value);
attributeListMap.put(key, stringList);
stringListMap.put(attrId, attributeListMap);
}
}
newAttributeList.append(colorStr);
newAttributeList.append(',');
newAttributeList.append(sizeStr);
newAttributeList.append('}');
stockLog.setAttributeList(newAttributeList.toString());
}
for (StockLog stockLog : stockLogList) {
// 根据商品id、店铺id、商品属性获取当前库存
int stockCount = 0;
@ -1022,7 +1117,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
stockLog.setOrderId(purchaseId);
stockLog.setDetailId(purchaseDetail.getId());
//入库
stockLog.setChangeType("0");
stockLog.setChangeType(StockLogConstant.CHANGE_TYPE[0]);
//入库前数量
stockLog.setStock(stockCount);
stockLog.setShopId(shopId);
@ -1030,55 +1125,6 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
stockLog.setPurchasePrice(purchaseDetail.getPurchasePrice());
stockLogAddList.add(stockLog);
}
for (StockLog stockLog : stockLogList) {
final String attributeList = stockLog.getAttributeList();
// Ai入库只能识别颜色和尺码,所以这里可以直接写死
final JSONObject jsonObject = JSON.parseObject(attributeList);
// 通过 keySet() 方法获取所有 key 值并遍历
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
// 根据 key 值获取相应的 value
String value = (String) entry.getValue();
// 对value 进行解析
final String key = entry.getKey();
// 20240330 只能新增颜色和尺码,颜色统一改为*色、尺码统一转大写,加‘码’;
// 根据规格id规格是颜色、还是尺码。
if ("颜色".equals(key)) {
if (!value.contains("色")) {
value += '色';
}
} else if ("尺码".equals(key)) {
final String valueUpperCase = value.toUpperCase();
if (value.contains("码")) {
value = valueUpperCase;
} else {
value = valueUpperCase + '码';
}
} else {
// 暂不支持其他规格
}
if (stringListMap.containsKey(attrId)) {
final Map<String, List<String>> stringListMap1 = stringListMap.get(attrId);
if (stringListMap1.containsKey(key)) {
final List<String> stringList = stringListMap1.get(key);
if (!stringList.contains(value)) {
stringList.add(value);
}
} else {
final List<String> stringList = new ArrayList<>();
stringList.add(value);
stringListMap1.put(key, stringList);
}
} else {
final Map<String, List<String>> attributeListMap = new HashMap<>();
final List<String> stringList = new ArrayList<>();
stringList.add(value);
attributeListMap.put(key, stringList);
stringListMap.put(attrId, attributeListMap);
}
}
}
}
// 去新增规格及属性信息
@ -1184,6 +1230,11 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
stockMapper.batchReduceStockByLog(stockLogList);
}
@Override
public void batchIncreaseStockByLog(List<StockLog> stockLogList) {
stockMapper.batchIncreaseStockByLog(stockLogList);
}
@Override
public List<Stock> getDefaultStockCount(List<String> productIdList) {
return stockMapper.getDefaultStockCount(productIdList);
@ -1200,4 +1251,84 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
public void deleteStockById(String id) {
stockMapper.deleteById(id);
}
@Override
public Result putOutPrice(PurchaseReturnVo purchaseReturnVo) {
// shopId从缓存中设置
final String shopId = securityUtil.getShopId();
// 获取当前登录人
final User user = securityUtil.getCurrUser();
// 1. 入库单主表信息
final PurchaseReturn putOutPurchase = purchaseReturnVo.getPurchase();
putOutPurchase.setCreateByName(user.getNickname());
putOutPurchase.setShopId(shopId);
putOutPurchase.setTotalAmount(putOutPurchase.getTotalAmount());
putOutPurchase.setShouldPay(putOutPurchase.getShouldPay());
putOutPurchase.setAlreadyPay(putOutPurchase.getAlreadyPay());
putOutPurchase.setNoPay(putOutPurchase.getNoPay());
putOutPurchase.setOtherPay(putOutPurchase.getOtherPay());
// 先保存一遍,因为后边用到了入库单的id
purchaseReturnService.saveOrUpdate(putOutPurchase);
// 需要新增的履历集合
final List<StockLog> stockLogAddList = new ArrayList<>();
// 2. 保存商品明细
final List<PurchaseReturnDetail> purchaseReturnDetails = purchaseReturnVo.getPurchaseDetails();
// 2. 扣减库存
// 需要修改的商品信息集合,商品中的平均采购价需要计算
final List<String> productIdList = new ArrayList<>();
for (PurchaseReturnDetail purchaseReturnDetail : purchaseReturnDetails) {
productIdList.add(purchaseReturnDetail.getProductId());
// 将退货id放进去
purchaseReturnDetail.setPurchaseId(putOutPurchase.getId());
// 封装一些其他参数
purchaseReturnDetail.setShopId(shopId);
}
purchaseReturnDetailService.saveBatch(purchaseReturnDetails);
// 根据商品id集合获取库存信息
final List<Stock> productStock = stockService.getProductStock(productIdList);
// 封装为商品id+商品属性为key ,Stock为value的map
final Map<String, Stock> stockMap = new HashMap<>();
for (Stock stock : productStock) {
stockMap.put(stock.getProductId() + stock.getAttributeList(), stock);
}
for (PurchaseReturnDetail purchaseReturnDetail : purchaseReturnDetails) {
final List<StockLog> changeStockLogs = purchaseReturnDetail.getStockLogList1();
for (StockLog changeStockLog : changeStockLogs) {
// 获取商品id+商品属性为key ,Stock为value的map
final String changeProductId = purchaseReturnDetail.getProductId();
final String changeAttributeList = changeStockLog.getAttributeList();
final String getKey = changeProductId + changeAttributeList;
if (stockMap.containsKey(getKey)) {
final Stock stock = stockMap.get(getKey);
//入库前数量
changeStockLog.setStock(stock.getStockCount());
} else {
// 不存在库存?应该没有吧
throw new HiverException("商品id为" + changeProductId + "的商品属性为" + changeAttributeList + "的商品库存不存在");
}
// 整理入库商品规格明细表数据
// 记录库存履历
changeStockLog.setProductId(purchaseReturnDetail.getProductId());
changeStockLog.setOrderId(putOutPurchase.getId());
changeStockLog.setDetailId(purchaseReturnDetail.getId());
//入库
changeStockLog.setChangeType(StockLogConstant.CHANGE_TYPE[1]);
changeStockLog.setShopId(shopId);
changeStockLog.setPurchasePrice(purchaseReturnDetail.getPurchasePrice());
stockLogAddList.add(changeStockLog);
}
}
// 批量更新库存数
stockService.batchReduceStockByLog(stockLogAddList);
// 库存记录
stockLogService.saveBatch(stockLogAddList);
// 3. 回退供应商欠款
// 异步更新供应商欠款信息机欠款记录
debtService.purchaseReturnToDebt(putOutPurchase, PurchaseReturnConstant.TYPE[0]);
return ResultUtil.success("退货成功!");
}
}

13
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/utils/AliOcrUtil.java

@ -837,13 +837,15 @@ public class AliOcrUtil {
final Message systemMsg =
Message.builder().role(Role.SYSTEM.getValue()).content("You are a helpful assistant.").build();
//questionMsg += "请帮我把所有内容封装为JSON,json格式为:[{ \"productSn\": \"货号\", \"attributeList\": [{\"color\":\"颜色\",\"size\":\"尺码\",\"productCount\": \"数量\"}] }]。以下是几点要求: 1.“货号”两个字和颜色中间的内容代表productSn,productSn可能包含\"新\"、\"退\"、\"旧\"、\"换\"、\"补\"。 2.\"SYYS色\"代表“所有颜色”,\"color\"字段返回“SYYS色”。 3.\"SYCM码\"代表“所有尺码”,\"size\"字段返回“SYCM码”。 4.只输出JSON数据即可,不用返回字段描述和解析过程。";
questionMsg += "你是一个服装行业库管专家,请帮我把所有内容封装为JSON,json格式为:[{ \"productSn\": \"货号\", \"attributeList\": [{\"color\":\"颜色\",\"size\":\"尺码\",\"productCount\": \"数量\"}] }],\n" +
questionMsg += "你是一个服装行业库管专家,请帮我把所有内容封装为JSON,json格式为:[{ \"productSn\": \"货号\", \"attributeList\": [{\"color\":\"颜色\",\"size\":\"尺码\",\"productCount\": \"数量\"}] }, \"wholesalePrice\":\"价格\"],\n" +
"1.productSn的返回值中去掉颜色,尺码等信息,\n" +
"2.如果没有识别到\"color\"的内容,则\"color\"赋值“均色”。如果没有识别到\"size\"的内容,则\"size\"赋值“均码”,返回1条JSON数据即可。\n" +
"3.如果指令内容中有\"SYYS色\"则\"color\"字段返回“SYYS色”即可,如果指令内容中有\"SYCM码\"则\"size\"字段返回“SYCM码”即可,没有则忽略。\n" +
"4.如果指令中有“各N件”,则每个尺码数量返回N。\n" +
"5.如果指令中尺码是?码到?码,请完整返回跨度内所有尺码JSON。\n" +
"6.只输出JSON数据即可,禁止返回除JSON数据外的任何内容!";
"6.如果没有识别到\"wholesalePrice\"的内容,则\"wholesalePrice\"赋值\"0\"。\n" +
"7.只输出JSON数据即可,禁止返回除JSON数据外的任何内容!" +
"8.返回的JSON数据不用换行,以最快的速度返回!";
final Message userMsg = Message.builder().role(Role.USER.getValue()).content(questionMsg).build();
msgManager.add(systemMsg);
msgManager.add(userMsg);
@ -888,14 +890,15 @@ public class AliOcrUtil {
final Message systemMsg =
Message.builder().role(Role.SYSTEM.getValue()).content("You are a helpful assistant.").build();
// questionMsg += "请帮我把所有内容封装为JSON,json格式为:[{ \"productSn\": \"货号\", \"productName\": \"名称\" , \"price\":\"单价\",\"attributeList\": [{\"color\":\"颜色\",\"size\":\"尺码\",\"productCount\": \"数量\"}] }]。以下是几点要求: 1.“货号”两个字和\"名称\"两个字中间的内容代表productSn的值,如果没有名称则“货号”两个字和颜色中间的内容代表productSn的值,productSn可能包含\"新\"、\"退\"、\"旧\"、\"换\"、\"补\"。2.\"SYYS色\"代表“所有颜色”,\"color\"字段返回“SYYS色”。 3.\"SYCM码\"代表“所有尺码”,\"size\"字段返回“SYCM码”。4.如果没有名称,productName字段返回\"\"。5.只输出JSON数据即可,不用返回字段描述和解析过程。";
questionMsg += "你是一个服装行业库管专家,请帮我把所有内容封装为JSON,json格式为:[{ \"productSn\": \"货号\", \"productName\": \"名称\" , \"attributeList\": [{\"color\":\"颜色\",\"size\":\"尺码\",\"productCount\": \"数量\"}], \"price\":\"单价\" , \"wholesalePrice\":\"批发价\" }]\n" +
questionMsg += "你是一个服装行业库管专家,请帮我把所有内容封装为JSON,json格式为:[{ \"productSn\": \"货号\", \"productName\": \"名称\" , \"attributeList\": [{\"color\":\"颜色\",\"size\":\"尺码\",\"productCount\": \"数量\"}], \"price\":\"单价\" , \"wholesalePrice\":\"批发价\" }]\n" +
"1.如果没有识别到\"price\"的内容,则\"price\"赋值\"0\"。如果没有识别到\"wholesalePrice\"的内容,则\"wholesalePrice\"赋值\"0\"。\n" +
"2.如果没有识别到\"productSn\"的内容,则\"productSn\"赋值\"\"。\n" +
"3.如果没有识别到\"productName\"的内容,则\"productName\"使用\"productSn\"的值填充。\n" +
"4.如果没有识别到\"color\"的内容,则\"color\"赋值“均色”,如果没有识别到\"size\"的内容,则\"size\"赋值“均码”,返回一条JSON数据即可。\n" +
"5.如果指令中有“各N件”,则每个尺码数量返回N。\n" +
"6.如果指令中尺码是?码到?码,请完整返回跨度内所有尺码JSON。\n" +
"6.只输出JSON数据即可,禁止返回除JSON数据外的任何内容!";
"6.如果指令中尺码是?码到?码,请结合服装鞋帽尺码规则完整返回跨度内所有尺码JSON。\n" +
"7.返回的JSON数据不用换行,以最快的速度返回!\n" +
"8.只输出JSON数据即可,禁止返回除JSON数据外的任何内容!";
final Message userMsg = Message.builder().role(Role.USER.getValue()).content(questionMsg).build();
msgManager.add(systemMsg);
msgManager.add(userMsg);

2
hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml

@ -403,7 +403,7 @@
and name like concat('%',#{queryParams.searchStr},'%')
</if>
<if test=" queryParams.notBuyDays != null and queryParams.notBuyDays != ''">
and t.not_buy_days > #{queryParams.notBuyDays}
and t.not_buy_days >= #{queryParams.notBuyDays}
</if>
<choose>
<when test="queryParams.sort!=null and queryParams.sort.trim() neq '' and queryParams.sort.trim() eq 'no_earn' ">

35
hiver-modules/hiver-mall/src/main/resources/mapper/DealingsRecordMapper.xml

@ -148,6 +148,7 @@
ts.balance_deduction_amount,
ts.real_amount,
ts.already_earn,
ts.remark,
trs.return_sale_total_amount
from
t_dealings_record tdr
@ -187,7 +188,8 @@
ts.should_pay,
ts.balance_deduction_amount,
ts.already_pay,
ts.create_time as purchase_time
ts.create_time as purchase_time,
ts.remark
from
t_dealings_record tdr
left join t_purchase ts on ts.id = tdr.sale_id and ts.shop_id = #{supplierBillQueryVo.shopId}
@ -200,7 +202,36 @@
<if test='supplierBillQueryVo.startDate !=null and supplierBillQueryVo.endDate !=null'>
and tdr.create_time BETWEEN #{supplierBillQueryVo.startDate} AND #{supplierBillQueryVo.endDate}
</if>
order by tdr.create_time asc
<!-- 追加退货记录-->
UNION
select
tdr.id,
tdr.sale_id as purchase_id,
tdr.create_by_name,
tdr.create_time,
tdr.last_debt_amount,
tdr.amount,
tdr.balance_due,
tdr.dealings_type,
tdr.del_flag,
ts.should_pay,
ts.balance_deduction_amount,
ts.already_pay,
ts.create_time as purchase_time,
ts.remark
from
t_dealings_record tdr
left join t_purchase_return ts on ts.id = tdr.sale_id and ts.shop_id = #{supplierBillQueryVo.shopId}
WHERE
<!--20240802 排除掉删除的交易记录-->
tdr.del_flag != 2
and tdr.dealings_type in ('9','10')
and tdr.dealings_user_id = #{supplierBillQueryVo.supplierId}
and tdr.shop_id = #{supplierBillQueryVo.shopId}
<if test='supplierBillQueryVo.startDate !=null and supplierBillQueryVo.endDate !=null'>
and tdr.create_time BETWEEN #{supplierBillQueryVo.startDate} AND #{supplierBillQueryVo.endDate}
</if>
order by create_time asc
</select>
<!-- cancelRecord-->

27
hiver-modules/hiver-mall/src/main/resources/mapper/ProductMapper.xml

@ -558,7 +558,8 @@
t.print_barcode,
t.tail_warn,
t.in_storage_status,
(CASE WHEN ss.stock_count is NULL THEN 0 ELSE ss.stock_count END) as stock_count
COALESCE(ss.stock_count, 0) AS stock_count,
COALESCE(sd.total_sold, 0) AS total_sold
FROM t_product t
LEFT JOIN (
SELECT
@ -573,6 +574,25 @@
) ss
ON ss.product_id = t.id
and ss.shop_id = t.shop_id
LEFT JOIN (
SELECT
sd.product_id,
SUM(sd.product_count) AS total_sold
FROM
t_sale_detail sd
INNER JOIN t_sale s ON sd.sale_id = s.id
WHERE
s.del_flag = '0'
AND s.status = '4'
<if test='queryParams.startDate !=null and queryParams.startDate.trim() neq "" and queryParams.endDate !=null and queryParams.endDate.trim() neq ""'>
and s.create_time BETWEEN #{queryParams.startDate} AND #{queryParams.endDate}
</if>
<if test='(queryParams.startDate == null or queryParams.startDate eq "" ) and (queryParams.endDate == null or queryParams.endDate eq "")'>
and s.create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
</if>
GROUP BY
product_id
) sd ON t.id = sd.product_id
<where>
<!--已上架的-->
AND t.del_flag != '2'
@ -616,8 +636,9 @@
</if>
</where>
ORDER BY
<if test='queryParams.sortField!=null and queryParams.sortField.trim() neq "" and queryParams.sortField !=null and queryParams.sort.trim() neq ""'>
#{queryParams.sortField} #{queryParams.sort} ,
<!--销量排序-->
<if test='queryParams.sortField!=null and queryParams.sortField.trim() neq "" and queryParams.sortField eq "totalSold"'>
sd.total_sold desc,
</if>
t.in_storage_status asc, t.del_flag desc,t.create_time desc, id
</select>

24
hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseDetailMapper.xml

@ -681,4 +681,28 @@
#{listItem}
</foreach>
</select>
<select id="queryPurchasingCount" resultType="java.lang.Integer">
SELECT
IFNULL( Sum( product_count ), 0 ) AS productCount
FROM
t_purchase_detail
WHERE
del_flag = '0'
and shop_id = #{supplierBillQueryVo.shopId}
<if test='supplierBillQueryVo.supplierId != null and supplierBillQueryVo.supplierId.trim() neq "" '>
and supplier_id = #{supplierBillQueryVo.supplierId,jdbcType=VARCHAR}
</if>
AND purchase_id IN (
SELECT
id
FROM
t_purchase tp
WHERE
tp.in_storage_status = '1'
<if test='supplierBillQueryVo.startDate !=null and supplierBillQueryVo.endDate !=null'>
AND tp.create_time BETWEEN #{supplierBillQueryVo.startDate} AND #{supplierBillQueryVo.endDate}
</if>
)
</select>
</mapper>

239
hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseReturnDetailMapper.xml

@ -0,0 +1,239 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.hiver.mall.purchasereturn.mapper.PurchaseReturnDetailMapper">
<resultMap id="BaseResultMap" type="cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="del_flag" jdbcType="INTEGER" property="delFlag" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="purchase_id" jdbcType="VARCHAR" property="purchaseId" />
<result column="product_id" jdbcType="VARCHAR" property="productId" />
<result column="product_name" jdbcType="VARCHAR" property="productName" />
<result column="unit" jdbcType="VARCHAR" property="unit" />
<result column="shop_id" jdbcType="VARCHAR" property="shopId" />
<result column="category_id" jdbcType="VARCHAR" property="categoryId" />
<result column="attribute_list" jdbcType="VARCHAR" property="attributeList" />
<result column="supplier_id" jdbcType="VARCHAR" property="supplierId" />
<result column="supplier_name" jdbcType="VARCHAR" property="supplierName" />
<result column="product_sn" jdbcType="VARCHAR" property="productSn" />
<result column="barcode" jdbcType="VARCHAR" property="barcode" />
<result column="price" jdbcType="DECIMAL" property="price" />
<result column="purchase_price" jdbcType="DECIMAL" property="purchasePrice" />
<result column="wholesale_price" jdbcType="DECIMAL" property="wholesalePrice" />
<result column="product_picture" jdbcType="VARCHAR" property="productPicture" />
<result column="product_video" jdbcType="VARCHAR" property="productVideo" />
<result column="product_intro" jdbcType="VARCHAR" property="productIntro" />
<result column="sales_week" jdbcType="TIMESTAMP" property="salesWeek" />
<result column="tail_warn" jdbcType="INTEGER" property="tailWarn" />
<result column="print_barcode" jdbcType="VARCHAR" property="printBarcode" />
<result column="product_count" jdbcType="INTEGER" property="productCount" />
<result column="ocr_picture_path" jdbcType="VARCHAR" property="ocrPicturePath" />
<result column="sort" jdbcType="INTEGER" property="sort" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, create_by, create_time, del_flag, update_by, update_time, purchase_id, product_id,
product_name, unit, shop_id, category_id, attribute_list, supplier_id,supplier_name, product_sn,
barcode, price, purchase_price, wholesale_price, product_picture, product_video,
product_intro, sales_week, tail_warn, print_barcode, product_count,ocr_picture_path,sort
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_purchase_return_detail
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from t_purchase_return_detail
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="cc.hiver.mall.purchasereturn.entity.PurchaseReturnDetail">
insert into t_purchase_return_detail (id, create_by, create_time,
del_flag, update_by, update_time,
purchase_id, product_id, product_name,
unit, shop_id, category_id,
attribute_list, supplier_id,supplier_name, product_sn,
barcode, price, purchase_price,
wholesale_price, product_picture, product_video,
product_intro, sales_week, tail_warn,
print_barcode, product_count,ocr_picture_path,sort)
values (#{id,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=INTEGER}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP},
#{purchaseId,jdbcType=VARCHAR}, #{productId,jdbcType=VARCHAR}, #{productName,jdbcType=VARCHAR},
#{unit,jdbcType=VARCHAR}, #{shopId,jdbcType=VARCHAR}, #{categoryId,jdbcType=VARCHAR},
#{attributeList,jdbcType=VARCHAR}, #{supplierId,jdbcType=VARCHAR},#{supplierName,jdbcType=VARCHAR}, #{productSn,jdbcType=VARCHAR},
#{barcode,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, #{purchasePrice,jdbcType=DECIMAL},
#{wholesalePrice,jdbcType=DECIMAL}, #{productPicture,jdbcType=VARCHAR}, #{productVideo,jdbcType=VARCHAR},
#{productIntro,jdbcType=VARCHAR}, #{salesWeek,jdbcType=TIMESTAMP}, #{tailWarn,jdbcType=INTEGER},
#{printBarcode,jdbcType=VARCHAR}, #{productCount,jdbcType=INTEGER},#{ocrPicturePath,jdbcType=VARCHAR},#{sort,jdbcType=INTEGER})
</insert>
<!--getByPurchaseId-->
<select id="getByPurchaseReturnId" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_purchase_return_detail
where purchase_id = #{id,jdbcType=VARCHAR}
order by create_time desc ,sort asc
</select>
<select id="getByPurchaseIdList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_purchase_return_detail
where del_flag ='0'
<if test='productId != null and productId.trim() neq "" '>
and product_id = #{productId,jdbcType=VARCHAR}
</if>
and purchase_id in
<foreach close=")" collection="purchaseIds" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</select>
<insert id="batchSavePurchaseList" parameterType="java.util.List">
insert into t_purchase_return_detail (id, create_by, create_time, del_flag, update_by, update_time, purchase_id, product_id,
product_name, unit, shop_id, category_id, attribute_list, supplier_id,supplier_name, product_sn,
barcode, price, purchase_price, wholesale_price, product_picture, product_video,
product_intro, sales_week, tail_warn, print_barcode, product_count, ocr_picture_path,sort) values
<foreach item="purchaseDetail" collection="purchaseDetails" index="index" separator=",">
(#{purchaseDetail.id}, #{purchaseDetail.createBy}, #{purchaseDetail.createTime}, #{purchaseDetail.delFlag},
#{purchaseDetail.updateBy}, #{purchaseDetail.updateTime}, #{purchaseDetail.purchaseId}, #{purchaseDetail.productId},
#{purchaseDetail.productName}, #{purchaseDetail.unit}, #{purchaseDetail.shopId}, #{purchaseDetail.categoryId},
#{purchaseDetail.attributeList}, #{purchaseDetail.supplierId}, #{purchaseDetail.supplierName}, #{purchaseDetail.productSn},
#{purchaseDetail.barcode}, #{purchaseDetail.price}, #{purchaseDetail.purchasePrice}, #{purchaseDetail.wholesalePrice},
#{purchaseDetail.productPicture}, #{purchaseDetail.productVideo}, #{purchaseDetail.productIntro},
#{purchaseDetail.salesWeek}, #{purchaseDetail.tailWarn}, #{purchaseDetail.printBarcode}, #{purchaseDetail.productCount},
#{purchaseDetail.ocrPicturePath},#{purchaseDetail.sort})
</foreach>
</insert>
<select id="selectByProductSn" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_purchase_return_detail
where purchase_id = #{purchaseId,jdbcType=VARCHAR}
and del_flag ='0'
and product_sn = #{productSn,jdbcType=VARCHAR} and product_name = #{productName,jdbcType=VARCHAR}
</select>
<update id="batchUpdatePurchaseList">
<foreach collection="purchaseDetails" item="item" separator=";" open="" close="">
update t_purchase_return_detail set product_count = #{item.productCount} WHERE id = #{item.id}
</foreach>
</update>
<update id="cancelByPurchaseReturnId" parameterType="java.lang.String">
update t_purchase_return_detail set del_flag = '1' where purchase_id = #{purchaseId,jdbcType=VARCHAR}
</update>
<!--根据入库单id真删除-->
<delete id="realDeleteByPurchaseId" parameterType="java.lang.String">
delete from t_purchase_return_detail
where purchase_id = #{purchaseId,jdbcType=VARCHAR}
</delete>
<select id="getPurchaseDetails" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_purchase_return_detail
where purchase_id in
<foreach close=")" collection="purchaseIdList" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</select>
<select id="getPurchaseDetailListByProductIds" resultMap="BaseResultMap">
select
tpd.id, tpd.create_by, tpd.create_time, tpd.del_flag, tpd.update_by, tpd.update_time, tpd.purchase_id, tpd.product_id,
tpd.product_name, tpd.unit, tpd.shop_id, tpd.category_id, tpd.attribute_list, tpd.supplier_id, tpd.supplier_name, tpd.product_sn,
tpd.barcode, tpd.price, tpd.purchase_price, tpd.wholesale_price, tpd.product_picture, tpd.product_video,
tpd.product_intro, tpd.sales_week, tpd.tail_warn, tpd.print_barcode, tpd.product_count,tpd.ocr_picture_path,tpd.sort
from t_purchase_return_detail tpd
left join t_purchase_return tp on tpd.purchase_id = tp.id
where
<!-- 已入库的-->
tp.in_storage_status = '1'
and tpd.purchase_id != #{id,jdbcType=VARCHAR}
and tpd.del_flag = '0'
and tpd.product_id in
<foreach close=")" collection="productIdList" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</select>
<select id="getPurchaseReturnDetails" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_purchase_return_detail
where purchase_id in
<foreach close=")" collection="purchaseIdList" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</select>
</mapper>

73
hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseReturnMapper.xml

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.hiver.mall.purchasereturn.mapper.PurchaseReturnMapper">
<resultMap id="BaseResultMap" type="cc.hiver.mall.purchasereturn.entity.PurchaseReturn">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="create_by_name" jdbcType="VARCHAR" property="createByName" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="del_flag" jdbcType="INTEGER" property="delFlag" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="supplier_id" jdbcType="VARCHAR" property="supplierId" />
<result column="supplier_name" jdbcType="VARCHAR" property="supplierName" />
<result column="shop_id" jdbcType="VARCHAR" property="shopId" />
<result column="total_amount" jdbcType="DECIMAL" property="totalAmount" />
<result column="should_pay" jdbcType="DECIMAL" property="shouldPay" />
<result column="already_pay" jdbcType="DECIMAL" property="alreadyPay" />
<result column="no_pay" jdbcType="DECIMAL" property="noPay" />
<result column="other_pay" jdbcType="DECIMAL" property="otherPay" />
<result column="in_storage_status" jdbcType="INTEGER" property="inStorageStatus" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="balance_deduction_amount" jdbcType="DECIMAL" property="balanceDeductionAmount" />
<result column="purchase_time" jdbcType="TIMESTAMP" property="purchaseTime" />
</resultMap>
<sql id="Base_Column_List">
id, create_by,create_by_name, create_time, del_flag, update_by, update_time, supplier_id,supplier_name, shop_id,
total_amount, should_pay, already_pay, no_pay,other_pay, in_storage_status,remark, balance_deduction_amount,
purchase_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_purchase_return
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from t_purchase_return
where id = #{id,jdbcType=VARCHAR}
</delete>
<select id="getPurchaseReturnList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_purchase_return t
<where>
and shop_id = #{queryParams.shopId}
<!--反馈内容-->
<if test='queryParams.startDate != null and queryParams.startDate.trim() neq ""'>
AND t.create_time between #{queryParams.startDate} and #{queryParams.endDate}
</if>
<!-- 模糊查询 -->
<if test='queryParams.queryStr != null and queryParams.queryStr neq "" '>
and (t.create_by_name like concat('%',#{queryParams.queryStr,jdbcType=VARCHAR},'%')
or t.supplier_name like concat('%',#{queryParams.queryStr,jdbcType=VARCHAR},'%')
)
</if>
</where>
ORDER BY
t.create_time desc
</select>
<!--撤销入库退货-->
<update id="cancelPurchaseReturnById">
update t_purchase_return
set del_flag = '1'
where id = #{id}
</update>
</mapper>

3
hiver-modules/hiver-mall/src/main/resources/mapper/ReturnSaleMapper.xml

@ -594,7 +594,8 @@
<select id="getTotalReturn" resultType="cc.hiver.mall.bill.vo.ArrearsVo">
select
sum(ts.total_amount) as total_return
sum(ts.total_amount) as total_return,
sum(ts.product_count) as return_product_count
from
t_return_sale ts
WHERE

55
hiver-modules/hiver-mall/src/main/resources/mapper/SaleDetailMapper.xml

@ -496,7 +496,8 @@
sale_id IN (
SELECT id FROM t_sale
WHERE
status != '2'
del_flag = '0'
and status != '2'
and status != '6'
and status != '7'
and shop_id = #{shopId}
@ -533,4 +534,56 @@
#{listItem}
</foreach>
</select>
<select id="selectDetailListByProductIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_sale_detail
where sale_id != #{sale.id}
and sale_id IN (
SELECT id FROM t_sale
WHERE del_flag = '0'
and user_id = #{sale.userId}
and status != '2'
and status != '6'
and status != '7'
and shop_id = #{sale.shopId}
)
and product_id in
<foreach close=")" collection="productIdList" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</select>
<select id="getTotalProfit" resultType="java.math.BigDecimal">
SELECT SUM(( sd.discount_amount - COALESCE(pd.purchase_price, 0) ) * sd.product_count
) AS profit
FROM
t_sale_detail sd
JOIN t_product pd ON sd.product_id = pd.id
WHERE
sd.shop_id = #{shopId}
<if test='startDate !=null and endDate !=null'>
and sd.create_time BETWEEN #{startDate} AND #{endDate}
</if>
AND sale_id IN (
SELECT
id
FROM
t_sale ts
WHERE
ts.del_flag = '0'
AND ts.id IN ( SELECT sale_id FROM t_sale_detail tsd WHERE tsd.shop_id = #{shopId}
<if test='startDate !=null and endDate !=null'>
AND tsd.create_time BETWEEN #{startDate} AND #{endDate}
</if>
)
AND ts.shop_id = #{shopId}
AND ts.STATUS NOT IN ( '2', '6', '7' )
<if test='startDate !=null and endDate !=null'>
AND ts.create_time BETWEEN #{startDate} AND #{endDate}
</if>
)
</select>
</mapper>

140
hiver-modules/hiver-mall/src/main/resources/mapper/SaleMapper.xml

@ -1087,7 +1087,8 @@ GROUP BY
<select id="getArrearsAndTotalSale" resultType="cc.hiver.mall.bill.vo.ArrearsVo">
select
sum(ts.no_earn) as arrears,
sum(ts.total_amount) as total_sale
sum(ts.total_amount) as total_sale,
sum(ts.product_count) as sale_product_count
from
t_sale ts
WHERE
@ -1116,7 +1117,8 @@ GROUP BY
from
t_sale ts
left join
(select tsd.sale_id, IFNULL(sum(tsd.purchase_price * tsd.product_count),0.00) as total_cost from t_sale_detail tsd where tsd.shop_id = #{salePageQuery.shopId} group by tsd.sale_id) cb
(select tsd.sale_id, IFNULL(sum(pd.purchase_price * tsd.product_count),0.00) as total_cost from t_sale_detail tsd JOIN t_product pd ON tsd.product_id = pd.id
where tsd.shop_id = #{salePageQuery.shopId} group by tsd.sale_id) cb
on ts.id = cb.sale_id
WHERE
ts.del_flag ='0'
@ -1129,7 +1131,7 @@ GROUP BY
)
<!--订单状态不为:2:已作废;分享页提交订单:6:待配货;挂单页提交订单:7:挂单-->
and ts.shop_id = #{salePageQuery.shopId}
and ts.status not in ( '2', '6', '7' )
and ts.status = '4'
<if test='salePageQuery.createByName !=null and salePageQuery.createByName !=""'>
and ts.create_by_name like concat('%',#{salePageQuery.createByName},'%')
</if>
@ -1192,7 +1194,8 @@ GROUP BY
FROM
t_sale ts
left join
(select tsd.sale_id, IFNULL(sum(tsd.purchase_price * tsd.product_count),0.00) as total_cost from t_sale_detail tsd where tsd.shop_id = #{salePageQuery.shopId} group by tsd.sale_id) cb
(select tsd.sale_id, IFNULL(sum(pd.purchase_price * tsd.product_count),0.00) as total_cost from t_sale_detail tsd JOIN t_product pd ON tsd.product_id = pd.id
where tsd.shop_id = #{salePageQuery.shopId} group by tsd.sale_id) cb
on ts.id = cb.sale_id
WHERE
ts.del_flag ='0'
@ -1234,4 +1237,133 @@ GROUP BY
and status = '4'
and create_time BETWEEN #{startTime} AND #{endTime}
</select>
<select id="totalAmountDetailByCustomer" resultType="cc.hiver.mall.pojo.vo.TotalAmountDetailByCustomerVo">
WITH ProfitSummary AS (
SELECT
m.user_id,
m.user_name,
sum(m.profit) AS profit
FROM
(
select
id as sale_id,
create_by,
create_by_name,
user_id,
user_name,
create_time as sale_date,
total_amount,
cb.total_cost,
total_amount -cb.total_cost as profit
from
t_sale ts
left join
(select tsd.sale_id, IFNULL(sum(pd.purchase_price * tsd.product_count),0.00) as total_cost from t_sale_detail tsd
JOIN t_product pd ON tsd.product_id = pd.id
where tsd.shop_id = #{salePageQuery.shopId} group by tsd.sale_id) cb
on ts.id = cb.sale_id
WHERE
ts.del_flag ='0'
<!--开单仅退货的销售单,不记入查询-->
and ts.id in (select sale_id from t_sale_detail tsd
where tsd.shop_id = #{salePageQuery.shopId}
<if test='salePageQuery.startDate !=null and salePageQuery.endDate !=null'>
and tsd.create_time BETWEEN #{salePageQuery.startDate} AND #{salePageQuery.endDate}
</if>
)
<!--订单状态不为:2:已作废;分享页提交订单:6:待配货;挂单页提交订单:7:挂单-->
and ts.shop_id = #{salePageQuery.shopId}
and ts.status not in ( '2', '6', '7' )
<if test='salePageQuery.createByName !=null and salePageQuery.createByName !=""'>
and ts.create_by_name like concat('%',#{salePageQuery.createByName},'%')
</if>
<!--按客户查询-->
<if test='salePageQuery.createBy !=null and salePageQuery.createBy !=""'>
and ts.create_by = #{salePageQuery.createBy}
</if>
<!--按商品查询-->
<if test='salePageQuery.productId !=null and salePageQuery.productId !=""'>
and ts.product_id = #{salePageQuery.productId}
</if>
<if test='salePageQuery.userName !=null and salePageQuery.userName !=""'>
and ts.user_name like concat('%',#{salePageQuery.userName},'%')
</if>
<if test='salePageQuery.startDate !=null and salePageQuery.endDate !=null'>
and ts.create_time BETWEEN #{salePageQuery.startDate} AND #{salePageQuery.endDate}
</if>
) m
group by m.user_id,m.user_name
)
SELECT
user_id,
user_name,
profit,
ROUND((profit / SUM(profit) OVER ()) * 100.0, 2) AS profit_proportion
FROM
ProfitSummary
ORDER BY
profit DESC
</select>
<select id="totalAmountDetailByProduct" resultType="cc.hiver.mall.pojo.vo.TotalAmountDetailByProductVo">
WITH ProductProfitSummary AS (
SELECT
sd.product_id,
sd.product_name,
pd.product_sn,
SUM((sd.discount_amount - COALESCE(pd.purchase_price, 0)) * sd.product_count) AS profit
FROM
t_sale_detail sd
JOIN t_product pd ON sd.product_id = pd.id
WHERE
sd.shop_id = #{salePageQuery.shopId}
<if test='salePageQuery.startDate !=null and salePageQuery.endDate !=null'>
and sd.create_time BETWEEN #{salePageQuery.startDate} AND #{salePageQuery.endDate}
</if>
and sale_id in(
select id from t_sale ts where
ts.del_flag ='0'
<!--开单仅退货的销售单,不记入查询-->
and ts.id in (select sale_id from t_sale_detail tsd
where tsd.shop_id = #{salePageQuery.shopId}
<if test='salePageQuery.startDate !=null and salePageQuery.endDate !=null'>
and tsd.create_time BETWEEN #{salePageQuery.startDate} AND #{salePageQuery.endDate}
</if>
)
<!--订单状态不为:2:已作废;分享页提交订单:6:待配货;挂单页提交订单:7:挂单-->
and ts.shop_id = #{salePageQuery.shopId}
and ts.status not in ( '2', '6', '7' )
<if test='salePageQuery.createByName !=null and salePageQuery.createByName !=""'>
and ts.create_by_name like concat('%',#{salePageQuery.createByName},'%')
</if>
<!--按客户查询-->
<if test='salePageQuery.createBy !=null and salePageQuery.createBy !=""'>
and ts.create_by = #{salePageQuery.createBy}
</if>
<!--按商品查询-->
<if test='salePageQuery.productId !=null and salePageQuery.productId !=""'>
and ts.product_id = #{salePageQuery.productId}
</if>
<if test='salePageQuery.userName !=null and salePageQuery.userName !=""'>
and ts.user_name like concat('%',#{salePageQuery.userName},'%')
</if>
<if test='salePageQuery.startDate !=null and salePageQuery.endDate !=null'>
and ts.create_time BETWEEN #{salePageQuery.startDate} AND #{salePageQuery.endDate}
</if>
)
GROUP BY
sd.product_id, sd.product_name
)
SELECT
product_id,
product_name,
product_sn,
profit,
ROUND((profit / SUM(profit) OVER ()) * 100.0, 2) AS profit_proportion
FROM
ProductProfitSummary
ORDER BY
profit DESC
</select>
</mapper>

6
hiver-modules/hiver-mall/src/main/resources/mapper/StockMapper.xml

@ -687,6 +687,12 @@
</foreach>
</update>
<update id="batchIncreaseStockByLog">
<foreach collection="stockLogList" item="item" separator=";" open="" close="">
update t_stock set stock_count = stock_count + #{item.productCount} WHERE product_id = #{item.productId} and attribute_list = #{item.attributeList}
</foreach>
</update>
<select id="getDefaultStockCount" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />

Loading…
Cancel
Save