|
|
|
@ -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) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|