Commit 8a11d2c1 by 徐高华

素材分组排序

parent 601f61a2
...@@ -19,8 +19,18 @@ public class MaterialCategoryDTO implements Serializable{ ...@@ -19,8 +19,18 @@ public class MaterialCategoryDTO implements Serializable{
private Date updateTime; private Date updateTime;
private Integer sortNum;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public Integer getSortNum() {
return sortNum;
}
public void setSortNum(Integer sortNum) {
this.sortNum = sortNum;
}
public String getCategoryId() { public String getCategoryId() {
return categoryId; return categoryId;
} }
......
package com.gic.haoban.manage.api.dto.qdto;
import java.io.Serializable;
public class MaterialCategorySortQDTO implements Serializable {
private String categoryId;
private String wxEnterpriseId;
private Integer sortNum ;
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public Integer getSortNum() {
return sortNum;
}
public void setSortNum(Integer sortNum) {
this.sortNum = sortNum;
}
}
...@@ -7,6 +7,7 @@ import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO; ...@@ -7,6 +7,7 @@ import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO; import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO; import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO; import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.dto.qdto.MaterialCategorySortQDTO;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO; import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import java.util.List; import java.util.List;
...@@ -88,4 +89,9 @@ public interface MaterialApiService { ...@@ -88,4 +89,9 @@ public interface MaterialApiService {
com.gic.api.base.commons.ServiceResponse<String> getMaterialIdByCombined(String wxEnterpriseId, CombinedQDTO combinedQDTO); com.gic.api.base.commons.ServiceResponse<String> getMaterialIdByCombined(String wxEnterpriseId, CombinedQDTO combinedQDTO);
/**
* 排序
* @param qdto
*/
void materialSortCategory(MaterialCategorySortQDTO qdto);
} }
...@@ -8,18 +8,15 @@ import com.gic.haoban.manage.api.dto.MaterialCategoryDTO; ...@@ -8,18 +8,15 @@ import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.service.entity.TabHaobanMaterialCategory; import com.gic.haoban.manage.service.entity.TabHaobanMaterialCategory;
public interface TabHaobanMaterialCategoryMapper { public interface TabHaobanMaterialCategoryMapper {
int deleteByPrimaryKey(String categoryId);
int insert(TabHaobanMaterialCategory record); int insert(TabHaobanMaterialCategory record);
int insertSelective(TabHaobanMaterialCategory record); int getMaxSortNum(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("parentId")String parentId) ;
TabHaobanMaterialCategory selectByPrimaryKey(String categoryId); TabHaobanMaterialCategory selectByPrimaryKey(String categoryId);
int updateByPrimaryKeySelective(TabHaobanMaterialCategory record); int updateByPrimaryKeySelective(TabHaobanMaterialCategory record);
int updateByPrimaryKey(TabHaobanMaterialCategory record);
TabHaobanMaterialCategory selectByCategoryNameAndParentId(@Param("categoryName")String categoryName, TabHaobanMaterialCategory selectByCategoryNameAndParentId(@Param("categoryName")String categoryName,
@Param("categoryParentId")String categoryParentId, @Param("categoryParentId")String categoryParentId,
@Param("wxEnterpriseId")String wxEnterpriseId); @Param("wxEnterpriseId")String wxEnterpriseId);
...@@ -27,4 +24,6 @@ public interface TabHaobanMaterialCategoryMapper { ...@@ -27,4 +24,6 @@ public interface TabHaobanMaterialCategoryMapper {
List<TabHaobanMaterialCategory> listCategory(@Param("wxEnterpriseId")String wxEnterpriseId); List<TabHaobanMaterialCategory> listCategory(@Param("wxEnterpriseId")String wxEnterpriseId);
List<TabHaobanMaterialCategory> listByParentCategory(@Param("categoryId")String categoryId); List<TabHaobanMaterialCategory> listByParentCategory(@Param("categoryId")String categoryId);
void updateSortNum(@Param("list")List<MaterialCategoryDTO> list);
} }
\ No newline at end of file
...@@ -18,8 +18,18 @@ public class TabHaobanMaterialCategory implements Serializable { ...@@ -18,8 +18,18 @@ public class TabHaobanMaterialCategory implements Serializable {
private Date updateTime; private Date updateTime;
private Integer sortNum;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public Integer getSortNum() {
return sortNum;
}
public void setSortNum(Integer sortNum) {
this.sortNum = sortNum;
}
public String getCategoryId() { public String getCategoryId() {
return categoryId; return categoryId;
} }
......
...@@ -3,6 +3,7 @@ package com.gic.haoban.manage.service.service; ...@@ -3,6 +3,7 @@ package com.gic.haoban.manage.service.service;
import java.util.List; import java.util.List;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO; import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.qdto.MaterialCategorySortQDTO;
public interface MaterialCategoryService { public interface MaterialCategoryService {
...@@ -18,4 +19,5 @@ public interface MaterialCategoryService { ...@@ -18,4 +19,5 @@ public interface MaterialCategoryService {
List<MaterialCategoryDTO> listByParentCategory(String categoryId); List<MaterialCategoryDTO> listByParentCategory(String categoryId);
void materialSortCategory(MaterialCategorySortQDTO qdto);
} }
...@@ -3,6 +3,8 @@ package com.gic.haoban.manage.service.service.impl; ...@@ -3,6 +3,8 @@ package com.gic.haoban.manage.service.service.impl;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.gic.haoban.manage.api.dto.qdto.MaterialCategorySortQDTO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -30,6 +32,7 @@ public class MaterialCategoryServiceImpl implements MaterialCategoryService{ ...@@ -30,6 +32,7 @@ public class MaterialCategoryServiceImpl implements MaterialCategoryService{
materialCategoryDTO.setCreateTime(new Date()); materialCategoryDTO.setCreateTime(new Date());
materialCategoryDTO.setUpdateTime(materialCategoryDTO.getCreateTime()); materialCategoryDTO.setUpdateTime(materialCategoryDTO.getCreateTime());
materialCategoryDTO.setStatusFlag(1); materialCategoryDTO.setStatusFlag(1);
materialCategoryDTO.setSortNum(this.mapper.getMaxSortNum(materialCategoryDTO.getWxEnterpriseId(),materialCategoryDTO.getCategoryParentId()) + 1);
mapper.insert(EntityUtil.changeEntityByJSON(TabHaobanMaterialCategory.class, materialCategoryDTO)); mapper.insert(EntityUtil.changeEntityByJSON(TabHaobanMaterialCategory.class, materialCategoryDTO));
} }
...@@ -54,4 +57,51 @@ public class MaterialCategoryServiceImpl implements MaterialCategoryService{ ...@@ -54,4 +57,51 @@ public class MaterialCategoryServiceImpl implements MaterialCategoryService{
return EntityUtil.changeEntityListByJSON(MaterialCategoryDTO.class, mapper.listByParentCategory(categoryId)); return EntityUtil.changeEntityListByJSON(MaterialCategoryDTO.class, mapper.listByParentCategory(categoryId));
} }
@Override
public void materialSortCategory(MaterialCategorySortQDTO qdto) {
String categoryId = qdto.getCategoryId();
Integer sortNum = qdto.getSortNum();
MaterialCategoryDTO dto = this.selectMaterialCategoryById(categoryId) ;
String parentId = dto.getCategoryParentId();
List<MaterialCategoryDTO> list = this.listByParentCategory(parentId) ;
int oldSortNum = 0 ;
for(int i=0;i<list.size();i++) {
MaterialCategoryDTO item = list.get(i) ;
if(item.getCategoryId().equals(categoryId)) {
oldSortNum = i+1 ;
}
}
int index = 1 ;
int maxIndex = sortNum + 1 ;
if(CollectionUtils.isNotEmpty(list)) {
for (int i=0;i<list.size();i++) {
int x = i+1 ;
MaterialCategoryDTO item = list.get(i) ;
if(item.getCategoryId().equals(categoryId)) {
item.setSortNum(sortNum);
continue;
}
// 往后排
if(sortNum > oldSortNum) {
if(x > sortNum) {
item.setSortNum(maxIndex);
maxIndex++ ;
}else {
item.setSortNum(index);
index++ ;
}
continue;
}
// 往前排
if(x >= sortNum) {
item.setSortNum(maxIndex);
maxIndex++ ;
}else {
item.setSortNum(index);
index++ ;
}
}
}
this.mapper.updateSortNum(list) ;
}
} }
...@@ -10,6 +10,7 @@ import java.util.stream.Collectors; ...@@ -10,6 +10,7 @@ import java.util.stream.Collectors;
import com.gic.commons.util.TraceIdUtil; import com.gic.commons.util.TraceIdUtil;
import com.gic.dubbo.entity.ProviderLocalTag; import com.gic.dubbo.entity.ProviderLocalTag;
import com.gic.haoban.manage.api.dto.qdto.MaterialCategorySortQDTO;
import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO; import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import com.gic.haoban.manage.service.context.combined.ImageCombined; import com.gic.haoban.manage.service.context.combined.ImageCombined;
import com.gic.redis.data.util.RedisUtil; import com.gic.redis.data.util.RedisUtil;
...@@ -107,8 +108,11 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -107,8 +108,11 @@ public class MaterialApiServiceImpl implements MaterialApiService {
@Override @Override
public void editCategory(MaterialCategoryDTO materialCategoryDTO) { public void editCategory(MaterialCategoryDTO materialCategoryDTO) {
materialCategoryService.editCategory(materialCategoryDTO); materialCategoryService.editCategory(materialCategoryDTO);
}
@Override
public void materialSortCategory(MaterialCategorySortQDTO qdto) {
this.materialCategoryService.materialSortCategory(qdto) ;
} }
@Override @Override
......
...@@ -9,10 +9,11 @@ ...@@ -9,10 +9,11 @@
<result column="status_flag" property="statusFlag" jdbcType="INTEGER" /> <result column="status_flag" property="statusFlag" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" /> <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="sort_num" property="sortNum" />
</resultMap> </resultMap>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
category_id, category_name, category_parent_id, wx_enterprise_id, status_flag, create_time, category_id, category_name, category_parent_id, wx_enterprise_id, status_flag, create_time,
update_time update_time , sort_num
</sql> </sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" > <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select select
...@@ -20,102 +21,40 @@ ...@@ -20,102 +21,40 @@
from tab_haoban_material_category from tab_haoban_material_category
where category_id = #{categoryId,jdbcType=VARCHAR} where category_id = #{categoryId,jdbcType=VARCHAR}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from tab_haoban_material_category
where category_id = #{categoryId,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterialCategory" > <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterialCategory" >
insert into tab_haoban_material_category (category_id, category_name, category_parent_id, insert into tab_haoban_material_category (category_id, category_name, category_parent_id,
wx_enterprise_id, status_flag, create_time, wx_enterprise_id, status_flag, create_time, sort_num ,
update_time) update_time)
values (#{categoryId,jdbcType=VARCHAR}, #{categoryName,jdbcType=VARCHAR}, #{categoryParentId,jdbcType=VARCHAR}, values (#{categoryId,jdbcType=VARCHAR}, #{categoryName,jdbcType=VARCHAR}, #{categoryParentId,jdbcType=VARCHAR},
#{wxEnterpriseId,jdbcType=VARCHAR}, #{statusFlag,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{wxEnterpriseId,jdbcType=VARCHAR}, #{statusFlag,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{sortNum} ,
#{updateTime,jdbcType=TIMESTAMP}) #{updateTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterialCategory" >
insert into tab_haoban_material_category
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="categoryId != null" >
category_id,
</if>
<if test="categoryName != null" >
category_name,
</if>
<if test="categoryParentId != null" >
category_parent_id,
</if>
<if test="wxEnterpriseId != null" >
wx_enterprise_id,
</if>
<if test="statusFlag != null" >
status_flag,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="categoryId != null" >
#{categoryId,jdbcType=VARCHAR},
</if>
<if test="categoryName != null" >
#{categoryName,jdbcType=VARCHAR},
</if>
<if test="categoryParentId != null" >
#{categoryParentId,jdbcType=VARCHAR},
</if>
<if test="wxEnterpriseId != null" >
#{wxEnterpriseId,jdbcType=VARCHAR},
</if>
<if test="statusFlag != null" >
#{statusFlag,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterialCategory" > <update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterialCategory" >
update tab_haoban_material_category update tab_haoban_material_category
<set > <set >
<if test="categoryName != null" > <if test="categoryName != null" >
category_name = #{categoryName,jdbcType=VARCHAR}, category_name = #{categoryName,jdbcType=VARCHAR},
</if> </if>
<if test="categoryParentId != null" >
category_parent_id = #{categoryParentId,jdbcType=VARCHAR},
</if>
<if test="wxEnterpriseId != null" >
wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
</if>
<if test="statusFlag != null" > <if test="statusFlag != null" >
status_flag = #{statusFlag,jdbcType=INTEGER}, status_flag = #{statusFlag,jdbcType=INTEGER},
</if> </if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" > <if test="updateTime != null" >
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
</set> </set>
where category_id = #{categoryId,jdbcType=VARCHAR} where category_id = #{categoryId,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterialCategory" >
update tab_haoban_material_category <update id="updateSortNum">
set category_name = #{categoryName,jdbcType=VARCHAR}, <foreach collection="list" item="item" separator=";">
category_parent_id = #{categoryParentId,jdbcType=VARCHAR}, UPDATE tab_haoban_material_category
wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}, SET sort_num = #{item.sortNum}
status_flag = #{statusFlag,jdbcType=INTEGER}, WHERE category_id = #{item.categoryId}
create_time = #{createTime,jdbcType=TIMESTAMP}, </foreach>
update_time = #{updateTime,jdbcType=TIMESTAMP}
where category_id = #{categoryId,jdbcType=VARCHAR}
</update> </update>
<select id="selectByCategoryNameAndParentId" resultMap="BaseResultMap" parameterType="java.lang.String" > <select id="selectByCategoryNameAndParentId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
...@@ -131,7 +70,7 @@ ...@@ -131,7 +70,7 @@
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from tab_haoban_material_category from tab_haoban_material_category
where status_flag = 1 where status_flag = 1
and wx_enterprise_id = #{wxEnterpriseId} order by sort_num desc , create_time desc and wx_enterprise_id = #{wxEnterpriseId} order by sort_num asc , create_time desc
</select> </select>
<select id="listByParentCategory" resultMap="BaseResultMap" parameterType="java.lang.String" > <select id="listByParentCategory" resultMap="BaseResultMap" parameterType="java.lang.String" >
...@@ -139,6 +78,12 @@ ...@@ -139,6 +78,12 @@
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from tab_haoban_material_category from tab_haoban_material_category
where status_flag = 1 where status_flag = 1
and category_parent_id = #{categoryId} and category_parent_id = #{categoryId} order by sort_num asc , create_time desc
</select>
<select id="getMaxSortNum" resultType="java.lang.Integer">
select max(sort_num) from tab_haoban_material_category
where wx_enterprise_id = #{wxEnterpriseId}
and category_parent_id = #{parentId} and status_flag = 1
</select> </select>
</mapper> </mapper>
\ No newline at end of file
...@@ -7,6 +7,7 @@ import java.util.Objects; ...@@ -7,6 +7,7 @@ import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.gic.haoban.manage.api.dto.qdto.MaterialCategorySortQDTO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -56,6 +57,26 @@ public class MaterialController extends WebBaseController { ...@@ -56,6 +57,26 @@ public class MaterialController extends WebBaseController {
} }
/** /**
* 排序
* @param qdto
* @return
*/
@RequestMapping("/mateial-sort-category")
public HaobanResponse materialSortCategory(MaterialCategorySortQDTO qdto) {
WebLoginDTO login = AuthWebRequestUtil.getLoginUser();
String wxEnterpriseId = login.getWxEnterpriseId();
qdto.setWxEnterpriseId(wxEnterpriseId);
if (StringUtils.isAnyBlank(qdto.getCategoryId())) {
return resultResponse(HaoBanErrCode.ERR_2);
}
if(null == qdto.getSortNum()) {
return resultResponse(HaoBanErrCode.ERR_2);
}
this.materialApiService.materialSortCategory(qdto);
return resultResponse(HaoBanErrCode.ERR_1);
}
/**
* 素材分组查询 * 素材分组查询
* *
* @return * @return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment