package com.engine.htsc.sendimage.cmd;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.htsc.cus.HTUtil;

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

/**
 * Author:DTY-PC
 * Date:2020/10/22 20:39
 * Description:
 * Copyright:上海泛微网络科技股份有限公司
 */
public class SendImageCmd extends AbstractCommonCommand<Map<String,Object>> {

    public SendImageCmd(User user,Map<String,Object> params) {
        this.user = user;
        this.params = params;
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String,Object> apidatas  = new HashMap<>();
        BaseBean bb = new BaseBean();
        int uid = user.getUID();
        try {
            ResourceComInfo rc = new ResourceComInfo();
            String workcode = rc.getWorkcode(uid+"");//工号
            String fileids = Util.null2String(params.get("fileids"));//新增文件id
            String billid = Util.null2String(params.get("billid"));//流程编号
            String filetype = Util.null2String(params.get("filetype"));//文件类型 0：非票据  1：票据
            HTUtil ht = new HTUtil();
            List<String> fileidsList = Util.splitString2List(fileids,",");
            Map<String,Object> para = new HashMap<>();
            para.put("workcode",workcode);
            para.put("billid",billid);
            para.put("filetype",filetype);
            JSONArray array = new JSONArray();
            for(String ids : fileidsList){
                JSONObject jsonObject = new JSONObject();
                para.put("fileids",ids);
                String datas = ht.SendImage(para);
                jsonObject.put("datas",datas);
                jsonObject.put("ids",ids);
                array.add(jsonObject);
            }
            apidatas.put("datas",array);
        } catch (Exception e) {
            e.printStackTrace();
            return apidatas;
        }
        return apidatas;
    }

}
