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

/**
 * @version : V1.0
 * @ClassName: ProjectInsuranceController
 * @Description: 项目保险
 * @Auther: JiangYuQi
 * @Date: 2020/7/7 18:03
 */
@RestController
@RequestMapping("/wechat/projectInsurance")
public class ProjectInsuranceController extends BaseController {

    @Autowired
    ISysDictDataService sysDictDataService;

    @Autowired
    private ISurProjectInsuranceService surProjectInsuranceService;

    /**
     *  查询项目项目保险列表
     * @param surProjectInsurance
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(SurProjectInsurance surProjectInsurance){
        if(surProjectInsurance.getDeptId()==0){
            surProjectInsurance.setDeptId(null);
        }
        return success(surProjectInsuranceService.selectSurProjectInsuranceList(surProjectInsurance));
    }

    /**
     * 查询项目保险详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    public AjaxResult info(Long id){
        return success(surProjectInsuranceService.selectSurProjectInsuranceById(id));
    }

    /**
     * 新增项目保险
     * @param surProjectInsurance
     * @return
     */
    @PostMapping("/add")
    @Log(title = "项目保险", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody SurProjectInsurance surProjectInsurance){
        return success(surProjectInsuranceService.insertSurProjectInsurance(surProjectInsurance));
    }

    /**
     * 删除项目保险
     */
    @Log(title = "项目保险", businessType = BusinessType.DELETE)
    @GetMapping("/remove")
    public AjaxResult remove(@RequestParam Long id)
    {
        return toAjax(surProjectInsuranceService.deleteSurProjectInsuranceById(id));
    }
    
    /**
     * 根据项目分组查询统计
     * @param projectId
     * @return
     */
    @GetMapping("/selectGroupCountByProjectId")
    public AjaxResult selectGroupCountByProjectId(Long projectId){
        return success(surProjectInsuranceService.findGroupCountByProjectId(projectId));
    }

    /**
     * 查询项目保险类型
     * @return
     */
    @GetMapping("/queryInsuranceType")
    public AjaxResult queryInsuranceType(){
        SysDictData dictData = new SysDictData();
        dictData.setDictType("sur_project_insurance_type");
        dictData.setStatus(PublicStateEnum.OK.getCode());
        return success(sysDictDataService.selectDictDataList(dictData));
    }
}
