1.类目同步 2.增加是否检测开启代扣接口

20230922-ljl-fixBug
wangchaoxu 1 year ago
parent 0373d02170
commit bde0462c2a

@ -1,6 +1,10 @@
package com.ms.api.service;
import com.doudian.open.api.shop_getShopCategory.data.DataItem;
import com.ms.dal.entity.Category;
import com.ms.dal.entity.RsyncCategoryQueue;
import java.util.List;
/**
*
@ -18,4 +22,14 @@ public interface CategoryService {
int updateByPrimaryKeySelective(Category record);
int updateByPrimaryKey(Category record);
RsyncCategoryQueue lockSyncShopCategoryQueue();
boolean deleteShopCategoryQueue(Integer shopId);
List<DataItem> getAllShopCategorysFromDd(Long cid);
void recordShopCategorys(Integer shopId, List<DataItem> shopAllCategoryList);
void getAllLeafProductCatListFromTos(Integer shopId, boolean isFlushCache);
}

@ -23,4 +23,5 @@ public interface CategoryShopService {
int updateByPrimaryKey(CategoryShop record);
List<Category> getCategoryListByShopId(long shopId, long maxCid, int stepLen);
}

@ -91,4 +91,6 @@ public interface PurchaseOrderService {
boolean addDsAutoPurchaseLog(DsAutoPurchaseLog logData);
boolean updateDsAutoPurchaseLog(DsAutoPurchaseLog logData);
boolean checkSignedAutoPayProtocol(Long shopId) throws Exception;
}

@ -1,21 +1,48 @@
package com.ms.api.service.impl;
import com.doudian.open.api.shop_getShopCategory.data.DataItem;
import com.ms.api.consts.RedisKeyConst;
import com.ms.api.tool.CommonTool;
import com.ms.api.util.DdRequestUtil;
import com.ms.dal.entity.Category;
import com.ms.api.service.CategoryService;
import com.ms.dal.entity.CategoryShop;
import com.ms.dal.entity.RsyncCategoryQueue;
import com.ms.dal.mapper.CategoryMapper;
import com.ms.dal.mapper.CategoryShopMapper;
import com.ms.dal.mapper.RsyncCategoryQueueMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*
*/
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService{
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private RsyncCategoryQueueMapper rsyncCategoryQueueMapper;
@Autowired
private CategoryMapper categoryMapper;
@Autowired
private CategoryShopMapper categoryShopMapper;
@Override
public int deleteByPrimaryKey(Long id) {
return categoryMapper.deleteByPrimaryKey(id);
@ -46,6 +73,80 @@ public class CategoryServiceImpl implements CategoryService{
return categoryMapper.updateByPrimaryKey(record);
}
@Override
public RsyncCategoryQueue lockSyncShopCategoryQueue() {
final String redisKey = RedisKeyConst.RSYNC_CATEGORY_QUEUE;
String shopIdStr = redisTemplate.opsForList().rightPop(redisKey);
if (StringUtils.isEmpty(shopIdStr)) {
log.info("lockSyncShopCategoryQueue getEmpty");
return null;
}
Long shopId = Long.valueOf(shopIdStr);
RsyncCategoryQueue updateData = new RsyncCategoryQueue();
updateData.setShopId(shopId.intValue());
updateData.setLocked(1);
// updateData.setHostname("");
updateData.setGmtLocked(new Date());
updateData.setGmtModified(new Date());
int affRows = rsyncCategoryQueueMapper.updateByShopId(updateData);
if (affRows > 0) {
return rsyncCategoryQueueMapper.selectFirstRowByShopId(shopId.intValue());
}
log.info(String.format("lockSyncShopCategoryQueue fail. shopId: %s", shopId));
return null;
}
@Override
public boolean deleteShopCategoryQueue(Integer shopId) {
int affRow = rsyncCategoryQueueMapper.deleteByShopId(shopId);
return affRow > 0;
}
@Override
public List<DataItem> getAllShopCategorysFromDd(Long cid) {
List<DataItem> dataAll = new ArrayList<>();
List<DataItem> dataGet = DdRequestUtil.getShopCategory(cid);
if (dataGet.isEmpty()) {
return dataGet;
}
dataAll.addAll(dataGet);
for (DataItem datum : dataGet) {
if (datum.getEnable() && !datum.getIsLeaf()) {
List<DataItem> data1 = DdRequestUtil.getShopCategory(datum.getId());
dataAll.addAll(data1);
}
}
return dataAll;
}
@Override
public void recordShopCategorys(Integer shopId, List<DataItem> shopAllCategoryList) {
// Map<Long, DataItem> shopAllCategoryMap = CommonTool.convertListToMap(shopAllCategoryList, DataItem::getId);
List<Long> existCids = categoryShopMapper.selectCategoryIdListByShopId(shopId);
List<Long> realCids = shopAllCategoryList.stream().map(DataItem::getId).collect(Collectors.toList());
List<Long> needDelCids = (List<Long>) ((ArrayList<Long>) existCids).clone();
List<Long> needInsertCids = (List<Long>) ((ArrayList<Long>) realCids).clone();
needInsertCids.removeAll(existCids);
needDelCids.removeAll(realCids);
for (Long cid : needInsertCids) {
CategoryShop categoryShopNew = new CategoryShop();
categoryShopNew.setShopId(shopId);
categoryShopNew.setCategoryId(cid);
categoryShopNew.setGmtCreate(new Date());
categoryShopNew.setGmtModified(new Date());
categoryShopMapper.insertSelective(categoryShopNew);
}
if (!needDelCids.isEmpty()) {
categoryShopMapper.deleteByShopIdAndCategoryIds(shopId, needDelCids);
}
}
@Override
public void getAllLeafProductCatListFromTos(Integer shopId, boolean isFlushCache) {
}
}

@ -1,8 +1,8 @@
package com.ms.api.service.impl;
import com.ms.api.service.CategoryShopService;
import com.ms.dal.entity.Category;
import com.ms.dal.entity.CategoryShop;
import com.ms.api.service.CategoryShopService;
import com.ms.dal.mapper.CategoryShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@ -28,14 +28,7 @@ import com.doudian.open.api.order_BatchSearchIndex.param.PlainTextListItem;
import com.ms.api.common.ApiResult;
import com.ms.api.common.MSException;
import com.ms.api.common.Pager;
import com.ms.api.consts.AfterSaleConst;
import com.ms.api.consts.DsOrderConst;
import com.ms.api.consts.OrderChildTagConst;
import com.ms.api.consts.OrderConst;
import com.ms.api.consts.PurchaseOrderConst;
import com.ms.api.consts.RedisKeyConst;
import com.ms.api.consts.StatusConst;
import com.ms.api.consts.TblConst;
import com.ms.api.consts.*;
import com.ms.api.dto.dsorder.AppendVenderRemarkTplItemDTO;
import com.ms.api.dto.order.AllowAutoPurchaseProductDTO;
import com.ms.api.dto.order.DsPurchaseSettingDTO;
@ -60,11 +53,7 @@ import com.ms.api.service.ProductToDsItemService;
import com.ms.api.service.PurchaseOrderService;
import com.ms.api.service.PurchaseSettingService;
import com.ms.api.service.ShopService;
import com.ms.api.tool.CommonTool;
import com.ms.api.tool.DsOrderTool;
import com.ms.api.tool.OrderPrintTool;
import com.ms.api.tool.OrderTool;
import com.ms.api.tool.PurchaseTool;
import com.ms.api.tool.*;
import com.ms.api.util.DdRequestUtil;
import com.ms.api.util.WebUtil;
import com.ms.dal.bo.OpLogisticsPlatformBO;
@ -139,6 +128,9 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
@Autowired
private PlatformTransactionManager transactionManager;
@Autowired
private DsJsonRequestTemplate dsJsonRequestTemplate;
@Autowired
private PurchaseOrderMapper purchaseOrderMapper;
@ -2043,6 +2035,38 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
return affRow != 0;
}
/**
*
* @param shopId
* @return
* @throws Exception
*/
@Override
public boolean checkSignedAutoPayProtocol(Long shopId) throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("shopId", SecurityTool.encodeByAES(String.valueOf(shopId)));
params.put("platform", CommonConst.PLATFORM);
String res = dsJsonRequestTemplate.execute("/order/getOrderPayProtocolPay", params);
log.info(res);
JSONObject jsonObject = JSON.parseObject(res);
boolean isSigned = false;
if (jsonObject.getString("result").equals("fail")) {
log.error("自动扣款协议请求失败,原因:" + jsonObject.getString("reason"));
throw new MSException(jsonObject.getString("reason"));
} else {
JSONArray paymentAgreements = jsonObject.getJSONObject("data").getJSONArray("paymentAgreements");
for (int i = 0; i < paymentAgreements.size(); i++) {
JSONObject obj = paymentAgreements.getJSONObject(i);
String signedStatus = obj.getString("signedStatus");
if (signedStatus.equals("true")) {
isSigned = true;
break;
}
}
}
return isSigned;
}
}

@ -0,0 +1,38 @@
package com.ms.api.spi.order;
import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import com.ms.api.common.SPIBaseService;
import com.ms.api.service.PurchaseOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import java.util.Map;
@ExtensionService("checkSignedAutoPayProtocol")
@Slf4j
public class CheckSignedAutoPayProtocolService extends SPIBaseService implements ExtensionServiceHandler<Void, Ret> {
@Autowired
private PurchaseOrderService purchaseOrderService;
@Override
public BaseResponse<Ret> handle(BaseRequest<Void> req) {
initHandle(req);
boolean checkRes = false;
try {
checkRes = purchaseOrderService.checkSignedAutoPayProtocol(shopId);
} catch (Exception e) {
log.error("检测是否开通自动扣款失败", e);
return R.ok(Ret.fail("检测是否开通自动扣款失败"));
}
Map retMap = new HashMap();
retMap.put("isSignedAutoPayProtocol", checkRes ? 1 : 0);
return R.ok(Ret.success());
}
}

@ -2,8 +2,6 @@ package com.ms.api.spi.order;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
@ -70,7 +68,7 @@ public class SavePurchaseSettingService extends SPIBaseService implements Extens
try {
// 判断是否开启自动扣款协议
if (requestDTO.getDsPurchaseSetting().getIsAutoPay() != 0) {
if (!checkSignedAutoPayProtocal(shopId)) {
if (!purchaseOrderService.checkSignedAutoPayProtocol(shopId)) {
return R.ok(Ret.fail("您未开通自动扣款协议"));
}
}
@ -200,34 +198,5 @@ public class SavePurchaseSettingService extends SPIBaseService implements Extens
return R.ok(Ret.success());
}
/**
*
* @param shopId
* @return
* @throws Exception
*/
private boolean checkSignedAutoPayProtocal(Long shopId) throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("shopId", SecurityTool.encodeByAES(String.valueOf(shopId)));
params.put("platform", CommonConst.PLATFORM);
String res = dsJsonRequestTemplate.execute("/order/getOrderPayProtocolPay", params);
log.info(res);
JSONObject jsonObject = JSON.parseObject(res);
boolean isSigned = false;
if (jsonObject.getString("result").equals("fail")) {
log.error("自动扣款协议请求失败,原因:" + jsonObject.getString("reason"));
throw new RuntimeException(jsonObject.getString("reason"));
} else {
JSONArray paymentAgreements = jsonObject.getJSONObject("data").getJSONArray("paymentAgreements");
for (int i = 0; i < paymentAgreements.size(); i++) {
JSONObject obj = paymentAgreements.getJSONObject(i);
String signedStatus = obj.getString("signedStatus");
if (signedStatus.equals("true")) {
isSigned = true;
break;
}
}
}
return isSigned;
}
}

@ -1,10 +1,17 @@
package com.ms.api.task;
import com.alibaba.fastjson.JSON;
import com.doudian.open.api.shop_getShopCategory.data.DataItem;
import com.ms.api.common.Ret;
import com.ms.api.common.TaskBaseService;
import com.ms.api.paas.StorageService;
import com.ms.api.service.CategoryService;
import com.ms.api.service.CategoryShopService;
import com.ms.api.tool.CommonTool;
import com.ms.api.util.DdRequestUtil;
import com.ms.dal.entity.CategoryShop;
import com.ms.dal.entity.DoudianMsgParseQueue;
import com.ms.dal.entity.RsyncCategoryQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@ -13,15 +20,20 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.Executor;
@Configuration
@Component
@Slf4j
public class SyncShopCategoryQueueTaskService extends TaskBaseService {
@Autowired
private StorageService storageService;
@Autowired
private CategoryService categoryService;
@Autowired
private CategoryShopService categoryShopService;
/**
@ -60,46 +72,49 @@ public class SyncShopCategoryQueueTaskService extends TaskBaseService {
@Override
public Object getTask() {
return null;
RsyncCategoryQueue queue = categoryService.lockSyncShopCategoryQueue();
return queue;
}
@Override
public Object processTask(Object params) {
// List<DataItem> dataAll = this.findChildShopCategory(0L);
// if (!dataAll.isEmpty()) {
// for (DataItem datum : dataAll) {
// CategoryShop categoryShop = categoryShopService.selectByPrimaryKey(shopId,datum.getId());
// if (categoryShop==null) {
// CategoryShop categoryShopNew=new CategoryShop();
// categoryShopNew.setShopId(Math.toIntExact(shopId));
// categoryShopNew.setCategoryId(datum.getId());
// categoryShopNew.setGmtCreate(new Date());
// categoryShopNew.setGmtModified(new Date());
// categoryShopService.insertSelective(categoryShopNew);
// }
// }
if (params == null) {
return null;
}
RsyncCategoryQueue queue = (RsyncCategoryQueue) params;
Integer shopId = queue.getShopId();
log.info("getAllShopCategorysFromDd");
List<DataItem> shopAllCategoryList = categoryService.getAllShopCategorysFromDd(0L);
log.info("recordShopCategorys");
categoryService.recordShopCategorys(shopId, shopAllCategoryList);
log.info("start flush ShopCategorys oss");
// oss
categoryService.getAllLeafProductCatListFromTos(shopId, true);
// String ossPath = String.format("move_product_publish_to_pic_queue/%s/%s.txt", shopId, detailId);
// Ret ret = storageService.uploadContent(ossPath, JSON.toJSONString(data));
// if (CommonTool.isFailRet(ret)) {
// return ret;
// }
return null;
}
// String ossUrl = storageService.getPubOssUrlByOssPath(ossPath);
// log.info("uploadMoveDataToOss success ossUrl: " + ossUrl);
// return CommonTool.successResult("ossUrl", ossUrl);
private List<DataItem> findChildShopCategory(Long cid) {
List<DataItem> dataAll = new ArrayList<DataItem>();
List<DataItem> dataGet = DdRequestUtil.getShopCategory(cid);
if (dataGet.isEmpty()) {
return dataGet;
}
dataAll.addAll(dataGet);
for (DataItem datum : dataGet) {
if (datum.getEnable() && !datum.getIsLeaf()) {
List<DataItem> data1 = DdRequestUtil.getShopCategory(datum.getId());
dataAll.addAll(data1);
}
}
return dataAll;
log.info("end flush ShopCategorys oss");
return queue;
}
@Override
public void clearTask(Object params) {
if (params == null) {
return;
}
RsyncCategoryQueue queue = (RsyncCategoryQueue) params;
categoryService.deleteShopCategoryQueue(queue.getShopId());
}
}

@ -3,6 +3,7 @@ package com.ms.dal.mapper;
import com.ms.dal.entity.Category;
import com.ms.dal.entity.CategoryShop;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -25,4 +26,8 @@ public interface CategoryShopMapper {
int updateByPrimaryKey(CategoryShop record);
List<Category> getCategoryListByShopId(long shopId, long maxCid, int stepLen);
List<Long> selectCategoryIdListByShopId(Integer shopId);
int deleteByShopIdAndCategoryIds(@Param("shopId") Integer shopId, @Param("categoryIds") List<Long> categoryIds);
}

@ -23,4 +23,9 @@ public interface RsyncCategoryQueueMapper {
int updateByPrimaryKey(RsyncCategoryQueue record);
int updateByShopId(RsyncCategoryQueue record);
RsyncCategoryQueue selectFirstRowByShopId(Integer shopId);
int deleteByShopId(Integer shopId);
}

@ -31,13 +31,27 @@
select
<include refid="Base_Column_List" />
from category_shop
where shop_id = #{shopId,jdbcType=INTEGER} AND category_id = #{categoryId,jdbcType=BIGINT}
where shop_id = #{shopId,jdbcType=INTEGER} AND category_id = #{categoryId,jdbcType=BIGINT}
</select>
<select id="selectCategoryIdListByShopId" parameterType="java.lang.Integer" resultType="java.lang.Long">
select category_id
from category_shop
where shop_id = #{shopId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from category_shop
where shop_id = #{shopId,jdbcType=INTEGER} AND category_id = #{categoryId,jdbcType=BIGINT}
where shop_id = #{shopId,jdbcType=INTEGER} AND category_id = #{categoryId,jdbcType=BIGINT}
</delete>
<delete id="deleteByShopIdAndCategoryIds">
delete from category_shop
where shop_id = #{shopId,jdbcType=INTEGER}
AND category_id in
<foreach collection="categoryIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
<insert id="insert">
insert into category_shop
( shop_id,category_id,gmt_create
@ -70,13 +84,13 @@
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
</if>
</set>
where shop_id = #{shopId,jdbcType=INTEGER} AND category_id = #{categoryId,jdbcType=BIGINT}
where shop_id = #{shopId,jdbcType=INTEGER} AND category_id = #{categoryId,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.CategoryShop">
update category_shop
set
set
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where shop_id = #{shopId,jdbcType=INTEGER} AND category_id = #{categoryId,jdbcType=BIGINT}
where shop_id = #{shopId,jdbcType=INTEGER} AND category_id = #{categoryId,jdbcType=BIGINT}
</update>
</mapper>

@ -21,16 +21,26 @@
gmt_create,gmt_modified
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from rsync_category_queue
where rsync_category_queue_id = #{rsyncCategoryQueueId,jdbcType=INTEGER}
where rsync_category_queue_id = #{rsyncCategoryQueueId,jdbcType=INTEGER}
</select>
<select id="selectFirstRowByShopId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from rsync_category_queue
where shop_id = #{shopId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from rsync_category_queue
where rsync_category_queue_id = #{rsyncCategoryQueueId,jdbcType=INTEGER}
</delete>
<delete id="deleteByShopId" parameterType="java.lang.Integer">
delete from rsync_category_queue
where rsync_category_queue_id = #{rsyncCategoryQueueId,jdbcType=INTEGER}
where shop_id = #{shopId,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="rsync_category_queue_id" keyProperty="rsyncCategoryQueueId" parameterType="com.ms.dal.entity.RsyncCategoryQueue" useGeneratedKeys="true">
insert into rsync_category_queue
@ -101,11 +111,11 @@
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
</if>
</set>
where rsync_category_queue_id = #{rsyncCategoryQueueId,jdbcType=INTEGER}
where rsync_category_queue_id = #{rsyncCategoryQueueId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.RsyncCategoryQueue">
update rsync_category_queue
set
set
shop_id = #{shopId,jdbcType=INTEGER},
hostname = #{hostname,jdbcType=VARCHAR},
locked = #{locked,jdbcType=INTEGER},
@ -113,6 +123,30 @@
gmt_locked = #{gmtLocked,jdbcType=TIMESTAMP},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where rsync_category_queue_id = #{rsyncCategoryQueueId,jdbcType=INTEGER}
where rsync_category_queue_id = #{rsyncCategoryQueueId,jdbcType=INTEGER}
</update>
<update id="updateByShopId" parameterType="com.ms.dal.entity.RsyncCategoryQueue">
update rsync_category_queue
<set>
<if test="hostname != null">
hostname = #{hostname,jdbcType=VARCHAR},
</if>
<if test="locked != null">
locked = #{locked,jdbcType=INTEGER},
</if>
<if test="tryTimes != null">
try_times = #{tryTimes,jdbcType=BOOLEAN},
</if>
<if test="gmtLocked != null">
gmt_locked = #{gmtLocked,jdbcType=TIMESTAMP},
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
</if>
</set>
where shop_id = #{shopId,jdbcType=INTEGER}
</update>
</mapper>

Loading…
Cancel
Save