|
@@ -0,0 +1,143 @@
|
|
|
+package com.sd.business.service.price.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.sd.business.entity.bom.dto.BomSelectDto;
|
|
|
+import com.sd.business.entity.bom.po.BomSpec;
|
|
|
+import com.sd.business.entity.bom.vo.BomVo;
|
|
|
+import com.sd.business.entity.price.dto.PriceSystemDto;
|
|
|
+import com.sd.business.entity.price.dto.PriceSystemSelectDto;
|
|
|
+import com.sd.business.entity.price.po.PriceSystem;
|
|
|
+import com.sd.business.entity.price.po.PriceSystemBom;
|
|
|
+import com.sd.business.entity.price.po.PriceSystemBomSpec;
|
|
|
+import com.sd.business.entity.price.vo.PriceSystemVo;
|
|
|
+import com.sd.business.mapper.price.PriceSystemMapper;
|
|
|
+import com.sd.business.service.bom.BomService;
|
|
|
+import com.sd.business.service.price.PriceSystemBomService;
|
|
|
+import com.sd.business.service.price.PriceSystemBomSpecService;
|
|
|
+import com.sd.business.service.price.PriceSystemService;
|
|
|
+import com.sd.framework.util.Assert;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 售价_售价体系 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-07-12
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PriceSystemServiceImpl extends ServiceImpl<PriceSystemMapper, PriceSystem> implements PriceSystemService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PriceSystemBomService priceSystemBomService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PriceSystemBomSpecService priceSystemBomSpecService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomService bomService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<PriceSystemVo> getPage(PriceSystemSelectDto dto) {
|
|
|
+ IWrapper<PriceSystem> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("ps", PriceSystem::getId);
|
|
|
+ wrapper.eq("ps", PriceSystem::getName, dto.getName());
|
|
|
+ Page<PriceSystemVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PriceSystemVo detail(Long id) {
|
|
|
+ PriceSystem PriceSystem = this.getById(id);
|
|
|
+ PriceSystemVo result = BeanUtil.toBean(PriceSystem, PriceSystemVo.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(PriceSystemDto priceSystemDto) {
|
|
|
+ this.save(priceSystemDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(PriceSystemDto priceSystemDto) {
|
|
|
+ this.updateById(priceSystemDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ priceSystemBomService.remove(q -> q.eq(PriceSystemBom::getPriceSystemId, id));
|
|
|
+ priceSystemBomSpecService.remove(q -> q.eq(PriceSystemBomSpec::getPriceSystemId, id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<BomVo> getBomPriceDetail(BomSelectDto dto) {
|
|
|
+ // 售价体系id
|
|
|
+ Long priceSystemId = dto.getPriceSystemId();
|
|
|
+ Assert.notNull(priceSystemId, "售价体系id不能为空");
|
|
|
+
|
|
|
+ Page<BomVo> page = bomService.getPage(dto);
|
|
|
+ List<BomVo> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值bom售价体系
|
|
|
+ List<Long> bomIdList = records.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ if (bomIdList.size() > 0) {
|
|
|
+ Map<Long, Long> priceSystemBomMap = priceSystemBomService.mapKV(
|
|
|
+ PriceSystemBom::getBomId,
|
|
|
+ PriceSystemBom::getPriceBillingStandardId,
|
|
|
+ q -> q.in(PriceSystemBom::getBomId, bomIdList));
|
|
|
+
|
|
|
+ for (BomVo record : records) {
|
|
|
+ record.setPriceBillingStandardId(priceSystemBomMap.get(record.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值bom规格对内售价和对外售价
|
|
|
+ List<Long> bomSpecIdList = records.stream()
|
|
|
+ .filter(item -> ObjectUtil.isNotEmpty(item.getBomSpecList()))
|
|
|
+ .flatMap(item -> item.getBomSpecList().stream())
|
|
|
+ .map(BaseIdPo::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (bomSpecIdList.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+ Map<Long, PriceSystemBomSpec> priceSystemBomSpecMap = priceSystemBomSpecService.mapKEntity(
|
|
|
+ PriceSystemBomSpec::getBomSpecId,
|
|
|
+ q -> q.in(PriceSystemBomSpec::getBomSpecId, bomSpecIdList));
|
|
|
+ for (BomVo record : records) {
|
|
|
+ List<BomSpec> bomSpecList = record.getBomSpecList();
|
|
|
+ if (ObjectUtil.isEmpty(bomSpecList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (BomSpec bomSpec : bomSpecList) {
|
|
|
+ PriceSystemBomSpec priceSystemBomSpec = priceSystemBomSpecMap.get(bomSpec.getId());
|
|
|
+ if (ObjectUtil.isEmpty(priceSystemBomSpec)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ bomSpec.setInternalSellingPrice(priceSystemBomSpec.getInternalSellingPrice());
|
|
|
+ bomSpec.setExternalSellingPrice(priceSystemBomSpec.getExternalSellingPrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|