package com.yanzhu.jh.project.controller;

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

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.SysRoleEnum;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.yanzhu.jh.project.domain.SurProjectChecking;
import com.yanzhu.jh.project.service.ISurProjectCheckingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 举牌验收Controller
 * 
 * @author JiangYuQi
 * @date 2023-08-18
 */
@RestController
@RequestMapping("/project/projectChecking")
public class SurProjectCheckingController extends BaseController
{
    @Autowired
    private ISurProjectCheckingService surProjectCheckingService;

    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 查询举牌验收列表
     */
    @PreAuthorize("@ss.hasPermi('project:projectChecking:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurProjectChecking surProjectChecking)
    {
        startPage();
        surProjectChecking.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectChecking.getNowRole())){
            surProjectChecking.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectChecking.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectChecking.setNowUser(Convert.toStr(getUserId()));
        surProjectChecking.setNowUserName(getUsername());
        List<SurProjectChecking> list = surProjectCheckingService.selectSurProjectCheckingList(surProjectChecking);
        return getDataTable(list);
    }

    /**
     * 导出举牌验收列表
     */
    @PreAuthorize("@ss.hasPermi('project:projectChecking:export')")
    @Log(title = "举牌验收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurProjectChecking surProjectChecking)
    {
        surProjectChecking.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectChecking.getNowRole())){
            surProjectChecking.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectChecking.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectChecking.setNowUser(Convert.toStr(getUserId()));
        surProjectChecking.setNowUserName(getUsername());
        List<SurProjectChecking> list = surProjectCheckingService.selectSurProjectCheckingList(surProjectChecking);
        ExcelUtil<SurProjectChecking> util = new ExcelUtil<SurProjectChecking>(SurProjectChecking.class);
        util.exportExcel(response, list, "举牌验收数据");
    }

    /**
     * 获取举牌验收详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:projectChecking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surProjectCheckingService.selectSurProjectCheckingById(id));
    }

    /**
     * 新增举牌验收
     */
    @PreAuthorize("@ss.hasPermi('project:projectChecking:add')")
    @Log(title = "举牌验收", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurProjectChecking surProjectChecking)
    {
        surProjectChecking.setCreateBy(getUsername());
        return toAjax(surProjectCheckingService.insertSurProjectChecking(surProjectChecking));
    }

    /**
     * 修改举牌验收
     */
    @PreAuthorize("@ss.hasPermi('project:projectChecking:edit')")
    @Log(title = "举牌验收", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurProjectChecking surProjectChecking)
    {
        return toAjax(surProjectCheckingService.updateSurProjectChecking(surProjectChecking));
    }

    /**
     * 删除举牌验收
     */
    @PreAuthorize("@ss.hasPermi('project:projectChecking:remove')")
    @Log(title = "举牌验收", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surProjectCheckingService.deleteSurProjectCheckingByIds(ids));
    }

}
