package com.yanzhu.jh.trouble.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 com.yanzhu.jh.trouble.domain.SmzSspProblemmodify;
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.trouble.domain.SmzSspProblemmodifyDraft;
import com.yanzhu.jh.trouble.service.ISmzSspProblemmodifyDraftService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 随手拍问题整改质量留痕信息Controller
 * 
 * @author JiangYuQi
 * @date 2023-10-15
 */
@RestController
@RequestMapping("/trouble/smzSspProblemmodifyDraft")
public class SmzSspProblemmodifyDraftController extends BaseController
{
    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private ISmzSspProblemmodifyDraftService smzSspProblemmodifyDraftService;

    /**
     * 查询随手拍问题整改质量留痕信息列表
     */
    @PreAuthorize("@ss.hasPermi('trouble:smzSspProblemmodifyDraft:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmzSspProblemmodifyDraft smzSspProblemmodifyDraft)
    {
        startPage();
        smzSspProblemmodifyDraft.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(smzSspProblemmodifyDraft.getNowRole())){
            smzSspProblemmodifyDraft.setProjectDeptId(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            smzSspProblemmodifyDraft.setProjectDeptId(Convert.toStr(getDeptId()));
        }
        smzSspProblemmodifyDraft.setNowUserName(getLoginUser().getUsername());
        List<SmzSspProblemmodifyDraft> list = smzSspProblemmodifyDraftService.selectSmzSspProblemmodifyDraftList(smzSspProblemmodifyDraft);
        return getDataTable(list);
    }

    /**
     * 导出随手拍问题整改质量留痕信息列表
     */
    @PreAuthorize("@ss.hasPermi('trouble:smzSspProblemmodifyDraft:export')")
    @Log(title = "随手拍问题整改质量留痕信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmzSspProblemmodifyDraft smzSspProblemmodifyDraft)
    {
        smzSspProblemmodifyDraft.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(smzSspProblemmodifyDraft.getNowRole())){
            smzSspProblemmodifyDraft.setProjectDeptId(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            smzSspProblemmodifyDraft.setProjectDeptId(Convert.toStr(getDeptId()));
        }
        smzSspProblemmodifyDraft.setNowUserName(getLoginUser().getUsername());
        List<SmzSspProblemmodifyDraft> list = smzSspProblemmodifyDraftService.selectSmzSspProblemmodifyDraftList(smzSspProblemmodifyDraft);
        ExcelUtil<SmzSspProblemmodifyDraft> util = new ExcelUtil<SmzSspProblemmodifyDraft>(SmzSspProblemmodifyDraft.class);
        util.exportExcel(response, list, "随手拍问题整改质量留痕信息数据");
    }

    /**
     * 获取随手拍问题整改质量留痕信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('trouble:smzSspProblemmodifyDraft:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(smzSspProblemmodifyDraftService.selectSmzSspProblemmodifyDraftById(id));
    }

    /**
     * 新增随手拍问题整改质量留痕信息
     */
    @PreAuthorize("@ss.hasPermi('trouble:smzSspProblemmodifyDraft:add')")
    @Log(title = "随手拍问题整改质量留痕信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmzSspProblemmodifyDraft smzSspProblemmodifyDraft)
    {
        return toAjax(smzSspProblemmodifyDraftService.insertSmzSspProblemmodifyDraft(smzSspProblemmodifyDraft));
    }

    /**
     * 批量修改随手拍问题整改质量留痕信息
     */
    @PreAuthorize("@ss.hasPermi('trouble:smzSspProblemmodifyDraft:add')")
    @Log(title = "随手拍问题整改质量留痕信息", businessType = BusinessType.INSERT)
    @PostMapping("/batchUpdate")
    public AjaxResult batchAdd(@RequestBody List<SmzSspProblemmodify> smzSspProblemmodifytList)
    {
        return toAjax(smzSspProblemmodifyDraftService.batchUpdateSmzSspProblemmodifyDraft(smzSspProblemmodifytList));
    }

    /**
     * 修改随手拍问题整改质量留痕信息
     */
    @PreAuthorize("@ss.hasPermi('trouble:smzSspProblemmodifyDraft:edit')")
    @Log(title = "随手拍问题整改质量留痕信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmzSspProblemmodify smzSspProblemmodify)
    {
        return toAjax(smzSspProblemmodifyDraftService.updateSmzSspProblemmodifyDraft(smzSspProblemmodify));
    }

    /**
     * 删除随手拍问题整改质量留痕信息
     */
    @PreAuthorize("@ss.hasPermi('trouble:smzSspProblemmodifyDraft:remove')")
    @Log(title = "随手拍问题整改质量留痕信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smzSspProblemmodifyDraftService.deleteSmzSspProblemmodifyDraftByIds(ids));
    }
}
