DeparmentController.java 3.3 KB
package com.tianbo.warehouse.controller;

import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.Company;
import com.tianbo.warehouse.model.Department;
import com.tianbo.warehouse.service.CompanyService;
import com.tianbo.warehouse.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@RestController
@RequestMapping("/department")
public class DeparmentController {

    @Autowired
    DepartmentService departmentService;

    @GetMapping("/list")
    public PageInfo<Department> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
                                             int pageNum,
                                     @RequestParam(value = "pageSize",required = false,defaultValue = "5")
                                             int pageSize,
                                     @RequestParam(value = "departmentName", required = false) String departmentName){
        return departmentService.findAll(pageNum,pageSize, departmentName);

    }

    @LogAnnotation(moduleName = "部门管理",operate = "部门添加")
    @PostMapping("/add")
    public ResultJson add(@RequestBody Department department){

        int i =departmentService.insertSelective(department);

        ResultJson resultJson = new ResultJson();
        if (1==i){
            resultJson = new ResultJson("200","添加成功");
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }

    @LogAnnotation(moduleName = "部门管理",operate = "部门修改")
    @PutMapping("/edit")
    @ResponseBody
    public ResultJson edit(@RequestBody @Valid Department department){

        int i =departmentService.updateByPrimaryKeySelective(department);

        ResultJson resultJson = new ResultJson();
        if (1==i){
            resultJson = new ResultJson("200","修改成功");
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }

    @LogAnnotation(moduleName = "部门管理",operate = "部门删除")
    @DeleteMapping("/del")
    public ResultJson reomve(@RequestBody Department department, HttpServletRequest request, HttpServletResponse response){

        int i =departmentService.deleteByPrimaryKey(department.getDepartmentId());

        ResultJson resultJson = new ResultJson();
        if (1==i){
            resultJson = new ResultJson("200","删除成功");
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }

    @LogAnnotation(moduleName = "部门管理",operate = "部门批量删除")
    @GetMapping("/batchremove")
    public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){

        ResultJson resultJson = new ResultJson();

        if (departmentService.deleteByPrimaryKey(ids)>0){
            resultJson = new ResultJson("200","删除成功");
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }

}