Browse Source

同步Stand商品

v1.0
Yen 2 years ago
parent
commit
50b09a21e9
  1. 29
      src/main/java/com/qs/serve/modules/goods/controller/GoodsSyncController.java
  2. 2
      src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java
  3. 6
      src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsCategoryTreeVo.java
  4. 34
      src/main/java/com/qs/serve/modules/goods/entity/dto/StandInventory.java
  5. 100
      src/main/java/com/qs/serve/modules/goods/mapper/GoodsCrmSkuMapper.java
  6. 134
      src/main/java/com/qs/serve/modules/goods/service/GoodsApplicationService.java
  7. 3
      src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java
  8. 26
      src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java
  9. 5
      src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsCostBudgetRelateInfo.java
  10. 1
      src/main/resources/mapper/goods/GoodsSkuMapper.xml
  11. 1
      src/main/resources/mapper/goods/GoodsSpuMapper.xml

29
src/main/java/com/qs/serve/modules/goods/controller/GoodsSyncController.java

@ -0,0 +1,29 @@
package com.qs.serve.modules.goods.controller;
import com.qs.serve.common.model.dto.R;
import com.qs.serve.modules.goods.service.GoodsApplicationService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author YenHex
* @since 2023/11/22
*/
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("goods/sync")
public class GoodsSyncController {
private GoodsApplicationService goodsApplicationService;
@GetMapping("/stand")
public R<?> toStandList(Integer fullUpdate){
goodsApplicationService.syncStandGoods(fullUpdate!=null&&fullUpdate==1);
return R.ok();
}
}

2
src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java

@ -122,7 +122,7 @@ public class GoodsSpu implements Serializable {
/** 展示的价格 */
@TableField(exist = false)
private Double showPrice = 123D;
private Double showPrice = 0D;
/** 选中的类目ID */
@TableField(exist = false)

6
src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsCategoryTreeVo.java

@ -31,6 +31,12 @@ public class GoodsCategoryTreeVo extends TreeNode {
@Length(max = 32,message = "父分类编号长度不能超过32字")
private String parentId;
/** 等级路径id */
private String levelPath;
/** 等级路径 */
private String levelPathNames;
/** 名称 */
@Length(max = 16,message = "名称长度不能超过16字")
private String name;

34
src/main/java/com/qs/serve/modules/goods/entity/dto/StandInventory.java

@ -0,0 +1,34 @@
package com.qs.serve.modules.goods.entity.dto;
import lombok.Data;
/**
* @author YenHex
* @since 2023/11/21
*/
@Data
public class StandInventory {
private String id;
private String invCode;
private String invName;
private String invSku;
private String invSkuCode;
private String invSeries;
private String invCategory;
private String invBrand;
private String invOrderStatus;
private String invCostStatus;
private String chestCasing;
private String invUnitWeight;
private String invUnit;
private String invVolume;
private String invWeight;
private String invGrossWeight;
private String invPlace;
private String invTaste;
private String invStartDate;
private String invEndDate;
private String rowCreateTime;
}

100
src/main/java/com/qs/serve/modules/goods/mapper/GoodsCrmSkuMapper.java

@ -0,0 +1,100 @@
package com.qs.serve.modules.goods.mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.List;
/**
* @author YenHex
* @since 2023/11/21
*/
public interface GoodsCrmSkuMapper {
/**
* 上架商品
* @param codes
* @return
*/
@Update("<script>" +
"update goods_sku set `enable` = 1 where sku_code in " +
" <foreach collection='invCodes' item='invCode' open='(' separator=',' close=')'> "+
" #{invCode} "+
" </foreach> " +
"</script>")
int updateShelfOnInCodes(@Param("invCodes")List<String> codes);
/**
* 下架商品
* @param codes
* @return
*/
@Update("<script>" +
"update goods_sku set `enable` = 0 where sku_code not in " +
" <foreach collection='invCodes' item='invCode' open='(' separator=',' close=')'> "+
" #{invCode} "+
" </foreach> " +
"</script>")
int updateShelfOffNotInCodes(@Param("invCodes")List<String> codes);
/**
* 设置非特殊品
* @param codes
* @return
*/
@Update("<script>" +
"update goods_sku set `special_flag` = 0 where sku_code not in " +
" <foreach collection='invCodes' item='invCode' open='(' separator=',' close=')'> "+
" #{invCode} "+
" </foreach> " +
"</script>")
int updateSpecialNotInCodes(@Param("invCodes")List<String> codes);
/**
* 设置特殊品
* @param codes
* @return
*/
@Update("<script>" +
"update goods_sku set `special_flag` = 1 where sku_code in " +
" <foreach collection='invCodes' item='invCode' open='(' separator=',' close=')'> "+
" #{invCode} "+
" </foreach> " +
"</script>")
int updateSpecialInCodes(@Param("invCodes")List<String> codes);
/**
* 根据sku修改spu非特殊品
* @return
*/
@Update("update goods_spu set goods_spu.special_sku_id = 0 " +
"where goods_spu.id not in ( " +
" select spu_id from goods_sku where goods_spu.special_sku_id is not null and goods_spu.special_sku_id !=0 )")
int updateSpuSpecialIdBySku();
/**
* 根据sku状态更新spu上架状态
* @return
*/
@Update("update goods_spu set shelf = 0 where goods_spu.id not in ( " +
" select goods_sku.spu_id from goods_sku where goods_sku.`enable` = 1 " +
") ")
int updateSpuShelfBySku();
//设置错误的产地,下架
//select concat(spu_id,'_',belong) tmp,count(1) from goods_sku where `enable` = 1 and special_flag = 0 group by tmp HAVING count(1)>1
/**
* 根据sku是否特殊商品更新spu特殊商品标识
* @return
*/
@Update("update goods_spu " +
" left join " +
" (select goods_sku.spu_id,goods_sku.id as sku_id from goods_sku where goods_sku.`enable` = 1 and special_flag = 1) sku_tmp" +
" on sku_tmp.spu_id = goods_spu.id" +
" set goods_spu.special_sku_id = sku_tmp.sku_id " +
" where sku_tmp.sku_id is not null ")
int updateSpuSpecSkuId();
}

134
src/main/java/com/qs/serve/modules/goods/service/GoodsApplicationService.java

@ -1,5 +1,10 @@
package com.qs.serve.modules.goods.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qs.serve.common.model.dto.R;
import com.qs.serve.common.util.AuthContextUtils;
import com.qs.serve.common.util.JsonUtil;
import com.qs.serve.common.util.StringUtils;
import com.qs.serve.modules.bms.service.BmsChannelPointService;
import com.qs.serve.modules.bms.service.BmsChannelService;
import com.qs.serve.modules.bms.service.BmsSubjectService;
@ -9,15 +14,19 @@ 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.goods.entity.dto.StandInventory;
import com.qs.serve.modules.goods.mapper.GoodsCrmSkuMapper;
import com.qs.serve.modules.seeyon.service.impl.SeeYonRequestBaseService;
import com.qs.serve.modules.tbs.common.TbsGoodsType;
import com.qs.serve.modules.tbs.common.TbsSeeYonConst;
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;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author YenHex
@ -31,8 +40,127 @@ public class GoodsApplicationService {
private final GoodsSkuService goodsSkuService;
private final GoodsSpuService goodsSpuService;
private final GoodsCategoryService goodsCategoryService;
private final SeeYonRequestBaseService seeYonRequestBaseService;
private final GoodsCrmSkuMapper goodsCrmSkuMapper;
public void syncStandGoods(boolean isFullUpdate){
//兼容任务调度
AuthContextUtils.setTenant("001");
//获取stand表的存货
R<String> result = seeYonRequestBaseService.getBase(TbsSeeYonConst.ERP_CUS_INV_STAND,"");
String listJson = result.getData();
List<StandInventory> inventoryList = JsonUtil.jsonToList(listJson,StandInventory.class);
List<String> spuCodes = inventoryList.stream().map(StandInventory::getInvSkuCode).distinct().collect(Collectors.toList());
List<String> skuCodes = inventoryList.stream().map(StandInventory::getInvCode).distinct().collect(Collectors.toList());
LambdaQueryWrapper<GoodsSpu> spuLqw = new LambdaQueryWrapper<>();
spuLqw.select(GoodsSpu::getId,GoodsSpu::getSpuCode);
spuLqw.in(GoodsSpu::getSpuCode,spuCodes);
List<GoodsSpu> goodsSpuList = goodsSpuService.list(spuLqw);
Map<String,Long> spuCodeGetIdMap = new HashMap<>();
for (GoodsSpu spu : goodsSpuList) {
spuCodeGetIdMap.put(spu.getSpuCode(),spu.getId());
}
LambdaQueryWrapper<GoodsSku> skuLqw = new LambdaQueryWrapper<>();
skuLqw.select(GoodsSku::getId,GoodsSku::getSkuCode);
skuLqw.in(GoodsSku::getSkuCode,skuCodes);
List<GoodsSku> skus = goodsSkuService.list(skuLqw);
Map<String,Long> skuCodeGetIdMap = new HashMap<>();
for (GoodsSku sku : skus) {
skuCodeGetIdMap.put(sku.getSkuCode(),sku.getId());
}
//更新sku
for (StandInventory inventory : inventoryList) {
//空值 默认开平
if(inventory.getInvPlace()==null){
inventory.setInvPlace("开平");
}
//开平康力 改 康力
if("开平康力".equals(inventory.getInvPlace())){
inventory.setInvPlace("康力");
}
//移除产字眼
inventory.setInvPlace(inventory.getInvPlace().replace("产",""));
Long skuId = skuCodeGetIdMap.get(inventory.getInvCode());
Long spuId = spuCodeGetIdMap.get(inventory.getInvSkuCode());
if(!isFullUpdate&&skuId!=null){
continue;
}
if(spuId==null){
//add new spu
GoodsSpu spu = new GoodsSpu();
spu.setId(spuId);
spu.setSpuCode(inventory.getInvSkuCode());
spu.setName(inventory.getInvSku());
//匹配类目
LambdaQueryWrapper<GoodsCategory> cateLqw = new LambdaQueryWrapper<>();
cateLqw.likeRight(GoodsCategory::getLevelPathNames,inventory.getInvBrand())
.likeLeft(GoodsCategory::getLevelPathNames,inventory.getInvSeries())
.like(GoodsCategory::getLevelPathNames,inventory.getInvCategory());
List<GoodsCategory> categoryList = goodsCategoryService.list(cateLqw);
if(categoryList.size()>0){
GoodsCategory goodsCategory = categoryList.get(0);
String[] cateIds = goodsCategory.getLevelPath().split("_");
if(cateIds.length>2){
spu.setCategoryFirst(cateIds[0]);
spu.setCategorySecond(cateIds[1]);
spu.setCategoryThird(cateIds[2]);
spu.setCategoryLast(cateIds[2]);
}
}
if(spu.getCategoryFirst()==null) {
spu.setCategoryFirst("1");
spu.setCategorySecond("2");
spu.setCategoryThird("3");
spu.setCategoryLast("3");
}
spu.setShelf(1);
spu.setOrderFlag(Integer.parseInt(inventory.getInvOrderStatus()));
spu.setCostFlag(Integer.parseInt(inventory.getInvCostStatus()));
goodsSpuService.save(spu);
//防止多次保存
spuId = spu.getId();
spuCodeGetIdMap.put(spu.getSpuCode(),spuId);
}
GoodsSku sku = new GoodsSku();
sku.setId(skuId);
sku.setSkuCode(inventory.getInvCode());
sku.setSkuName(inventory.getInvName());
sku.setSpuId(spuId);
sku.setSpecInfos(inventory.getInvPlace()+";"+inventory.getInvTaste()+";"+inventory.getChestCasing());
if(StringUtils.hasText(inventory.getInvWeight())){
sku.setWeight(new BigDecimal(inventory.getInvWeight()));
}
if(StringUtils.hasText(inventory.getInvVolume())){
sku.setVolume(new BigDecimal(inventory.getInvVolume()));
}
sku.setOrderFlag(Integer.parseInt(inventory.getInvOrderStatus()));
sku.setUnitId(0L);
sku.setUnitName(inventory.getInvUnit());
sku.setBelong(inventory.getInvPlace());
sku.setWrapVal(inventory.getChestCasing());
sku.setTasteVal(inventory.getInvTaste());
sku.setCostFlag(Integer.parseInt(inventory.getInvCostStatus()));
if(sku.getId()==null){
sku.setSalesPrice(BigDecimal.ZERO);
sku.setMarketPrice(BigDecimal.ZERO);
sku.setCostPrice(BigDecimal.ZERO);
goodsSkuService.save(sku);
}else {
goodsSkuService.updateById(sku);
}
}
//更新商品状态
seeYonRequestBaseService.getBase(TbsSeeYonConst.ERP_CUS_INV_SPECIAL,"");
seeYonRequestBaseService.getBase(TbsSeeYonConst.ERP_CUS_INV_SHELF,"");
}
public GoodsTargetInfo getGoodsTargetInfo(String goodsType,Long goodsIds){
List<GoodsTargetInfo> list = this.getGoodsTargetInfo(goodsType, Arrays.asList(goodsIds));
if(list.size()>0){

3
src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java

@ -89,6 +89,9 @@ public interface TbsSeeYonConst {
/** 客户账单余额 */
String ERP_CUS_AMOUNT = "/erp/customer/amount";
String ERP_CUS_INV_PRICE = "/erp/inventory/invPrices";
String ERP_CUS_INV_STAND = "/erp/inventory/standList";
String ERP_CUS_INV_SPECIAL = "/erp/inventory/specialSyncCrm";
String ERP_CUS_INV_SHELF = "/erp/inventory/shelfSyncCrm";
String ERP_ORDER_CREATE = "/erp/order/create";
String ERP_ORDER_STATUS = "/erp/order/getStatus";
String ERP_ORDER_CANCEL = "/erp/order/cancelOrder";

26
src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java

@ -457,10 +457,20 @@ public class TbsCostApplyController {
* @return
*/
@GetMapping("/listBudgetInfo")
public R<List<TbsCostBudgetRelateInfo>> listBudgetInfo(String costApplyId){
public R<List<TbsCostBudgetRelateInfo>> listBudgetInfo(String costApplyId,String policyId){
LambdaQueryWrapper<TbsBudgetLog> loadCostLogLqw = new LambdaQueryWrapper<>();
loadCostLogLqw.eq(TbsBudgetLog::getCostApplyId,costApplyId);
if(costApplyId!=null){
loadCostLogLqw.eq(TbsBudgetLog::getCostApplyId,costApplyId);
}else if(policyId!=null){
loadCostLogLqw.eq(TbsBudgetLog::getPolicyId,policyId);
}else {
return R.error("error params");
}
List<TbsBudgetLog> costApplyBudgetLogs = tbsBudgetLogService.list(loadCostLogLqw);
if(costApplyBudgetLogs.size()<1){
return R.ok();
}
Map<Long,List<TbsBudgetLog>> groupCurrentMap = costApplyBudgetLogs.stream().collect(Collectors.groupingBy(TbsBudgetLog::getScheduleItemBudgetId));
List<Long> budgetIds = costApplyBudgetLogs.stream().map(TbsBudgetLog::getBudgetId).distinct().collect(Collectors.toList());
List<TbsCostBudgetRelateInfo> resultInfoList = new ArrayList<>();
for (Long budgetId : budgetIds) {
@ -479,7 +489,17 @@ public class TbsCostApplyController {
for (TbsCostBudgetRelateInfo info : relateInfoList) {
for (TbsScheduleItemBudget itemBudget : scheduleItemBudgetList) {
if(info.getScheduleItemBudgetId().equals(itemBudget.getId())){
info.setScheduleName(itemBudget.getItemName());
info.setScheduleItemName(itemBudget.getItemName());
//关联当前项
List<TbsBudgetLog> budgetLogList = groupCurrentMap.get(itemBudget.getId());
BigDecimal currentAmt = BigDecimal.ZERO;
if(budgetLogList!=null){
for (TbsBudgetLog budgetLog : budgetLogList) {
//log负数,取正数
currentAmt = currentAmt.add(budgetLog.getAmount().negate());
}
}
info.setCurrentItemAmt(currentAmt);
break;
}
}

5
src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsCostBudgetRelateInfo.java

@ -18,6 +18,9 @@ public class TbsCostBudgetRelateInfo extends TbsBudgetScheduleWithAmount{
String budgetTitle;
/** 周期名称 */
String scheduleName;
String scheduleItemName;
/** 当前政策或费用占用 */
BigDecimal currentItemAmt;
}

1
src/main/resources/mapper/goods/GoodsSkuMapper.xml

@ -57,6 +57,7 @@
goods_sku.`create_by`,
goods_sku.`cost_flag`,
goods_sku.`update_by`,
goods_sku.`special_flag`,
goods_sku.`belong`
</sql>

1
src/main/resources/mapper/goods/GoodsSpuMapper.xml

@ -51,6 +51,7 @@
goods_spu.`tenant_id`,
goods_spu.`cost_flag`,
goods_spu.`del_flag`,
goods_spu.`special_sku_id`,
goods_spu.`belong`
</sql>

Loading…
Cancel
Save