xiaoCJ
parent 78d5f43333
commit 56a75f41d1

@ -153,10 +153,9 @@ public class CourseTagManageController {
@AnonymousAccess
@ApiOperation("二级目录重新排序")
@PostMapping("setTwoCatalogueRank")
public ResultEntity setTwoCatalogueRank(@ApiParam("需要一级ID二级ID和sort")@RequestBody List<SysTwoCatalog> sysTwoCatalogs) {
public ResultEntity setTwoCatalogueRank(@ApiParam("一级ID(可为空)二级ID和sort必传")@RequestBody List<SysTwoCatalog> sysTwoCatalogs) {
for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) {
if (StringUtils.isBlank(sysTwoCatalog.getOneId())
|| StringUtils.isBlank(sysTwoCatalog.getTwoId())
if (StringUtils.isBlank(sysTwoCatalog.getTwoId())
|| sysTwoCatalog.getSort() == null) {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "更新失败,缺少必须的数据!");
}
@ -169,13 +168,13 @@ public class CourseTagManageController {
@AnonymousAccess
@ApiOperation("三级目录重新排序")
@PostMapping("setThreeCatalogueRank")
public ResultEntity setThreeCatalogueRank(@ApiParam("需要一级二级三级ID和sort")@RequestBody List<SysOneCatalog> sysOneCatalogs) {
for (SysOneCatalog sysOneCatalog : sysOneCatalogs) {
if (StringUtils.isBlank(sysOneCatalog.getOneId()) || sysOneCatalog.getSort() == null) {
public ResultEntity setThreeCatalogueRank(@ApiParam("需要一级可为空二级可为空三级ID和sort必传")@RequestBody List<SysThreeCatalog> sysThreeCatalogs) {
for (SysThreeCatalog sysThreeCatalog : sysThreeCatalogs) {
if (StringUtils.isBlank(sysThreeCatalog.getThreeId()) || sysThreeCatalog.getSort() == null) {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "更新失败,缺少必须的数据!");
}
}
sysOneCatalogMapper.updateByBatch(sysOneCatalogs);
sysThreeCatalogMapper.updateByBatch(sysThreeCatalogs);
return null;
}

@ -34,4 +34,6 @@ public interface SysThreeCatalogMapper {
@Select("select three_id,three_name from sys_three_catalog where ont_id = #{oneId} and two_id =#{twoId} order by sort ASC")
List<Map<String, String>> getAllThreeCatalogList(@Param("oneId")String oneId, @Param("twoId")String twoId);
void updateByBatch(@Param("sysThreeCatalogs") List<SysThreeCatalog> sysThreeCatalogs);
}

@ -240,4 +240,57 @@
create_time = #{createTime,jdbcType=TIMESTAMP}
where three_id = #{threeId,jdbcType=VARCHAR}
</update>
<update id="updateByBatch" parameterType="java.util.List">
UPDATE sys_three_catalog
<set>
<!-- 更新 ont_id 字段 -->
<foreach collection="sysThreeCatalogs" item="item" separator=",">
<if test="item.ontId != null and item.ontId != ''">
ont_id = CASE
<foreach collection="sysThreeCatalogs" item="innerItem" separator=" ">
<if test="innerItem.twoId != null and innerItem.ontId != null and innerItem.threeId == item.threeId">
WHEN three_id = #{innerItem.threeId} THEN #{innerItem.ontId}
</if>
</foreach>
ELSE ont_id
END,
</if>
</foreach>
<!-- 更新 two_id 字段 -->
<foreach collection="sysThreeCatalogs" item="item" separator=",">
<if test="item.twoId != null and item.twoId != ''">
two_id = CASE
<foreach collection="sysThreeCatalogs" item="innerItem" separator=" ">
<if test="innerItem.twoId != null and innerItem.ontId != null and innerItem.threeId == item.threeId">
WHEN three_id = #{innerItem.threeId} THEN #{innerItem.twoId}
</if>
</foreach>
ELSE two_id
END,
</if>
</foreach>
<!-- 更新 sort 字段 -->
<foreach collection="sysThreeCatalogs" item="item" separator=",">
<if test="item.sort != null">
sort = CASE
<foreach collection="sysThreeCatalogs" item="innerItem" separator=" ">
<if test="innerItem.twoId != null and innerItem.sort != null and innerItem.threeId == item.threeId">
WHEN three_id = #{innerItem.threeId} THEN #{innerItem.sort}
</if>
</foreach>
ELSE sort
END
</if>
</foreach>
</set>
WHERE three_id IN
<foreach collection="sysThreeCatalogs" item="item" open="(" close=")" separator=",">
#{item.threeId}
</foreach>
</update>
</mapper>

@ -226,24 +226,35 @@
where two_id = #{twoId,jdbcType=VARCHAR}
</update>
<!-- 批量更新方法 -->
<update id="updateByBatch" parameterType="java.util.List">
UPDATE sys_two_catalog
<set>
<foreach collection="sysTwoCatalogs" item="item" separator=",">
sort = CASE
<foreach collection="sysTwoCatalogs" item="item" separator=" ">
<if test="item.oneId != null and item.sort != null">
WHEN one_id = #{item.oneId} THEN #{item.sort}
<!-- 批量更新方法 -->
<update id="updateByBatch" parameterType="java.util.List">
UPDATE sys_two_catalog
<set>
<foreach collection="sysTwoCatalogs" item="item" separator=",">
<if test="item.oneId != null and item.oneId != ''" >
one_id = CASE
<foreach collection="sysTwoCatalogs" item="item" separator=" ">
<if test="item.twoId != null and item.oneId != null">
WHEN two_id = #{item.twoId} THEN #{item.oneId}
</if>
</foreach>
ELSE one_id -- 可选项,用于处理未在 list 中的 twoId
END,
</if>
sort = CASE
<foreach collection="sysTwoCatalogs" item="item" separator=" ">
<if test="item.twoId != null and item.sort != null">
WHEN two_id = #{item.twoId} THEN #{item.sort}
</if>
</foreach>
ELSE sort -- 可选项,用于处理未在 list 中的 twoId
END
</foreach>
ELSE sort -- 可选项,用于处理未在 list 中的 oneId
END
</set>
WHERE two_id IN
<foreach collection="sysTwoCatalogs" item="item" open="(" close=")" separator=",">
#{item.twoId}
</foreach>
</set>
WHERE one_id IN
<foreach collection="sysTwoCatalogs" item="item" open="(" close=")" separator=",">
#{item.oneId}
</foreach>
</update>
</update>
</mapper>
Loading…
Cancel
Save