diff --git a/wms/src/main/java/com/cyl/wms/controller/ShipmentOrderController.java b/wms/src/main/java/com/cyl/wms/controller/ShipmentOrderController.java index 413a0ec..6939e4e 100644 --- a/wms/src/main/java/com/cyl/wms/controller/ShipmentOrderController.java +++ b/wms/src/main/java/com/cyl/wms/controller/ShipmentOrderController.java @@ -2,22 +2,29 @@ package com.cyl.wms.controller; import com.cyl.wms.convert.ShipmentOrderConvert; import com.cyl.wms.domain.ShipmentOrder; +import com.cyl.wms.pojo.query.CustomerShipmentStatQuery; import com.cyl.wms.pojo.query.ShipmentOrderQuery; +import com.cyl.wms.pojo.vo.CustomerShipmentStatVO; import com.cyl.wms.pojo.vo.ShipmentOrderVO; import com.cyl.wms.pojo.vo.form.ShipmentOrderFrom; import com.cyl.wms.service.ShipmentOrderService; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; + +import java.util.List; + /** * 出库单Controller * @@ -100,4 +107,13 @@ public class ShipmentOrderController extends BaseController { service.allocatedInventory(id,type); return ResponseEntity.ok().build(); } + + @ApiOperation("客户物料类型维度统计出库金额") + @PostMapping("/statByCustomerAndType") + public ResponseEntity> statByCustomerAndType(@RequestBody CustomerShipmentStatQuery query) { + if(StringUtils.isBlank(query.getBeginTime()) || StringUtils.isBlank(query.getEndTime())){ + throw new RuntimeException("开始或结束时间不可为空"); + } + return ResponseEntity.ok(service.statByCustomerAndType(query)); + } } diff --git a/wms/src/main/java/com/cyl/wms/mapper/ShipmentOrderDetailMapper.java b/wms/src/main/java/com/cyl/wms/mapper/ShipmentOrderDetailMapper.java index 4d82678..9963251 100644 --- a/wms/src/main/java/com/cyl/wms/mapper/ShipmentOrderDetailMapper.java +++ b/wms/src/main/java/com/cyl/wms/mapper/ShipmentOrderDetailMapper.java @@ -2,6 +2,9 @@ package com.cyl.wms.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.cyl.wms.domain.ShipmentOrderDetail; +import com.cyl.wms.pojo.query.CustomerShipmentStatQuery; +import com.cyl.wms.pojo.vo.CustomerShipmentStatVO; +import com.cyl.wms.pojo.vo.ShipmentOrderDetailVO; import com.cyl.wms.pojo.vo.ShipmentOrderVO; import org.apache.ibatis.annotations.Param; @@ -36,4 +39,6 @@ public interface ShipmentOrderDetailMapper extends BaseMapper selectListGroupByItemId(@Param("id") long ids); List selectDetailByWaveNo(String waveNo); + + List statByCustomerAndType(@Param("query") CustomerShipmentStatQuery query); } diff --git a/wms/src/main/java/com/cyl/wms/pojo/query/CustomerShipmentStatQuery.java b/wms/src/main/java/com/cyl/wms/pojo/query/CustomerShipmentStatQuery.java new file mode 100644 index 0000000..17201a9 --- /dev/null +++ b/wms/src/main/java/com/cyl/wms/pojo/query/CustomerShipmentStatQuery.java @@ -0,0 +1,11 @@ +package com.cyl.wms.pojo.query; + +import lombok.Data; + +@Data +public class CustomerShipmentStatQuery { + private String beginTime; + private String endTime; + private Long customerId; + private Long itemTypeId; +} diff --git a/wms/src/main/java/com/cyl/wms/pojo/vo/AmountStatByItemTypeVO.java b/wms/src/main/java/com/cyl/wms/pojo/vo/AmountStatByItemTypeVO.java new file mode 100644 index 0000000..bc56011 --- /dev/null +++ b/wms/src/main/java/com/cyl/wms/pojo/vo/AmountStatByItemTypeVO.java @@ -0,0 +1,11 @@ +package com.cyl.wms.pojo.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +@Data +public class AmountStatByItemTypeVO { + private Long itemTypeId; + private BigDecimal amount; +} diff --git a/wms/src/main/java/com/cyl/wms/pojo/vo/CustomerShipmentStatVO.java b/wms/src/main/java/com/cyl/wms/pojo/vo/CustomerShipmentStatVO.java new file mode 100644 index 0000000..1a58801 --- /dev/null +++ b/wms/src/main/java/com/cyl/wms/pojo/vo/CustomerShipmentStatVO.java @@ -0,0 +1,15 @@ +package com.cyl.wms.pojo.vo; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +@Data +public class CustomerShipmentStatVO { + private Long customerId; + private String customerName; + private List data; + private BigDecimal total; + //查询出customerId customerName amount type +} diff --git a/wms/src/main/java/com/cyl/wms/pojo/vo/ShipmentOrderDetailVO.java b/wms/src/main/java/com/cyl/wms/pojo/vo/ShipmentOrderDetailVO.java index e7fd0b5..6b341d3 100644 --- a/wms/src/main/java/com/cyl/wms/pojo/vo/ShipmentOrderDetailVO.java +++ b/wms/src/main/java/com/cyl/wms/pojo/vo/ShipmentOrderDetailVO.java @@ -101,4 +101,10 @@ public class ShipmentOrderDetailVO extends BaseAudit { private List place; private ItemVO item; + + private Long itemType; + + private String customerName; + + private Long customerId; } diff --git a/wms/src/main/java/com/cyl/wms/service/ShipmentOrderService.java b/wms/src/main/java/com/cyl/wms/service/ShipmentOrderService.java index 16645ef..72cd73d 100644 --- a/wms/src/main/java/com/cyl/wms/service/ShipmentOrderService.java +++ b/wms/src/main/java/com/cyl/wms/service/ShipmentOrderService.java @@ -8,16 +8,11 @@ import com.cyl.wms.convert.DeliveryConvert; import com.cyl.wms.convert.ShipmentOrderConvert; import com.cyl.wms.convert.ShipmentOrderDetailConvert; import com.cyl.wms.domain.*; +import com.cyl.wms.mapper.CustomerMapper; import com.cyl.wms.mapper.ShipmentOrderDetailMapper; import com.cyl.wms.mapper.ShipmentOrderMapper; -import com.cyl.wms.pojo.query.DeliveryQuery; -import com.cyl.wms.pojo.query.ItemQuery; -import com.cyl.wms.pojo.query.ShipmentOrderDetailQuery; -import com.cyl.wms.pojo.query.ShipmentOrderQuery; -import com.cyl.wms.pojo.vo.ItemVO; -import com.cyl.wms.pojo.vo.ReceiptOrderVO; -import com.cyl.wms.pojo.vo.ShipmentOrderDetailVO; -import com.cyl.wms.pojo.vo.ShipmentOrderVO; +import com.cyl.wms.pojo.query.*; +import com.cyl.wms.pojo.vo.*; import com.cyl.wms.pojo.vo.form.OrderWaveFrom; import com.cyl.wms.pojo.vo.form.ShipmentOrderFrom; import com.github.pagehelper.PageHelper; @@ -74,6 +69,8 @@ public class ShipmentOrderService { private CustomerTransactionService customerTransactionService; @Autowired private SysUserMapper userMapper; + @Autowired + private CustomerMapper customerMapper; /** * 查询出库单 @@ -488,4 +485,42 @@ public class ShipmentOrderService { qw.set(ShipmentOrder::getWaveNo, null); shipmentOrderMapper.update(null, qw); } + + public List statByCustomerAndType(CustomerShipmentStatQuery query) { + query.setBeginTime(query.getBeginTime() + " 00:00:00"); + query.setEndTime(query.getEndTime() + " 23:59:59"); + List shipmentOrderDetailVOS = shipmentOrderDetailMapper.statByCustomerAndType(query); + if (CollUtil.isEmpty(shipmentOrderDetailVOS)) { + return new ArrayList<>(); + } + //根据客户id和type分组统计 + // k:客户id k2:typeId v:统计后的金额 + Map> data = shipmentOrderDetailVOS.stream().collect(Collectors.groupingBy( + it -> it.getCustomerId() == null ? -1L : it.getCustomerId(), + Collectors.groupingBy( + ShipmentOrderDetailVO::getItemType, + Collectors.reducing( + BigDecimal.ZERO, + v -> v.getMoney() == null ? BigDecimal.ZERO : v.getMoney().multiply(new BigDecimal(String.valueOf(v.getRealQuantity()))), + BigDecimal::add))) + ); + Map customerNameMap = customerMapper.selectBatchIds(data.keySet()).stream().collect(Collectors.toMap(Customer::getId, Customer::getCustomerName)); + List result = new ArrayList<>(); + for (Map.Entry> entry : data.entrySet()) { + CustomerShipmentStatVO vo = new CustomerShipmentStatVO(); + vo.setCustomerId(entry.getKey()); + vo.setData(new ArrayList<>()); + vo.setCustomerName(customerNameMap.get(entry.getKey())); + vo.setTotal(BigDecimal.ZERO); + result.add(vo); + for (Map.Entry inner : entry.getValue().entrySet()) { + AmountStatByItemTypeVO innerVo = new AmountStatByItemTypeVO(); + innerVo.setItemTypeId(inner.getKey()); + innerVo.setAmount(inner.getValue()); + vo.getData().add(innerVo); + vo.setTotal(vo.getTotal().add(innerVo.getAmount())); + } + } + return result; + } } diff --git a/wms/src/main/resources/mapper/ShipmentOrderDetailMapper.xml b/wms/src/main/resources/mapper/ShipmentOrderDetailMapper.xml index 6320e12..d7d3d5e 100644 --- a/wms/src/main/resources/mapper/ShipmentOrderDetailMapper.xml +++ b/wms/src/main/resources/mapper/ShipmentOrderDetailMapper.xml @@ -142,4 +142,20 @@ where sod.del_flag = 0 and so.wave_no = #{waveNo}; +