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.project.domain.SurProjectCheckDetection;
import com.yanzhu.jh.project.service.ISurProjectCheckDetectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version : V1.0
 * @ClassName: ProjectCheckDetectionController
 * @Description: 项目取样复试
 * @Auther: JiangYuQi
 * @Date: 2020/7/7 18:03
 */
@RestController
@RequestMapping("/wechat/projectDetection")
public class ProjectDetectionController extends BaseController {

    @Autowired
    ISysDictDataService sysDictDataService;

    @Autowired
    private ISurProjectCheckDetectionService surProjectCheckDetectionService;

    /**
     *  查询项目取样复试列表
     * @param surProjectCheckDetection
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(SurProjectCheckDetection surProjectCheckDetection){
        if(surProjectCheckDetection.getDeptId()==0){
            surProjectCheckDetection.setDeptId(null);
        }
        return success(surProjectCheckDetectionService.selectSurProjectCheckDetectionList(surProjectCheckDetection));
    }

    /**
     *  查询项目取样复试统计
     * @param surProjectCheckDetection
     * @return
     */
    @GetMapping("/findGroupCountByApprove")
    public AjaxResult findGroupCountByApprove(SurProjectCheckDetection surProjectCheckDetection){
        if(surProjectCheckDetection.getDeptId()==0){
            surProjectCheckDetection.setDeptId(null);
        }
        return success(surProjectCheckDetectionService.findGroupCountByApprove(surProjectCheckDetection));
    }

    /**
     * 查询取样复试详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    public AjaxResult info(Long id){
        return success(surProjectCheckDetectionService.selectSurProjectCheckDetectionById(id));
    }

    /**
     * 新增取样复试
     * @param surProjectCheckDetection
     * @return
     */
    @PostMapping("/add")
    @Log(title = "取样复试", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody SurProjectCheckDetection surProjectCheckDetection){
        return success(surProjectCheckDetectionService.insertSurProjectCheckDetection(surProjectCheckDetection));
    }

    /**
     * 修改取样复试
     * @param surProjectCheckDetection
     * @return
     */
    @PostMapping("/edit")
    @Log(title = "取样复试", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody SurProjectCheckDetection surProjectCheckDetection){
        return success(surProjectCheckDetectionService.updateSurProjectCheckDetection(surProjectCheckDetection));
    }

    /**
     * 删除取样复试
     */
    @Log(title = "取样复试", businessType = BusinessType.DELETE)
    @GetMapping("/remove")
    public AjaxResult remove(@RequestParam Long id)
    {
        return toAjax(surProjectCheckDetectionService.deleteSurProjectCheckDetectionById(id));
    }

    /**
     * 查询复试类型
     * @return
     */
    @GetMapping("/queryType")
    public AjaxResult queryType(){
        SysDictData dictData = new SysDictData();
        dictData.setDictType("check_detection_check_type");
        dictData.setStatus(PublicStateEnum.OK.getCode());
        return success(sysDictDataService.selectDictDataList(dictData));
    }

    /**
     * 根据项目分组查询统计
     * @param projectId
     * @return
     */
    @GetMapping("/selectGroupCountByProjectId")
    public AjaxResult selectGroupCountByProjectId(Long projectId){
        return success(surProjectCheckDetectionService.findGroupCountByProjectId(projectId));
    }
}
