|
@@ -1,15 +1,34 @@
|
|
|
package com.fjhx.service.stock.impl;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.base.Condition;
|
|
|
+import com.fjhx.constants.StatusConstant;
|
|
|
+import com.fjhx.entity.product.ProductInfo;
|
|
|
import com.fjhx.entity.stock.StockTransfer;
|
|
|
-import com.fjhx.params.stock.StockTransferVo;
|
|
|
+import com.fjhx.enums.stock.OutTypeEnum;
|
|
|
import com.fjhx.mapper.stock.StockTransferMapper;
|
|
|
+import com.fjhx.params.stock.ChangeProduct;
|
|
|
+import com.fjhx.params.stock.StockChangeVo;
|
|
|
+import com.fjhx.params.stock.StockTransferAddVo;
|
|
|
+import com.fjhx.service.stock.StockService;
|
|
|
import com.fjhx.service.stock.StockTransferService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.utils.Assert;
|
|
|
+import com.fjhx.utils.UserClientUtil;
|
|
|
import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
|
+import com.fjhx.utils.wrapperUtil.KeywordData;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -22,27 +41,75 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class StockTransferServiceImpl extends ServiceImpl<StockTransferMapper, StockTransfer> implements StockTransferService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StockService stockService;
|
|
|
+
|
|
|
@Override
|
|
|
- public Page<StockTransfer> getPage(Map<String, Object> condition) {
|
|
|
+ public Page<Map<String, Object>> getPage(Condition condition) {
|
|
|
|
|
|
- IWrapper<StockTransfer> wrapper = IWrapper.getWrapper(condition);
|
|
|
+ IWrapper<Object> wrapper = IWrapper.getWrapper(condition);
|
|
|
+ wrapper.eq("st", StockTransfer::getInWarehouseId);
|
|
|
+ wrapper.eq("st", StockTransfer::getOutWarehouseId);
|
|
|
+ wrapper.eq("st", StockTransfer::getInStatus);
|
|
|
+ wrapper.keyword(new KeywordData("pi", ProductInfo::getName), new KeywordData("pi", ProductInfo::getCode));
|
|
|
|
|
|
- return page(condition, wrapper);
|
|
|
- }
|
|
|
+ Page<Map<String, Object>> page = baseMapper.getPage(condition.getPage(), wrapper);
|
|
|
+ List<Map<String, Object>> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void add(StockTransferVo stockTransferVo) {
|
|
|
- save(stockTransferVo);
|
|
|
- }
|
|
|
+ List<Long> userIdList = new ArrayList<>();
|
|
|
+ records.forEach(item -> {
|
|
|
+ userIdList.add(Convert.toLong(item.get("inUser")));
|
|
|
+ userIdList.add(Convert.toLong(item.get("createUser")));
|
|
|
+ });
|
|
|
|
|
|
- @Override
|
|
|
- public void edit(StockTransferVo stockTransferVo) {
|
|
|
- updateById(stockTransferVo);
|
|
|
+ Map<Long, String> userNameMap = UserClientUtil.getUserNameMap(userIdList);
|
|
|
+
|
|
|
+ for (Map<String, Object> item : records) {
|
|
|
+ item.put("inUserName", userNameMap.get(Convert.toLong(item.get("inUser"))));
|
|
|
+ item.put("outUserName", userNameMap.get(Convert.toLong(item.get("createUser"))));
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void delete(StockTransferVo stockTransferVo) {
|
|
|
- removeById(stockTransferVo.getId());
|
|
|
+ public void add(StockTransferAddVo stockTransferAddVo) {
|
|
|
+ // 调仓明细
|
|
|
+ List<ChangeProduct> changeProductList = stockTransferAddVo.getChangeProductList();
|
|
|
+ Assert.notEmpty(changeProductList, "调仓明细不能为空");
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ Long userId = AuthUtil.getUserId();
|
|
|
+ List<StockTransfer> stockTransferList = changeProductList.stream().map(item -> {
|
|
|
+ long id = IdWorker.getId();
|
|
|
+
|
|
|
+ StockTransfer stockTransfer = new StockTransfer();
|
|
|
+ stockTransfer.setId(id);
|
|
|
+ stockTransfer.setInWarehouseId(stockTransferAddVo.getInWarehouseId());
|
|
|
+ stockTransfer.setOutWarehouseId(stockTransferAddVo.getOutWarehouseId());
|
|
|
+ stockTransfer.setRemark(stockTransferAddVo.getRemark());
|
|
|
+ stockTransfer.setInStatus(StatusConstant.NO);
|
|
|
+ stockTransfer.setOutQuantity(item.getQuantity());
|
|
|
+ stockTransfer.setProductId(item.getProductId());
|
|
|
+ stockTransfer.setCreateTime(date);
|
|
|
+ stockTransfer.setCreateUser(userId);
|
|
|
+
|
|
|
+ item.setBusinessId(id);
|
|
|
+
|
|
|
+ return stockTransfer;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ saveBatch(stockTransferList);
|
|
|
+
|
|
|
+ StockChangeVo stockChangeVo = new StockChangeVo();
|
|
|
+ stockChangeVo.setDefaultWarehouseId(stockTransferAddVo.getOutWarehouseId());
|
|
|
+ stockChangeVo.setDefaultRemarks(stockTransferAddVo.getRemark());
|
|
|
+ stockChangeVo.setTypeEnum(OutTypeEnum.TRANSFER);
|
|
|
+ stockChangeVo.setChangeDetailsList(changeProductList);
|
|
|
+ stockService.changeQuantity(stockChangeVo);
|
|
|
}
|
|
|
|
|
|
}
|