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.enums.BusinessType;
import com.ruoyi.common.utils.DictUtils;
import com.yanzhu.jh.project.domain.SurProjectMeasure;
import com.yanzhu.jh.project.service.ISurProjectMeasureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version : V1.0
 * @ClassName: ProjectMeasureController
 * @Description: 项目实测实量
 * @Auther: JiangYuQi
 * @Date: 2020/7/7 18:03
 */
@RestController
@RequestMapping("/wechat/projectMeasure")
public class ProjectMeasureController extends BaseController {

    @Autowired
    private ISurProjectMeasureService surProjectMeasureService;

    /**
     *  查询项目实测实量列表
     * @param surProjectMeasure
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(SurProjectMeasure surProjectMeasure){
        if(surProjectMeasure.getDeptId()==0){
            surProjectMeasure.setDeptId(null);
        }
        return success(surProjectMeasureService.selectSurProjectMeasureList(surProjectMeasure));
    }

    /**
     *  统计实测实量
     * @param surProjectMeasure
     * @return
     */
    @GetMapping("/findGroupCountByApprove")
    public AjaxResult findGroupCountByApprove(SurProjectMeasure surProjectMeasure){
        if(surProjectMeasure.getDeptId()==0){
            surProjectMeasure.setDeptId(null);
        }
        return success(surProjectMeasureService.findGroupCountByApprove(surProjectMeasure));
    }

    /**
     * 查询实测实量详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    public AjaxResult info(Long id){
        return success(surProjectMeasureService.selectSurProjectMeasureById(id));
    }

    /**
     * 新增实测实量
     * @param surProjectMeasure
     * @return
     */
    @PostMapping("/add")
    @Log(title = "实测实量", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody SurProjectMeasure surProjectMeasure){
        return success(surProjectMeasureService.insertSurProjectMeasure(surProjectMeasure));
    }

    /**
     * 修改实测实量
     * @param surProjectMeasure
     * @return
     */
    @PostMapping("/edit")
    @Log(title = "实测实量", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody SurProjectMeasure surProjectMeasure){
        return success(surProjectMeasureService.updateSurProjectMeasure(surProjectMeasure));
    }

    /**
     * 删除实测实量
     */
    @Log(title = "实测实量", businessType = BusinessType.DELETE)
    @GetMapping("/remove")
    public AjaxResult remove(@RequestParam Long id)
    {
        return toAjax(surProjectMeasureService.deleteSurProjectMeasureById(id));
    }

    /**
     * 查询特种人员类型
     * @return
     */
    @GetMapping("/queryDictType")
    public AjaxResult queryDictType(String type){
        return success(DictUtils.getDictCache(type));
    }

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

}
