|
|
@@ -34,11 +34,12 @@ import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * @desc: 商品service TODO
|
|
|
+ * @desc: 商品service
|
|
|
* @author: yzc
|
|
|
* @date: 2023-06-25 14:47
|
|
|
*/
|
|
|
@@ -159,14 +160,14 @@ public class KwpGoodsService {
|
|
|
* @Param id:
|
|
|
* @return: com.sckw.product.model.vo.res.GoodsDetail
|
|
|
*/
|
|
|
- public GoodsDetail detail(Long id,Boolean isDubbo) {
|
|
|
+ public GoodsDetail detail(Long id, Boolean isDubbo) {
|
|
|
KwpGoods goods;
|
|
|
if (isDubbo) {
|
|
|
goods = kwpGoodsMapper.selectById(id);
|
|
|
if (Objects.isNull(goods)) {
|
|
|
return null;
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
goods = getGoodsById(id);
|
|
|
if (Objects.isNull(goods)) {
|
|
|
throw new BusinessException("当前商品信息为空!");
|
|
|
@@ -293,8 +294,8 @@ public class KwpGoodsService {
|
|
|
* @return: void
|
|
|
*/
|
|
|
private void judgeParameters(@NotNull UpdateGoodsParam param) {
|
|
|
- if (StringUtils.isBlank(param.getName())) {
|
|
|
- throw new BusinessException("商品名称不能为空!");
|
|
|
+ if (StringUtils.isBlank(param.getName()) || param.getName().length() > 100) {
|
|
|
+ throw new BusinessException("商品名称不能为空且最长100字符!");
|
|
|
}
|
|
|
if (StringUtils.isBlank(param.getGoodsType())) {
|
|
|
throw new BusinessException("商品类型不能为空!");
|
|
|
@@ -305,8 +306,8 @@ public class KwpGoodsService {
|
|
|
if (StringUtils.isBlank(param.getSpec())) {
|
|
|
throw new BusinessException("规格尺寸不能为空!");
|
|
|
}
|
|
|
- if (Objects.isNull(param.getAmount())) {
|
|
|
- throw new BusinessException("库存数量不能为空!");
|
|
|
+ if (Objects.isNull(param.getAmount()) || param.getAmount().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new BusinessException("库存数量不能为空且最小为零!");
|
|
|
}
|
|
|
if (Objects.isNull(param.getTaxRate())) {
|
|
|
throw new BusinessException("发票税率不能为空!");
|
|
|
@@ -317,22 +318,84 @@ public class KwpGoodsService {
|
|
|
if (Objects.equals(param.getTrading(), DictEnum.TRADE_TYPE_0.getValue()) && Objects.isNull(param.getAdvancePrice())) {
|
|
|
throw new BusinessException("交易方式为预付款时,预付款最低限额不能为空!");
|
|
|
}
|
|
|
- if (CollectionUtils.isEmpty(param.getPriceRanges())) {
|
|
|
+
|
|
|
+ List<GoodsAttributes> attributes = param.getAttributes();
|
|
|
+ if (CollectionUtils.isNotEmpty(attributes)) {
|
|
|
+ attributes.forEach(e -> {
|
|
|
+ if (StringUtils.isBlank(e.getName()) || e.getName().length() > 40) {
|
|
|
+ throw new BusinessException("参数名称不能为空且最长40字符!");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(e.getVal()) || e.getVal().length() > 40) {
|
|
|
+ throw new BusinessException("参数值不能为空且最长40字符!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ List<GoodsImages> images = param.getImages();
|
|
|
+ if (CollectionUtils.isNotEmpty(images)) {
|
|
|
+ images.forEach(e -> {
|
|
|
+ if (StringUtils.isBlank(e.getImage())) {
|
|
|
+ throw new BusinessException("商品图片地址不能为空!");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(e.getSort())) {
|
|
|
+ throw new BusinessException("商品图片排序不能为空!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ List<GoodsPriceRanges> priceRanges = param.getPriceRanges();
|
|
|
+ if (CollectionUtils.isEmpty(priceRanges)) {
|
|
|
throw new BusinessException("价格梯度不能为空!");
|
|
|
}
|
|
|
+ priceRanges.forEach(e -> {
|
|
|
+ if (Objects.isNull(e.getStartAmount()) || e.getStartAmount().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new BusinessException("起售量最小为零!");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(e.getEndAmount()) || e.getEndAmount().compareTo(new BigDecimal("-1.00")) < 0) {
|
|
|
+ throw new BusinessException("上限售量最小为零!");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(e.getPrice()) || e.getStartAmount().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new BusinessException("含税价最低为零!");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(e.getSort())) {
|
|
|
+ throw new BusinessException("梯度顺序不能为空!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ AddressInfo address = param.getAddressInfo();
|
|
|
+ if (Objects.isNull(address)) {
|
|
|
+ throw new BusinessException("地址信息不能为空!");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(address.getName()) || address.getName().length() > 60) {
|
|
|
+ throw new BusinessException("参数名称不能为空且最长60字符!");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(address.getType())) {
|
|
|
+ throw new BusinessException("地址类型不能为空!");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(address.getContacts())) {
|
|
|
+ throw new BusinessException("联系人不能为空!");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(address.getPhone())) {
|
|
|
+ throw new BusinessException("联系电话不能为空!");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(address.getCityCode())) {
|
|
|
+ throw new BusinessException("所在地区code不能为空!");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(address.getCityName()) || address.getCityName().length() > 40) {
|
|
|
+ throw new BusinessException("所属区域名称不能为空最长40字符!");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(address.getLat())) {
|
|
|
+ throw new BusinessException("纬度不能为空!");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(address.getLng())) {
|
|
|
+ throw new BusinessException("经度不能为空!");
|
|
|
+ }
|
|
|
if (Objects.isNull(param.getSupplyEntId())) {
|
|
|
throw new BusinessException("供应企业不能为空!");
|
|
|
}
|
|
|
- if (Objects.isNull(param.getAddressInfo())) {
|
|
|
- throw new BusinessException("地址信息不能为空!");
|
|
|
- }
|
|
|
if (Objects.isNull(param.getManager())) {
|
|
|
throw new BusinessException("客户经理不能为空!");
|
|
|
}
|
|
|
- if (StringUtils.isBlank(param.getAmount())) {
|
|
|
- throw new BusinessException("商品缩略图不能为空!");
|
|
|
+ if (StringUtils.isNotBlank(param.getRemark()) && param.getRemark().length() > 200) {
|
|
|
+ throw new BusinessException("备注最多支持200字!");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -487,23 +550,35 @@ public class KwpGoodsService {
|
|
|
* @desc: 批量上架
|
|
|
* @author: yzc
|
|
|
* @date: 2023-07-06 8:56
|
|
|
- * @Param ids:
|
|
|
+ * @Param id:
|
|
|
* @return: void
|
|
|
*/
|
|
|
- public void batchPutOnShelves(List<Long> ids) {
|
|
|
+ public void batchPutOnShelves(Long id) {
|
|
|
LambdaQueryWrapper<KwpGoods> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.in(KwpGoods::getId, ids).in(KwpGoods::getStatus, 0, 2)
|
|
|
- .eq(KwpGoods::getEntId, LoginUserHolder.getEntId()).eq(KwpGoods::getDelFlag, Global.NO);
|
|
|
- List<KwpGoods> list = kwpGoodsMapper.selectList(wrapper);
|
|
|
- if (!Objects.equals(ids.size(), list.size())) {
|
|
|
- throw new BusinessException("上架操作仅针对“已下架”“草稿”状态的单据");
|
|
|
+ wrapper.eq(KwpGoods::getId, id).eq(KwpGoods::getEntId, LoginUserHolder.getEntId())
|
|
|
+ .eq(KwpGoods::getDelFlag, Global.NO).last("LIMIT 1");
|
|
|
+ KwpGoods goods = kwpGoodsMapper.selectOne(wrapper);
|
|
|
+ if (Objects.isNull(goods)) {
|
|
|
+ throw new BusinessException("商品不存在!");
|
|
|
+ }
|
|
|
+ if (Objects.equals(GoodsStatusEnum.PUT_ON_SHELVES.getCode(), goods.getStatus())) {
|
|
|
+ throw new BusinessException("上架操作仅针对“已下架”“草稿”状态的单据!");
|
|
|
+ }
|
|
|
+ if (Objects.equals(GoodsStatusEnum.SAVED.getCode(), goods.getStatus())) {
|
|
|
+ UpdateGoodsParam updateParam = BeanUtils.copyProperties(goods, UpdateGoodsParam.class);
|
|
|
+ updateParam.setAttributes(BeanUtils.copyToList(kwpGoodsAttributeService.getByGoodsId(id), GoodsAttributes.class));
|
|
|
+ updateParam.setPriceRanges(BeanUtils.copyToList(kwpGoodsPriceRangeService.getByGoodsId(id), GoodsPriceRanges.class));
|
|
|
+ updateParam.setImages(BeanUtils.copyToList(kwpGoodsImageService.getByGoodsId(id), GoodsImages.class));
|
|
|
+ updateParam.setAddressInfo(BeanUtils.copyProperties(kwpGoodsAddressService.getByGoodsId(id), AddressInfo.class));
|
|
|
+ judgeParameters(updateParam);
|
|
|
}
|
|
|
LambdaUpdateWrapper<KwpGoods> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
updateWrapper.set(KwpGoods::getStatus, GoodsStatusEnum.PUT_ON_SHELVES.getCode()).set(KwpGoods::getAddedTime, new Date())
|
|
|
- .in(KwpGoods::getId, ids);
|
|
|
+ .eq(KwpGoods::getId, id);
|
|
|
kwpGoodsMapper.update(null, updateWrapper);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @desc: 批量下架
|
|
|
* @author: yzc
|