package com.cpms.project.plant.controller;

import com.cpms.common.annotation.Log;
import com.cpms.common.core.controller.BaseController;
import com.cpms.common.core.domain.AjaxResult;
import com.cpms.common.core.page.TableDataInfo;
import com.cpms.common.enums.BusinessType;
import com.cpms.common.utils.poi.ExcelUtil;
import com.cpms.project.plant.domain.TMtPerson;
import com.cpms.project.plant.mapper.TStaffmgrMapper;
import com.cpms.project.plant.service.ITMtPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会议人员Controller
 *
 * @author ruoyi
 * @date 2021-01-14
 */
@RestController
@RequestMapping("/plant/person")
public class TMtPersonController extends BaseController
{
    @Autowired
    private ITMtPersonService tMtPersonService;
    @Resource
    private TStaffmgrMapper tStaffmgrMapper;
    /**
     * 查询会议人员列表
     */
    @PreAuthorize("@ss.hasPermi('plant:keymaintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMtPerson tMtPerson)
    {
        startPage();
        List<TMtPerson> list = tMtPersonService.selectTMtPersonList(tMtPerson);
        return getDataTable(list);
    }

    /**
     * 导出会议人员列表
     */
    @PreAuthorize("@ss.hasPermi('plant:keymaintenance:export')")
    @Log(title = "会议人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMtPerson tMtPerson)
    {
        List<TMtPerson> list = tMtPersonService.selectTMtPersonList(tMtPerson);
        ExcelUtil<TMtPerson> util = new ExcelUtil<TMtPerson>(TMtPerson.class);
        util.exportExcel(response, list, "person");
    }

    /**
     * 获取会议人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('plant:keymaintenance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMtPersonService.selectTMtPersonById(id));
    }

    /**
     * 新增会议人员
     */
    @PreAuthorize("@ss.hasPermi('plant:keymaintenance:add')")
    @Log(title = "会议人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMtPerson tMtPerson)
    {
//        TStaffmgr t = tStaffmgrMapper.selectTStaffmgrByStaffId(tMtPerson.getStaffid());
//        tMtPerson.setActualpost(t.getActualpost());
//        tMtPerson.setDeptId(t.getDeptId());
//        tMtPerson.setName(t.getName());
//        tMtPerson.setPlantCode(t.getPlantCode());
//        tMtPerson.setUnit(t.getUnit());
//        tMtPerson.setContact(t.getContact());
//        tMtPerson.setTeam(t.getTeam());
//        tMtPerson.setSex(t.getSex());
        return toAjax(tMtPersonService.insertTMtPerson(tMtPerson));
    }

    /**
     * 修改会议人员
     */
    @PreAuthorize("@ss.hasPermi('plant:keymaintenance:edit')")
    @Log(title = "会议人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMtPerson tMtPerson)
    {
        return toAjax(tMtPersonService.updateTMtPerson(tMtPerson));
    }

    /**
     * 删除会议人员
     */
    @PreAuthorize("@ss.hasPermi('plant:keymaintenance:remove')")
    @Log(title = "会议人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMtPersonService.deleteTMtPersonByIds(ids));
    }
}
