package com.ruoyi.project.ehs.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.ehs.domain.TMatter;
import com.ruoyi.project.ehs.domain.TMatterProtect;
import com.ruoyi.project.ehs.service.ITMatterFeatureService;
import com.ruoyi.project.ehs.service.ITMatterProtectService;
import com.ruoyi.project.ehs.service.ITMatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 工作票-危害物质Controller
 *
 * @author ruoyi
 * @date 2021-09-22
 */
@RestController
@RequestMapping("/ehs/matter")
public class TMatterController extends BaseController {
    @Autowired
    private ITMatterService tMatterService;

    @Autowired
    private ITMatterFeatureService itMatterFeatureService;

    @Autowired
    private ITMatterProtectService itMatterProtectService;

    /**
     * 获取所有的危害物料
     *
     * @return
     */
    @GetMapping("/listMatters")
    public AjaxResult list() {
        List<TMatter> tMatters = this.tMatterService.selectTMatterList(new TMatter());
        for (TMatter tMatter : tMatters) {
            //获取危害分类
            String matterFeatures = tMatter.getMatterFeatures();
            String[] split = matterFeatures.split(",");
            List<String> matterFeatureList = this.itMatterFeatureService.queryByIds(split);
            tMatter.setMatterFeatureList(matterFeatureList);
            //获取危害防护
            String matterProtects = tMatter.getMatterProtects();
            String[] protectIds = matterProtects.split(",");
            List<TMatterProtect> tMatterProtects = this.itMatterProtectService.queryByIds(protectIds);
            tMatter.setProtects(tMatterProtects);
        }
        return AjaxResult.success(tMatters);
    }
}
