package org.jeecg.modules.orderplatform.service.impl;

import cn.com.ctop.common.module.entity.MaterialInfo;
import cn.com.ctop.common.module.service.IMaterialInfoService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.orderplatform.entity.PlatformMaterial;
import org.jeecg.modules.orderplatform.mapper.PlatformMaterialMapper;
import org.jeecg.modules.orderplatform.service.IPlatformMaterialService;
import org.jeecg.modules.orderplatform.util.JsonArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 物料审批流程
 */
@Service
public class PlatformMaterialServiceImpl extends ServiceImpl<PlatformMaterialMapper, PlatformMaterial> implements IPlatformMaterialService {

    @Autowired
    PlatformMaterialMapper platformMaterialMapper;

    @Autowired
    IMaterialInfoService materialInfoService;

    @Override
    public List<JSONObject> queryMaterialsByDesignUserId(String materialStatus, String designUserId) {
        JSONArray materialStatusJsonArray = JsonArrayUtil.Varchar2JSONArray(materialStatus);
        List<JSONObject> result=new ArrayList<>();
        if(materialStatus.equals("0")){
            result=platformMaterialMapper.queryMaterialsByDesignLeader(materialStatusJsonArray,designUserId);
        }else {
            result=platformMaterialMapper.queryMaterialsByDesignUserId(materialStatusJsonArray, designUserId);
        }
        return result;
    }

    @Override
    public List<JSONObject> queryMaterialsByOperatorUserId(String operatorUserId) {
        return platformMaterialMapper.queryMaterialsByOperatorUserId(operatorUserId);
    }

    @Override
    public JSONObject queryScriptDetailById(String scriptId) {
        return platformMaterialMapper.queryScriptDetailById(scriptId);
    }

    @Override
    public JSONObject queryVideoDetailById(String videoId) {
        return platformMaterialMapper.queryVideoDetailById(videoId);
    }

    @Override
    public void updateMaterialStatusById(String id) {
        MaterialInfo materialInfo = new MaterialInfo();
        materialInfo.setId(id);
        materialInfo.setStatus(1);
        materialInfoService.updateById(materialInfo);
    }
}
