思迅同步
This commit is contained in:
parent
48ecde00a5
commit
bc40ac66d6
@ -55,12 +55,12 @@ public class SxSyncCategory implements Serializable {
|
||||
@ApiModelProperty(value = "是否显示:1-前台显示 0-前台不显示")
|
||||
private Integer display_flag;
|
||||
|
||||
@ApiModelProperty(value = "同步时间戳")
|
||||
private Long sync_time;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "同步时间戳")
|
||||
private Long sync_time;
|
||||
|
||||
@ApiModelProperty(value = "新增时间")
|
||||
private Date created_at;
|
||||
|
||||
|
||||
@ -96,6 +96,12 @@ public class SxSyncGoods implements Serializable {
|
||||
@ApiModelProperty(value = "状态")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "同步时间戳")
|
||||
private Long sync_time;
|
||||
|
||||
@ApiModelProperty(value = "同步备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "新增时间")
|
||||
private Date created_at;
|
||||
|
||||
|
||||
@ -39,9 +39,6 @@ public class SxSyncVip implements Serializable {
|
||||
@ApiModelProperty(value = "店铺Id")
|
||||
private String store_id;
|
||||
|
||||
@ApiModelProperty(value = "会员编号")
|
||||
private String vip_no;
|
||||
|
||||
@ApiModelProperty(value = "会员名称")
|
||||
private String vip_name;
|
||||
|
||||
@ -54,7 +51,7 @@ public class SxSyncVip implements Serializable {
|
||||
@ApiModelProperty(value = "会员生日")
|
||||
private String birthday;
|
||||
|
||||
@ApiModelProperty(value = "会员卡号")
|
||||
@ApiModelProperty(value = "会员卡号(唯一键)")
|
||||
private String card_no;
|
||||
|
||||
@ApiModelProperty(value = "会员等级")
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.controller;
|
||||
|
||||
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.shop.sixun.service.SxSyncCategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(tags = "思迅同步商品分类")
|
||||
@RestController
|
||||
@RequestMapping("/admin/sixun/goods/category")
|
||||
public class SxSyncCategoryController {
|
||||
@Resource
|
||||
private SxSyncCategoryService sxSyncCategoryService;
|
||||
|
||||
@ApiOperation(value = "获取思迅商品分类新增到数据库", notes = "获取思迅商品分类新增到数据库")
|
||||
@RequestMapping(value = "/sync", method = RequestMethod.POST)
|
||||
public CommonResult list(@RequestParam(name = "storeId", defaultValue = "1") String storeId,
|
||||
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(name = "pageSize", defaultValue = "100") Integer pageSize) {
|
||||
|
||||
return sxSyncCategoryService.syncCategory(storeId, pageNum, pageSize);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.controller;
|
||||
|
||||
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.shop.sixun.service.SxSyncCategoryService;
|
||||
import com.suisung.mall.shop.sixun.service.SxSyncGoodsService;
|
||||
import com.suisung.mall.shop.sixun.service.SxSyncVipService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(tags = "思迅同步商品分类")
|
||||
@RestController
|
||||
@RequestMapping("/admin/sixun")
|
||||
public class SxSyncController {
|
||||
@Resource
|
||||
private SxSyncCategoryService sxSyncCategoryService;
|
||||
|
||||
@Resource
|
||||
private SxSyncVipService sxSyncVipService;
|
||||
|
||||
@Resource
|
||||
private SxSyncGoodsService sxSyncGoodsService;
|
||||
|
||||
@ApiOperation(value = "获取思迅商品分类新增到数据库", notes = "获取思迅商品分类新增到数据库")
|
||||
@RequestMapping(value = "/goods/category/sync", method = RequestMethod.POST)
|
||||
public CommonResult syncGoodsCategory(@RequestParam(name = "storeId", defaultValue = "1") String storeId,
|
||||
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(name = "pageSize", defaultValue = "100") Integer pageSize) {
|
||||
|
||||
return sxSyncCategoryService.syncCategory(storeId, pageNum, pageSize);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取思迅会员新增到数据库", notes = "获取思迅会员新增到数据库")
|
||||
@RequestMapping(value = "/vip/sync", method = RequestMethod.POST)
|
||||
public CommonResult syncVip(@RequestParam(name = "storeId", defaultValue = "1") String storeId,
|
||||
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(name = "pageSize", defaultValue = "100") Integer pageSize) {
|
||||
|
||||
return sxSyncVipService.syncVip(storeId, pageNum, pageSize);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取思迅商品新增到数据库", notes = "获取思迅商品新增到数据库")
|
||||
@RequestMapping(value = "/goods/sync", method = RequestMethod.POST)
|
||||
public CommonResult syncGoods(@RequestParam(name = "storeId", defaultValue = "1") String storeId,
|
||||
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(name = "pageSize", defaultValue = "100") Integer pageSize) {
|
||||
|
||||
return sxSyncGoodsService.syncGoods(storeId, pageNum, pageSize);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncGoodsLog;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SxSyncGoodsLogMapper extends BaseMapper<SxSyncGoodsLog> {
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncGoods;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SxSyncGoodsMapper extends BaseMapper<SxSyncGoods> {
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncPlanDetail;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SxSyncPlanDetailMapper extends BaseMapper<SxSyncPlanDetail> {
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncPlan;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SxSyncPlanMapper extends BaseMapper<SxSyncPlan> {
|
||||
}
|
||||
@ -9,7 +9,6 @@
|
||||
package com.suisung.mall.shop.sixun.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncCategory;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncVip;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.service;
|
||||
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncGoods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SxSyncGoodsLogService {
|
||||
|
||||
/**
|
||||
* 同步记录
|
||||
*
|
||||
* @param storeId
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
CommonResult syncGoods(String storeId, Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 新增记录,存在了就不新增
|
||||
*
|
||||
* @param sxSyncGoods
|
||||
* @return
|
||||
*/
|
||||
Integer insert(SxSyncGoods sxSyncGoods);
|
||||
|
||||
/**
|
||||
* 批量更新记录,有判断是否已存在逻辑
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
Integer insertBatch(String storeId, List<SxSyncGoods> list);
|
||||
|
||||
/**
|
||||
* 根据编号更新一条记录
|
||||
*
|
||||
* @param sxSyncGoods
|
||||
* @return
|
||||
*/
|
||||
Boolean updateByGoodsNo(SxSyncGoods sxSyncGoods);
|
||||
|
||||
/**
|
||||
* 根据编号获取一条记录
|
||||
*
|
||||
* @param storeId
|
||||
* @param goodsNo
|
||||
* @return
|
||||
*/
|
||||
SxSyncGoods getByGoodsNo(String storeId, String goodsNo);
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.service;
|
||||
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncGoods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SxSyncGoodsService {
|
||||
|
||||
/**
|
||||
* 同步记录
|
||||
*
|
||||
* @param storeId
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
CommonResult syncGoods(String storeId, Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 新增记录,存在了就不新增
|
||||
*
|
||||
* @param sxSyncGoods
|
||||
* @return
|
||||
*/
|
||||
Integer insert(SxSyncGoods sxSyncGoods);
|
||||
|
||||
/**
|
||||
* 批量更新记录,有判断是否已存在逻辑
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
Integer insertBatch(String storeId, List<SxSyncGoods> list);
|
||||
|
||||
/**
|
||||
* 根据编号更新一条记录
|
||||
*
|
||||
* @param sxSyncGoods
|
||||
* @return
|
||||
*/
|
||||
Boolean updateByGoodsNo(SxSyncGoods sxSyncGoods);
|
||||
|
||||
/**
|
||||
* 根据编号获取一条记录
|
||||
*
|
||||
* @param storeId
|
||||
* @param goodsNo
|
||||
* @return
|
||||
*/
|
||||
SxSyncGoods getByGoodsNo(String storeId, String goodsNo);
|
||||
}
|
||||
@ -9,7 +9,6 @@
|
||||
package com.suisung.mall.shop.sixun.service;
|
||||
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncCategory;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncVip;
|
||||
|
||||
import java.util.List;
|
||||
@ -17,7 +16,7 @@ import java.util.List;
|
||||
public interface SxSyncVipService {
|
||||
|
||||
/**
|
||||
* 同步店铺的会员
|
||||
* 同步记录
|
||||
*
|
||||
* @param storeId
|
||||
* @param pageNum
|
||||
@ -35,7 +34,7 @@ public interface SxSyncVipService {
|
||||
Integer insert(SxSyncVip sxSyncVip);
|
||||
|
||||
/**
|
||||
* 批量更新思迅的会员,有判断是否已存在逻辑
|
||||
* 批量更新记录,有判断是否已存在逻辑
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
|
||||
@ -10,13 +10,12 @@ package com.suisung.mall.shop.sixun.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.constant.CommonConstant;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncCategory;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.sixun.mapper.SxSyncCategoryMapper;
|
||||
@ -24,12 +23,12 @@ import com.suisung.mall.shop.sixun.service.SxSyncCategoryService;
|
||||
import com.suisung.mall.shop.sixun.utils.CommonUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class SxSyncCategoryServiceImpl extends BaseServiceImpl<SxSyncCategoryMapper, SxSyncCategory> implements SxSyncCategoryService {
|
||||
|
||||
/**
|
||||
* 同步店铺的商品分类
|
||||
*
|
||||
@ -41,55 +40,63 @@ public class SxSyncCategoryServiceImpl extends BaseServiceImpl<SxSyncCategoryMap
|
||||
@Override
|
||||
public CommonResult syncCategory(String storeId, Integer pageNum, Integer pageSize) {
|
||||
// 记录总数
|
||||
Integer total = getCategoryRecordTotal("", pageNum, pageSize);
|
||||
Integer total = getCategoryRecordTotal(pageNum, pageSize);
|
||||
// 总页数
|
||||
int pages = CommonUtil.getPagesCount(total,pageSize);
|
||||
int pages = CommonUtil.getPagesCount(total, pageSize);
|
||||
|
||||
int syncCount = 0;
|
||||
|
||||
for (int i = 0; i < pages; i++) {
|
||||
List<SxSyncCategory> list = pageCategoryListFromSiXun("", pageNum, pageSize);
|
||||
int syncCount =0;
|
||||
for (int i = 1; i <= pages; i++) {
|
||||
int count = 0;
|
||||
List<SxSyncCategory> list = pageCategoryListFromSiXun(i, pageSize);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
syncCount = insertBatch(storeId, list);
|
||||
if (syncCount <= 0) {
|
||||
count = insertBatch(storeId, list);
|
||||
if (count <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
syncCount++;
|
||||
syncCount+=count;
|
||||
}
|
||||
|
||||
return CommonResult.success(null, syncCount + "条数据同步成功!");
|
||||
return CommonResult.success(null, syncCount + "数据同步成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
*
|
||||
* @param sxSyncCategory
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Integer insert(SxSyncCategory sxSyncCategory) {
|
||||
SxSyncCategory existsCategory = getByItemClsno(sxSyncCategory.getStore_id(), sxSyncCategory.getItem_clsno());
|
||||
if (existsCategory != null) {
|
||||
public Integer insert(SxSyncCategory record) {
|
||||
SxSyncCategory exists = getByItemClsno(record.getStore_id(), record.getItem_clsno());
|
||||
if (exists != null) {
|
||||
Long id = exists.getId();
|
||||
Date createdAt = exists.getCreated_at();
|
||||
// 置空无关的属性值
|
||||
existsCategory.setId(null);
|
||||
existsCategory.setStatus(null);
|
||||
existsCategory.setSync_time(null);
|
||||
existsCategory.setCreated_at(null);
|
||||
existsCategory.setUpdated_at(null);
|
||||
exists.setId(null);
|
||||
exists.setStatus(null);
|
||||
exists.setSync_time(null);
|
||||
exists.setCreated_at(null);
|
||||
exists.setUpdated_at(null);
|
||||
|
||||
// 比较对象各个字段是否有改变?
|
||||
if (Objects.deepEquals(existsCategory, sxSyncCategory)) {
|
||||
if (Objects.deepEquals(exists, record)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return updateByItemClsNo(sxSyncCategory) ? 1 : 0;
|
||||
record.setId(id);
|
||||
record.setSync_time(0L);
|
||||
record.setCreated_at(createdAt);
|
||||
record.setUpdated_at(new Date());
|
||||
record.setStatus(CommonConstant.Disable2);
|
||||
return this.updateById(record)? 1 : 0;
|
||||
}
|
||||
|
||||
return baseMapper.insert(sxSyncCategory);
|
||||
return baseMapper.insert(record);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,57 +151,48 @@ public class SxSyncCategoryServiceImpl extends BaseServiceImpl<SxSyncCategoryMap
|
||||
|
||||
// ########### 从思迅商锐9.7系统获取数据区域 开始
|
||||
|
||||
public List<SxSyncCategory> pageCategoryListFromSiXun(String clsParent, Integer pageNo, Integer pageSize) {
|
||||
public List<SxSyncCategory> pageCategoryListFromSiXun(Integer pageNo, Integer pageSize) {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("clsParent", clsParent);
|
||||
params.put("pageNo", pageNo);
|
||||
params.put("pageSize", pageSize);
|
||||
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun( "/v1/category/page", params);
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun("/v1/category/page", params);
|
||||
if (respObj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!respObj.getStr("code").equals("0") || respObj.get("data") == null) {
|
||||
if (!CommonUtil.hasSuccessData(respObj)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 驼峰命名改成下划线命名
|
||||
String listJson = StrUtil.toUnderlineCase(respObj.getByPath("data.list", String.class));
|
||||
return JSONUtil.toList(listJson, SxSyncCategory.class);
|
||||
return JSONUtil.toList(CommonUtil.toUnderlineJson(respObj, "data.list"), SxSyncCategory.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类的页数
|
||||
*
|
||||
* @param clsParent
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public Integer getCategoryRecordTotal(String clsParent, Integer pageNo, Integer pageSize) {
|
||||
public Integer getCategoryRecordTotal(Integer pageNo, Integer pageSize) {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("clsParent", clsParent);
|
||||
params.put("pageNo", pageNo);
|
||||
params.put("pageSize", pageSize);
|
||||
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun( "/v1/category/page", params);
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun("/v1/category/page", params);
|
||||
if (respObj == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!respObj.getStr("code").equals("0") || respObj.get("total") == null) {
|
||||
if (!CommonUtil.isSuccess(respObj) || respObj.getByPath("data.total")== null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Convert.toInt(respObj.get("total"));
|
||||
return Convert.toInt(respObj.getByPath("data.total"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ########### 从思迅商锐9.7系统获取数据区域 结束
|
||||
}
|
||||
|
||||
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.shop.sixun.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.constant.CommonConstant;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncGoods;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.sixun.mapper.SxSyncGoodsMapper;
|
||||
import com.suisung.mall.shop.sixun.service.SxSyncGoodsService;
|
||||
import com.suisung.mall.shop.sixun.utils.CommonUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class SxSyncGoodsServiceImpl extends BaseServiceImpl<SxSyncGoodsMapper, SxSyncGoods> implements SxSyncGoodsService {
|
||||
|
||||
/**
|
||||
* 同步记录
|
||||
*
|
||||
* @param storeId
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CommonResult syncGoods(String storeId, Integer pageNum, Integer pageSize) {
|
||||
// 记录总数
|
||||
Integer total = getGoodsRecordTotal(pageNum, pageSize);
|
||||
// 总页数
|
||||
int pages = CommonUtil.getPagesCount(total, pageSize);
|
||||
|
||||
int syncCount = 0;
|
||||
|
||||
for (int i = 1; i <= pages; i++) {
|
||||
int count = 0;
|
||||
List<SxSyncGoods> list = pageGoodsListFromSiXun(i, pageSize);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
count = insertBatch(storeId, list);
|
||||
if (count <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
syncCount+=count;
|
||||
}
|
||||
|
||||
return CommonResult.success(null, syncCount + "条数据同步成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
*
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Integer insert(SxSyncGoods record) {
|
||||
SxSyncGoods exists = getByGoodsNo(record.getStore_id(), record.getItem_no());
|
||||
if (exists != null) {
|
||||
Long id = exists.getId();
|
||||
Date createdAt = exists.getCreated_at();
|
||||
// 置空无关的属性值
|
||||
exists.setId(null);
|
||||
exists.setStatus(null);
|
||||
exists.setSync_time(null);
|
||||
exists.setRemark(null);
|
||||
exists.setCreated_at(null);
|
||||
exists.setUpdated_at(null);
|
||||
|
||||
// 比较对象各个字段是否有改变?
|
||||
if (Objects.deepEquals(exists, record)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
record.setId(id);
|
||||
record.setCreated_at(createdAt);
|
||||
record.setUpdated_at(new Date());
|
||||
record.setStatus(CommonConstant.Disable2);
|
||||
record.setSync_time(0L);
|
||||
record.setRemark("");
|
||||
return this.updateById(record)? 1 : 0;
|
||||
}
|
||||
|
||||
return baseMapper.insert(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新记录,有判断是否已存在逻辑
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Integer insertBatch(String storeId, List<SxSyncGoods> list) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (SxSyncGoods sxSyncGoods : list) {
|
||||
sxSyncGoods.setStore_id(storeId);
|
||||
if (insert(sxSyncGoods) > 0) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号更新一条记录
|
||||
*
|
||||
* @param sxSyncGoods
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByGoodsNo(SxSyncGoods sxSyncGoods) {
|
||||
UpdateWrapper<SxSyncGoods> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("item_no", sxSyncGoods.getItem_no());
|
||||
return update(sxSyncGoods, updateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号获取一条记录
|
||||
*
|
||||
* @param goodsNo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SxSyncGoods getByGoodsNo(String storeId, String goodsNo) {
|
||||
QueryWrapper<SxSyncGoods> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("store_id", storeId);
|
||||
queryWrapper.eq("item_no", goodsNo);
|
||||
return baseMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
// ########### 从思迅商锐9.7系统获取数据区域 开始
|
||||
|
||||
public List<SxSyncGoods> pageGoodsListFromSiXun(Integer pageNo, Integer pageSize) {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("pageNo", pageNo);
|
||||
params.put("pageSize", pageSize);
|
||||
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun("/v1/goods/page", params);
|
||||
if (!CommonUtil.hasSuccessData(respObj)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 驼峰命名改成下划线命名
|
||||
return JSONUtil.toList(CommonUtil.toUnderlineJson(respObj, "data.list"), SxSyncGoods.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取记录总数
|
||||
*
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public Integer getGoodsRecordTotal(Integer pageNo, Integer pageSize) {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("pageNo", pageNo);
|
||||
params.put("pageSize", pageSize);
|
||||
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun("/v1/goods/page", params);
|
||||
if (!CommonUtil.isSuccess(respObj) || respObj.getByPath("data.total")== null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Convert.toInt(respObj.getByPath("data.total"));
|
||||
}
|
||||
|
||||
// ########### 从思迅商锐9.7系统获取数据区域 结束
|
||||
|
||||
}
|
||||
@ -10,12 +10,12 @@ package com.suisung.mall.shop.sixun.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.constant.CommonConstant;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncVip;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.sixun.mapper.SxSyncVipMapper;
|
||||
@ -23,6 +23,7 @@ import com.suisung.mall.shop.sixun.service.SxSyncVipService;
|
||||
import com.suisung.mall.shop.sixun.utils.CommonUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -30,7 +31,7 @@ import java.util.Objects;
|
||||
public class SxSyncVipServiceImpl extends BaseServiceImpl<SxSyncVipMapper, SxSyncVip> implements SxSyncVipService {
|
||||
|
||||
/**
|
||||
* 同步店铺的会员
|
||||
* 同步店铺的
|
||||
*
|
||||
* @param storeId
|
||||
* @param pageNum
|
||||
@ -42,22 +43,23 @@ public class SxSyncVipServiceImpl extends BaseServiceImpl<SxSyncVipMapper, SxSyn
|
||||
// 记录总数
|
||||
Integer total = getVipRecordTotal(pageNum, pageSize);
|
||||
// 总页数
|
||||
int pages = CommonUtil.getPagesCount(total,pageSize);
|
||||
int pages = CommonUtil.getPagesCount(total, pageSize);
|
||||
|
||||
int syncCount = 0;
|
||||
|
||||
for (int i = 0; i < pages; i++) {
|
||||
List<SxSyncVip> list = pageVipListFromSiXun(pageNum, pageSize);
|
||||
for (int i = 1; i <= pages; i++) {
|
||||
int count = 0;
|
||||
List<SxSyncVip> list = pageVipListFromSiXun(i, pageSize);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
syncCount = insertBatch(storeId, list);
|
||||
if (syncCount <= 0) {
|
||||
count = insertBatch(storeId, list);
|
||||
if (count <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
syncCount++;
|
||||
syncCount+=count;
|
||||
}
|
||||
|
||||
return CommonResult.success(null, syncCount + "条数据同步成功!");
|
||||
@ -66,33 +68,40 @@ public class SxSyncVipServiceImpl extends BaseServiceImpl<SxSyncVipMapper, SxSyn
|
||||
/**
|
||||
* 新增记录
|
||||
*
|
||||
* @param sxSyncVip
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Integer insert(SxSyncVip sxSyncVip) {
|
||||
SxSyncVip existsVip = getByVipNo(sxSyncVip.getStore_id(), sxSyncVip.getVip_no());
|
||||
if (existsVip != null) {
|
||||
public Integer insert(SxSyncVip record) {
|
||||
SxSyncVip exists = getByVipNo(record.getStore_id(), record.getCard_no());
|
||||
if (exists != null) {
|
||||
Long id = exists.getId();
|
||||
Date createdAt = exists.getCreated_at();
|
||||
// 置空无关的属性值
|
||||
existsVip.setId(null);
|
||||
existsVip.setStatus(null);
|
||||
existsVip.setSync_time(null);
|
||||
existsVip.setCreated_at(null);
|
||||
existsVip.setUpdated_at(null);
|
||||
exists.setId(null);
|
||||
exists.setStatus(null);
|
||||
exists.setSync_time(null);
|
||||
exists.setCreated_at(null);
|
||||
exists.setUpdated_at(null);
|
||||
|
||||
// 比较对象各个字段是否有改变?
|
||||
if (Objects.deepEquals(existsVip, sxSyncVip)) {
|
||||
if (Objects.deepEquals(exists, record)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return updateByVipNo(sxSyncVip) ? 1 : 0;
|
||||
record.setId(id);
|
||||
record.setSync_time(0L);
|
||||
record.setCreated_at(createdAt);
|
||||
record.setUpdated_at(new Date());
|
||||
record.setStatus(CommonConstant.Disable2);
|
||||
return this.updateById(record)? 1 : 0;
|
||||
}
|
||||
|
||||
return baseMapper.insert(sxSyncVip);
|
||||
return baseMapper.insert(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新思迅的会员,有判断是否已存在逻辑
|
||||
* 批量更新记录,有判断是否已存在逻辑
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
@ -114,7 +123,7 @@ public class SxSyncVipServiceImpl extends BaseServiceImpl<SxSyncVipMapper, SxSyn
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据会员编号更新一条记录
|
||||
* 根据编号更新一条记录
|
||||
*
|
||||
* @param sxSyncVip
|
||||
* @return
|
||||
@ -122,48 +131,43 @@ public class SxSyncVipServiceImpl extends BaseServiceImpl<SxSyncVipMapper, SxSyn
|
||||
@Override
|
||||
public Boolean updateByVipNo(SxSyncVip sxSyncVip) {
|
||||
UpdateWrapper<SxSyncVip> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("vip_no", sxSyncVip.getVip_no());
|
||||
updateWrapper.eq("vip_no", sxSyncVip.getCard_no());
|
||||
return update(sxSyncVip, updateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据会员编号获取一条记录
|
||||
* 根据编号获取一条记录
|
||||
*
|
||||
* @param vipNo
|
||||
* @param cardNo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SxSyncVip getByVipNo(String storeId, String vipNo) {
|
||||
public SxSyncVip getByVipNo(String storeId, String cardNo) {
|
||||
QueryWrapper<SxSyncVip> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("store_id", storeId);
|
||||
queryWrapper.eq("vip_no", vipNo);
|
||||
queryWrapper.eq("card_no", cardNo);
|
||||
return baseMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
// ########### 从思迅商锐9.7系统获取数据区域 开始
|
||||
|
||||
public List<SxSyncVip> pageVipListFromSiXun( Integer pageNo, Integer pageSize) {
|
||||
public List<SxSyncVip> pageVipListFromSiXun(Integer pageNo, Integer pageSize) {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("pageNo", pageNo);
|
||||
params.put("pageSize", pageSize);
|
||||
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun( "/v1/vip/page", params);
|
||||
if (respObj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!respObj.getStr("code").equals("0") || respObj.get("data") == null) {
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun("/v1/vip/page", params);
|
||||
if (!CommonUtil.hasSuccessData(respObj)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 驼峰命名改成下划线命名
|
||||
String listJson = StrUtil.toUnderlineCase(respObj.getByPath("data.list", String.class));
|
||||
return JSONUtil.toList(listJson, SxSyncVip.class);
|
||||
return JSONUtil.toList(CommonUtil.toUnderlineJson(respObj, "data.list"), SxSyncVip.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员的页数
|
||||
* 获取记录总数
|
||||
*
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
@ -174,16 +178,12 @@ public class SxSyncVipServiceImpl extends BaseServiceImpl<SxSyncVipMapper, SxSyn
|
||||
params.put("pageNo", pageNo);
|
||||
params.put("pageSize", pageSize);
|
||||
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun( "/v1/vip/page", params);
|
||||
if (respObj == null) {
|
||||
JSONObject respObj = CommonUtil.sendPostRequestToSiXun("/v1/vip/page", params);
|
||||
if (!CommonUtil.isSuccess(respObj) || respObj.getByPath("data.total")== null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!respObj.getStr("code").equals("0") || respObj.get("total") == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Convert.toInt(respObj.get("total"));
|
||||
return Convert.toInt(respObj.getByPath("data.total"));
|
||||
}
|
||||
|
||||
// ########### 从思迅商锐9.7系统获取数据区域 结束
|
||||
|
||||
@ -54,4 +54,45 @@ public class CommonUtil {
|
||||
|
||||
return pagesCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口是否成功执行返回
|
||||
*
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
public static Boolean isSuccess(JSONObject jsonObject) {
|
||||
if (jsonObject == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return jsonObject.get("code") != null && jsonObject.getStr("code").equals("0");
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口是否成功执行返回
|
||||
*
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
public static Boolean hasSuccessData(JSONObject jsonObject) {
|
||||
if (jsonObject == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return jsonObject.get("code") != null && jsonObject.getStr("code").equals("0") && jsonObject.get("data") != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过json节点表达式,获取节点json字符串,注:驼峰命名改成下划线命名
|
||||
*
|
||||
* @param jsonObject
|
||||
* @param expression json 节点表达式比如: data.list, msg, code
|
||||
* @return
|
||||
*/
|
||||
public static String toUnderlineJson(JSONObject jsonObject, String expression) {
|
||||
return StrUtil.toUnderlineCase(jsonObject.getByPath(expression, String.class));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user