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

/**
 * @version : V1.0
 * @ClassName: ProjectMaterialSealController
 * @Description: 项目材料封样
 * @Auther: JiangYuQi
 * @Date: 2020/7/7 18:03
 */
@RestController
@RequestMapping("/wechat/projectMaterialSeal")
public class ProjectMaterialSealController extends BaseController {

    @Autowired
    private ISurProjectMaterialSealService surProjectMaterialSealService;

    /**
     *  查询项目材料封样列表
     * @param surProjectMaterialSeal
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(SurProjectMaterialSeal surProjectMaterialSeal){
        if(surProjectMaterialSeal.getDeptId()==0){
            surProjectMaterialSeal.setDeptId(null);
        }
        return success(surProjectMaterialSealService.selectSurProjectMaterialSealList(surProjectMaterialSeal));
    }

    /**
     *  统计材料封样
     * @param surProjectMaterialSeal
     * @return
     */
    @GetMapping("/findGroupCountByApprove")
    public AjaxResult findGroupCountByApprove(SurProjectMaterialSeal surProjectMaterialSeal){
        if(surProjectMaterialSeal.getDeptId()==0){
            surProjectMaterialSeal.setDeptId(null);
        }
        return success(surProjectMaterialSealService.findGroupCountByApprove(surProjectMaterialSeal));
    }

    /**
     * 查询材料封样详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    public AjaxResult info(Long id){
        return success(surProjectMaterialSealService.selectSurProjectMaterialSealById(id));
    }

    /**
     * 新增材料封样
     * @param surProjectMaterialSeal
     * @return
     */
    @PostMapping("/add")
    @Log(title = "材料封样", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody SurProjectMaterialSeal surProjectMaterialSeal){
        return success(surProjectMaterialSealService.insertSurProjectMaterialSeal(surProjectMaterialSeal));
    }

    /**
     * 修改材料封样
     * @param surProjectMaterialSeal
     * @return
     */
    @PostMapping("/edit")
    @Log(title = "材料封样", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody SurProjectMaterialSeal surProjectMaterialSeal){
        return success(surProjectMaterialSealService.updateSurProjectMaterialSeal(surProjectMaterialSeal));
    }

    /**
     * 删除材料封样
     */
    @Log(title = "材料封样", businessType = BusinessType.DELETE)
    @GetMapping("/remove")
    public AjaxResult remove(@RequestParam Long id)
    {
        return toAjax(surProjectMaterialSealService.deleteSurProjectMaterialSealById(id));
    }

    /**
     * 根据使用部分查询统计材料封样
     * @param projectId
     * @return
     */
    @GetMapping("/selectGroupCountByProjectId")
    public AjaxResult selectGroupCountByProjectId(Long projectId){
        return success(surProjectMaterialSealService.findGroupCountByProjectId(projectId));
    }
}
