zhangjinli 3 years ago
parent 09b8b686ae
commit 4e40c02444

@ -3,6 +3,7 @@ package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zh.project0512.annotation.adminTokenValid;
import com.zh.project0512.model.Brand;
import com.zh.project0512.service.IBrandService;
@ -64,11 +65,11 @@ public class BrandController {
private Integer id;
}
@Operation(summary = "删除品牌")
@Operation(summary = "删除品牌(软删除)")
@PostMapping("/del")
@adminTokenValid
public Result del(@Validated @RequestBody DelBParam param) {
return MybatisPlusUtil.sqlResult(brandService.removeById(param.getId()), "删除");
return MybatisPlusUtil.sqlResult(brandService.update(new UpdateWrapper<Brand>().eq("id", param.getId()).set("sortWeight",0).set("isDeleted", 1)), "删除");
}
@Data
@ -115,6 +116,9 @@ public class BrandController {
@adminTokenValid
public Result updSort(@Validated @RequestBody UpdBSParam param) {
Brand brand = brandService.getById(param.getId());
if(brand.getIsDeleted() == 1){
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION,"该品牌已被删除");
}
int origin = brand.getSortWeight();
int current = param.getSortWeight();
if(origin==current){

@ -117,6 +117,9 @@ public class TagController {
@adminTokenValid
public Result updSort(@Validated @RequestBody UpdBSParam param) {
Tag tag = tagService.getById(param.getId());
if(tag.getIsDeleted() == 1){
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION,"该标签已被删除");
}
int origin = tag.getSortWeight();
int current = param.getSortWeight();
if (origin == current) {

@ -61,7 +61,7 @@ public class TeachingRefeController {
if (fileUrl.lastIndexOf(".") == -1) {
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "文件错误");
}
teachingRefeService.save(new TeachingRefe().setFileUrl(fileUrl).setType(FileTypeUtil.getcontentTypeNum(fileUrl.substring(fileUrl.lastIndexOf("."))))
teachingRefeService.addTeachingRefe(new TeachingRefe().setFileUrl(fileUrl).setType(FileTypeUtil.getcontentTypeNum(fileUrl.substring(fileUrl.lastIndexOf("."))))
.setTitle(param.getTitle()).setCreatAt(LocalDateTime.now()));
return Result.success("添加完成");
}
@ -74,11 +74,11 @@ public class TeachingRefeController {
private Integer id;
}
@Operation(summary = "删除")
@Operation(summary = "删除(软删除)")
@PostMapping("/del")
@adminTokenValid
public Result del(@Validated @RequestBody DelTCRParam param) {
return MybatisPlusUtil.sqlResult(teachingRefeService.removeById(param.getId()), "删除");
return MybatisPlusUtil.sqlResult(teachingRefeService.update(new UpdateWrapper<TeachingRefe>().eq("id", param.getId()).set("sortWeight",0).set("isDeleted", 1)), "删除");
}
@Data
@ -93,7 +93,7 @@ public class TeachingRefeController {
private String fileUrl;
}
@Operation(summary = "更新标签名称")
@Operation(summary = "更新教程")
@PostMapping("/upd")
@adminTokenValid
public Result upd(@Validated @RequestBody UpdTCRParam param) {
@ -122,8 +122,37 @@ public class TeachingRefeController {
@adminTokenValid
public Result list(@Validated @RequestBody listTCRParam param) {
QueryWrapper<TeachingRefe> qw = new QueryWrapper<>();
qw.orderByDesc("updateAt", "creatAt").like(param.getTitle() != null, "title", param.getTitle());
qw.eq("isDeleted",0).orderByDesc("updateAt", "creatAt").like(param.getTitle() != null, "title", param.getTitle());
return Result.success(teachingRefeService.pageMaps(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()), qw));
}
@Data
static class UpdTRSParam {
@NotNull(message = "id不能为空")
@Min(value = 1, message = "id最小值为1")
@Schema(title = "教程id")
private Integer id;
@NotNull(message = "排序权重不能为空")
@Min(value = 1, message = "排序权重最小值为1")
@Schema(title = "排序权重:数字越小排序靠前")
private Integer sortWeight;
}
@Operation(summary = "修改排序")
@PostMapping("/updSort")
@adminTokenValid
public Result updSort(@Validated @RequestBody UpdTRSParam param) {
TeachingRefe teachingRefe = teachingRefeService.getById(param.getId());
if(teachingRefe.getIsDeleted() == 1){
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION,"该标签已被删除");
}
int origin = teachingRefe.getSortWeight();
int current = param.getSortWeight();
if (origin == current) {
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "权重无变化");
}
teachingRefeService.updSort(origin, current, origin > current);
return Result.success("修改完成");
}
}

@ -42,7 +42,7 @@ public class BrandUController {
@PostMapping("/list")
public Result list(@RequestBody(required = false) @Parameter(hidden = true) JSONObject obj) {
QueryWrapper<Brand> qw = new QueryWrapper<>();
qw.orderByAsc("sortWeight").orderByDesc("updateAt","creatAt");
qw.eq("isDeleted",0).orderByAsc("sortWeight").orderByDesc("updateAt","creatAt");
return Result.success(brandService.pageMaps(MybatisPlusUtil.SetPage(obj),qw));
}
}

@ -33,6 +33,7 @@ import java.time.LocalDateTime;
@RestController
@RequestMapping("/wxApp/tag")
@io.swagger.v3.oas.annotations.tags.Tag(name = "标签")
public class TagUController {
@Autowired
private ITagService tagService;
@ -41,7 +42,7 @@ public class TagUController {
@PostMapping("/list")
public Result list(@RequestBody(required = false) JSONObject obj) {
QueryWrapper<Tag> qw = new QueryWrapper<>();
qw.orderByAsc("sortWeight").orderByDesc("updateAt","creatAt");
qw.eq("isDeleted",0).orderByAsc("sortWeight").orderByDesc("updateAt","creatAt");
return Result.success(tagService.pageMaps(MybatisPlusUtil.SetPage(obj),qw));
}
}

@ -13,16 +13,16 @@ import org.apache.ibatis.annotations.Update;
* @since 2022-05-26
*/
public interface BrandMapper extends BaseMapper<Brand> {
@Update("update brand set sortWeight = sortWeight + 1;\n" +
@Update("update brand set sortWeight = sortWeight + 1 where sortWeight &lt;&gt; 0;;\n" +
"insert into brand ( name, creatAt,sortWeight) VALUES ( #{name}, #{creatAt},1 );")
void addBrand(Brand brand);
@Update("<script>" +
"update brand set sortWeight = -1 where sortWeight = #{origin};\n" +
"<if test='originHigherCurrent'> " +
"update brand set sortWeight = sortWeight + 1 where sortWeight &gt;= #{current} and sortWeight &lt; #{origin};"+
"update brand set sortWeight = sortWeight + 1 where sortWeight &lt;&gt; 0 and sortWeight &gt;= #{current} and sortWeight &lt; #{origin};"+
"</if>" +
"<if test='!originHigherCurrent'> " +
"update brand set sortWeight = sortWeight - 1 where sortWeight &gt; #{origin} and sortWeight &lt;= #{current};\n" +
"update brand set sortWeight = sortWeight - 1 where sortWeight &lt;&gt; 0 and sortWeight &gt; #{origin} and sortWeight &lt;= #{current};\n" +
"</if>" +
"update brand set sortWeight = #{current} where sortWeight = -1;" +
"</script>")

@ -14,7 +14,7 @@ import org.apache.ibatis.annotations.Update;
* @since 2022-05-22
*/
public interface TagMapper extends BaseMapper<Tag> {
@Update("update tag set sortWeight = sortWeight + 1;\n" +
@Update("update tag set sortWeight = sortWeight + 1 where sortWeight &lt;&gt; 0;\n" +
"insert into tag ( title, creatAt,sortWeight) VALUES ( #{title}, #{creatAt},1 );")
void addTag(Tag tag);
@Update("<script>" +

@ -1,7 +1,9 @@
package com.zh.project0512.mapper;
import com.zh.project0512.model.Brand;
import com.zh.project0512.model.TeachingRefe;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Update;
/**
* <p>
@ -12,5 +14,18 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @since 2022-06-14
*/
public interface TeachingRefeMapper extends BaseMapper<TeachingRefe> {
@Update("update teachingRefe set sortWeight = sortWeight + 1 where sortWeight &lt;&gt; 0;;\n" +
"insert into teachingRefe ( fileUrl,type,title, creatAt,sortWeight) VALUES ( #{fileUrl},#{type},#{title}, #{creatAt},1 );")
void addTeachingRefe(TeachingRefe teachingRefe);
@Update("<script>" +
"update teachingRefe set sortWeight = -1 where sortWeight = #{origin};\n" +
"<if test='originHigherCurrent'> " +
"update teachingRefe set sortWeight = sortWeight + 1 where sortWeight &lt;&gt; 0 and sortWeight &gt;= #{current} and sortWeight &lt; #{origin};"+
"</if>" +
"<if test='!originHigherCurrent'> " +
"update teachingRefe set sortWeight = sortWeight - 1 where sortWeight &lt;&gt; 0 and sortWeight &gt; #{origin} and sortWeight &lt;= #{current};\n" +
"</if>" +
"update teachingRefe set sortWeight = #{current} where sortWeight = -1;" +
"</script>")
void updSort(int origin, int current, boolean originHigherCurrent);
}

@ -12,5 +12,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2022-06-14
*/
public interface ITeachingRefeService extends IService<TeachingRefe> {
void addTeachingRefe(TeachingRefe teachingRefe);
void updSort(int origin, int current, boolean originHigherCurrent);
}

@ -1,9 +1,12 @@
package com.zh.project0512.serviceImpl;
import com.zh.project0512.mapper.TagMapper;
import com.zh.project0512.model.Tag;
import com.zh.project0512.model.TeachingRefe;
import com.zh.project0512.mapper.TeachingRefeMapper;
import com.zh.project0512.service.ITeachingRefeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@ -16,5 +19,12 @@ import org.springframework.stereotype.Service;
*/
@Service
public class TeachingRefeServiceImpl extends ServiceImpl<TeachingRefeMapper, TeachingRefe> implements ITeachingRefeService {
@Autowired
private TeachingRefeMapper teachingRefeMapper;
public void addTeachingRefe(TeachingRefe teachingRefe){
teachingRefeMapper.addTeachingRefe(teachingRefe);
}
public void updSort(int origin, int current, boolean originHigherCurrent) {
teachingRefeMapper.updSort(origin, current, originHigherCurrent);
}
}

Loading…
Cancel
Save