“mitao”
2026-01-24 f72c546ff9d03608251a4186ce899b6facba6d05
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.estate.expert.admin.controller.admin;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.estate.expert.admin.domain.business.accidentbrief.AccidentBrief;
import com.estate.expert.admin.domain.business.accidentclassification.AccidentClassification;
import com.estate.expert.admin.domain.common.request.PageReq;
import com.estate.expert.admin.service.AccidentBriefService;
import com.estate.expert.admin.service.AccidentClassificationService;
import com.estate.expert.common.rpc.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
@Slf4j
@CrossOrigin
@Api(tags = "管理后台/故事简讯分类")
@RequestMapping("/admin/accident-classification")
@RestController
@Validated
public class AccidentClassificationController {
 
    @Resource
    private AccidentClassificationService accidentClassificationService;
 
    @ApiOperation(value = "列表")
    @PostMapping("/list")
    public Result list(@ApiParam(value = "名称") @RequestParam(value = "name", required = false) String name,
                       @Validated @RequestBody PageReq pageReq) {
 
        Page<AccidentClassification> page = new Page<>(pageReq.getPage(), pageReq.getSize());
        LambdaQueryWrapper<AccidentClassification> wrapper = new LambdaQueryWrapper<>();
        if(name!=null && !name.isEmpty()){
            wrapper.like(AccidentClassification::getName, name);
        }
        wrapper.eq(AccidentClassification::getDeleted,false);
        wrapper.orderByDesc(AccidentClassification::getId);
        Page<AccidentClassification> res = accidentClassificationService.page(page, wrapper);
        return Result.success(res);
    }
 
 
 
    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public Result add(@Validated @RequestBody AccidentClassification dto) {
        long count = accidentClassificationService.count(new LambdaQueryWrapper<AccidentClassification>().eq(AccidentClassification::getName, dto.getName()));
        if (count > 0) {
            return Result.error("名称已存在");
        }
        dto.setDeleted(false);
        return Result.success(accidentClassificationService.save(dto));
    }
 
 
    @ApiOperation(value = "编辑")
    @PostMapping("/edit")
    public Result edit(@Validated @RequestBody AccidentClassification dto) {
        AccidentClassification accidentClassification = accidentClassificationService.getById(dto.getId());
        long count = accidentClassificationService.count(new LambdaQueryWrapper<AccidentClassification>().eq(AccidentClassification::getName, dto.getName()).ne(AccidentClassification::getId,dto.getId()));
        if (count > 0) {
            return Result.error("名称已存在");
        }
        if (accidentClassification == null) {
            return Result.error("故事简讯类型不存在");
        }
        BeanUtils.copyProperties(dto, accidentClassification);
        dto.setDeleted(false);
        return Result.success(accidentClassificationService.updateById(dto));
    }
 
 
    @ApiOperation(value = "删除")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        AccidentClassification accidentClassification = accidentClassificationService.getById(id);
        if (accidentClassification == null) {
            return Result.error("故事简讯类型不存在");
        }
        accidentClassification.setDeleted( true);
        return Result.success(accidentClassificationService.updateById(accidentClassification));
    }
 
 
 
 
}