package com.ruoyi.web.project.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.PublicStateEnum;
import com.ruoyi.system.service.ISysDictDataService;
import com.yanzhu.jh.trouble.domain.SmzSspAuditinfo;
import com.yanzhu.jh.trouble.domain.SmzSspProblemmodify;
import com.yanzhu.jh.trouble.service.ISmzSspAuditinfoService;
import com.yanzhu.jh.trouble.service.ISmzSspProblemmodifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @version : V1.0
 * @ClassName: ProjectProblemmodifyController
 * @Description: 项目问题修改
 * @Auther: JiangYuQi
 * @Date: 2020/7/7 18:03
 */
@RestController
@RequestMapping("/wechat/projectProblemmodify")
public class ProjectProblemmodifyController extends BaseController {

    @Autowired
    ISysDictDataService sysDictDataService;

    @Autowired
    ISmzSspAuditinfoService smzSspAuditinfoService;

    @Autowired
    ISmzSspProblemmodifyService smzSspProblemmodifyService;



    /**
     *  查询当前用户问题整改列表
     * @param smzSspProblemmodify
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(SmzSspProblemmodify smzSspProblemmodify){
        return success(smzSspProblemmodifyService.selectWechatSmzSspProblemmodifyList(smzSspProblemmodify));
    }

    /**
     *  查询当前用户问题整改列表
     * @param smzSspProblemmodify
     * @return
     */
    @GetMapping("/queryCount")
    public AjaxResult queryCount(SmzSspProblemmodify smzSspProblemmodify){
        return success(smzSspProblemmodifyService.findProblemmodifyGroupByCheckState(smzSspProblemmodify));
    }

    /**
     * 查询问题整改详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    public AjaxResult info(Long id){
        return success(smzSspProblemmodifyService.selectSmzSspProblemmodifyInfoById(id));
    }

    /**
     * 删除质量整改
     */
    @Log(title = "质量整改", businessType = BusinessType.DELETE)
    @GetMapping("/removeSafety")
    public AjaxResult removeSafety(@RequestParam Long id)
    {
        return toAjax(smzSspProblemmodifyService.deleteSmzSspProblemmodifyById(id));
    }

    /**
     * 删除质量整改
     */
    @Log(title = "质量隐患排查", businessType = BusinessType.DELETE)
    @GetMapping("/removeQuality")
    public AjaxResult removeQuality(@RequestParam Long id)
    {
        return toAjax(smzSspProblemmodifyService.deleteSmzSspProblemmodifyById(id));
    }

    /**
     * 新增问题整改
     * @param smzSspProblemmodify
     * @return
     */
    @PostMapping("/addSafety")
    @Log(title = "安全隐患排查", businessType = BusinessType.INSERT)
    public AjaxResult addSafety(@RequestBody SmzSspProblemmodify smzSspProblemmodify){
        return success(smzSspProblemmodifyService.insertSmzSspProblemmodify(smzSspProblemmodify));
    }

    /**
     * 新增问题整改
     * @param smzSspProblemmodify
     * @return
     */
    @PostMapping("/addQuality")
    @Log(title = "质量隐患排查", businessType = BusinessType.INSERT)
    public AjaxResult addQuality(@RequestBody SmzSspProblemmodify smzSspProblemmodify){
        return success(smzSspProblemmodifyService.insertSmzSspProblemmodify(smzSspProblemmodify));
    }

    /**
     * 查询问题整改详情
     * @param id
     * @return
     */
    @GetMapping("/queryAuditInfo")
    public AjaxResult queryAuditInfo(@RequestParam Long id){
        return success(smzSspAuditinfoService.selectLastSmzSspAuditinfoByMainId(id));
    }

    /**
     * 提交问题整改
     * @param smzSspAuditinfo
     * @return
     */
    @PostMapping("/modifyProblem")
    @Log(title = "举牌验收", businessType = BusinessType.INSERT)
    public AjaxResult modifyProblem(@RequestBody SmzSspAuditinfo smzSspAuditinfo){
        return success(smzSspAuditinfoService.insertSmzSspAuditinfo(smzSspAuditinfo));
    }

    /**
     * 查询隐患类型
     * @param type
     * @return
     */
    @GetMapping("/queryDangerType")
    public AjaxResult queryDangerType(@RequestParam String type){
        SysDictData dictData = new SysDictData();
        dictData.setDictType(type);
        dictData.setStatus(PublicStateEnum.OK.getCode());
        return success(sysDictDataService.selectDictDataList(dictData));
    }



}
