Authored by Lixiaodi

资源位修改

@@ -15,4 +15,8 @@ public interface ResourcesContentDataMapper { @@ -15,4 +15,8 @@ public interface ResourcesContentDataMapper {
15 void insertOrUpdate(@Param("param") ResContentDataModifyBo param); 15 void insertOrUpdate(@Param("param") ResContentDataModifyBo param);
16 16
17 void updateByResContentBo(@Param("param") ResContentDataModifyBo param); 17 void updateByResContentBo(@Param("param") ResContentDataModifyBo param);
  18 +
  19 + int deleteByPrimaryKey(Integer id);
  20 +
  21 + int insert(ResourcesContentData record);
18 } 22 }
@@ -10,4 +10,8 @@ import java.util.List; @@ -10,4 +10,8 @@ import java.util.List;
10 */ 10 */
11 public interface ResourcesContentMapper { 11 public interface ResourcesContentMapper {
12 List<ResourcesContent> selectByResourceId(@Param("id") Integer id); 12 List<ResourcesContent> selectByResourceId(@Param("id") Integer id);
  13 +
  14 + int deleteByPrimaryKey(Integer id);
  15 +
  16 + int insert(ResourcesContent record);
13 } 17 }
@@ -12,4 +12,8 @@ public interface ResourcesMapper { @@ -12,4 +12,8 @@ public interface ResourcesMapper {
12 List<Resources> selectResourcesByPage(@Param("start") int start,@Param("size") int size); 12 List<Resources> selectResourcesByPage(@Param("start") int start,@Param("size") int size);
13 13
14 Resources selectById(@Param("id") Integer id); 14 Resources selectById(@Param("id") Integer id);
  15 +
  16 + int insert(Resources record);
  17 + int updateByPrimaryKeySelective(Resources record);
  18 +
15 } 19 }
@@ -111,4 +111,21 @@ @@ -111,4 +111,21 @@
111 #{id} 111 #{id}
112 </foreach> 112 </foreach>
113 </select> 113 </select>
  114 +
  115 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  116 + delete from resources_content_data
  117 + where id = #{id,jdbcType=INTEGER}
  118 + </delete>
  119 + <insert id="insert" parameterType="com.yoho.ufo.model.resource.ResourcesContentData" >
  120 + insert into resources_content_data (id, platform_id, sort_id,
  121 + resource_content_id, template_key, create_time,
  122 + publish_time, update_time, pre_content_id,
  123 + status, type, content_data
  124 + )
  125 + values (#{id,jdbcType=INTEGER}, #{platformId,jdbcType=INTEGER}, #{sortId,jdbcType=INTEGER},
  126 + #{resourceContentId,jdbcType=INTEGER}, #{templateKey,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER},
  127 + #{publishTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}, #{preContentId,jdbcType=INTEGER},
  128 + #{status,jdbcType=TINYINT}, #{type,jdbcType=TINYINT}, #{contentData,jdbcType=LONGVARCHAR}
  129 + )
  130 + </insert>
114 </mapper> 131 </mapper>
@@ -18,4 +18,16 @@ @@ -18,4 +18,16 @@
18 select <include refid="Base_Column_List" /> from resources_content 18 select <include refid="Base_Column_List" /> from resources_content
19 where resources_id=#{id} 19 where resources_id=#{id}
20 </select> 20 </select>
  21 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  22 + delete from resources_content
  23 + where id = #{id,jdbcType=INTEGER}
  24 + </delete>
  25 + <insert id="insert" parameterType="com.yoho.ufo.model.resource.ResourcesContent" keyProperty="id" useGeneratedKeys="true" >
  26 + insert into resources_content (id, platform_id, sort_id,
  27 + resources_id, name, order_by,
  28 + create_time, status)
  29 + values (#{id,jdbcType=INTEGER}, #{platformId,jdbcType=INTEGER}, #{sortId,jdbcType=INTEGER},
  30 + #{resourcesId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{orderBy,jdbcType=INTEGER},
  31 + #{createTime,jdbcType=INTEGER}, #{status,jdbcType=TINYINT})
  32 + </insert>
21 </mapper> 33 </mapper>
@@ -28,4 +28,56 @@ @@ -28,4 +28,56 @@
28 select <include refid="Base_Column_List" /> from resources 28 select <include refid="Base_Column_List" /> from resources
29 where id=#{id} limit 1 29 where id=#{id} limit 1
30 </select> 30 </select>
  31 +
  32 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.model.resource.Resources" >
  33 + update resources
  34 + <set >
  35 + <if test="name != null" >
  36 + name = #{name,jdbcType=VARCHAR},
  37 + </if>
  38 + <if test="sortId != null" >
  39 + sort_id = #{sortId,jdbcType=INTEGER},
  40 + </if>
  41 + <if test="platformId != null" >
  42 + platform_id = #{platformId,jdbcType=INTEGER},
  43 + </if>
  44 + <if test="code != null" >
  45 + code = #{code,jdbcType=VARCHAR},
  46 + </if>
  47 + <if test="matchCode != null" >
  48 + match_code = #{matchCode,jdbcType=VARCHAR},
  49 + </if>
  50 + <if test="createTime != null" >
  51 + create_time = #{createTime,jdbcType=INTEGER},
  52 + </if>
  53 + <if test="publishTime != null" >
  54 + publish_time = #{publishTime,jdbcType=INTEGER},
  55 + </if>
  56 + <if test="lockPersonName != null" >
  57 + lock_person_name = #{lockPersonName,jdbcType=VARCHAR},
  58 + </if>
  59 + <if test="lockPersonId != null" >
  60 + lock_person_id = #{lockPersonId,jdbcType=VARCHAR},
  61 + </if>
  62 + <if test="lockTime != null" >
  63 + lock_time = #{lockTime,jdbcType=INTEGER},
  64 + </if>
  65 + <if test="status != null" >
  66 + status = #{status,jdbcType=TINYINT},
  67 + </if>
  68 + </set>
  69 + where id = #{id,jdbcType=INTEGER}
  70 + </update>
  71 + <insert id="insert" parameterType="com.yoho.ufo.model.resource.Resources" >
  72 + insert into resources (id, name, sort_id,
  73 + platform_id, code, match_code,
  74 + create_time, publish_time, lock_person_name,
  75 + lock_person_id, lock_time, status
  76 + )
  77 + values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{sortId,jdbcType=INTEGER},
  78 + #{platformId,jdbcType=INTEGER}, #{code,jdbcType=VARCHAR}, #{matchCode,jdbcType=VARCHAR},
  79 + #{createTime,jdbcType=INTEGER}, #{publishTime,jdbcType=INTEGER}, #{lockPersonName,jdbcType=VARCHAR},
  80 + #{lockPersonId,jdbcType=VARCHAR}, #{lockTime,jdbcType=INTEGER}, #{status,jdbcType=TINYINT}
  81 + )
  82 + </insert>
31 </mapper> 83 </mapper>
@@ -6,6 +6,7 @@ import com.yoho.ufo.service.model.ApiResponse; @@ -6,6 +6,7 @@ import com.yoho.ufo.service.model.ApiResponse;
6 import com.yoho.ufo.service.model.PageRequestBO; 6 import com.yoho.ufo.service.model.PageRequestBO;
7 import com.yohobuy.ufo.resource.req.ResContentDataModifyBo; 7 import com.yohobuy.ufo.resource.req.ResContentDataModifyBo;
8 import com.yohobuy.ufo.resource.req.ResGoodsPoolEditBo; 8 import com.yohobuy.ufo.resource.req.ResGoodsPoolEditBo;
  9 +import com.yohobuy.ufo.resource.req.ResourceReqBo;
9 import com.yohobuy.ufo.resource.resp.ResourceGetBo; 10 import com.yohobuy.ufo.resource.resp.ResourceGetBo;
10 import org.apache.commons.collections.CollectionUtils; 11 import org.apache.commons.collections.CollectionUtils;
11 import org.apache.commons.lang3.StringUtils; 12 import org.apache.commons.lang3.StringUtils;
@@ -70,4 +71,24 @@ public class ResourceController { @@ -70,4 +71,24 @@ public class ResourceController {
70 this.resourceService.batchEditResourceGoodsPool(param); 71 this.resourceService.batchEditResourceGoodsPool(param);
71 return new ApiResponse.ApiResponseBuilder().code(200).build(); 72 return new ApiResponse.ApiResponseBuilder().code(200).build();
72 } 73 }
  74 +
  75 + @RequestMapping(value = "/addOrUpdateResource")
  76 + public ApiResponse addOrUpdateResource(ResourceReqBo req) {
  77 + LOGGER.info("enter addOrUpdateResource,param is {}",req);
  78 + if(req == null){
  79 + return new ApiResponse(400, "参数为空", null);
  80 + }
  81 + resourceService.addOrUpdateResource(req);
  82 + return new ApiResponse.ApiResponseBuilder().code(200).data("修改成功").build();
  83 + }
  84 +
  85 + @RequestMapping(value = "/addOrUpdateResourceDeatil")
  86 + public ApiResponse addOrUpdateResourceDeatil(@RequestBody ResourceReqBo req) {
  87 + LOGGER.info("enter addOrUpdateResourceDeatil,param is {}",req);
  88 + if(req == null) {
  89 + return new ApiResponse(400, "参数为空", null);
  90 + }
  91 + resourceService.addOrUpdateResourceDeatil(req);
  92 + return new ApiResponse.ApiResponseBuilder().code(200).data("修改成功").build();
  93 + }
73 } 94 }
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
4 import com.yoho.ufo.service.model.PageRequestBO; 4 import com.yoho.ufo.service.model.PageRequestBO;
5 import com.yohobuy.ufo.resource.req.ResContentDataModifyBo; 5 import com.yohobuy.ufo.resource.req.ResContentDataModifyBo;
6 import com.yohobuy.ufo.resource.req.ResGoodsPoolEditBo; 6 import com.yohobuy.ufo.resource.req.ResGoodsPoolEditBo;
  7 +import com.yohobuy.ufo.resource.req.ResourceReqBo;
7 import com.yohobuy.ufo.resource.resp.ResourceGetBo; 8 import com.yohobuy.ufo.resource.resp.ResourceGetBo;
8 9
9 import java.util.List; 10 import java.util.List;
@@ -19,4 +20,8 @@ public interface IResourceService { @@ -19,4 +20,8 @@ public interface IResourceService {
19 void editResourceContentData(ResContentDataModifyBo param); 20 void editResourceContentData(ResContentDataModifyBo param);
20 21
21 void batchEditResourceGoodsPool(List<ResGoodsPoolEditBo> param); 22 void batchEditResourceGoodsPool(List<ResGoodsPoolEditBo> param);
  23 +
  24 + void addOrUpdateResource(ResourceReqBo req);
  25 +
  26 + void addOrUpdateResourceDeatil(ResourceReqBo req);
22 } 27 }
1 package com.yoho.ufo.resource.service.impl; 1 package com.yoho.ufo.resource.service.impl;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.core.common.utils.MD5;
  5 +import com.yoho.error.exception.ServiceException;
4 import com.yoho.ufo.dal.ResourcesContentDataMapper; 6 import com.yoho.ufo.dal.ResourcesContentDataMapper;
5 import com.yoho.ufo.dal.ResourcesContentMapper; 7 import com.yoho.ufo.dal.ResourcesContentMapper;
6 import com.yoho.ufo.dal.ResourcesGoodsPoolMapper; 8 import com.yoho.ufo.dal.ResourcesGoodsPoolMapper;
@@ -11,19 +13,25 @@ import com.yoho.ufo.model.resource.ResourcesContentData; @@ -11,19 +13,25 @@ import com.yoho.ufo.model.resource.ResourcesContentData;
11 import com.yoho.ufo.model.resource.ResourcesGoodsPool; 13 import com.yoho.ufo.model.resource.ResourcesGoodsPool;
12 import com.yoho.ufo.resource.service.IResourceService; 14 import com.yoho.ufo.resource.service.IResourceService;
13 import com.yoho.ufo.service.model.PageRequestBO; 15 import com.yoho.ufo.service.model.PageRequestBO;
  16 +import com.yoho.ufo.util.CollectionUtil;
14 import com.yoho.ufo.util.DateUtil; 17 import com.yoho.ufo.util.DateUtil;
15 import com.yohobuy.ufo.resource.req.ResContentDataModifyBo; 18 import com.yohobuy.ufo.resource.req.ResContentDataModifyBo;
16 import com.yohobuy.ufo.resource.req.ResGoodsPoolEditBo; 19 import com.yohobuy.ufo.resource.req.ResGoodsPoolEditBo;
  20 +import com.yohobuy.ufo.resource.req.ResourceReqBo;
17 import com.yohobuy.ufo.resource.resp.ResourceGetBo; 21 import com.yohobuy.ufo.resource.resp.ResourceGetBo;
18 import com.yohobuy.ufo.resource.resp.ResourceInfoGetBo; 22 import com.yohobuy.ufo.resource.resp.ResourceInfoGetBo;
19 import org.apache.commons.collections.CollectionUtils; 23 import org.apache.commons.collections.CollectionUtils;
  24 +import org.apache.commons.lang3.StringUtils;
20 import org.slf4j.Logger; 25 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 26 import org.slf4j.LoggerFactory;
  27 +import org.springframework.beans.BeanUtils;
22 import org.springframework.beans.factory.annotation.Autowired; 28 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Service; 29 import org.springframework.stereotype.Service;
24 30
25 import java.util.ArrayList; 31 import java.util.ArrayList;
  32 +import java.util.Iterator;
26 import java.util.List; 33 import java.util.List;
  34 +import java.util.Map;
27 import java.util.stream.Collectors; 35 import java.util.stream.Collectors;
28 36
29 /** 37 /**
@@ -52,6 +60,7 @@ public class ResourceServiceImpl implements IResourceService{ @@ -52,6 +60,7 @@ public class ResourceServiceImpl implements IResourceService{
52 for(Resources res : resourcesList){ 60 for(Resources res : resourcesList){
53 ResourceGetBo bo = new ResourceGetBo(res.getId(), res.getName(), Integer.valueOf(1).equals(res.getPlatformId()) ? "APP" : "小程序", 61 ResourceGetBo bo = new ResourceGetBo(res.getId(), res.getName(), Integer.valueOf(1).equals(res.getPlatformId()) ? "APP" : "小程序",
54 res.getCode(), res.getCreateTime()); 62 res.getCode(), res.getCreateTime());
  63 + bo.setSortId(res.getSortId());
55 resourceGetBoList.add(bo); 64 resourceGetBoList.add(bo);
56 } 65 }
57 return resourceGetBoList; 66 return resourceGetBoList;
@@ -98,6 +107,147 @@ public class ResourceServiceImpl implements IResourceService{ @@ -98,6 +107,147 @@ public class ResourceServiceImpl implements IResourceService{
98 resourcesGoodsPoolMapper.updateBatchByResGoodsPoolBo(param); 107 resourcesGoodsPoolMapper.updateBatchByResGoodsPoolBo(param);
99 } 108 }
100 109
  110 + @Override
  111 + public void addOrUpdateResource(ResourceReqBo req) {
  112 + if (StringUtils.isBlank(req.getName())) {
  113 + throw new ServiceException(400, "资源位名称不能为空!");
  114 + }
  115 + if (req.getSortId() == null || req.getSortId() < 1) {
  116 + throw new ServiceException(400, "请选择类别");
  117 + }
  118 + if (req.getPlatformId() == null || req.getPlatformId() < 1) {
  119 + throw new ServiceException(400, "请选择平台");
  120 + }
  121 + int now = (int) (System.currentTimeMillis() / 1000);
  122 + if (req.getId() == null || req.getId() < 1) {
  123 + // add
  124 + Resources r = new Resources();
  125 + BeanUtils.copyProperties(req, r);
  126 + r.setCode(MD5.md5(System.currentTimeMillis() + ""));
  127 + // 生效
  128 + r.setStatus(1);
  129 +
  130 + //////////////// 未使用 /////////////////
  131 + r.setMatchCode("");
  132 + r.setLockPersonId("");
  133 + r.setLockPersonName("");
  134 + r.setLockTime(0);
  135 + r.setPublishTime(0);
  136 + r.setCreateTime(now);
  137 + /////////////// 未使用 /////////////////
  138 + resourcesMapper.insert(r);
  139 + } else {
  140 + Resources db = resourcesMapper.selectById(req.getId());
  141 + if (db == null) {
  142 + throw new ServiceException(400, "资源位不存在!");
  143 + }
  144 + boolean isChanged = false;
  145 + Resources r = new Resources();
  146 + if (!db.getSortId().equals(req.getSortId())) {
  147 + isChanged = true;
  148 + r.setSortId(req.getSortId());
  149 + }
  150 + if (!db.getPlatformId().equals(req.getPlatformId())) {
  151 + isChanged = true;
  152 + r.setPlatformId(req.getPlatformId());
  153 + }
  154 + if (!db.getName().equals(req.getName())) {
  155 + isChanged = true;
  156 + r.setName(req.getName());
  157 + }
  158 + // update
  159 + if (isChanged) {
  160 + r.setId(req.getId());
  161 + resourcesMapper.updateByPrimaryKeySelective(r);
  162 + }
  163 + }
  164 + }
  165 +
  166 + @Override
  167 + public void addOrUpdateResourceDeatil(ResourceReqBo req) {
  168 + if (req.getId() == null || req.getId() < 1) {
  169 + throw new ServiceException(400, "资源位id不能为空!");
  170 + }
  171 + if (CollectionUtils.isEmpty(req.getItems())) {
  172 + throw new ServiceException(400, "资源位内容不能为空!");
  173 + }
  174 +
  175 + int index = 0;
  176 + // 新增子项目
  177 + for (ResContentDataModifyBo itemBo : req.getItems()) {
  178 + itemBo.setOrderBy(++index);
  179 + }
  180 +
  181 + Resources db = resourcesMapper.selectById(req.getId());
  182 + if (db == null) {
  183 + throw new ServiceException(400, "资源位不存在!");
  184 + }
  185 + int now = (int) (System.currentTimeMillis() / 1000);
  186 + List<ResourcesContent> content = resourcesContentMapper.selectByResourceId(req.getId());
  187 + if (CollectionUtils.isNotEmpty(content)) {
  188 + List<ResourcesContentData> data = resourcesContentDataMapper.selectByContentIds(CollectionUtil.distinct(content, ResourcesContent::getId));
  189 + Map<Integer, ResourcesContentData> dataMap = CollectionUtil.extractMap(data, ResourcesContentData::getResourceContentId);
  190 + Map<Integer, ResourcesContent> contentMap = CollectionUtil.extractMap(content, ResourcesContent::getId);
  191 + for (Iterator<ResContentDataModifyBo> iterator = req.getItems().iterator(); iterator.hasNext();) {
  192 + ResContentDataModifyBo bo = iterator.next();
  193 + if (bo.getId() == null || bo.getId() < 1) {
  194 + continue;
  195 + }
  196 + ResourcesContent c = contentMap.get(bo.getId());
  197 + if (c == null) {
  198 + throw new ServiceException(400, "资源位item:" + bo.getId() + "不存在!");
  199 + }
  200 + ResourcesContentData rcd = dataMap.get(c.getId());
  201 + if (rcd == null) {
  202 + throw new ServiceException(400, "资源位item:" + bo.getId() + "code不存在!");
  203 + }
  204 + if(bo.getTemplateKey().equals(rcd.getTemplateKey())
  205 + && bo.getContentData().equals(rcd.getContentData())
  206 + && bo.getContentName().equals(c.getName())
  207 + && bo.getOrderBy().equals(c.getOrderBy())) {
  208 + iterator.remove();
  209 + contentMap.remove(bo.getId());
  210 + }
  211 + }
  212 + contentMap.forEach((cId, c) -> {
  213 + resourcesContentMapper.deleteByPrimaryKey(cId);
  214 + ResourcesContentData d = dataMap.get(cId);
  215 + if (d != null) {
  216 + resourcesContentDataMapper.deleteByPrimaryKey(d.getId());
  217 + }
  218 + });
  219 + }
  220 +
  221 + // 新增子项目
  222 + for (ResContentDataModifyBo itemBo : req.getItems()) {
  223 + ResourcesContent rc = new ResourcesContent();
  224 + rc.setResourcesId(db.getId());
  225 + rc.setSortId(db.getSortId());
  226 + rc.setPlatformId(db.getPlatformId());
  227 +
  228 + rc.setName(itemBo.getContentName());
  229 + rc.setCreateTime(now);
  230 + rc.setOrderBy(itemBo.getOrderBy());
  231 + rc.setStatus(1);
  232 +
  233 + resourcesContentMapper.insert(rc);
  234 + ResourcesContentData data = new ResourcesContentData();
  235 + data.setResourceContentId(rc.getId());
  236 + data.setSortId(db.getSortId());
  237 + data.setPlatformId(db.getPlatformId());
  238 + data.setTemplateKey(itemBo.getTemplateKey());
  239 + data.setContentData(itemBo.getContentData());
  240 + data.setType(itemBo.getType());
  241 +
  242 + data.setCreateTime(0);
  243 + data.setPublishTime(0);
  244 + data.setStatus(1);
  245 + data.setPreContentId(0);
  246 + data.setUpdateTime(0);
  247 + resourcesContentDataMapper.insert(data);
  248 + }
  249 + }
  250 +
101 private List<ResourceInfoGetBo> initResourceInfoGetBoList(List<ResourcesContent> contentList, List<ResourcesContentData> contentDataList) { 251 private List<ResourceInfoGetBo> initResourceInfoGetBoList(List<ResourcesContent> contentList, List<ResourcesContentData> contentDataList) {
102 LOGGER.info("enter initResourceInfoGetBoList,contentList is {},contentDataList is {}",contentList,contentDataList); 252 LOGGER.info("enter initResourceInfoGetBoList,contentList is {},contentDataList is {}",contentList,contentDataList);
103 List<ResourceInfoGetBo> resInfoList = new ArrayList<>(); 253 List<ResourceInfoGetBo> resInfoList = new ArrayList<>();
@@ -118,4 +268,5 @@ public class ResourceServiceImpl implements IResourceService{ @@ -118,4 +268,5 @@ public class ResourceServiceImpl implements IResourceService{
118 } 268 }
119 return resInfoList; 269 return resInfoList;
120 } 270 }
  271 +
121 } 272 }