package com.ym.mec.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.entity.Organization;
import com.ym.mec.biz.dal.page.OrganizationQueryInfo;
import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("organization")
@Api(tags = "分部服务")
@RestController
public class OrganizationController extends BaseController {

    @Autowired
    private OrganizationService organizationService;

    @ApiOperation(value = "分页查询分部列表")
    @GetMapping("/queryPage")
    public Object queryPage(OrganizationQueryInfo queryInfo){
        return succeed(organizationService.queryPage(queryInfo));
    }

    @ApiOperation(value = "新增分部")
    @PostMapping("/add")
    public Object add(Organization organization){
        return succeed(organizationService.insert(organization));
    }

    @ApiOperation(value = "根据分部编号删除分部")
    @PostMapping("/del/{id}")
    public Object del(@ApiParam(value = "分部编号", required = true) @PathVariable("id") Integer id){
        return succeed(organizationService.delete(id));
    }

    @ApiOperation(value = "修改分部信息")
    @PostMapping("/update")
    public Object update(Organization organization){
        organization.setUpdateTime(new Date());
        return succeed(organizationService.update(organization));
    }

    @ApiOperation(value = "根据分部编号查询分部详情")
    @GetMapping("/get/{id}")
    @ApiParam(value = "分部编号", required = true)
    public Object get( @PathVariable("id") Integer id){
        return succeed(organizationService.get(id));
    }
}
