审查视图

src/main/java/com/tianbo/warehouse/controller/DeptController.java 2.1 KB
zhangFan authored
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
package com.tianbo.warehouse.controller;

import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.SysDept;
import com.tianbo.warehouse.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author
 * @time 2019-12-18 11:39
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    SysDeptService sysDeptService;

    @GetMapping("/list")
    public ResultJson findAllDept(){
        ResultJson resultJson = new ResultJson();
        resultJson.setData(sysDeptService.findAllDept());
        resultJson.setMsg("success");
        resultJson.setCode("1");
        return resultJson;
    }

    @PostMapping("/add")
    public ResultJson addDept(@RequestBody SysDept sysDept){
        ResultJson resultJson = new ResultJson();
        int count = sysDeptService.insertSelective(sysDept);
        if(count >0){
            resultJson.setMsg("新增成功");
            resultJson.setCode("1");
        }else {
            resultJson.setMsg("新增失败,请稍后重试");
            resultJson.setCode("0");
        }
        return resultJson;
    }

    @PutMapping("/edit")
    public ResultJson updateDept(@RequestBody SysDept sysDept){
        ResultJson resultJson = new ResultJson();
        int count = sysDeptService.updateByPrimaryKeySelective(sysDept);
        if(count >0){
            resultJson.setMsg("更新成功");
            resultJson.setCode("1");
        }else {
            resultJson.setMsg("更新失败,请稍后重试");
            resultJson.setCode("0");
        }
        return resultJson;
    }

    @DeleteMapping("/del")
    public ResultJson updateDept(@RequestParam Integer id){
        ResultJson resultJson = new ResultJson();
        int count = sysDeptService.deleteByPrimaryKey(id);
        if(count >0){
            resultJson.setMsg("删除成功");
            resultJson.setCode("1");
        }else {
            resultJson.setMsg("删除失败,请稍后重试");
            resultJson.setCode("0");
        }
        return resultJson;
    }
}