Authored by Lixiaodi

资源位修改

... ... @@ -15,4 +15,8 @@ public interface ResourcesContentDataMapper {
void insertOrUpdate(@Param("param") ResContentDataModifyBo param);
void updateByResContentBo(@Param("param") ResContentDataModifyBo param);
int deleteByPrimaryKey(Integer id);
int insert(ResourcesContentData record);
}
... ...
... ... @@ -10,4 +10,8 @@ import java.util.List;
*/
public interface ResourcesContentMapper {
List<ResourcesContent> selectByResourceId(@Param("id") Integer id);
int deleteByPrimaryKey(Integer id);
int insert(ResourcesContent record);
}
... ...
... ... @@ -12,4 +12,8 @@ public interface ResourcesMapper {
List<Resources> selectResourcesByPage(@Param("start") int start,@Param("size") int size);
Resources selectById(@Param("id") Integer id);
int insert(Resources record);
int updateByPrimaryKeySelective(Resources record);
}
... ...
... ... @@ -111,4 +111,21 @@
#{id}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from resources_content_data
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.model.resource.ResourcesContentData" >
insert into resources_content_data (id, platform_id, sort_id,
resource_content_id, template_key, create_time,
publish_time, update_time, pre_content_id,
status, type, content_data
)
values (#{id,jdbcType=INTEGER}, #{platformId,jdbcType=INTEGER}, #{sortId,jdbcType=INTEGER},
#{resourceContentId,jdbcType=INTEGER}, #{templateKey,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER},
#{publishTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}, #{preContentId,jdbcType=INTEGER},
#{status,jdbcType=TINYINT}, #{type,jdbcType=TINYINT}, #{contentData,jdbcType=LONGVARCHAR}
)
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -18,4 +18,16 @@
select <include refid="Base_Column_List" /> from resources_content
where resources_id=#{id}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from resources_content
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.model.resource.ResourcesContent" keyProperty="id" useGeneratedKeys="true" >
insert into resources_content (id, platform_id, sort_id,
resources_id, name, order_by,
create_time, status)
values (#{id,jdbcType=INTEGER}, #{platformId,jdbcType=INTEGER}, #{sortId,jdbcType=INTEGER},
#{resourcesId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{orderBy,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER}, #{status,jdbcType=TINYINT})
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -28,4 +28,56 @@
select <include refid="Base_Column_List" /> from resources
where id=#{id} limit 1
</select>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.model.resource.Resources" >
update resources
<set >
<if test="name != null" >
name = #{name,jdbcType=VARCHAR},
</if>
<if test="sortId != null" >
sort_id = #{sortId,jdbcType=INTEGER},
</if>
<if test="platformId != null" >
platform_id = #{platformId,jdbcType=INTEGER},
</if>
<if test="code != null" >
code = #{code,jdbcType=VARCHAR},
</if>
<if test="matchCode != null" >
match_code = #{matchCode,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="publishTime != null" >
publish_time = #{publishTime,jdbcType=INTEGER},
</if>
<if test="lockPersonName != null" >
lock_person_name = #{lockPersonName,jdbcType=VARCHAR},
</if>
<if test="lockPersonId != null" >
lock_person_id = #{lockPersonId,jdbcType=VARCHAR},
</if>
<if test="lockTime != null" >
lock_time = #{lockTime,jdbcType=INTEGER},
</if>
<if test="status != null" >
status = #{status,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<insert id="insert" parameterType="com.yoho.ufo.model.resource.Resources" >
insert into resources (id, name, sort_id,
platform_id, code, match_code,
create_time, publish_time, lock_person_name,
lock_person_id, lock_time, status
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{sortId,jdbcType=INTEGER},
#{platformId,jdbcType=INTEGER}, #{code,jdbcType=VARCHAR}, #{matchCode,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}, #{publishTime,jdbcType=INTEGER}, #{lockPersonName,jdbcType=VARCHAR},
#{lockPersonId,jdbcType=VARCHAR}, #{lockTime,jdbcType=INTEGER}, #{status,jdbcType=TINYINT}
)
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.ufo.service.model.ApiResponse;
import com.yoho.ufo.service.model.PageRequestBO;
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 org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -70,4 +71,24 @@ public class ResourceController {
this.resourceService.batchEditResourceGoodsPool(param);
return new ApiResponse.ApiResponseBuilder().code(200).build();
}
@RequestMapping(value = "/addOrUpdateResource")
public ApiResponse addOrUpdateResource(ResourceReqBo req) {
LOGGER.info("enter addOrUpdateResource,param is {}",req);
if(req == null){
return new ApiResponse(400, "参数为空", null);
}
resourceService.addOrUpdateResource(req);
return new ApiResponse.ApiResponseBuilder().code(200).data("修改成功").build();
}
@RequestMapping(value = "/addOrUpdateResourceDeatil")
public ApiResponse addOrUpdateResourceDeatil(@RequestBody ResourceReqBo req) {
LOGGER.info("enter addOrUpdateResourceDeatil,param is {}",req);
if(req == null) {
return new ApiResponse(400, "参数为空", null);
}
resourceService.addOrUpdateResourceDeatil(req);
return new ApiResponse.ApiResponseBuilder().code(200).data("修改成功").build();
}
}
... ...
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.ufo.service.model.PageRequestBO;
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 java.util.List;
... ... @@ -19,4 +20,8 @@ public interface IResourceService {
void editResourceContentData(ResContentDataModifyBo param);
void batchEditResourceGoodsPool(List<ResGoodsPoolEditBo> param);
void addOrUpdateResource(ResourceReqBo req);
void addOrUpdateResourceDeatil(ResourceReqBo req);
}
... ...
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;
}
}
... ...