package com.dk.mdm.controller.core;

import com.dk.common.model.pojo.PageList;
import com.dk.common.response.ResponseResultVO;
import com.dk.common.service.BaseService;
import com.dk.mdm.model.pojo.core.Organization;
import com.dk.mdm.model.query.core.OrganizationQuery;
import com.dk.mdm.model.response.core.OrganizationResponse;
import com.dk.mdm.model.vo.core.OrganizationVO;
import com.dk.mdm.service.core.OrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@Api(tags = "组织部门API接口")
@RestController
@RequestMapping("/core/organization")
public class OrganizationController{

    public BaseService<Organization> getService() {
        return organizationService;
    }

    @Autowired
    private OrganizationService organizationService;

    /**
     * @desc   : 条件查询
     * @author : 姜宁
     * @date   : 2023/1/10 17:00
     */
    @ApiOperation( value = "分页、关联、条件查询", notes = "分页、关联、条件查询" )
    @PostMapping({"list_by"})
    public ResponseResultVO<PageList<OrganizationResponse>> selectByCond(@RequestBody OrganizationQuery organizationQuery) {
        return organizationService.selectByCond(organizationQuery);
    }

    /**
     * @desc   : 通过ID查询
     * @author : 姜宁
     * @date   : 2023/1/4 13:50
     */
    @PostMapping({"{id}"})
    public ResponseResultVO selectById(@PathVariable Integer id) {
        return organizationService.selectById(id);
    }


    /**
     * @desc   : 新建组织部门
     * @author : 姜宁
     * @date   : 2023/1/11 8:51
     */
    @ApiOperation( value = "新建组织部门", notes = "新建组织部门" )
    @PostMapping({"insert"})
    @Transactional(rollbackFor = Exception.class)
    public ResponseResultVO<?> insert(@RequestBody OrganizationVO organizationVO) {
        return organizationService.insert(organizationVO);
    }

    /**
     * @desc   : 编辑组织部门
     * @author : 姜宁
     * @date   : 2023/1/11 8:51
     */
    @ApiOperation( value = "编辑组织部门", notes = "编辑组织部门" )
    @PostMapping({"update"})
    @Transactional(rollbackFor = Exception.class)
    public ResponseResultVO<Boolean> update(@RequestBody OrganizationVO organizationVO) {
        return organizationService.update(organizationVO);
    }

    /**
     * @desc   : 停用
     * @author : 姜宁
     * @date   : 2023/1/10 17:00
     */
    @ApiOperation(value = "停用", notes = "停用")
    @PostMapping("disable/{id}")
    public ResponseResultVO<Boolean> disable(@PathVariable Integer id) {
        return organizationService.updateOrgFlgValid(id,false);
    }

    /**
     * @desc   : 启用
     * @author : 姜宁
     * @date   : 2023/1/10 17:01
     */
    @ApiOperation(value = "启用", notes = "启用")
    @PostMapping("enable/{id}")
    public ResponseResultVO<Boolean> enable(@PathVariable Integer id) {
        return organizationService.updateOrgFlgValid(id, true);
    }
}
