15 changed files with 286 additions and 286 deletions
@ -0,0 +1,17 @@ |
|||
package com.qs.serve.modules.goods.entity.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/2/20 |
|||
*/ |
|||
@Data |
|||
@AllArgsConstructor |
|||
public class GoodTargetParam { |
|||
|
|||
private String goodsType; |
|||
private String goodsId; |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package com.qs.serve.modules.goods.entity.dto; |
|||
|
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/2/20 |
|||
*/ |
|||
@Data |
|||
public class GoodsTargetInfo { |
|||
|
|||
/** 目标类型(brand、category、series、spu、sku) */ |
|||
private String targetType; |
|||
|
|||
/** 目标id */ |
|||
private Long targetId; |
|||
|
|||
/** 目标编码 */ |
|||
private String targetCode; |
|||
|
|||
/** 目标名称 */ |
|||
private String targetName; |
|||
|
|||
/** 目标等级id路径 */ |
|||
private String targetLevelPathIds; |
|||
|
|||
/** 目标等级名称路径 */ |
|||
private String targetLevelPathNames; |
|||
|
|||
} |
@ -0,0 +1,94 @@ |
|||
package com.qs.serve.modules.goods.service; |
|||
|
|||
import com.qs.serve.modules.bms.service.BmsChannelPointService; |
|||
import com.qs.serve.modules.bms.service.BmsChannelService; |
|||
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|||
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|||
import com.qs.serve.modules.goods.entity.GoodsCategory; |
|||
import com.qs.serve.modules.goods.entity.GoodsSku; |
|||
import com.qs.serve.modules.goods.entity.GoodsSpu; |
|||
import com.qs.serve.modules.goods.entity.dto.GoodTargetParam; |
|||
import com.qs.serve.modules.goods.entity.dto.GoodsTargetInfo; |
|||
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|||
import com.qs.serve.modules.tbs.entity.TbsActivityGoods; |
|||
import com.qs.serve.modules.tbs.entity.bo.TbsActivityGoodsBo; |
|||
import lombok.AllArgsConstructor; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/2/20 |
|||
*/ |
|||
@Service |
|||
@AllArgsConstructor |
|||
public class GoodsApplicationService { |
|||
|
|||
|
|||
private final GoodsSkuService goodsSkuService; |
|||
private final GoodsSpuService goodsSpuService; |
|||
private final GoodsCategoryService goodsCategoryService; |
|||
|
|||
|
|||
public GoodsTargetInfo getGoodsTargetInfo(String goodsType,Long goodsIds){ |
|||
List<GoodsTargetInfo> list = this.getGoodsTargetInfo(goodsType, Arrays.asList(goodsIds)); |
|||
if(list.size()>0){ |
|||
return list.get(0); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public List<GoodsTargetInfo> getGoodsTargetInfo(String goodsType,List<Long> goodsIds){ |
|||
List<GoodsTargetInfo> resultList = new ArrayList<>(); |
|||
if(goodsType.equals(TbsGoodsType.spu.name())){ |
|||
for (Long spuId : goodsIds) { |
|||
GoodsSpu goodsSpu = goodsSpuService.getById(spuId); |
|||
GoodsCategory category1 = goodsCategoryService.getById(goodsSpu.getCategoryFirst()); |
|||
GoodsCategory category2 = goodsCategoryService.getById(goodsSpu.getCategorySecond()); |
|||
GoodsCategory category3 = goodsCategoryService.getById(goodsSpu.getCategoryThird()); |
|||
GoodsTargetInfo targetInfo = new GoodsTargetInfo(); |
|||
targetInfo.setTargetType(goodsType); |
|||
targetInfo.setTargetId(goodsSpu.getId()); |
|||
targetInfo.setTargetCode(goodsSpu.getSpuCode()); |
|||
targetInfo.setTargetName(goodsSpu.getName()); |
|||
targetInfo.setTargetLevelPathIds(category1.getId()+"_"+category2.getId()+"_"+category3.getId()+"_"+goodsSpu.getId()); |
|||
targetInfo.setTargetLevelPathNames(category1.getName()+"_"+category2.getName()+"_"+category3.getName()+"_"+goodsSpu.getName()); |
|||
resultList.add(targetInfo); |
|||
} |
|||
}else if (goodsType.equals(TbsGoodsType.sku.name())){ |
|||
for (Long skuId : goodsIds) { |
|||
GoodsSku sku = goodsSkuService.getById(skuId); |
|||
GoodsSpu goodsSpu = goodsSpuService.getById(sku.getSpuId()); |
|||
GoodsCategory category1 = goodsCategoryService.getById(goodsSpu.getCategoryFirst()); |
|||
GoodsCategory category2 = goodsCategoryService.getById(goodsSpu.getCategorySecond()); |
|||
GoodsCategory category3 = goodsCategoryService.getById(goodsSpu.getCategoryThird()); |
|||
GoodsTargetInfo targetInfo = new GoodsTargetInfo(); |
|||
targetInfo.setTargetType(goodsType); |
|||
targetInfo.setTargetId(sku.getId()); |
|||
targetInfo.setTargetCode(sku.getSkuCode()); |
|||
targetInfo.setTargetName(sku.getSpecInfos()); |
|||
targetInfo.setTargetLevelPathIds(category1.getId()+"_"+category2.getId()+"_"+category3.getId()+"_"+goodsSpu.getId()+"_"+sku.getId()); |
|||
targetInfo.setTargetLevelPathNames(category1.getName()+"_"+category2.getName()+"_"+category3.getName()+"_"+goodsSpu.getName()+"_"+sku.getSpecInfos()); |
|||
resultList.add(targetInfo); |
|||
} |
|||
}else { |
|||
//品牌、品类、系列
|
|||
for (Long categoryId : goodsIds) { |
|||
GoodsCategory category = goodsCategoryService.getById(categoryId); |
|||
GoodsTargetInfo targetInfo = new GoodsTargetInfo(); |
|||
targetInfo.setTargetType(goodsType); |
|||
targetInfo.setTargetId(category.getId()); |
|||
targetInfo.setTargetCode(category.getCode()); |
|||
targetInfo.setTargetName(category.getName()); |
|||
targetInfo.setTargetLevelPathIds(category.getLevelPath()); |
|||
targetInfo.setTargetLevelPathNames(category.getLevelPathNames()); |
|||
resultList.add(targetInfo); |
|||
} |
|||
} |
|||
return resultList; |
|||
} |
|||
|
|||
} |
@ -1,141 +0,0 @@ |
|||
package com.qs.serve.modules.tzc.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.qs.serve.common.model.annotation.SysLog; |
|||
import com.qs.serve.common.model.dto.PageVo; |
|||
import com.qs.serve.common.model.dto.R; |
|||
import com.qs.serve.common.model.enums.BizType; |
|||
import com.qs.serve.common.model.enums.SystemModule; |
|||
import com.qs.serve.common.util.Assert; |
|||
import com.qs.serve.common.util.PageUtil; |
|||
import com.qs.serve.common.util.CopierUtil; |
|||
import com.qs.serve.common.util.StringUtils; |
|||
import com.qs.serve.modules.tzc.entity.TzcPolicy; |
|||
import com.qs.serve.modules.tzc.entity.TzcPolicyItem; |
|||
import com.qs.serve.modules.tzc.service.TzcPolicyService; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import com.qs.serve.modules.tzc.entity.bo.TzcPolicyGoodsBo; |
|||
import com.qs.serve.modules.tzc.entity.TzcPolicyGoods; |
|||
import com.qs.serve.modules.tzc.service.TzcPolicyGoodsService; |
|||
|
|||
import javax.validation.Valid; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 政策 政策商品 |
|||
* @author YenHex |
|||
* @since 2023-02-20 |
|||
*/ |
|||
@Slf4j |
|||
@AllArgsConstructor |
|||
@RestController |
|||
@RequestMapping("tzc/policyGoods") |
|||
public class TzcPolicyGoodsController { |
|||
|
|||
private TzcPolicyService tzcPolicyService; |
|||
private TzcPolicyGoodsService tzcPolicyGoodsService; |
|||
|
|||
/** |
|||
* 列表 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@GetMapping("/list") |
|||
public R<List<TzcPolicyGoods>> getList(TzcPolicyGoods param){ |
|||
LambdaQueryWrapper<TzcPolicyGoods> lqw = new LambdaQueryWrapper<>(param); |
|||
List<TzcPolicyGoods> list = tzcPolicyGoodsService.list(lqw); |
|||
return R.ok(list); |
|||
} |
|||
|
|||
/** |
|||
* 翻页 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@GetMapping("/page") |
|||
public R<PageVo<TzcPolicyGoods>> getPage(TzcPolicyGoods param){ |
|||
LambdaQueryWrapper<TzcPolicyGoods> lqw = new LambdaQueryWrapper<>(param); |
|||
PageUtil.startPage(); |
|||
List<TzcPolicyGoods> list = tzcPolicyGoodsService.list(lqw); |
|||
return R.byPageHelperList(list); |
|||
} |
|||
|
|||
/** |
|||
* ID查询 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
@GetMapping("/getById/{id}") |
|||
@SysLog(module = SystemModule.Policy, title = "政策商品", biz = BizType.QUERY) |
|||
public R<TzcPolicyGoods> getById(@PathVariable("id") String id){ |
|||
TzcPolicyGoods tzcPolicyGoods = tzcPolicyGoodsService.getById(id); |
|||
return R.ok(tzcPolicyGoods); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 更新 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/updateById") |
|||
@SysLog(module = SystemModule.Policy, title = "政策商品", biz = BizType.UPDATE) |
|||
@PreAuthorize("hasRole('tzc:policy:insert')") |
|||
public R<?> updateById(@RequestBody @Valid TzcPolicyGoodsBo param){ |
|||
TzcPolicy tzcPolicy = tzcPolicyService.getById(param.getPolicyId()); |
|||
if(!tzcPolicy.allowEditFlag()){ |
|||
return R.error("当前状态不支持编辑"); |
|||
} |
|||
TzcPolicyGoods entity = CopierUtil.copy(param,new TzcPolicyGoods()); |
|||
boolean result = tzcPolicyGoodsService.updateById(entity); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
/** |
|||
* 新增 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/save") |
|||
@SysLog(module = SystemModule.Policy, title = "政策商品", biz = BizType.INSERT) |
|||
@PreAuthorize("hasRole('tzc:policy:insert')") |
|||
public R<?> save(@RequestBody @Valid TzcPolicyGoodsBo param){ |
|||
TzcPolicy tzcPolicy = tzcPolicyService.getById(param.getPolicyId()); |
|||
if(!tzcPolicy.allowEditFlag()){ |
|||
return R.error("当前状态不支持编辑"); |
|||
} |
|||
TzcPolicyGoods entity = CopierUtil.copy(param,new TzcPolicyGoods()); |
|||
boolean result = tzcPolicyGoodsService.save(entity); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
/** |
|||
* 删除 |
|||
* @param ids |
|||
* @return |
|||
*/ |
|||
@DeleteMapping("/deleteById/{ids}") |
|||
@SysLog(module = SystemModule.Policy, title = "政策商品", biz = BizType.DELETE) |
|||
@PreAuthorize("hasRole('tzc:policy:insert')") |
|||
public R<?> deleteById(@PathVariable("ids") String ids){ |
|||
List<Long> idsLong = StringUtils.splitIdLong(ids); |
|||
List<TzcPolicyGoods> policyGoods = tzcPolicyGoodsService.listByIds(idsLong); |
|||
List<Long> policyIdsList = policyGoods.stream().map(TzcPolicyGoods::getPolicyId).distinct().collect(Collectors.toList()); |
|||
List<TzcPolicy> policyList = tzcPolicyService.listByIds(policyIdsList); |
|||
policyList.forEach(a->{ |
|||
if(!a.allowEditFlag()){ |
|||
Assert.throwEx("当前状态不支持编辑"); |
|||
} |
|||
}); |
|||
boolean result = tzcPolicyGoodsService.removeByIds(idsLong); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
} |
|||
|
Loading…
Reference in new issue