xiaoCJ 8 months ago
parent 78d5f43333
commit 56a75f41d1

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

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