|
@@ -1,17 +1,31 @@
|
|
|
package com.sd.business.service.bom.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.constant.StatusConstant;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.sd.business.entity.bom.dto.BomSpecDto;
|
|
|
import com.sd.business.entity.bom.dto.BomSpecSelectDto;
|
|
|
+import com.sd.business.entity.bom.dto.BomSpecUpdateBoardDto;
|
|
|
+import com.sd.business.entity.bom.dto.BomSpecUpdateBoardSortDto;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
+import com.sd.business.entity.bom.vo.BomSpecBoardSelectVo;
|
|
|
import com.sd.business.entity.bom.vo.BomSpecVo;
|
|
|
+import com.sd.business.entity.inventory.po.Inventory;
|
|
|
import com.sd.business.mapper.bom.BomSpecMapper;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
|
+import com.sd.business.service.inventory.InventoryService;
|
|
|
+import com.sd.framework.util.StreamUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -23,6 +37,8 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
@Service
|
|
|
public class BomSpecServiceImpl extends ServiceImpl<BomSpecMapper, BomSpec> implements BomSpecService {
|
|
|
+ @Autowired
|
|
|
+ private InventoryService inventoryService;
|
|
|
|
|
|
@Override
|
|
|
public Page<BomSpecVo> getPage(BomSpecSelectDto dto) {
|
|
@@ -56,4 +72,46 @@ public class BomSpecServiceImpl extends ServiceImpl<BomSpecMapper, BomSpec> impl
|
|
|
this.removeById(id);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void editBoard(BomSpecUpdateBoardDto dto) {
|
|
|
+ List<Long> bomSpecIdList = dto.getBomSpecIdList();
|
|
|
+ this.update(q -> q.set(BomSpec::getIsShowBoard, StatusConstant.NO).set(BomSpec::getSort, null).eq(BomSpec::getIsShowBoard, StatusConstant.YES));
|
|
|
+ if (ObjectUtil.isNotEmpty(bomSpecIdList)) {
|
|
|
+ for (int i = 0; i < bomSpecIdList.size(); i++) {
|
|
|
+ Long bomSpecId = bomSpecIdList.get(i);
|
|
|
+ int sort = i;
|
|
|
+ this.update(q -> q.set(BomSpec::getIsShowBoard, StatusConstant.YES)
|
|
|
+ .set(BomSpec::getSort, sort).eq(BomSpec::getId, bomSpecId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BomSpecBoardSelectVo> getBoardList() {
|
|
|
+ List<BomSpec> list = this.list(q -> q.eq(BomSpec::getIsShowBoard, StatusConstant.YES).orderByAsc(BomSpec::getSort));
|
|
|
+ List<BomSpecBoardSelectVo> boardSelectList = BeanUtil.copyToList(list, BomSpecBoardSelectVo.class);
|
|
|
+ List<BomSpecBoardSelectVo> collect = boardSelectList.stream().peek(item -> {
|
|
|
+ List<Inventory> inventoryList = inventoryService.list(q -> q.eq(Inventory::getBomSpecId, item.getId()));
|
|
|
+ BigDecimal inventoryQuantity = ObjectUtil.isEmpty(inventoryList) ? BigDecimal.ZERO : StreamUtil.bigDecimalAdd(inventoryList, Inventory::getQuantity);
|
|
|
+ item.setInventoryQuantity(inventoryQuantity);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void editBoardSort(BomSpecUpdateBoardSortDto dto) {
|
|
|
+ BomSpec bomSpec = this.getById(dto.getId());
|
|
|
+ if (bomSpec != null && !Objects.equals(dto.getCurrentSort(), bomSpec.getSort())) {
|
|
|
+ Integer oldSort = bomSpec.getSort();
|
|
|
+ Integer currentSort = dto.getCurrentSort();
|
|
|
+ // 如果当前排序大于原排序,当前排序到原排序之间 -1
|
|
|
+ if (oldSort < currentSort) {
|
|
|
+ this.update(q -> q.setSql("sort = sort - 1").le(BomSpec::getSort, currentSort).gt(BomSpec::getSort, oldSort));
|
|
|
+ } else {
|
|
|
+ this.update(q -> q.setSql("sort = sort + 1").lt(BomSpec::getSort, oldSort).ge(BomSpec::getSort, currentSort));
|
|
|
+ }
|
|
|
+ // 更新当前bom排序
|
|
|
+ this.update(q -> q.set(BomSpec::getSort, currentSort).eq(BomSpec::getId, bomSpec.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|