package com.bonus.sgzb.base.controller;



import com.bonus.sgzb.base.domain.BmUnitPerson;
import com.bonus.sgzb.base.service.BmUnitPersonService;
import com.bonus.sgzb.base.service.DeptService;
import com.bonus.sgzb.common.core.utils.StringUtils;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.system.api.domain.SysDept;
import com.bonus.sgzb.system.api.domain.SysUser;
import com.bonus.sgzb.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 基础管理  往来单位管理-人员配置
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/bmUnitPerson")
public class BmUnitPersonController extends BaseController{

    @Autowired
    private BmUnitPersonService bmUnitPersonService;

    @Autowired
    private DeptService deptService;

    @Autowired(required = false)
    private ISysUserService iSysUserService;


    /**
     * 获取往来单位管理-人员配置列表
     */
    @GetMapping("/unitPersonAll")
    public TableDataInfo getUnitPersonAll()
    {
        startPage();
        List<BmUnitPerson> list = bmUnitPersonService.getUnitPersonAll();
        return getDataTable(list);

    }

    /**
     * 根据条件进行往来单位管理-人员配置查询
     */
    @PostMapping ("/getUnitPerson")
    public TableDataInfo getUnitPerson(@Validated @RequestBody BmUnitPerson bmUnitPerson)
    {
        startPage();
        List<BmUnitPerson> list = bmUnitPersonService.getUnitPerson(bmUnitPerson);
        return getDataTable(list);

    }


    /**
     * 新增往来单位管理-人员配置
     */
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult unitPersonAdd(@Validated @RequestBody BmUnitPerson bmUnitPerson)
    {
        return toAjax(bmUnitPersonService.unitPersonAdd(bmUnitPerson));
    }

    /**
     * 删除往来单位管理-人员配置
     */
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{unitIds}")
    public AjaxResult remove(@PathVariable Long[] unitIds)
    {
        bmUnitPersonService.remove(unitIds);
        return success();
    }

    /**
     * 修改往来单位管理-人员配置
     */
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BmUnitPerson bmUnitPerson)
    {

        return toAjax(bmUnitPersonService.updateBmUnitPerson(bmUnitPerson));
    }

    /**
     * 获取人员列表
     */
    @PostMapping("/getDeptList")
    public TableDataInfo getDeptList()
    {

        List<SysDept> list = deptService.getDeptList();
        return getDataTable(list);

    }

    /**
     * 根据部门获取人员信息
     */
    @PostMapping("/getUserList")
    public AjaxResult getUserList(@Validated @RequestBody SysDept sysDept)
    {

        if (sysDept.getDeptId()==null) {
            return error("部门id为空！");
        }
        SysUser sysUser = new SysUser();
        sysUser.setDeptId(sysDept.getDeptId());
        List<SysUser> list = iSysUserService.selectUserList(sysUser);
        return success(list);

    }



}
