|
|
package com.yoho.ufo.resource.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.common.utils.MD5;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.ufo.dal.ResourcesContentDataMapper;
|
|
|
import com.yoho.ufo.dal.ResourcesContentMapper;
|
|
|
import com.yoho.ufo.dal.ResourcesGoodsPoolMapper;
|
...
|
...
|
@@ -11,19 +13,25 @@ import com.yoho.ufo.model.resource.ResourcesContentData; |
|
|
import com.yoho.ufo.model.resource.ResourcesGoodsPool;
|
|
|
import com.yoho.ufo.resource.service.IResourceService;
|
|
|
import com.yoho.ufo.service.model.PageRequestBO;
|
|
|
import com.yoho.ufo.util.CollectionUtil;
|
|
|
import com.yoho.ufo.util.DateUtil;
|
|
|
import com.yohobuy.ufo.resource.req.ResContentDataModifyBo;
|
|
|
import com.yohobuy.ufo.resource.req.ResGoodsPoolEditBo;
|
|
|
import com.yohobuy.ufo.resource.req.ResourceReqBo;
|
|
|
import com.yohobuy.ufo.resource.resp.ResourceGetBo;
|
|
|
import com.yohobuy.ufo.resource.resp.ResourceInfoGetBo;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -52,6 +60,7 @@ public class ResourceServiceImpl implements IResourceService{ |
|
|
for(Resources res : resourcesList){
|
|
|
ResourceGetBo bo = new ResourceGetBo(res.getId(), res.getName(), Integer.valueOf(1).equals(res.getPlatformId()) ? "APP" : "小程序",
|
|
|
res.getCode(), res.getCreateTime());
|
|
|
bo.setSortId(res.getSortId());
|
|
|
resourceGetBoList.add(bo);
|
|
|
}
|
|
|
return resourceGetBoList;
|
...
|
...
|
@@ -98,6 +107,147 @@ public class ResourceServiceImpl implements IResourceService{ |
|
|
resourcesGoodsPoolMapper.updateBatchByResGoodsPoolBo(param);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addOrUpdateResource(ResourceReqBo req) {
|
|
|
if (StringUtils.isBlank(req.getName())) {
|
|
|
throw new ServiceException(400, "资源位名称不能为空!");
|
|
|
}
|
|
|
if (req.getSortId() == null || req.getSortId() < 1) {
|
|
|
throw new ServiceException(400, "请选择类别");
|
|
|
}
|
|
|
if (req.getPlatformId() == null || req.getPlatformId() < 1) {
|
|
|
throw new ServiceException(400, "请选择平台");
|
|
|
}
|
|
|
int now = (int) (System.currentTimeMillis() / 1000);
|
|
|
if (req.getId() == null || req.getId() < 1) {
|
|
|
// add
|
|
|
Resources r = new Resources();
|
|
|
BeanUtils.copyProperties(req, r);
|
|
|
r.setCode(MD5.md5(System.currentTimeMillis() + ""));
|
|
|
// 生效
|
|
|
r.setStatus(1);
|
|
|
|
|
|
//////////////// 未使用 /////////////////
|
|
|
r.setMatchCode("");
|
|
|
r.setLockPersonId("");
|
|
|
r.setLockPersonName("");
|
|
|
r.setLockTime(0);
|
|
|
r.setPublishTime(0);
|
|
|
r.setCreateTime(now);
|
|
|
/////////////// 未使用 /////////////////
|
|
|
resourcesMapper.insert(r);
|
|
|
} else {
|
|
|
Resources db = resourcesMapper.selectById(req.getId());
|
|
|
if (db == null) {
|
|
|
throw new ServiceException(400, "资源位不存在!");
|
|
|
}
|
|
|
boolean isChanged = false;
|
|
|
Resources r = new Resources();
|
|
|
if (!db.getSortId().equals(req.getSortId())) {
|
|
|
isChanged = true;
|
|
|
r.setSortId(req.getSortId());
|
|
|
}
|
|
|
if (!db.getPlatformId().equals(req.getPlatformId())) {
|
|
|
isChanged = true;
|
|
|
r.setPlatformId(req.getPlatformId());
|
|
|
}
|
|
|
if (!db.getName().equals(req.getName())) {
|
|
|
isChanged = true;
|
|
|
r.setName(req.getName());
|
|
|
}
|
|
|
// update
|
|
|
if (isChanged) {
|
|
|
r.setId(req.getId());
|
|
|
resourcesMapper.updateByPrimaryKeySelective(r);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addOrUpdateResourceDeatil(ResourceReqBo req) {
|
|
|
if (req.getId() == null || req.getId() < 1) {
|
|
|
throw new ServiceException(400, "资源位id不能为空!");
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(req.getItems())) {
|
|
|
throw new ServiceException(400, "资源位内容不能为空!");
|
|
|
}
|
|
|
|
|
|
int index = 0;
|
|
|
// 新增子项目
|
|
|
for (ResContentDataModifyBo itemBo : req.getItems()) {
|
|
|
itemBo.setOrderBy(++index);
|
|
|
}
|
|
|
|
|
|
Resources db = resourcesMapper.selectById(req.getId());
|
|
|
if (db == null) {
|
|
|
throw new ServiceException(400, "资源位不存在!");
|
|
|
}
|
|
|
int now = (int) (System.currentTimeMillis() / 1000);
|
|
|
List<ResourcesContent> content = resourcesContentMapper.selectByResourceId(req.getId());
|
|
|
if (CollectionUtils.isNotEmpty(content)) {
|
|
|
List<ResourcesContentData> data = resourcesContentDataMapper.selectByContentIds(CollectionUtil.distinct(content, ResourcesContent::getId));
|
|
|
Map<Integer, ResourcesContentData> dataMap = CollectionUtil.extractMap(data, ResourcesContentData::getResourceContentId);
|
|
|
Map<Integer, ResourcesContent> contentMap = CollectionUtil.extractMap(content, ResourcesContent::getId);
|
|
|
for (Iterator<ResContentDataModifyBo> iterator = req.getItems().iterator(); iterator.hasNext();) {
|
|
|
ResContentDataModifyBo bo = iterator.next();
|
|
|
if (bo.getId() == null || bo.getId() < 1) {
|
|
|
continue;
|
|
|
}
|
|
|
ResourcesContent c = contentMap.get(bo.getId());
|
|
|
if (c == null) {
|
|
|
throw new ServiceException(400, "资源位item:" + bo.getId() + "不存在!");
|
|
|
}
|
|
|
ResourcesContentData rcd = dataMap.get(c.getId());
|
|
|
if (rcd == null) {
|
|
|
throw new ServiceException(400, "资源位item:" + bo.getId() + "code不存在!");
|
|
|
}
|
|
|
if(bo.getTemplateKey().equals(rcd.getTemplateKey())
|
|
|
&& bo.getContentData().equals(rcd.getContentData())
|
|
|
&& bo.getContentName().equals(c.getName())
|
|
|
&& bo.getOrderBy().equals(c.getOrderBy())) {
|
|
|
iterator.remove();
|
|
|
contentMap.remove(bo.getId());
|
|
|
}
|
|
|
}
|
|
|
contentMap.forEach((cId, c) -> {
|
|
|
resourcesContentMapper.deleteByPrimaryKey(cId);
|
|
|
ResourcesContentData d = dataMap.get(cId);
|
|
|
if (d != null) {
|
|
|
resourcesContentDataMapper.deleteByPrimaryKey(d.getId());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 新增子项目
|
|
|
for (ResContentDataModifyBo itemBo : req.getItems()) {
|
|
|
ResourcesContent rc = new ResourcesContent();
|
|
|
rc.setResourcesId(db.getId());
|
|
|
rc.setSortId(db.getSortId());
|
|
|
rc.setPlatformId(db.getPlatformId());
|
|
|
|
|
|
rc.setName(itemBo.getContentName());
|
|
|
rc.setCreateTime(now);
|
|
|
rc.setOrderBy(itemBo.getOrderBy());
|
|
|
rc.setStatus(1);
|
|
|
|
|
|
resourcesContentMapper.insert(rc);
|
|
|
ResourcesContentData data = new ResourcesContentData();
|
|
|
data.setResourceContentId(rc.getId());
|
|
|
data.setSortId(db.getSortId());
|
|
|
data.setPlatformId(db.getPlatformId());
|
|
|
data.setTemplateKey(itemBo.getTemplateKey());
|
|
|
data.setContentData(itemBo.getContentData());
|
|
|
data.setType(itemBo.getType());
|
|
|
|
|
|
data.setCreateTime(0);
|
|
|
data.setPublishTime(0);
|
|
|
data.setStatus(1);
|
|
|
data.setPreContentId(0);
|
|
|
data.setUpdateTime(0);
|
|
|
resourcesContentDataMapper.insert(data);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<ResourceInfoGetBo> initResourceInfoGetBoList(List<ResourcesContent> contentList, List<ResourcesContentData> contentDataList) {
|
|
|
LOGGER.info("enter initResourceInfoGetBoList,contentList is {},contentDataList is {}",contentList,contentDataList);
|
|
|
List<ResourceInfoGetBo> resInfoList = new ArrayList<>();
|
...
|
...
|
@@ -118,4 +268,5 @@ public class ResourceServiceImpl implements IResourceService{ |
|
|
}
|
|
|
return resInfoList;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|