|
|
@@ -18,19 +18,33 @@ package org.springblade.stock.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.client.entity.CorpsDesc;
|
|
|
+import org.springblade.client.entity.GoodsDesc;
|
|
|
+import org.springblade.client.feign.ICorpsDescClient;
|
|
|
+import org.springblade.client.feign.IGoodsDescClient;
|
|
|
+import org.springblade.client.vo.GoodsDescVO;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.stock.entity.StockGoods;
|
|
|
+import org.springblade.stock.excel.StockGoodsExcel;
|
|
|
import org.springblade.stock.vo.StockGoodsVO;
|
|
|
import org.springblade.stock.mapper.StockGoodsMapper;
|
|
|
import org.springblade.stock.service.IStockGoodsService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 库存账 服务实现类
|
|
|
@@ -39,8 +53,11 @@ import java.util.Date;
|
|
|
* @since 2021-09-26
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class StockGoodsServiceImpl extends ServiceImpl<StockGoodsMapper, StockGoods> implements IStockGoodsService {
|
|
|
-
|
|
|
+ private ICorpsDescClient corpsDescClient;//获取客户信息
|
|
|
+ private IGoodsDescClient goodsDescClient;//商品信息
|
|
|
+ private IUserClient userClient;//用户信息
|
|
|
@Override
|
|
|
public IPage<StockGoodsVO> selectStockGoodsPage(IPage<StockGoodsVO> page, StockGoodsVO stockGoods) {
|
|
|
return page.setRecords(baseMapper.selectStockGoodsPage(page, stockGoods));
|
|
|
@@ -85,4 +102,113 @@ public class StockGoodsServiceImpl extends ServiceImpl<StockGoodsMapper, StockGo
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void importUser(List<StockGoodsExcel> data, Boolean isCovered) {
|
|
|
+ for (StockGoodsExcel datum : data) {
|
|
|
+ StockGoods stockGoods = new StockGoods();
|
|
|
+ stockGoods.setLockingQuantity(datum.getLockingQuantity());
|
|
|
+ stockGoods.setBalanceQuantity(datum.getBalanceQuantity());
|
|
|
+ stockGoods.setSurplusRouteQuantity(datum.getSurplusRouteQuantity());
|
|
|
+ stockGoods.setTenantId(SecureUtil.getTenantId());
|
|
|
+ //获取商品id
|
|
|
+ R<GoodsDesc> goodsDesc = goodsDescClient.GoodsByCode(datum.getCode());
|
|
|
+ if (goodsDesc.isSuccess() && goodsDesc.getData() != null){
|
|
|
+ stockGoods.setGoodsId(goodsDesc.getData().getId());
|
|
|
+ if (StringUtils.isNotBlank(goodsDesc.getData().getBrand())){
|
|
|
+ stockGoods.setBrand(goodsDesc.getData().getBrand());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(goodsDesc.getData().getBrandItem())){
|
|
|
+ stockGoods.setBrandItem(goodsDesc.getData().getBrandItem());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(goodsDesc.getData().getTypeno())){
|
|
|
+ stockGoods.setTypeno(goodsDesc.getData().getTypeno());
|
|
|
+ }
|
|
|
+ stockGoods.setCname(goodsDesc.getData().getCname());
|
|
|
+ stockGoods.setCode(goodsDesc.getData().getCode());
|
|
|
+ }else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //获取客户id
|
|
|
+ R<CorpsDesc> corpsDesc = corpsDescClient.getCorpByName(datum.getCorpName(), SecureUtil.getTenantId());
|
|
|
+ if (corpsDesc.isSuccess() && corpsDesc.getData() != null){
|
|
|
+ stockGoods.setCorpId(corpsDesc.getData().getId());
|
|
|
+ stockGoods.setCorpName(corpsDesc.getData().getCname());
|
|
|
+ }else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //查询库存账
|
|
|
+ StockGoods goods = baseMapper.selectOne(new QueryWrapper<StockGoods>().eq("goods_id", stockGoods.getGoodsId())
|
|
|
+ .eq("corp_id", stockGoods.getCorpId()).eq("tenant_id", SecureUtil.getTenantId()).eq("is_deleted", 0));
|
|
|
+ if (goods == null){
|
|
|
+ stockGoods.setCreateTime(new Date());
|
|
|
+ stockGoods.setCreateUser(SecureUtil.getUserId());
|
|
|
+ baseMapper.insert(stockGoods);
|
|
|
+ }else {
|
|
|
+ stockGoods.setUpdateUser(SecureUtil.getUserId());
|
|
|
+ stockGoods.setUpdateTime(new Date());
|
|
|
+ stockGoods.setId(goods.getId());
|
|
|
+ baseMapper.updateById(stockGoods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<StockGoods> listMessage(IPage<StockGoods> page, QueryWrapper<StockGoods> queryWrapper) {
|
|
|
+ IPage<StockGoods> stockGoodsIPage = baseMapper.selectPage(page, queryWrapper);
|
|
|
+ if (CollectionUtils.isNotEmpty(stockGoodsIPage.getRecords())){
|
|
|
+ stockGoodsIPage.getRecords().stream().forEach(item ->{
|
|
|
+ //获取商品信息
|
|
|
+ R<GoodsDescVO> goodsMessage = goodsDescClient.selectGoodsMessage(item.getGoodsId());
|
|
|
+ if (goodsMessage.isSuccess() && goodsMessage.getData() != null){
|
|
|
+ if (StringUtils.isNotBlank(goodsMessage.getData().getBrand())){
|
|
|
+ item.setBrand(goodsMessage.getData().getBrand());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(goodsMessage.getData().getBrandItem())){
|
|
|
+ item.setBrandItem(goodsMessage.getData().getBrandItem());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(goodsMessage.getData().getTypeno())){
|
|
|
+ item.setTypeno(goodsMessage.getData().getTypeno());
|
|
|
+ }
|
|
|
+ item.setCname(goodsMessage.getData().getCname());
|
|
|
+ item.setCode(goodsMessage.getData().getCode());
|
|
|
+ }
|
|
|
+ //获取客户信息
|
|
|
+ R<CorpsDesc> corpMessage = corpsDescClient.getCorpMessage(item.getCorpId());
|
|
|
+ if (corpMessage.isSuccess() && corpMessage.getData() != null){
|
|
|
+ item.setCorpName(corpMessage.getData().getCname());
|
|
|
+ }
|
|
|
+ //获取用户信息
|
|
|
+ if (item.getCreateUser() != null){
|
|
|
+ R<User> createUser = userClient.userInfoById(item.getCreateUser());
|
|
|
+ if (createUser.isSuccess() && createUser.getData() != null){
|
|
|
+ item.setCreateUserName(createUser.getData().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (item.getUpdateUser() != null){
|
|
|
+ R<User> updateUser = userClient.userInfoById(item.getUpdateUser());
|
|
|
+ if (updateUser.isSuccess() && updateUser.getData() != null){
|
|
|
+ item.setUpdateUserName(updateUser.getData().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return stockGoodsIPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<StockGoods> updateMessage(StockGoods stockGoods) {
|
|
|
+ if (stockGoods.getId() == null){
|
|
|
+ stockGoods.setCreateTime(new Date());
|
|
|
+ stockGoods.setCreateUser(SecureUtil.getUserId());
|
|
|
+ stockGoods.setTenantId(SecureUtil.getTenantId());
|
|
|
+ baseMapper.insert(stockGoods);
|
|
|
+ }else {
|
|
|
+ stockGoods.setUpdateUser(SecureUtil.getUserId());
|
|
|
+ stockGoods.setUpdateTime(new Date());
|
|
|
+ baseMapper.updateById(stockGoods);
|
|
|
+ }
|
|
|
+ return R.data(stockGoods);
|
|
|
+ }
|
|
|
+
|
|
|
}
|