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.SurProjectMaterialSeal;
import com.yanzhu.jh.project.service.ISurProjectMaterialSealService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料封样Controller
 * 
 * @author JiangYuQi
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/project/materialSeal")
public class SurProjectMaterialSealController extends BaseController
{
    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private ISurProjectMaterialSealService surProjectMaterialSealService;

    /**
     * 查询材料封样列表
     */
    @PreAuthorize("@ss.hasPermi('project:materialSeal:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurProjectMaterialSeal surProjectMaterialSeal)
    {
        startPage();
        surProjectMaterialSeal.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectMaterialSeal.getNowRole())){
            surProjectMaterialSeal.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectMaterialSeal.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectMaterialSeal.setNowUser(Convert.toStr(getUserId()));
        List<SurProjectMaterialSeal> list = surProjectMaterialSealService.selectSurProjectMaterialSealList(surProjectMaterialSeal);
        return getDataTable(list);
    }

    /**
     * 导出材料封样列表
     */
    @PreAuthorize("@ss.hasPermi('project:materialSeal:export')")
    @Log(title = "材料封样", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurProjectMaterialSeal surProjectMaterialSeal)
    {
        surProjectMaterialSeal.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectMaterialSeal.getNowRole())){
            surProjectMaterialSeal.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectMaterialSeal.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectMaterialSeal.setNowUser(Convert.toStr(getUserId()));
        List<SurProjectMaterialSeal> list = surProjectMaterialSealService.selectSurProjectMaterialSealList(surProjectMaterialSeal);
        ExcelUtil<SurProjectMaterialSeal> util = new ExcelUtil<SurProjectMaterialSeal>(SurProjectMaterialSeal.class);
        util.exportExcel(response, list, "材料封样数据");
    }

    /**
     * 获取材料封样详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:materialSeal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surProjectMaterialSealService.selectSurProjectMaterialSealById(id));
    }

    /**
     * 新增材料封样
     */
    @PreAuthorize("@ss.hasPermi('project:materialSeal:add')")
    @Log(title = "材料封样", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurProjectMaterialSeal surProjectMaterialSeal)
    {
        return toAjax(surProjectMaterialSealService.insertSurProjectMaterialSeal(surProjectMaterialSeal));
    }

    /**
     * 修改材料封样
     */
    @PreAuthorize("@ss.hasPermi('project:materialSeal:edit')")
    @Log(title = "材料封样", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurProjectMaterialSeal surProjectMaterialSeal)
    {
        return toAjax(surProjectMaterialSealService.updateSurProjectMaterialSeal(surProjectMaterialSeal));
    }

    /**
     * 删除材料封样
     */
    @PreAuthorize("@ss.hasPermi('project:materialSeal:remove')")
    @Log(title = "材料封样", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surProjectMaterialSealService.deleteSurProjectMaterialSealByIds(ids));
    }
}
