12 changed files with 520 additions and 351 deletions
@ -0,0 +1,29 @@ |
|||||
|
package com.qs.serve.modules.goods.common; |
||||
|
|
||||
|
import com.qs.serve.common.util.StringUtils; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2024/8/28 |
||||
|
*/ |
||||
|
public class GoodsSpuColumnUtil { |
||||
|
|
||||
|
private static Map<String,String> ORDER_SPU_COLUMN = new HashMap<>(); |
||||
|
|
||||
|
static { |
||||
|
ORDER_SPU_COLUMN.put("createTime","goods_spu.create_time"); |
||||
|
ORDER_SPU_COLUMN.put("updateTime","goods_spu.update_time"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static String getSpuColumn(String orderProp){ |
||||
|
if(!StringUtils.hasText(orderProp)){ |
||||
|
return null; |
||||
|
} |
||||
|
return ORDER_SPU_COLUMN.get(orderProp); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,357 @@ |
|||||
|
package com.qs.serve.modules.goods.controller; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollUtil; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
|
import com.qs.serve.common.config.DevEnvironmentConfig; |
||||
|
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.*; |
||||
|
import com.qs.serve.modules.bms.common.BookAccountUtil; |
||||
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
||||
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
||||
|
import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; |
||||
|
import com.qs.serve.modules.goods.common.GoodsConst; |
||||
|
import com.qs.serve.modules.goods.entity.*; |
||||
|
import com.qs.serve.modules.goods.entity.bo.GoodsSpuBo; |
||||
|
import com.qs.serve.modules.goods.entity.bo.GoodsSpuImportBo; |
||||
|
import com.qs.serve.modules.goods.entity.dto.GoodsAccrIdsDto; |
||||
|
import com.qs.serve.modules.goods.entity.dto.GoodsRuleItemDTO; |
||||
|
import com.qs.serve.modules.goods.entity.dto.InventoryCusPrice; |
||||
|
import com.qs.serve.modules.goods.entity.so.GoodsHisOrderQuery; |
||||
|
import com.qs.serve.modules.goods.entity.vo.GoodsSpuExportVo; |
||||
|
import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo; |
||||
|
import com.qs.serve.modules.goods.mapper.GoodsSkuMapper; |
||||
|
import com.qs.serve.modules.goods.mapper.GoodsSpuMapper; |
||||
|
import com.qs.serve.modules.goods.service.*; |
||||
|
import com.qs.serve.modules.oms.entity.dto.OmsSpuToSkuKey; |
||||
|
import com.qs.serve.modules.seeyon.service.impl.SeeYonRequestBaseService; |
||||
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
||||
|
import com.qs.serve.modules.tbs.service.TbsActivityGoodsService; |
||||
|
import com.qs.serve.modules.tbs.service.TbsBudgetConditionService; |
||||
|
import io.netty.util.internal.StringUtil; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.jetbrains.annotations.NotNull; |
||||
|
import org.jetbrains.annotations.Nullable; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.validation.Valid; |
||||
|
import java.time.LocalDate; |
||||
|
import java.util.*; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 商品 spu |
||||
|
* @author YenHex |
||||
|
* @since 2022-10-09 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@AllArgsConstructor |
||||
|
@RestController |
||||
|
@RequestMapping("goods/spu") |
||||
|
public class GoodsSpuOptionController { |
||||
|
|
||||
|
private GoodsSpuMapper goodsSpuMapper; |
||||
|
private GoodsSkuMapper goodsSkuMapper; |
||||
|
private GoodsRuleService goodsRuleService; |
||||
|
private GoodsSkuService goodsSkuService; |
||||
|
private GoodsSpuService goodsSpuService; |
||||
|
private GoodsSpuSpecService goodsSpuSpecService; |
||||
|
private GoodsSkuSpecValueService goodsSkuSpecValueService; |
||||
|
private GoodsCategoryRuleService goodsCategoryRuleService; |
||||
|
private TbsActivityGoodsService activityGoodsService; |
||||
|
private TbsBudgetConditionService budgetConditionService; |
||||
|
private BmsSupplierService bmsSupplierService; |
||||
|
private GoodsCategoryService goodsCategoryService; |
||||
|
private SeeYonRequestBaseService seeYonRequestBaseService; |
||||
|
private ErpDispatchDataMapper dispatchDataMapper; |
||||
|
private GoodsAccreditService goodsAccreditService; |
||||
|
private GoodsCustomerPriceService goodsCustomerPriceService; |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 商品上下架 |
||||
|
* @param spuId |
||||
|
* @param shelf |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/shelf") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.UPDATE) |
||||
|
@PreAuthorize("hasRole('goods:spu:update')") |
||||
|
public R<?> updateById(Long spuId,Integer shelf){ |
||||
|
GoodsSpu goodsSpu = new GoodsSpu(); |
||||
|
goodsSpu.setId(spuId); |
||||
|
goodsSpu.setShelf(shelf); |
||||
|
goodsSpuService.updateById(goodsSpu); |
||||
|
return R.ok(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 翻页搜索 |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/initSkuNum") |
||||
|
public R<List<GoodsSpu>> initSkuNum(){ |
||||
|
goodsSpuService.initSkuNum(); |
||||
|
return R.ok(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 更新spu下单状态 |
||||
|
* @param spuCode |
||||
|
* @param state |
||||
|
* @return |
||||
|
*/ |
||||
|
@PutMapping("/orderState/{spuCode}/{state}") |
||||
|
public R<?> updateOrderState(@PathVariable("spuCode")String spuCode, |
||||
|
@PathVariable("state") Integer state){ |
||||
|
boolean ok = goodsSpuService.update(new LambdaUpdateWrapper<GoodsSpu>() |
||||
|
.eq(GoodsSpu::getSpuCode,spuCode).set(GoodsSpu::getOrderFlag,state)); |
||||
|
return R.isTrue(ok); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* @param id |
||||
|
* @return |
||||
|
*/ |
||||
|
@DeleteMapping("/deleteById/{id}") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.DELETE) |
||||
|
@PreAuthorize("hasRole('goods:spu:delete')") |
||||
|
public R<?> deleteById(@PathVariable("id") Long id){ |
||||
|
QueryWrapper lqw1 = new QueryWrapper<>(); |
||||
|
lqw1.in("target_type", TbsGoodsType.spu.name()); |
||||
|
lqw1.eq("target_id",id); |
||||
|
if(activityGoodsService.count(lqw1)>0){ |
||||
|
return R.error("活动含有当前商品,删除失败"); |
||||
|
} |
||||
|
if(budgetConditionService.count(lqw1)>0){ |
||||
|
return R.error("预算含有当前商品,删除失败"); |
||||
|
} |
||||
|
goodsSpuMapper.updateSpuCodeAndDelFlag(id,IdUtil.timeStampId()); |
||||
|
//删除商品规格
|
||||
|
LambdaQueryWrapper<GoodsSpuSpec> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.eq(GoodsSpuSpec::getSpuId,id); |
||||
|
goodsSpuSpecService.remove(lqw); |
||||
|
//删除商品规格值
|
||||
|
LambdaQueryWrapper<GoodsSkuSpecValue> lqw2 = new LambdaQueryWrapper<>(); |
||||
|
lqw2.eq(GoodsSkuSpecValue::getSpuId,id); |
||||
|
goodsSkuSpecValueService.remove(lqw2); |
||||
|
//删除商品sku
|
||||
|
LambdaQueryWrapper<GoodsSku> lqw3 = new LambdaQueryWrapper<>(); |
||||
|
lqw3.eq(GoodsSku::getSpuId,id); |
||||
|
goodsSkuService.remove(lqw3); |
||||
|
return R.ok(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存 口味品类SPU |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/saveTasteSpu") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.INSERT) |
||||
|
@PreAuthorize("hasRole('goods:spu:insert')") |
||||
|
public R<?> saveTasteSpu(@RequestBody @Valid GoodsSpuBo param){ |
||||
|
param.setId(null); |
||||
|
if(StringUtil.isNullOrEmpty(param.getCategoryId())){ |
||||
|
return R.error("参数缺少"); |
||||
|
} |
||||
|
return R.ok(goodsSpuService.editTasteSpu(param)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 口味品类SPU |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/updTasteSpu") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.INSERT) |
||||
|
@PreAuthorize("hasRole('goods:spu:update')") |
||||
|
public R<?> updTasteSpu(@RequestBody @Valid GoodsSpuBo param){ |
||||
|
if(param.getId()==null){ |
||||
|
return R.error(); |
||||
|
} |
||||
|
return R.ok(goodsSpuService.editTasteSpu(param)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 导入 |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/importSpu") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "import", biz = BizType.INSERT) |
||||
|
public R<?> importSpu(@RequestBody @Valid GoodsSpuImportBo param){ |
||||
|
final String UPDATE = "2"; |
||||
|
final String DELETE = "3"; |
||||
|
final String SAVE = "1"; |
||||
|
final String NONE = "4"; |
||||
|
|
||||
|
//导入
|
||||
|
List<String> spuCodes = new ArrayList<>(); |
||||
|
List<String> cateCodes = new ArrayList<>(); |
||||
|
for (GoodsSpuImportBo.SpuItem item : param.getSpuList()) { |
||||
|
spuCodes.add(item.getSpuCode()); |
||||
|
//删除只需要spu编码
|
||||
|
if(StringUtils.hasText(item.getCategoryCode())&&!item.getOpt().equals(DELETE)){ |
||||
|
cateCodes.add(item.getCategoryCode()); |
||||
|
} |
||||
|
} |
||||
|
if(spuCodes.size()<1){ |
||||
|
return R.error("获取SKU编码失败"); |
||||
|
} |
||||
|
LambdaQueryWrapper<GoodsSpu> spuLqw = new LambdaQueryWrapper<>(); |
||||
|
spuLqw.in(GoodsSpu::getSpuCode,spuCodes); |
||||
|
List<GoodsSpu> spuList = goodsSpuService.list(spuLqw); |
||||
|
|
||||
|
List<GoodsCategory> cateList = null; |
||||
|
if(cateCodes.size()>0){ |
||||
|
LambdaQueryWrapper<GoodsCategory> cateLqw = new LambdaQueryWrapper<>(); |
||||
|
cateLqw.in(GoodsCategory::getCode,cateCodes); |
||||
|
cateLqw.eq(GoodsCategory::getLevel,3); |
||||
|
cateList = goodsCategoryService.list(cateLqw); |
||||
|
} |
||||
|
|
||||
|
boolean isError = false; |
||||
|
for (GoodsSpuImportBo.SpuItem item : param.getSpuList()) { |
||||
|
if(item.getOpt().equals(NONE)){ |
||||
|
continue; |
||||
|
} |
||||
|
spuCodes.add(item.getSpuCode()); |
||||
|
//更新或者保存,需要校验类目名称
|
||||
|
if(StringUtils.hasText(item.getCategoryCode())&&!item.getOpt().equals(DELETE)){ |
||||
|
if(cateList==null){ |
||||
|
isError = true; |
||||
|
item.setErrMsg("["+item.getCategoryCode()+"]类目不存在"); |
||||
|
}else { |
||||
|
String cateName = item.getCategoryCode(); |
||||
|
boolean existCate = cateList.stream().anyMatch(a->a.getCode().equals(cateName)); |
||||
|
if(!existCate){ |
||||
|
isError = true; |
||||
|
item.setErrMsg("["+item.getCategoryCode()+"]类目不存在"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
String spuCode = item.getSpuCode(); |
||||
|
boolean existSpu = spuList.stream().anyMatch(a->a.getSpuCode().equals(spuCode)); |
||||
|
|
||||
|
if(existSpu&&item.getOpt().equals(SAVE)){ |
||||
|
isError = true; |
||||
|
item.setErrMsg("SKU编码已存在"); |
||||
|
}else if(!existSpu && item.getOpt().equals(UPDATE)){ |
||||
|
isError = true; |
||||
|
item.setErrMsg("SKU编码不存在"); |
||||
|
} |
||||
|
long count = goodsSpuService.count(new LambdaQueryWrapper<GoodsSpu>() |
||||
|
.eq(GoodsSpu::getName,item.getName()) |
||||
|
.ne(GoodsSpu::getSpuCode,spuCode) |
||||
|
); |
||||
|
if(count>0){ |
||||
|
isError = true; |
||||
|
item.setErrMsg("SKU名称已存在"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if(isError){ |
||||
|
return R.ok(param,"数据错误"); |
||||
|
} |
||||
|
|
||||
|
List<Long> rmIds = new ArrayList<>(); |
||||
|
List<GoodsSpu> spuUpdateList = new ArrayList<>(); |
||||
|
List<GoodsSpu> spuSaveList = new ArrayList<>(); |
||||
|
|
||||
|
for (GoodsSpuImportBo.SpuItem spuItem : param.getSpuList()) { |
||||
|
|
||||
|
if(spuItem.getOpt().equals(SAVE)){ |
||||
|
GoodsSpu goodsSpu = new GoodsSpu(); |
||||
|
goodsSpu.setSpuCode(spuItem.getSpuCode()); |
||||
|
goodsSpu.setName(spuItem.getName()); |
||||
|
//修改类目
|
||||
|
this.toSetSpuCate(cateList, spuItem, goodsSpu); |
||||
|
goodsSpu.setShelf(spuItem.getShelf()); |
||||
|
goodsSpu.setCostFlag(spuItem.getCostFlag()); |
||||
|
goodsSpu.setOrderFlag(spuItem.getOrderFlag()); |
||||
|
goodsSpu.setSpuCunhuoFlag(spuItem.getSpuCunhuoFlag()); |
||||
|
spuSaveList.add(goodsSpu); |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
for (GoodsSpu spu : spuList) { |
||||
|
if(spu.getSpuCode().equals(spuItem.getSpuCode())){ |
||||
|
if(spuItem.getOpt().equals(NONE)){ |
||||
|
continue; |
||||
|
} |
||||
|
//删除
|
||||
|
if(spuItem.getOpt().equals(DELETE)){ |
||||
|
rmIds.add(spu.getId()); |
||||
|
continue; |
||||
|
} |
||||
|
//更新start
|
||||
|
if(StringUtils.hasText(spuItem.getName())){ |
||||
|
spu.setName(spuItem.getName()); |
||||
|
} |
||||
|
spu.setShelf(spuItem.getShelf()); |
||||
|
spu.setCostFlag(spuItem.getCostFlag()); |
||||
|
spu.setOrderFlag(spuItem.getOrderFlag()); |
||||
|
spu.setSpuCunhuoFlag(spuItem.getSpuCunhuoFlag()); |
||||
|
//修改类目
|
||||
|
this.toSetSpuCate(cateList, spuItem, spu); |
||||
|
//关联
|
||||
|
if(spuItem.getOpt().equals(UPDATE)){ |
||||
|
spuUpdateList.add(spu); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if(rmIds.size()>0){ |
||||
|
goodsSpuService.removeBatchByIds(rmIds); |
||||
|
} |
||||
|
if(spuUpdateList.size()>0){ |
||||
|
goodsSpuService.updateBatchById(spuUpdateList); |
||||
|
} |
||||
|
if(spuSaveList.size()>0){ |
||||
|
goodsSpuService.saveBatch(spuSaveList); |
||||
|
} |
||||
|
|
||||
|
return R.ok(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改类目 |
||||
|
* @param cateList |
||||
|
* @param spuItem |
||||
|
* @param spu |
||||
|
*/ |
||||
|
private void toSetSpuCate(List<GoodsCategory> cateList, GoodsSpuImportBo.SpuItem spuItem, GoodsSpu spu) { |
||||
|
if(cateList !=null){ |
||||
|
for (GoodsCategory category : cateList) { |
||||
|
if(category.getCode().equals(spuItem.getCategoryCode())){ |
||||
|
spu.setBookName(category.getBookName()); |
||||
|
spu.setBookBelong(category.getBookBelong()); |
||||
|
String[] cateIds = category.getLevelPath().split("_"); |
||||
|
if(cateIds.length==3){ |
||||
|
spu.setCategoryFirst(cateIds[0]); |
||||
|
spu.setCategorySecond(cateIds[1]); |
||||
|
spu.setCategoryThird(cateIds[2]); |
||||
|
spu.setCategoryLast(cateIds[2]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
Loading…
Reference in new issue