ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysGoodsController.java
@@ -1,8 +1,27 @@ package com.ruoyi.web.controller.api; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.BaseModel; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.dto.TErpGoodsUpdateStatusDto; import com.ruoyi.system.model.*; import com.ruoyi.system.query.TSysGoodsExchangeQuery; import com.ruoyi.system.query.TSysGoodsQuery; import com.ruoyi.system.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; import java.util.stream.Collectors; /** * <p> @@ -14,7 +33,184 @@ */ @RestController @RequestMapping("/t-sys-goods") @Api(tags = "积分商品管理") public class TSysGoodsController { private final TSysGoodsService sysGoodsService; private final TokenService tokenService; private final TCrmSupplierService crmSupplierService; private final TSysGoodsExchangeService sysGoodsExchangeService; @Autowired public TSysGoodsController(TokenService tokenService, TSysGoodsService sysGoodsService, TCrmSupplierService crmSupplierService, TSysGoodsExchangeService sysGoodsExchangeService) { this.sysGoodsService = sysGoodsService; this.tokenService = tokenService; this.crmSupplierService = crmSupplierService; this.sysGoodsExchangeService = sysGoodsExchangeService; } /** * 获取积分商品列表 */ @ApiOperation(value = "获取积分商品列表") @PostMapping(value = "/pageList") public R<PageInfo<TSysGoods>> pageList(@RequestBody TSysGoodsQuery query) { SysUser user = tokenService.getLoginUser().getUser(); Integer roleType = user.getRoleType(); PageInfo<TSysGoods> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); if (roleType == 4) { // 供应商 TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) .eq(TCrmSupplier::getUserId, user.getUserId()) .last("LIMIT 1")); LambdaQueryWrapper<TSysGoods> tSysGoodsLambdaQueryWrapper = new LambdaQueryWrapper<>(); tSysGoodsLambdaQueryWrapper.eq(TSysGoods::getSupplierId, crmSupplier.getId()); if (query.getGoodsName() != null && !query.getGoodsName().isEmpty()) { tSysGoodsLambdaQueryWrapper.like(TSysGoods::getGoodsName, query.getGoodsName()); } if (query.getStatus() != null) { tSysGoodsLambdaQueryWrapper.eq(TSysGoods::getStatus, query.getStatus()); } tSysGoodsLambdaQueryWrapper.orderByDesc(BaseModel::getCreateTime); Page<TSysGoods> page = sysGoodsService.page(pageInfo, tSysGoodsLambdaQueryWrapper); List<TSysGoods> records = page.getRecords(); if (!records.isEmpty()) { List<TSysGoodsExchange> list = sysGoodsExchangeService.list(new LambdaQueryWrapper<TSysGoodsExchange>().in(TSysGoodsExchange::getGoodsId, records.stream().map(TSysGoods::getId).collect(Collectors.toList()))); records.forEach(item -> { item.setExchangeQuantity(list.stream().filter(item1 -> item1.getGoodsId().equals(item.getId())).mapToInt(TSysGoodsExchange::getGoodsCount).sum()); item.setSurplusQuantity(item.getGoodsTotal() - item.getExchangeQuantity()); }); } pageInfo.setRecords(records); return R.ok(pageInfo); } return R.ok(pageInfo); } @ApiOperation(value = "添加积分商品") @PostMapping(value = "/add") public R<String> add(@RequestBody TSysGoods goods) { SysUser user = tokenService.getLoginUser().getUser(); Integer roleType = user.getRoleType(); if (roleType == 4) { // 供应商 TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) .eq(TCrmSupplier::getUserId, user.getUserId()) .last("LIMIT 1")); goods.setSupplierId(crmSupplier.getId()); sysGoodsService.save(goods); return R.ok(goods.getId()); } return R.ok(); } @ApiOperation(value = "编辑积分商品") @PostMapping(value = "/update") public R<String> update(@RequestBody TSysGoods goods) { SysUser user = tokenService.getLoginUser().getUser(); Integer roleType = user.getRoleType(); List<TSysGoodsExchange> list = sysGoodsExchangeService.list(new LambdaQueryWrapper<TSysGoodsExchange>().eq(TSysGoodsExchange::getGoodsId, goods.getId())); int sum = list.stream().mapToInt(TSysGoodsExchange::getGoodsCount).sum(); if(goods.getGoodsTotal()< sum){ return R.fail("商品总数不能小于已兑换数量"); } if (roleType == 4) { // 供应商 TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) .eq(TCrmSupplier::getUserId, user.getUserId()) .last("LIMIT 1")); goods.setSupplierId(crmSupplier.getId()); sysGoodsService.updateById(goods); return R.ok(goods.getId()); } return R.ok(); } @ApiOperation(value = "删除积分商品") @DeleteMapping(value = "/delete/{id}") public R<String> delete(@PathVariable String id) { SysUser user = tokenService.getLoginUser().getUser(); Integer roleType = user.getRoleType(); if (roleType == 4) { // 供应商 TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) .eq(TCrmSupplier::getUserId, user.getUserId()) .last("LIMIT 1")); TSysGoods goods = sysGoodsService.getById(id); if(goods.getSupplierId().equals(crmSupplier.getId())){ sysGoodsService.removeById(id); }else { return R.fail("没有权限"); } } return R.ok(); } @ApiOperation(value = "积分商品 上下架") @PostMapping(value = "/updateStatus") public R<String> updateStatus(@RequestBody @Valid TErpGoodsUpdateStatusDto dto) { SysUser user = tokenService.getLoginUser().getUser(); Integer roleType = user.getRoleType(); if (roleType == 4) { // 供应商 TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class) .eq(TCrmSupplier::getUserId, user.getUserId()) .last("LIMIT 1")); TSysGoods goods = sysGoodsService.getById(dto.getId()); if(goods.getSupplierId().equals(crmSupplier.getId())){ goods.setStatus(dto.getState()); sysGoodsService.updateById(goods); }else { return R.fail("没有权限"); } } return R.ok(); } // 获取兑换记录 @ApiOperation(value = "获取兑换记录") @PostMapping(value = "/getExchangeRecord") public R<PageInfo<TSysGoodsExchange>> getExchangeRecord(@RequestBody @Valid TSysGoodsExchangeQuery query) { PageInfo<TSysGoodsExchange> page = new PageInfo<>(query.getPageNum(), query.getPageSize()); LambdaQueryWrapper<TSysGoodsExchange> wrapper = new LambdaQueryWrapper<TSysGoodsExchange>().eq(TSysGoodsExchange::getGoodsId, query.getId()); if(query.getClinicName()!=null && !query.getClinicName().isEmpty()){ wrapper.like(TSysGoodsExchange::getClinicName, query.getClinicName()); } if(query.getTime()!=null && !query.getTime().isEmpty()){ wrapper.between(TSysGoodsExchange::getCreateTime, query.getTime().split(" - ")[0]+ " 00:00:00", query.getTime().split(" - ")[1]+ " 23:59:59"); } if(query.getStatus()!=null){ wrapper.eq(TSysGoodsExchange::getStatus, query.getStatus()); } wrapper.orderByDesc(BaseModel::getCreateTime); PageInfo<TSysGoodsExchange> page1 = sysGoodsExchangeService.page(page, wrapper); return R.ok(page1); } // 获取兑换记录 @ApiOperation(value = "发货") @PostMapping(value = "/sendGoods") public R<?> sendGoods(@RequestBody @Valid TSysGoodsExchange exchange) { TSysGoodsExchange exchange1 = sysGoodsExchangeService.getById(exchange.getId()); if(exchange1.getStatus()==2){ return R.fail("该订单已发货"); } exchange1.setStatus(2); exchange1.setLogisticsNumber(exchange1.getLogisticsNumber()); sysGoodsExchangeService.updateById(exchange1); return R.ok(); } } ruoyi-system/src/main/java/com/ruoyi/system/dto/AddProcurementDto.java
@@ -26,6 +26,7 @@ private String supplierId; private BigDecimal goodsSalesAmount; @ApiModelProperty("状态 1草稿") ruoyi-system/src/main/java/com/ruoyi/system/model/TErpSupplierOutbound.java
@@ -55,5 +55,9 @@ private String outboundReason; @ApiModelProperty(value = "商品id") @TableField("goods_id") private String goodsId; } ruoyi-system/src/main/java/com/ruoyi/system/model/TSysGoods.java
@@ -62,4 +62,19 @@ @TableField("status") private Integer status; @ApiModelProperty(value = "供应商id") @TableField("supplier_id") private String supplierId; // 剩余数量 @ApiModelProperty(value = "剩余数量") @TableField(exist = false) private Integer surplusQuantity; // 已兑换数量 @ApiModelProperty(value = "已兑换数量") @TableField(exist = false) private Integer exchangeQuantity; } ruoyi-system/src/main/java/com/ruoyi/system/model/TSysGoodsExchange.java
@@ -59,4 +59,8 @@ @TableField("status") private Integer status; @ApiModelProperty(value = "物流单号") @TableField("logistics_number") private String logisticsNumber; } ruoyi-system/src/main/java/com/ruoyi/system/query/TSysGoodsExchangeQuery.java
New file @@ -0,0 +1,27 @@ package com.ruoyi.system.query; import com.ruoyi.common.core.domain.BasePage; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotBlank; @Data @ApiModel("兑换记录") public class TSysGoodsExchangeQuery extends BasePage { @ApiModelProperty("商品id") @NotBlank(message = "商品id不能为空") private String id; @ApiModelProperty("诊所名称") private String clinicName; @ApiModelProperty("兑换时间 2022-02-02 - 2023-02-02") private String time; @ApiModelProperty("状态 1=未发货 2=已发货") private Integer status; } ruoyi-system/src/main/java/com/ruoyi/system/query/TSysGoodsQuery.java
New file @@ -0,0 +1,21 @@ package com.ruoyi.system.query; import com.baomidou.mybatisplus.annotation.TableField; import com.ruoyi.common.core.domain.BasePage; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @ApiModel("积分商品PageQuery") public class TSysGoodsQuery extends BasePage { @ApiModelProperty(value = "商品名称") private String goodsName; @ApiModelProperty(value = "状态 1=上架 2=下架") private Integer status; } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java
@@ -117,13 +117,13 @@ if(tErpSupplierInventoryGoods1!=null){ // 盘盈 查入库 if(tErpSupplierInventoryGoods1.getInventoryType()==1){ TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId()); TErpClinicWarehousingBatch tErpSupplierWarehousing = erpClinicWarehousingBatchMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingBatchId()); // List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId())); // int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum(); String goodsId = tErpSupplierInventoryGoods1.getGoodsId(); TErpGoods goods = erpGoodsMapper.selectById(goodsId); // TErpGoods goods = erpGoodsMapper.selectById(goodsId); int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount(); BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count)); BigDecimal multiply = tErpSupplierWarehousing.getSalesAmount().multiply(new BigDecimal(count)); add = add.add(multiply); }else { // 盘亏 查出库 @@ -131,11 +131,11 @@ List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getOutboundId, tErpSupplierOutbound.getId())); for (TErpClinicOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) { TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(tErpSupplierOutboundGood.getWarehousingId()); String goodsId = tErpSupplierInventoryGoods1.getGoodsId(); TErpGoods goods = erpGoodsMapper.selectById(goodsId); TErpClinicWarehousingBatch tErpSupplierWarehousing = erpClinicWarehousingBatchMapper.selectById(tErpSupplierOutboundGood.getWarehousingBatchId()); // String goodsId = tErpSupplierInventoryGoods1.getGoodsId(); // TErpGoods goods = erpGoodsMapper.selectById(goodsId); int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount(); BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count)); BigDecimal multiply = tErpSupplierWarehousing.getSalesAmount().multiply(new BigDecimal(count)); add = add.add(multiply); } // int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum(); @@ -226,11 +226,11 @@ inventoryDetailVo.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber()); List<TErpClinicWarehousingBatch> tErpSupplierWarehousingBatches = erpClinicWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpClinicWarehousingBatch>().eq(TErpClinicWarehousingBatch::getBatchNumber, tErpSupplierWarehousingBatch.getBatchNumber())); List<TErpClinicWarehousingBatch> tErpSupplierWarehousingBatches = erpClinicWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpClinicWarehousingBatch>().eq(TErpClinicWarehousingBatch::getId, outboundGoods.getWarehousingBatchId())); int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpClinicWarehousingBatch::getWarehousingNumber).sum(); List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpClinicWarehousingBatch::getId).collect(Collectors.toList()); if(!collect.isEmpty()){ List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods1 = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getWarehousingBatchId, collect)); List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods1 = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().in(TErpClinicOutboundGoods::getWarehousingBatchId, collect)); int sum1 = tErpSupplierOutboundGoods1.stream().mapToInt(TErpClinicOutboundGoods::getOutboundCount).sum(); sum = sum-sum1; } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java
@@ -554,6 +554,9 @@ } else { TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch1 = erpSupplierWarehousingBatchMapper.selectById(inventoryGoodsDto.getId()); String warehousingId1 = tErpSupplierWarehousingBatch1.getWarehousingId(); TErpSupplierWarehousing tErpSupplierWarehousing2 = erpSupplierWarehousingMapper.selectById(warehousingId1); TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound(); tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId()); @@ -561,7 +564,8 @@ tErpSupplierOutbound.setOutboundType(6); tErpSupplierOutbound.setOutboundNumber("G" + s); int count = inventoryGoodsDto.getNum() - inventoryGoodsDto.getInventoryCount(); tErpSupplierOutbound.setTotalMoney(erpGoods.getSalesAmount().multiply(new BigDecimal(count))); tErpSupplierOutbound.setTotalMoney(tErpSupplierWarehousing1.getUnitAmount().multiply(new BigDecimal(count))); tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing2.getGoodsId()); erpSupplierOutboundMapper.insert(tErpSupplierOutbound); ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
@@ -391,6 +391,9 @@ BigDecimal add = BigDecimal.ZERO; BigDecimal supplierCommissionPrice = BigDecimal.ZERO; for (AddProcurementDto dto : value) { TErpProcurementGoods tErpProcurementGoods = new TErpProcurementGoods(); tErpProcurementGoods.setProcurementId(tErpProcurement.getId()); @@ -410,6 +413,7 @@ tErpProcurementGoods.setSupplierId(supplierClinicId); tErpProcurementGoods.setRecvMerchantNo(supplier.getRecvMerchantNo()); tErpProcurementGoods.setSupplierMoney(dto.getSalesAmount().subtract(dto.getPlatformCommissionPrice())); supplierCommissionPrice = supplierCommissionPrice.add(tErpProcurementGoods.getSupplierMoney().multiply(BigDecimal.valueOf(dto.getPurchaseCount()))); if (tErpProcurementGoods.getSupplierMoney().doubleValue() < 0) { throw new RuntimeException("平台抽成不能大于售卖价格"); } @@ -422,6 +426,7 @@ if (tErpProcurement.getMoney().doubleValue() < 0) { throw new RuntimeException("金额设置错误,请联系平台管理员"); } tErpProcurement.setSupplierMoney(supplierCommissionPrice); this.save(tErpProcurement); tErpProcurementGoods1.forEach(e -> e.setProcurementId(tErpProcurement.getId())); erpProcurementGoodsService.saveBatch(tErpProcurementGoods1); ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
@@ -396,9 +396,9 @@ // List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId())); // int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum(); String goodsId = tErpSupplierWarehousing.getGoodsId(); TErpGoods goods = erpGoodsMapper.selectById(goodsId); // TErpGoods goods = erpGoodsMapper.selectById(goodsId); int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount(); BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count)); BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().multiply(new BigDecimal(count)); add = add.add(multiply); }else { // 盘亏 查出库 @@ -408,9 +408,9 @@ for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) { TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierOutboundGood.getWarehousingId()); String goodsId = tErpSupplierWarehousing.getGoodsId(); TErpGoods goods = erpGoodsMapper.selectById(goodsId); // TErpGoods goods = erpGoodsMapper.selectById(goodsId); int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount(); BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count)); BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().multiply(new BigDecimal(count)); add = add.add(multiply); } // int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum(); @@ -483,11 +483,11 @@ inventoryDetailVo.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber()); List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getBatchNumber, tErpSupplierWarehousingBatch.getBatchNumber())); List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getId, tErpSupplierOutboundGoods2.getWarehousingBatchId())); int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum(); List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpSupplierWarehousingBatch::getId).collect(Collectors.toList()); if(!collect.isEmpty()){ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods1 = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getWarehousingBatchId, collect)); List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods1 = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().in(TErpSupplierOutboundGoods::getWarehousingBatchId, collect)); int sum1 = tErpSupplierOutboundGoods1.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum(); sum = sum-sum1; } ruoyi-system/src/main/java/com/ruoyi/system/vo/TErpGoodsInventoryVO.java
@@ -51,9 +51,13 @@ private String packingUnitId; @ApiModelProperty(value = "商品单价") @ApiModelProperty(value = "商品售价") private BigDecimal salesAmount; @ApiModelProperty(value = "商品单价") private BigDecimal unitAmount; @ApiModelProperty(value = "失效日期") private LocalDateTime expiryDate; ruoyi-system/src/main/resources/mapper/system/TErpGoodsMapper.xml
@@ -178,7 +178,8 @@ t1.warehousing_number, t2.create_time, t1.warehousing_number - coalesce(sum(t5.outbound_count),0) as num, t1.unit_amount as sales_amount, t1.unit_amount as unitAmount, t1.sales_amount as salesAmount, t1.expiry_date from t_erp_clinic_warehousing_batch t1 LEFT JOIN t_erp_clinic_warehousing t2 on t1.warehousing_id = t2.id