|
|
|
|
@ -26,13 +26,17 @@ |
|
|
|
|
package org.springblade.modules.jinchao.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.google.common.collect.Sets; |
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
import jakarta.validation.Valid; |
|
|
|
|
import lombok.Data; |
|
|
|
|
import lombok.EqualsAndHashCode; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.constant.BladeConstant; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.modules.jinchao.constant.BaseCol; |
|
|
|
|
import org.springblade.modules.jinchao.constant.ProductConst; |
|
|
|
|
import org.springblade.modules.jinchao.pojo.entity.BizPriceEntity; |
|
|
|
|
@ -40,23 +44,25 @@ import org.springblade.modules.jinchao.pojo.entity.CustomerEntity; |
|
|
|
|
import org.springblade.modules.jinchao.pojo.entity.ProductEntity; |
|
|
|
|
import org.springblade.modules.jinchao.excel.ProductExcel; |
|
|
|
|
import org.springblade.modules.jinchao.mapper.ProductMapper; |
|
|
|
|
import org.springblade.modules.jinchao.pojo.entity.RelCatalogProductEntity; |
|
|
|
|
import org.springblade.modules.jinchao.pojo.vo.ProductVO; |
|
|
|
|
import org.springblade.modules.jinchao.service.IBizPriceService; |
|
|
|
|
import org.springblade.modules.jinchao.service.ICustomerService; |
|
|
|
|
import org.springblade.modules.jinchao.service.IProductService; |
|
|
|
|
import org.springblade.modules.jinchao.service.IRelCatalogProductService; |
|
|
|
|
import org.springblade.modules.jinchao.wrapper.ProductWrapper; |
|
|
|
|
import org.springblade.modules.system.pojo.entity.User; |
|
|
|
|
import org.springblade.modules.system.service.IUserService; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.ListIterator; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -69,14 +75,20 @@ import java.util.stream.Collectors; |
|
|
|
|
@Data |
|
|
|
|
@EqualsAndHashCode(callSuper = true) |
|
|
|
|
@Slf4j |
|
|
|
|
public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEntity> implements IProductService { |
|
|
|
|
public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEntity> |
|
|
|
|
implements IProductService { |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
@Lazy |
|
|
|
|
private IProductService self; |
|
|
|
|
@Resource |
|
|
|
|
private IUserService userService; |
|
|
|
|
@Resource |
|
|
|
|
private IBizPriceService bizPriceService; |
|
|
|
|
@Resource |
|
|
|
|
private ICustomerService customerService; |
|
|
|
|
@Resource |
|
|
|
|
private IRelCatalogProductService relCatalogProductService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<ProductVO> selectProductPage(IPage<ProductVO> page, ProductVO product) { |
|
|
|
|
@ -93,13 +105,32 @@ public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEn |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R<IPage<ProductVO>> list(Map<String, Object> product, Query query) { |
|
|
|
|
IPage<ProductEntity> pages = page( |
|
|
|
|
public R<IPage<ProductVO>> list(Map<String, Object> map, Query query) { |
|
|
|
|
Long catalogId = Long.parseLong((String) map.get("catalogId")); // 是Id [坏笑]。不是ld
|
|
|
|
|
log.warn("catalogId {}", catalogId); |
|
|
|
|
if (catalogId == null || catalogId == 0L) { |
|
|
|
|
return R.fail("catalogId error."); |
|
|
|
|
} |
|
|
|
|
IPage<RelCatalogProductEntity> pageRel = relCatalogProductService.page( |
|
|
|
|
Condition.getPage(query), |
|
|
|
|
Condition.getQueryWrapper(product, ProductEntity.class).orderByAsc(BaseCol.ID) |
|
|
|
|
Condition.getQueryWrapper(map, RelCatalogProductEntity.class) |
|
|
|
|
.eq("catalog_id", catalogId) |
|
|
|
|
.orderByAsc("product_id") |
|
|
|
|
); |
|
|
|
|
IPage<ProductVO> pagesVo = ProductWrapper.build().pageVO(pages); |
|
|
|
|
ListIterator<ProductVO> it = pagesVo.getRecords().listIterator(); |
|
|
|
|
List<ProductVO> listVO = new ArrayList<>(); |
|
|
|
|
pageRel.getRecords().forEach(rel -> { |
|
|
|
|
ProductEntity p = getById(rel.getProductId()); |
|
|
|
|
if (p != null) { |
|
|
|
|
ProductVO vo = ProductWrapper.build().entityVO(p); |
|
|
|
|
vo.setCatalogId(catalogId); |
|
|
|
|
listVO.add(vo); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// 组装IPage
|
|
|
|
|
IPage<ProductVO> pagesVO = Condition.getPage(query); |
|
|
|
|
pagesVO.setRecords(listVO); |
|
|
|
|
// 迭代器去添加元素。
|
|
|
|
|
ListIterator<ProductVO> it = pagesVO.getRecords().listIterator(); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
ProductVO vo1 = it.next(); |
|
|
|
|
// 默认
|
|
|
|
|
@ -136,7 +167,18 @@ public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEn |
|
|
|
|
log.info("not contain."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return R.data(pagesVo); |
|
|
|
|
return R.data(pagesVO); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R remove(String ids) { |
|
|
|
|
List<Long> list = Func.toLongList(ids); |
|
|
|
|
// 同时 逻辑删除对应关联表
|
|
|
|
|
list.forEach(id -> { |
|
|
|
|
relCatalogProductService.deleteByProductId(id); |
|
|
|
|
bizPriceService.deleteByProductId(id); |
|
|
|
|
}); |
|
|
|
|
return R.status(self.deleteLogic(list)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@ -144,9 +186,11 @@ public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEn |
|
|
|
|
return baseMapper.exists(new QueryWrapper<ProductEntity>().eq(ProductEntity.COL_CODE, code)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean existsNameCn(String nameCn) { |
|
|
|
|
return baseMapper.exists(new QueryWrapper<ProductEntity>().eq(ProductEntity.COL_NAME_CN, nameCn)); |
|
|
|
|
public Boolean existsNameCn(Long catalogId, String nameCn) { |
|
|
|
|
Long count = baseMapper.countNameCn(catalogId, nameCn); |
|
|
|
|
return count != 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -155,11 +199,9 @@ public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEn |
|
|
|
|
* @param vo 传入的对象已经BizType赋值了. |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void setVoValue(ProductVO vo) { |
|
|
|
|
public void setVoValue(Long catalogId, ProductVO vo) { |
|
|
|
|
if (vo != null) { |
|
|
|
|
if (Objects.equals(ProductConst.TYPE_PRICE_CUSTOM, vo.getBizType())) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
vo.setCatalogId(catalogId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -167,16 +209,128 @@ public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, ProductEn |
|
|
|
|
public R<List<ProductVO>> oneKeyMatch(List<ProductVO> list) { |
|
|
|
|
List<ProductVO> listNew = list.stream() |
|
|
|
|
.map(vo -> { |
|
|
|
|
ProductEntity pFind = getOne(new QueryWrapper<ProductEntity>().eq(ProductEntity.COL_NAME_CN, vo.getNameCn())); |
|
|
|
|
if (pFind != null) { |
|
|
|
|
// 全部数据,用nameCn去匹配
|
|
|
|
|
ProductEntity find = getOne(new QueryWrapper<ProductEntity>().eq(ProductEntity.COL_NAME_CN, vo.getNameCn())); |
|
|
|
|
if (find != null) { |
|
|
|
|
ProductVO voNew = new ProductVO(); |
|
|
|
|
BeanUtils.copyProperties(pFind, voNew); |
|
|
|
|
BeanUtils.copyProperties(find, voNew); |
|
|
|
|
voNew.setBizType(ProductConst.TYPE_PRICE_STANDARD); |
|
|
|
|
return voNew; |
|
|
|
|
} else { |
|
|
|
|
// 前端要赋值catalogId,后续保存会用到。
|
|
|
|
|
// 数据原样返回。
|
|
|
|
|
return vo; |
|
|
|
|
} |
|
|
|
|
vo.setBizType(ProductConst.TYPE_PRICE_STANDARD); |
|
|
|
|
return vo; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
return R.data(listNew); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R submit(ProductVO vo) { |
|
|
|
|
if (vo.getId() == null || vo.getId() == 0L) { |
|
|
|
|
if (vo.getCatalogId() == null || vo.getCatalogId() == 0L) { |
|
|
|
|
return R.fail("catalogId无效"); |
|
|
|
|
} |
|
|
|
|
if (existsCode(vo.getCode())) { |
|
|
|
|
return R.fail("已经存在此code"); |
|
|
|
|
} |
|
|
|
|
if (existsNameCn(vo.getCatalogId(), vo.getNameCn())) { |
|
|
|
|
return R.fail("已经存在此nameCn"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (Objects.equals(vo.getBizType(), ProductConst.TYPE_PRICE_CUSTOM)) { |
|
|
|
|
// 跳过
|
|
|
|
|
return R.fail("bizType类型错误"); |
|
|
|
|
} |
|
|
|
|
boolean b = saveOrUpdate(vo); |
|
|
|
|
// 处理关联表 merge 关系
|
|
|
|
|
relCatalogProductService.merge(vo.getCatalogId(), vo.getId()); |
|
|
|
|
return R.status(b); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R submitBat(List<ProductVO> vos) { |
|
|
|
|
Long catalogId = 0L; |
|
|
|
|
log.warn("catalogId = {}", catalogId); |
|
|
|
|
// catalogId 设置值。
|
|
|
|
|
if (vos != null && !vos.isEmpty()) { |
|
|
|
|
catalogId = vos.get(0).getCatalogId(); |
|
|
|
|
} |
|
|
|
|
// 删除 先做删除,id还没有被赋值。
|
|
|
|
|
if (false && vos != null && !vos.isEmpty()) { |
|
|
|
|
// 前端传入数量
|
|
|
|
|
AtomicReference<Integer> sizeWeb = new AtomicReference<>(0); |
|
|
|
|
Objects.requireNonNull(vos).forEach(vo -> { |
|
|
|
|
if (vo != null && |
|
|
|
|
Objects.equals(vo.getBizType(), ProductConst.TYPE_PRICE_STANDARD) && |
|
|
|
|
vo.getId() != null && |
|
|
|
|
vo.getId() != 0L) { |
|
|
|
|
sizeWeb.set(sizeWeb.get() + 1); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// 数据库中数量
|
|
|
|
|
Integer sizeDb = Math.toIntExact(count(new QueryWrapper<>())); |
|
|
|
|
// 数量比较
|
|
|
|
|
if (Objects.equals(sizeWeb.get(), sizeDb)) { |
|
|
|
|
log.info("没有删除数据"); |
|
|
|
|
} else { |
|
|
|
|
// 前端传入id的Set
|
|
|
|
|
Set<Long> setWeb = vos.stream() |
|
|
|
|
.filter(vo -> ( |
|
|
|
|
Objects.equals(vo.getBizType(), ProductConst.TYPE_PRICE_STANDARD) && |
|
|
|
|
vo.getId() != null && |
|
|
|
|
vo.getId() != 0L |
|
|
|
|
)) |
|
|
|
|
.map(ProductVO::getId) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.collect(Collectors.toCollection(TreeSet::new)); |
|
|
|
|
//
|
|
|
|
|
Set<Long> setDB = null; |
|
|
|
|
Set<Long> setDel = Sets.difference(setDB, setWeb); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (vos != null && !vos.isEmpty()) { |
|
|
|
|
for (ProductVO vo : vos) { |
|
|
|
|
if (vo == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
final Integer bizType = vo.getBizType(); |
|
|
|
|
if (Objects.equals(bizType, ProductConst.TYPE_PRICE_STANDARD)) { // 标准价
|
|
|
|
|
// 添加 or 修改
|
|
|
|
|
if (Objects.requireNonNull(vo).getId() == null || vo.getId() == 0L) { |
|
|
|
|
// 新增check
|
|
|
|
|
if (vo.getCatalogId() == null || vo.getCatalogId() == 0L) { |
|
|
|
|
return R.fail("catalogId无效"); |
|
|
|
|
} |
|
|
|
|
if (existsCode(vo.getCode())) { |
|
|
|
|
return R.fail("已经存在此code"); |
|
|
|
|
} |
|
|
|
|
if (existsNameCn(catalogId, vo.getNameCn())) { |
|
|
|
|
return R.fail("已经存在此nameCn"); |
|
|
|
|
} |
|
|
|
|
// 新增 产品
|
|
|
|
|
save(vo); |
|
|
|
|
} else { |
|
|
|
|
// 修改 产品 根据id
|
|
|
|
|
updateById(vo); |
|
|
|
|
} |
|
|
|
|
// 处理关联表 merge 关系
|
|
|
|
|
relCatalogProductService.merge(vo.getCatalogId(), vo.getId()); |
|
|
|
|
} else if (Objects.equals(bizType, ProductConst.TYPE_PRICE_CUSTOM)) { // 指定价
|
|
|
|
|
QueryWrapper<BizPriceEntity> qw = new QueryWrapper<BizPriceEntity>() |
|
|
|
|
.eq(BaseCol.ID, vo.getBizPriceId()); |
|
|
|
|
Optional<BizPriceEntity> opt = bizPriceService.getOneOpt(qw); |
|
|
|
|
opt.ifPresent( |
|
|
|
|
bp -> { |
|
|
|
|
bp.setSaleUserId(vo.getSaleUserId()); |
|
|
|
|
bp.setCustomerId(vo.getCustomerId()); |
|
|
|
|
bp.setBizPrice(vo.getBizPrice()); |
|
|
|
|
bizPriceService.updateById(bp); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return R.success(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|