package com.ruoyi.project.sems.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.sems.domain.ApproveData;
import com.ruoyi.project.sems.domain.TApproverFile;
import com.ruoyi.project.sems.mapper.TApproverFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.sems.mapper.TApproveMapper;
import com.ruoyi.project.sems.domain.TApprove;
import com.ruoyi.project.sems.service.ITApproveService;

/**
 * 特种设备申请Service业务层处理
 *
 * @author ruoyi
 * @date 2021-08-05
 */
@Service("tApproveService")
public class TApproveServiceImpl  extends ServiceImpl<TApproveMapper, TApprove> implements ITApproveService
{
    @Autowired
    private TApproveMapper tApproveMapper;

    /**
     * 查询特种设备申请
     *
     * @param id 特种设备申请ID
     * @return 特种设备申请
     */
    @Override
    public TApprove selectTApproveById(Long id)
    {
        return tApproveMapper.selectTApproveById(id);
    }

    /**
     * 查询特种设备申请列表
     *
     * @param tApprove 特种设备申请
     * @return 特种设备申请
     */
    @Override
    public List<TApprove> selectTApproveList(TApprove tApprove)
    {
        return tApproveMapper.selectTApproveList(tApprove);
    }

    /**
     * 新增特种设备申请
     *
     * @param tApprove 特种设备申请
     * @return 结果
     */
    @Override
    public int insertTApprove(TApprove tApprove)
    {
        return tApproveMapper.insertTApprove(tApprove);
    }

    /**
     * 修改特种设备申请
     *
     * @param tApprove 特种设备申请
     * @return 结果
     */
    @Override
    public int updateTApprove(TApprove tApprove)
    {
        return tApproveMapper.updateTApprove(tApprove);
    }

    /**
     * 批量删除特种设备申请
     *
     * @param ids 需要删除的特种设备申请ID
     * @return 结果
     */
    @Override
    public int deleteTApproveByIds(Long[] ids)
    {
        return tApproveMapper.deleteTApproveByIds(ids);
    }

    /**
     * 删除特种设备申请信息
     *
     * @param id 特种设备申请ID
     * @return 结果
     */
    @Override
    public int deleteTApproveById(Long id)
    {
        return tApproveMapper.deleteTApproveById(id);
    }

    @Override
    public List<ApproveData> approveData(Map<String, Object> params) {
        List<ApproveData> list = new ArrayList<>();
        List<ApproveData> tempList = new ArrayList<>();
        //压力容器
        params.put("devType" , 1);
        tempList = tApproveMapper.approveDataByDevType(params);
        ApproveData data1 = getApproveData();
        data1.setDevName("压力容器");
        for (ApproveData a : tempList
        ) {
            if (a.getNum() == null){
                a.setNum(0l);
            }
            if (a.getApproveType() == 1) {
                data1.setQyNum(a.getNum());
            }else if (a.getApproveType() == 2){
                data1.setTyNum(a.getNum());
            }else if (a.getApproveType() == 3){
                data1.setBfNum(a.getNum());
            }else if (a.getApproveType() == 4){
                data1.setGzNum(a.getNum());
            }else if (a.getApproveType() == 5){
                data1.setYqNum(a.getNum());
            }else if (a.getApproveType() == 6){
                data1.setCsmNum(a.getNum());
            }
        }
        list.add(data1);
        //压力管道
        params.put("devType" , 2);
        tempList = tApproveMapper.approveDataByDevType(params);
        ApproveData data2 = getApproveData();
        data2.setDevName("压力管道");
        for (ApproveData a : tempList
        ) {
            if (a.getNum() == null){
                a.setNum(0l);
            }
            if (a.getApproveType() == 1) {
                data2.setQyNum(a.getNum());
            }else if (a.getApproveType() == 2){
                data2.setTyNum(a.getNum());
            }else if (a.getApproveType() == 3){
                data2.setBfNum(a.getNum());
            }else if (a.getApproveType() == 4){
                data2.setGzNum(a.getNum());
            }else if (a.getApproveType() == 5){
                data2.setYqNum(a.getNum());
            }else if (a.getApproveType() == 6){
                data2.setCsmNum(a.getNum());
            }
        }
        list.add(data2);
        //起重机械
        params.put("devType" , 3);
        tempList = tApproveMapper.approveDataByDevType(params);
        ApproveData data3 = getApproveData();
        data3.setDevName("起重机械");
        for (ApproveData a : tempList
        ) {
            if (a.getNum() == null){
                a.setNum(0l);
            }
            if (a.getApproveType() == 1) {
                data3.setQyNum(a.getNum());
            }else if (a.getApproveType() == 2){
                data3.setTyNum(a.getNum());
            }else if (a.getApproveType() == 3){
                data3.setBfNum(a.getNum());
            }else if (a.getApproveType() == 4){
                data3.setGzNum(a.getNum());
            }else if (a.getApproveType() == 5){
                data3.setYqNum(a.getNum());
            }else if (a.getApproveType() == 6){
                data3.setCsmNum(a.getNum());
            }
        }
        list.add(data3);
        //锅炉
        params.put("devType" , 4);
        tempList = tApproveMapper.approveDataByDevType(params);
        ApproveData data4 = getApproveData();
        data4.setDevName("锅炉");
        for (ApproveData a : tempList
        ) {
            if (a.getNum() == null){
                a.setNum(0l);
            }
            if (a.getApproveType() == 1) {
                data4.setQyNum(a.getNum());
            }else if (a.getApproveType() == 2){
                data4.setTyNum(a.getNum());
            }else if (a.getApproveType() == 3){
                data4.setBfNum(a.getNum());
            }else if (a.getApproveType() == 4){
                data4.setGzNum(a.getNum());
            }else if (a.getApproveType() == 5){
                data4.setYqNum(a.getNum());
            }else if (a.getApproveType() == 6){
                data4.setCsmNum(a.getNum());
            }
        }
        list.add(data4);
        //电梯
        params.put("devType" , 5);
        tempList = tApproveMapper.approveDataByDevType(params);
        ApproveData data5 = getApproveData();
        data5.setDevName("电梯");
        for (ApproveData a : tempList
        ) {
            if (a.getNum() == null){
                a.setNum(0l);
            }
            if (a.getApproveType() == 1) {
                data5.setQyNum(a.getNum());
            }else if (a.getApproveType() == 2){
                data5.setTyNum(a.getNum());
            }else if (a.getApproveType() == 3){
                data5.setBfNum(a.getNum());
            }else if (a.getApproveType() == 4){
                data5.setGzNum(a.getNum());
            }else if (a.getApproveType() == 5){
                data5.setYqNum(a.getNum());
            }else if (a.getApproveType() == 6){
                data5.setCsmNum(a.getNum());
            }
        }
        list.add(data5);
        //叉车
        params.put("devType" , 6);
        tempList = tApproveMapper.approveDataByDevType(params);
        ApproveData data6 = getApproveData();
        data6.setDevName("叉车");
        for (ApproveData a : tempList
        ) {
            if (a.getNum() == null){
                a.setNum(0l);
            }
            if (a.getApproveType() == 1) {
                data6.setQyNum(a.getNum());
            }else if (a.getApproveType() == 2){
                data6.setTyNum(a.getNum());
            }else if (a.getApproveType() == 3){
                data6.setBfNum(a.getNum());
            }else if (a.getApproveType() == 4){
                data6.setGzNum(a.getNum());
            }else if (a.getApproveType() == 5){
                data6.setYqNum(a.getNum());
            }else if (a.getApproveType() == 6){
                data6.setCsmNum(a.getNum());
            }
        }
        list.add(data6);
        return list;
    }

    public ApproveData getApproveData(){
        ApproveData a = new ApproveData();
        a.setTyNum(0l);
        a.setQyNum(0l);
        a.setBfNum(0l);
        a.setGzNum(0l);
        a.setYqNum(0l);
        a.setZxNum(0l);
        a.setCsmNum(0l);
        return a;
    }
}
