package com.engine.htsc.fzjgtravel.Service.Impl;

import com.engine.core.impl.Service;
import com.engine.htsc.ReimbursementFlow.tool.Apireturn;
import com.engine.htsc.fzjgtravel.Dao.SubsidyDao;
import com.engine.htsc.fzjgtravel.Service.SubsidyService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class SubsidyServiceImpl extends Service implements SubsidyService {

    private  SubsidyDao subsidyDao=new SubsidyDao();

    @Override
    public String getSubsidyService(Map<String, Object> Params) {

        String startdate = Util.null2String(Params.get("startdate"));
        String enddate = Util.null2String(Params.get("enddate"));
        String type=Util.null2String(Params.get("type"));
        if ("".equals(startdate) || "".equals(enddate) || "".equals(type)) {
            return Apireturn.returnmes(400, "参数有误", new JSONArray());
        }
        try{
         JSONArray relateWfAllowancesarray=new JSONArray();
        List<Map<String, Object>> listmap = subsidyDao.getWorkflowInfo(Params);

        for(Map<String, Object> entry : listmap){
            JSONObject relateWfAllowancesObj = new JSONObject();
            relateWfAllowancesObj.put("requestId", Util.null2String(entry.get("requestid")));
            relateWfAllowancesObj.put("workflowNumber", Util.null2String(entry.get("lcbh")));
            relateWfAllowancesObj.put("workflowName", Util.null2String(entry.get("requestname")));
            relateWfAllowancesObj.put("lastOperateTime",Util.null2String(entry.get("lastoperatedate")));
            relateWfAllowancesObj.put("workcode", Util.null2String(entry.get("workcode")));
            relateWfAllowancesObj.put("bankCardNum", Util.null2String(entry.get("yxzh")));
            relateWfAllowancesObj.put("bankName", Util.null2String(entry.get("khxmc")));
            relateWfAllowancesObj.put("allowance", Util.getDoubleValue(Util.null2String(entry.get("yxzfje"))));
            relateWfAllowancesObj.put("deptCode", Util.null2String(entry.get("departmentcode")));
            relateWfAllowancesObj.put("deptName", Util.null2String(entry.get("departmentname")));
            relateWfAllowancesarray.add(relateWfAllowancesObj);
        }
        return Apireturn.returnmes(200,"success",relateWfAllowancesarray);
    }catch (Exception exo){
        JAVATools.SetCmdwritelog("分支机构补贴数据error",exo.getMessage());
    }
        return Apireturn.returnmes(200,"success",new JSONArray());


}


}
