| | |
| | | import com.ruoyi.common.constant.OrderNumConstants; |
| | | import com.ruoyi.common.utils.CodeGenerateUtils; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.system.domain.TOrderSaleGoods; |
| | | import com.ruoyi.system.domain.TOrderStock; |
| | | import com.ruoyi.system.domain.TOrderStockGoods; |
| | | import com.ruoyi.system.domain.*; |
| | | import com.ruoyi.system.dto.TOrderSaleDTO; |
| | | import com.ruoyi.system.dto.TOrderStockDTO; |
| | | import com.ruoyi.system.mapper.TDataGeneratorMapper; |
| | | import com.ruoyi.system.mapper.TOrderSaleGoodsMapper; |
| | | import com.ruoyi.system.mapper.TOrderSaleMapper; |
| | | import com.ruoyi.system.mapper.TOrderStockMapper; |
| | | import com.ruoyi.system.query.TDataGeneratorQuery; |
| | | import com.ruoyi.system.query.TDataGeneratorStockQuery; |
| | | import com.ruoyi.system.query.TOrderStockQuery; |
| | | import com.ruoyi.system.service.TOrderStockGoodsService; |
| | | import com.ruoyi.system.service.TOrderStockService; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.TDataGeneratorVO; |
| | | import com.ruoyi.system.vo.TOrderStockVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private TOrderStockGoodsService tOrderStockGoodsService; |
| | | @Autowired |
| | | private TOrderSaleMapper orderSaleMapper; |
| | | @Autowired |
| | | private TOrderSaleGoodsService orderSaleGoodsService; |
| | | @Autowired |
| | | private TStockDataSetService stockDataSetService; |
| | | @Autowired |
| | | private TDataGeneratorMapper dataGeneratorMapper; |
| | | @Override |
| | | public void add(TOrderStockDTO dto) { |
| | | // 进货单号 |
| | |
| | | List<TOrderStockGoods> orderStockGoods = dto.getOrderStockGoods(); |
| | | // BigDecimal sum = orderStockGoods.stream().map(TOrderStockGoods::getStockPrice).reduce(BigDecimal::add).get(); |
| | | // dto.setStockTotalPrice(sum); |
| | | if(dto.getIsGenerator().equals(2)){ |
| | | dto.setIsCover(0); |
| | | } |
| | | this.save(dto); |
| | | // 添加商品 |
| | | orderStockGoods.forEach(orderSaleGoods1 -> { |
| | |
| | | if(!CollectionUtils.isEmpty(orderIds)){ |
| | | List<TOrderStockGoods> orderStockGoods = tOrderStockGoodsService.list(Wrappers.lambdaQuery(TOrderStockGoods.class) |
| | | .in(TOrderStockGoods::getOrderId, orderIds)); |
| | | list.forEach(orderSale -> { |
| | | List<TOrderStockGoods> collect = orderStockGoods.stream().filter(orderSaleGoods -> orderSaleGoods.getOrderId().equals(orderSale.getId())).collect(Collectors.toList()); |
| | | list.forEach(orderStockVO -> { |
| | | List<TOrderStockGoods> collect = orderStockGoods.stream().filter(orderSaleGoods -> orderSaleGoods.getOrderId().equals(orderStockVO.getId())).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(collect)){ |
| | | orderSale.setOrderStockGoods(collect); |
| | | orderSale.setTotalPrice(collect.stream().map(TOrderStockGoods::getCostPrice).reduce(BigDecimal::add).get()); |
| | | orderStockVO.setOrderStockGoods(collect); |
| | | orderStockVO.setOrderStockCount(collect.size()); |
| | | orderStockVO.setTotalPrice(collect.stream().map(TOrderStockGoods::getCostPrice).reduce(BigDecimal::add).get()); |
| | | } |
| | | }); |
| | | } |
| | |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public void editGenerator(TOrderStockDTO dto) { |
| | | TDataGenerator dataGenerator = dataGeneratorMapper.selectById(dto.getGeneratorId()); |
| | | // 查询生成数据的配置 |
| | | List<TStockDataSet> list = stockDataSetService.list(Wrappers.lambdaQuery(TStockDataSet.class) |
| | | .eq(TStockDataSet::getGeneratorId, dto.getGeneratorId())); |
| | | list = list.stream().sorted(Comparator.comparing(TStockDataSet::getStockDate)).collect(Collectors.toList()); |
| | | String startTime = null; |
| | | String endTime = null; |
| | | Iterator<TStockDataSet> iterator = list.iterator(); |
| | | while (iterator.hasNext()){ |
| | | TStockDataSet next = iterator.next(); |
| | | if(next.getStockDate().compareTo(dto.getStockTime()) == 0){ |
| | | startTime = DateUtils.localDateToString(next.getStockDate()); |
| | | } |
| | | if(Objects.nonNull(startTime)){ |
| | | endTime = DateUtils.localDateToString(next.getStockDate()); |
| | | } |
| | | if(Objects.nonNull(endTime)){ |
| | | break; |
| | | } |
| | | } |
| | | if(Objects.isNull(endTime)){ |
| | | endTime = DateUtils.localDateToString(dataGenerator.getEndTime()); |
| | | } |
| | | // 查询该数据生成的销售单的数据 |
| | | List<TOrderSale> orderSales = orderSaleMapper.selectList(Wrappers.lambdaQuery(TOrderSale.class) |
| | | .eq(TOrderSale::getGeneratorId, dto.getGeneratorId()) |
| | | .between(TOrderSale::getOrderTime, startTime + " 00:00:00", endTime + " 23:59:59")); |
| | | List<Long> saleOrderIds = orderSales.stream().map(TOrderSale::getId).collect(Collectors.toList()); |
| | | List<TOrderStockGoods> orderStockGoods = dto.getOrderStockGoods(); |
| | | if(!CollectionUtils.isEmpty(saleOrderIds)){ |
| | | List<TOrderSaleGoods> orderSaleGoods = orderSaleGoodsService.list(Wrappers.lambdaQuery(TOrderSaleGoods.class) |
| | | .in(TOrderSaleGoods::getOrderId, saleOrderIds)); |
| | | for (TOrderStockGoods orderStockGood : orderStockGoods) { |
| | | orderSaleGoods.stream().filter(e->e.getGoodsName().equals(orderStockGood.getGoodsName())).forEach(e->e.setGoodsCostPrice(orderStockGood.getThisCostPrice())); |
| | | } |
| | | orderSaleGoodsService.updateBatchById(orderSaleGoods); |
| | | } |
| | | this.updateById(dto); |
| | | // 刪除原有商品 |
| | | tOrderStockGoodsService.remove(Wrappers.lambdaQuery(TOrderStockGoods.class) |
| | | .eq(TOrderStockGoods::getOrderId,dto.getId())); |
| | | // 添加商品 |
| | | orderStockGoods.forEach(orderSaleGoods1 -> { |
| | | orderSaleGoods1.setId(null); |
| | | orderSaleGoods1.setOrderId(dto.getId()); |
| | | }); |
| | | tOrderStockGoodsService.saveBatch(orderStockGoods); |
| | | } |
| | | } |