package com.zcloud.controller.inspectAnnually;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.logs.LogAnno;
import com.zcloud.service.inspectAnnually.InspectAnnuallyService;
import com.zcloud.service.system.ImgFilesService;
import com.zcloud.util.DateUtil;
import com.zcloud.util.Jurisdiction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 年检管理
 */
@Controller
@RequestMapping("/inspectAnnually")
public class InspectAnnuallyController extends BaseController {

    @Autowired
    private InspectAnnuallyService inspectAnnuallyService;
    @Autowired
    private ImgFilesService imgfilesService;

    /**
     * 新增
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/add")
    // @RequiresPermissions( value = {"question:add" , "courseware:add"}, logical = Logical.OR)
    @ResponseBody
    @LogAnno(menuType = "机务档案", menuServer = "年检管理", instructionsOperate = "年检管理", instructionsType = "新增")
    public Object add() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("INSPECTANNUALLY_ID", this.get32UUID());    //主键
        pd.put("CREATOR", Jurisdiction.getUSER_ID());    //添加人id
        pd.put("CREATORNAME", Jurisdiction.getUsername());    //添加人
        pd.put("CREATTIME", DateUtil.date2Str(new Date()));    //添加时间
        pd.put("ISDELETE", "0");    //是否删除(0:有效 1:删除)
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());    //企业ID
        pd.put("ARCHIVES_TYPE", "正常");    //档案状态

        inspectAnnuallyService.save(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 删除
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/delete")
    // @RequiresPermissions( value = {"question:del" , "courseware:del"}, logical = Logical.OR)
    @ResponseBody
    @LogAnno(menuType = "机务档案", menuServer = "年检管理", instructionsOperate = "年检管理", instructionsType = "删除")
    public Object delete() throws Exception {
        Map<String, String> map = new HashMap<String, String>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("DELETEOR", Jurisdiction.getUSER_ID());    //删除人id
        pd.put("DELETEORNAME", Jurisdiction.getUsername());    //删除人
        pd.put("DELETTIME", DateUtil.date2Str(new Date()));    //删除时间
        inspectAnnuallyService.delete(pd);
        map.put("result", errInfo);                //返回结果
        return map;
    }

    /**
     * 修改
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/edit")
    // @RequiresPermissions( value = {"question:edit" , "courseware:edit"}, logical = Logical.OR)
    @ResponseBody
    @LogAnno(menuType = "机务档案", menuServer = "年检管理", instructionsOperate = "年检管理", instructionsType = "修改")
    public Object edit() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("OPERATOR", Jurisdiction.getUSER_ID());    //修改人id
        pd.put("OPERATORNAME", Jurisdiction.getUsername());    //修改人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
        inspectAnnuallyService.edit(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 修改
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/edit2")
    // @RequiresPermissions( value = {"question:edit" , "courseware:edit"}, logical = Logical.OR)
    @ResponseBody
    @LogAnno(menuType = "机务档案", menuServer = "年检管理", instructionsOperate = "年检管理", instructionsType = "修改")
    public Object edit2() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("OPERATOR", Jurisdiction.getUSER_ID());    //修改人id
        pd.put("OPERATORNAME", Jurisdiction.getUsername());    //修改人
        pd.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
        inspectAnnuallyService.edit2(pd);
        map.put("pd", pd);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    @RequestMapping(value = "/list")
    // @RequiresPermissions( value = {"question:list" , "courseware:list"}, logical = Logical.OR)
    @ResponseBody
    @LogAnno(menuType = "机务档案", menuServer = "年检管理", instructionsOperate = "年检管理", instructionsType = "列表")
    public Object list(Page page) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());    //企业ID
        page.setPd(pd);
        List<PageData> varList = inspectAnnuallyService.list(page);    //列出Question列表
        map.put("varList", varList);
        map.put("page", page);
        map.put("result", errInfo);
        return map;
    }

    /**
     * 去修改页面获取数据
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/goEdit")
    // @RequiresPermissions( value = {"question:edit" , "courseware:edit"}, logical = Logical.OR)
    @ResponseBody
    @LogAnno(menuType = "机务档案", menuServer = "年检管理", instructionsOperate = "年检管理", instructionsType = "去修改页面获取数据")
    public Object goEdit() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String errInfo = "success";
        PageData pd = new PageData();
        pd = this.getPageData();
        pd = inspectAnnuallyService.findById(pd);    //根据ID读取

        pd.put("FOREIGN_KEY", pd.getString("INSPECTANNUALLY_ID"));
        pd.put("TYPE",124);
        List<PageData> inspectinfoImgs = imgfilesService.listAll(pd);//年检资料图片

        map.put("pd", pd);
        map.put("inspectinfoImgs", inspectinfoImgs);
        map.put("result", errInfo);
        return map;
    }


}