XiaoRuby
2023-07-28 a33396e17dd847f31b62f416f7d9c5a58b79126b
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
package com.yuanchu.limslaboratory.controller;
 
 
import com.yuanchu.limslaboratory.pojo.Classify;
import com.yuanchu.limslaboratory.pojo.dto.UpdateClassifyDto;
import com.yuanchu.limslaboratory.service.ClassifyService;
import com.yuanchu.limslaboratory.utils.JackSonUtil;
import com.yuanchu.limslaboratory.utils.MyUtil;
import com.yuanchu.limslaboratory.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-20
 */
@Api(tags = "实验室-->1、设备台账-->1、分类模块")
@RestController
@RequestMapping("/classify")
public class ClassifyController {
 
    @Autowired
    private ClassifyService classifyService;
 
    @ApiOperation("添加分类:如果选择了name即添加的为子节点数据;如果没有选择即添加的为父节点数据;后台处理")
    @PostMapping("/add")
    public Result<?> addClassifyInformation(@RequestBody Classify classify) {
        if (ObjectUtils.isEmpty(classify.getSonName())){
            return Result.fail("请填写分类名称!");
        }
        Integer isAddClassifySuccess = classifyService.addClassifyInformation(classify);
        if (isAddClassifySuccess == 1) {
            if (ObjectUtils.isEmpty(classify.getSonName())){
                return Result.success("添加父级【"+ classify.getFatherName() +"】分类成功!");
            }
            return Result.success("添加分类【"+ classify.getSonName() +"】成功!");
        } else if (isAddClassifySuccess == 2){
            return Result.fail("抱歉重复添加父级【"+ classify.getFatherName() +"】分类,添加失败!");
        } else if (isAddClassifySuccess == 3) {
            return Result.fail("抱歉重复添加子级【"+ classify.getSonName() +"】,添加失败!");
        }
        return Result.fail("添加分类【"+ classify.getSonName() +"】失败!");
    }
 
    @ApiOperation("分类侧边栏列表:如果sonName为空,则带着father_name的Id进行点击操作")
    @GetMapping("/list")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(value = "分类名称", name = "classifyName", dataTypeClass = String.class)
    })
    public Result<?> getListClassifyInformation(String classifyName) {
        return Result.success(classifyService.getListClassifyInformation(classifyName));
    }
 
    @ApiOperation("删除分类")
    @DeleteMapping("/delete")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(value = "分类Id", name = "classifyId", dataTypeClass = String.class)
    })
    public Result<?> deleteClassifyInformation(String classifyId) {
        Boolean isDeleteSuccess = classifyService.deleteClassifyInformation(classifyId);
        if (isDeleteSuccess){
            return Result.success("删除分类成功!");
        }
        return Result.fail("删除分类失败!");
    }
 
    @ApiOperation("更新分类")
    @PutMapping("/update")
    public Result<?> updateClassifyInformation(@RequestBody UpdateClassifyDto updateClassifyDto) throws Exception {
        Classify classify = JackSonUtil.unmarshal(JackSonUtil.marshal(updateClassifyDto), Classify.class);
        Boolean isUpdateClassifySuccess = classifyService.updateClassifyInformation(classify);
        if (isUpdateClassifySuccess){
            return Result.success("更新分类成功!");
        }
        return Result.fail("更新分类失败!");
    }
}