package com.zcloud.controller.safetyMeeting;

import com.alibaba.fastjson.JSON;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.service.safetyMeeting.SafetyMeetingService;
import com.zcloud.service.system.ImgFilesService;
import com.zcloud.util.InitPageDataUtil;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.ReturnMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 说明：TODO
 * 作者：wangxuan
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/safetyMeeting")
public class SafetyMeetingController extends BaseController {

    @Resource
    private SafetyMeetingService safetyMeetingService;
    @Resource
    private ImgFilesService imgFilesService;
    @Resource
    private InitPageDataUtil initPageDataUtil;

    /**
     * @Description: 安全例会新增
     * @Author: dearLin
     * @Date: 2024/2/6/006 14:09
     * @Param: [] []
     * @Return: java.lang.Object
     */
    @RequestMapping(value = "/add")
    // @RequiresPermissions("safetyMeeting:add")
    @ResponseBody
    public Object add() throws Exception {
        PageData pageData = getPageData();
        pageData.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());

        initPageDataUtil.initSave(pageData,"SAFETY_MEETING_ID");
        safetyMeetingService.save(pageData);
        return ReturnMap.ok().put("SAFETY_MEETING_ID", pageData.getString("SAFETY_MEETING_ID"));
    }

    /**
     * @Description: 安全例会删除
     * @Author: dearLin
     * @Date: 2024/2/6/006 14:09
     * @Param: [] []
     * @Return: java.lang.Object
     */
    @RequestMapping(value = "/delete")
    // @RequiresPermissions("safetyMeeting:del")
    @ResponseBody
    public Object delete() throws Exception {
        PageData pageData = getPageData();
        initPageDataUtil.initEdit(pageData);
        safetyMeetingService.removeById(pageData);
        return ReturnMap.ok();
    }

    /**
     * @Description: 安全例会列表
     * @Author: dearLin
     * @Date: 2024/2/6/006 14:09
     * @Param: [com.zcloud.entity.Page] [page]
     * @Return: java.lang.Object
     */
    @RequestMapping(value = "/list")
    // @RequiresPermissions("safetyMeeting:list")
    @ResponseBody
    public Object list(Page page) throws Exception {
        PageData pageData = getPageData();
        pageData.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        page.setPd(pageData);
        return ReturnMap.ok().put("varList", safetyMeetingService.list(page)).put("page",page);
    }

    /**
     * @Description: 安全例会详情
     * @Author: dearLin
     * @Date: 2024/2/6/006 14:10
     * @Param: [] []
     * @Return: java.lang.Object
     */
    @RequestMapping(value = "/goEdit")
    // @RequiresPermissions("safetyMeeting:list")
    @ResponseBody
    public Object goEdit() throws Exception {
        PageData pageData = getPageData();
        return ReturnMap.ok().put("pd", safetyMeetingService.findById(pageData))
                .put("people", safetyMeetingService.saftPersonList(pageData))
                .put("imgs", imgFilesService.getListByKeyAndType(pageData.getString("SAFETY_MEETING_ID"), "105"))
                .put("feedbackList", safetyMeetingService.getfeedbackList(pageData))
                ;
    }
    /**
     * @Description: 安全例会 修改
     * @Author: dearLin
     * @Date: 2024/2/6/006 14:10
     * @Param: [] []
     * @Return: java.lang.Object
     */
    @RequestMapping(value = "/edit")
    // @RequiresPermissions("safetyMeeting:list")
    @ResponseBody
    public Object edit() throws Exception {
        PageData pageData = getPageData();
        safetyMeetingService.edit(pageData);
        return ReturnMap.ok().put("SAFETY_MEETING_ID", pageData.getString("SAFETY_MEETING_ID"));
    }
}
