package com.ruoyi.project.plant.controller;

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

import com.alibaba.fastjson.JSON;
import com.ruoyi.project.common.domain.DataEntity;
import com.ruoyi.project.plant.mapper.TMtActionlistMapper;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.system.service.ISysDictTypeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.plant.domain.TMtActionlist;
import com.ruoyi.project.plant.service.ITMtActionlistService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 装置会议执行Controller
 *
 * @author ruoyi
 * @date 2020-12-30
 */
@RestController
@RequestMapping("/plant/actionlist")
public class TMtActionlistController extends BaseController
{
    @Autowired
    private ITMtActionlistService tMtActionlistService;
    @Autowired
    private TMtActionlistMapper tMtActionlistMapper;
    @Autowired
    private ISysDictTypeService iSysDictTypeService;

    /**
     * 查询装置会议执行列表
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMtActionlist tMtActionlist)
    {
        logger.info(JSON.toJSONString(tMtActionlist));
        startPage();
        List<TMtActionlist> list = tMtActionlistService.selectTMtActionlistList(tMtActionlist);
        return getDataTable(list);
    }

    //情况统计
    @GetMapping("/actionStatusData")
    public List<DataEntity> actionStatusData(@RequestParam Map param)
    {
        param.put("params" , new HashMap<>());
        logger.info(JSON.toJSONString(param));
        List<DataEntity> list = tMtActionlistMapper.selectAcitonStatusData(param);
        List<SysDictData> dictList = iSysDictTypeService.selectDictDataByType("ACTION_STATUS");
        for (DataEntity d: list
        ) {
            for (SysDictData s: dictList
            ) {
                if (StringUtils.isBlank(d.getDataName())){
                    d.setDataName("未知");
                    break;
                }
                if (s.getDictValue().equals(d.getDataName())){
                    d.setDataName(s.getDictLabel());
                    break;
                }
            }
        }
        return list;
    }

    /**
     * 导出装置会议执行列表
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:export')")
    @Log(title = "装置会议执行", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMtActionlist tMtActionlist)
    {
        List<TMtActionlist> list = tMtActionlistService.selectTMtActionlistList(tMtActionlist);
        ExcelUtil<TMtActionlist> util = new ExcelUtil<TMtActionlist>(TMtActionlist.class);
        return util.exportExcel(list, "actionlist");
    }

    /**
     * 获取装置会议执行详细信息
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMtActionlistService.selectTMtActionlistById(id));
    }

    /**
     * 新增装置会议执行
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:add')")
    @Log(title = "装置会议执行", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMtActionlist tMtActionlist)
    {
        return toAjax(tMtActionlistService.insertTMtActionlist(tMtActionlist));
    }

    /**
     * 修改装置会议执行
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:edit')")
    @Log(title = "装置会议执行", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMtActionlist tMtActionlist)
    {
        return toAjax(tMtActionlistService.updateTMtActionlist(tMtActionlist));
    }

    /**
     * 删除装置会议执行
     */
    @PreAuthorize("@ss.hasPermi('plant:meeting:remove')")
    @Log(title = "装置会议执行", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMtActionlistService.deleteTMtActionlistByIds(ids));
    }
}
