package com.saye.hospitalgd.controller;

import com.saye.hospitalgd.commons.date.DateDUtil;
import com.saye.hospitalgd.commons.string.StringDUtil;
import com.saye.hospitalgd.model.Dicinfo;
import com.saye.hospitalgd.service.*;
import com.saye.hospitalgd.service.system.DicinfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author thuang
 * @version 1.0
 * @description: 主页数据
 * @date 2021/10/15 15:54
 */

@RequestMapping("/home")
@Controller
@Slf4j
@Api(tags = "主页数据")
public class HomeDateController {

    @Autowired
    private UnilateralService unilateralService;

    @Autowired
    private DicinfoService dicinfoService;

    @Autowired
    private BankbillHistoryService bankbillHistoryService;

    @Autowired
    private HisInterFaceConfigService hisInterFaceConfigService;

    @Autowired
    private HisDetailService hisDetailService;

    @Autowired
    private TransactionDetailService transactionDetailService;

    /**
     * @param modelMap
     * @return
     * @description 主页面
     * @author dqzhang
     * @created 2019年11月13日 下午5:10:21
     */
    @RequestMapping("/toHome")
    public String home(ModelMap modelMap) {

        return "home/home";
    }

    /**
     * @description: 查询对账总览数据
     * @author thuang
     * @date 2021/9/18 16:26
     * @version 1.0
     */
    @RequestMapping("/findDZData")
    @ResponseBody
    @ApiOperation(value = "查询对账总览数据")
    public HashMap<Object, Object> findDZData(@RequestBody HashMap<Object, Object> map) {
        HashMap<Object, Object> responseMap = new HashMap<>();
        String errCode = "0";
        String errMsg = "";

        try {

            //查询关联表数据
            map.put("is_active", "1");
            map.put("check_result", "1");
            List<HashMap<Object, Object>> hisAndThirdJoinData = transactionDetailService.findHisAndThirdJoinData(map);
            int unilateralNum = hisAndThirdJoinData.size();

            BigDecimal his_unilateral = new BigDecimal(0);
            BigDecimal third_unilateral = new BigDecimal(0);
            for (int i = 0; i < hisAndThirdJoinData.size(); i++) {
                HashMap<Object, Object> hashMap = hisAndThirdJoinData.get(i);
                String his_money = StringDUtil.changeNullToEmpty(hashMap.get("AMOUNT"));
                if (!"".equals(his_money)) {
                    his_unilateral = his_unilateral.add(new BigDecimal(his_money));
                }

                String third_money = StringDUtil.changeNullToEmpty(hashMap.get("I_JYJE"));
                if (!"".equals(third_money)) {
                    third_unilateral = third_unilateral.add(new BigDecimal(third_money));
                }
            }

            responseMap.put("unilateralNum", unilateralNum);
            responseMap.put("his_unilateral", his_unilateral);
            responseMap.put("third_unilateral", third_unilateral);
        } catch (Exception e) {
            e.printStackTrace();
        }
        responseMap.put("errCode", errCode);
        responseMap.put("errMsg", errMsg);
        return responseMap;
    }

    /**
     * @description: 查询交易总览数据
     * @author thuang
     * @date 2021/10/15 16:08
     * @version 1.0
     */
    @RequestMapping("/findJYData")
    @ResponseBody
    @ApiOperation(value = "查询交易总览数据")
    public HashMap<Object, Object> findJYData(@RequestBody HashMap<Object, Object> map) {
        HashMap<Object, Object> responseMap = new HashMap<>();
        String errCode = "0";
        String errMsg = "";

        try {
            String startTime = StringDUtil.changeNullToEmpty(map.get("startTime"));
            String endTime = StringDUtil.changeNullToEmpty(map.get("endTime"));
            //计算两个日期间总共的天
            //先计算相差几天
            long daysOfTowDiffDate = DateDUtil.getDaysOfTowDiffDate(startTime, endTime);
            //补充被减的当天
            daysOfTowDiffDate++;

            //从关联表查询交易笔数和金额
            List<HashMap<Object, Object>> list = transactionDetailService.findAllBankDetailNum(map);
            int num = 0;
            if (list.size() > 0) {
                num = Integer.parseInt(StringDUtil.changeNullToEmpty(list.get(0).get("NUM")));
            }

            BigDecimal avgNum = new BigDecimal(num).divide(new BigDecimal(daysOfTowDiffDate), 0, BigDecimal.ROUND_HALF_UP);


            List<HashMap<Object, Object>> list2 = transactionDetailService.findAllBankDetailSum(map);
            BigDecimal money = new BigDecimal(0);
            if (list2.size() > 0) {
                money = new BigDecimal(StringDUtil.changeNullToEmpty(list2.get(0).get("MONEY")));
            }

            BigDecimal avgMoney = money.divide(new BigDecimal(daysOfTowDiffDate), 2, BigDecimal.ROUND_HALF_UP);
            money = money.setScale(2, BigDecimal.ROUND_HALF_UP);


            responseMap.put("allNum", num);
            responseMap.put("avgNum", avgNum);
            responseMap.put("allMoney", money);
            responseMap.put("avgMoney", avgMoney);
        } catch (Exception e) {
            e.printStackTrace();
        }
        responseMap.put("errCode", errCode);
        responseMap.put("errMsg", errMsg);
        return responseMap;
    }

    /**
     * @description: 查询单边账数量
     * @author thuang
     * @date 2021/10/18 13:14
     * @version 1.0
     */
    @PostMapping("/findDBZNum")
    @ResponseBody
    @ApiOperation(value = "查询单边账数量")
    public HashMap<Object, Object> findDBZNum(@RequestBody HashMap<Object, Object> map) {

        HashMap<Object, Object> responseMap = new HashMap<>();
        String errCode = "0";
        String errMsg = "";

        try {
            String startTime = StringDUtil.changeNullToEmpty(map.get("startTime"));
            String endTime = StringDUtil.changeNullToEmpty(map.get("endTime"));

            List<String> betweenDate = DateDUtil.getBetweenDate(startTime, endTime);

            //先生成key为日期的linkhashMap
            LinkedHashMap<String, Integer> numMap = new LinkedHashMap<String, Integer>();
            for (String day : betweenDate) {
                numMap.put(day, 0);
            }


            List<HashMap<Object, Object>> list = transactionDetailService.findDBZNum(map);
            for (HashMap<Object, Object> hashMap : list) {
                String trade_date = StringDUtil.changeNullToEmpty(hashMap.get("TRADE_DATE"));
                String num = StringDUtil.changeNullToEmpty(hashMap.get("NUM"));
                numMap.put(trade_date, Integer.parseInt(num));
            }

            List<String> betweenDateList = new ArrayList<>();
            List<Integer> numList = new ArrayList<>();
            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
            for (String key : numMap.keySet()) {
                Date date = DateDUtil.strToDate(DateDUtil.yyyy_MM_dd, key);
                betweenDateList.add(sdf.format(date));

                Integer integer = numMap.get(key);
                numList.add(integer);
            }

            responseMap.put("betweenDate", betweenDateList);
            responseMap.put("numList", numList);
        } catch (Exception e) {
            e.printStackTrace();
            errCode = "999";
            errMsg = "查询单边账数量失败,原因：" + e.getMessage();
        }
        responseMap.put("errCode", errCode);
        responseMap.put("errMsg", errMsg);
        return responseMap;
    }

    /**
     * @description: 查询单边账概率
     * @author thuang
     * @date 2021/10/18 14:10
     * @version 1.0
     */
    @PostMapping("/findDBZPro")
    @ResponseBody
    @ApiOperation(value = "查询单边账概率")
    public HashMap<Object, Object> findDBZPro(@RequestBody HashMap<Object, Object> map) {
        HashMap<Object, Object> responseMap = new HashMap<>();
        String errCode = "0";
        String errMsg = "";

        try {
            String startTime = StringDUtil.changeNullToEmpty(map.get("startTime"));
            String endTime = StringDUtil.changeNullToEmpty(map.get("endTime"));

            List<String> betweenDate = DateDUtil.getBetweenDate(startTime, endTime);

            //查询字典表支付方式
            List<Dicinfo> pay_type = dicinfoService.findDicinfoTreeNodeList("THIRD_PAY");
            HashMap<String, String> payMethodMap = new HashMap<>();
            for (Dicinfo dicinfo : pay_type) {
                String dicname = dicinfo.getDicname();
                String dicvalue = dicinfo.getDicvalue();

                //聚合支付 银行卡支付 其他剩下的全算其他
                if ((dicname).contains("微信支付") || (dicname).contains("支付宝支付")) {
                    payMethodMap.put(dicvalue, dicname);
                }
            }

            //先组织好map
            LinkedHashMap<String, LinkedHashMap<String, String>> managerMap = new LinkedHashMap<>();// 每天每种数量map
            LinkedHashMap<String, LinkedHashMap<String, String>> unilateralMap = new LinkedHashMap<>();// 单边账记录数map
            LinkedHashMap<String, String> addMap = new LinkedHashMap<>();
            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
            List<String> betweenDateList = new ArrayList<>();
            for (String s : betweenDate) {
                addMap.put(s, "0");

                Date date = DateDUtil.strToDate(DateDUtil.yyyy_MM_dd, s);
                betweenDateList.add(sdf.format(date));
            }

            managerMap.put("微信支付", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});
            managerMap.put("支付宝支付", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});
            managerMap.put("其他", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});

            unilateralMap.put("微信支付", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});
            unilateralMap.put("支付宝支付", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});
            unilateralMap.put("其他", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});

            //返回格式化后的日期数组
            responseMap.put("betweenDate", betweenDateList);

            //查询能对上的数量 对不上的都不能确定该记录是否存在 所以除以对的上的数量
            map.put("is_active", "1");
            List<HashMap<Object, Object>> list = transactionDetailService.findJoinDataNumByTime(map);
            for (HashMap<Object, Object> hashMap : list) {
                String i_jyqd = StringDUtil.changeNullToEmpty(hashMap.get("I_ZFFS"));
                String i_jyrq = StringDUtil.changeNullToEmpty(hashMap.get("TRADE_DATE"));
                String totalNum = StringDUtil.changeNullToEmpty(hashMap.get("TOTALNUM"));
                String str_zffs = "";
                String s = payMethodMap.get(i_jyqd);
                if (s == null) {
                    str_zffs = "其他";
                } else {
                    str_zffs = s;
                }
                LinkedHashMap<String, String> zffsMap = managerMap.get(str_zffs);
                /*if (zffsMap==null){
                    managerMap.put(str_zffs,new LinkedHashMap<String,String>(){{putAll(addMap);}});
                    zffsMap = managerMap.get(str_zffs);
                }*/
                String countNum = zffsMap.get(i_jyrq);
                countNum = new BigDecimal(countNum).add(new BigDecimal(totalNum)).toString();
                zffsMap.put(i_jyrq, countNum);
            }

            //查询单边账记录
            List<HashMap<Object, Object>> dbzList = transactionDetailService.findDBZFLNumByTime(map);
            for (HashMap<Object, Object> hashMap : dbzList) {
                String payType = StringDUtil.changeNullToEmpty(hashMap.get("I_ZFFS"));
                String trade_date = StringDUtil.changeNullToEmpty(hashMap.get("TRADE_DATE"));
                String num = StringDUtil.changeNullToEmpty(hashMap.get("NUM"));
                String str_zffs = "";
                String s = payMethodMap.get(payType);
                if (s == null) {
                    str_zffs = "其他";
                } else {
                    str_zffs = s;
                }
                LinkedHashMap<String, String> zffsMap = unilateralMap.get(str_zffs);
                /*if (zffsMap==null){
                    unilateralMap.put(str_zffs,new LinkedHashMap<String,String>(){{putAll(addMap);}});
                    zffsMap = unilateralMap.get(str_zffs);
                }*/
                String countNum = zffsMap.get(trade_date);
                countNum = new BigDecimal(countNum).add(new BigDecimal(num)).toString();
                zffsMap.put(trade_date, countNum);
            }

            LinkedHashMap<String, String> alldayNumMap = new LinkedHashMap<>();
            LinkedHashMap<String, String> allDBZMap = new LinkedHashMap<>();

            List<HashMap<String, Object>> resultManagerList = new ArrayList<>();

            //key 支付方式
            for (String key : unilateralMap.keySet()) {
                LinkedHashMap<String, String> dbzMap = unilateralMap.get(key);
                LinkedHashMap<String, String> allMap = managerMap.get(key);

                List<String> newList = new ArrayList<>();

                //key2 日期
                for (String key2 : dbzMap.keySet()) {
                    String dbzNum = dbzMap.get(key2);
                    String allNum = allMap.get(key2);

                    //统计总共
                    String num = alldayNumMap.get(key2);
                    if (num != null) {
                        alldayNumMap.put(key2, new BigDecimal(num).add(new BigDecimal(allNum)).toString());
                    } else {
                        alldayNumMap.put(key2, allNum);
                    }

                    //统计单边账总共
                    String dbz = allDBZMap.get(key2);
                    if (dbz != null) {
                        allDBZMap.put(key2, new BigDecimal(dbz).add(new BigDecimal(dbzNum)).toString());
                    } else {
                        allDBZMap.put(key2, dbzNum);
                    }

                    //计算不同支付方式的数据
                    if ("0".equals(dbzNum)) {
                        newList.add("0");
                    } else {
                        if ("0".equals(allNum)) {
                            newList.add("100");
                        } else {
                            BigDecimal divide = new BigDecimal(dbzNum).multiply(new BigDecimal(100)).divide(new BigDecimal(allNum), 2, BigDecimal.ROUND_HALF_UP);
                            if (divide.compareTo(new BigDecimal(100)) > 0) {
                                newList.add("100");
                            } else {
                                newList.add(divide.toString());
                            }
                        }
                    }

                }

                HashMap<String, Object> newMap = new HashMap<>();
                newMap.put("name", key);
                newMap.put("data", newList);

                resultManagerList.add(newMap);
            }

            List<HashMap<String, Object>> resultList = new ArrayList<>();

            //计算总共的
            HashMap<String, Object> newMap = new HashMap<>();
            List<String> newList = new ArrayList<>();
            newMap.put("name", "全部");
            for (String s : allDBZMap.keySet()) {
                String dbzNum = allDBZMap.get(s);
                String allNum = alldayNumMap.get(s);

                //计算不同支付方式的数据
                if ("0".equals(dbzNum)) {
                    newList.add("0");
                } else {
                    if ("0".equals(allNum)) {
                        newList.add("100");
                    } else {
                        BigDecimal divide = new BigDecimal(dbzNum).multiply(new BigDecimal(100)).divide(new BigDecimal(allNum), 2, BigDecimal.ROUND_HALF_UP);
                        if (divide.compareTo(new BigDecimal(100)) > 0) {
                            newList.add("100");
                        } else {
                            newList.add(divide.toString());
                        }
                    }
                }
            }
            newMap.put("data", newList);
            resultList.add(newMap);
            resultList.addAll(resultManagerList);

            responseMap.put("resultList", resultList);
        } catch (Exception e) {
            e.printStackTrace();
            errCode = "999";
            errMsg = "查询单边账概率失败,原因：" + e.getMessage();
        }
        responseMap.put("errCode", errCode);
        responseMap.put("errMsg", errMsg);
        return responseMap;
    }

    /**
     * @description: 查询交易趋势
     * @author thuang
     * @date 2021/10/18 14:51
     * @version 1.0
     */
    @PostMapping("/findjyqsChartsData")
    @ResponseBody
    @ApiOperation(value = "查询交易趋势")
    public HashMap<Object, Object> findjyqsChartsData(@RequestBody HashMap<Object, Object> map) {
        HashMap<Object, Object> responseMap = new HashMap<>();
        String errCode = "0";
        String errMsg = "";

        try {
            String startTime = StringDUtil.changeNullToEmpty(map.get("startTime"));
            String endTime = StringDUtil.changeNullToEmpty(map.get("endTime"));
            String num = StringDUtil.changeNullToEmpty(map.get("num")); //1笔数 2金额

            List<String> betweenDate = DateDUtil.getBetweenDate(startTime, endTime);

            //查询字典表支付方式
            List<Dicinfo> pay_type = dicinfoService.findDicinfoTreeNodeList("THIRD_PAY");
            HashMap<String, String> payMethodMap = new HashMap<>();
            for (Dicinfo dicinfo : pay_type) {
                String dicname = dicinfo.getDicname();
                String dicvalue = dicinfo.getDicvalue();

                //聚合支付,银行卡支付 其他剩下的全算其他
                if ((dicname).contains("微信支付") || (dicname).contains("支付宝支付")) {
                    payMethodMap.put(dicvalue, dicname);
                }
            }

            //先组织好map
            LinkedHashMap<String, LinkedHashMap<String, String>> managerMap = new LinkedHashMap<>();
            LinkedHashMap<String, String> addMap = new LinkedHashMap<>();
            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
            List<String> betweenDateList = new ArrayList<>();
            for (String s : betweenDate) {
                addMap.put(s, "0");

                Date date = DateDUtil.strToDate(DateDUtil.yyyy_MM_dd, s);
                betweenDateList.add(sdf.format(date));
            }

            managerMap.put("微信支付", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});
            managerMap.put("支付宝支付", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});
            managerMap.put("其他", new LinkedHashMap<String, String>() {{
                putAll(addMap);
            }});

            //返回格式化后的日期数组
            responseMap.put("betweenDate", betweenDateList);

            //查询一段时间内每种支付方式的笔数或金额 以银行端为主要数据  num为区分查询笔数还是金额
            if ("1".equals(num)) {
                List<HashMap<Object, Object>> thirdList = transactionDetailService.findBankBillNumByTime(map);

                for (HashMap<Object, Object> hashMap : thirdList) {
                    String num1 = StringDUtil.changeNullToEmpty(hashMap.get("NUM"));
                    String i_jyrq = StringDUtil.changeNullToEmpty(hashMap.get("TRADE_DATE"));
                    String i_zffs = StringDUtil.changeNullToEmpty(hashMap.get("I_JYQD"));
                    String str_zffs = "";
                    String s = payMethodMap.get(i_zffs);
                    if (s == null) {
                        str_zffs = "其他";
                    } else {
                        str_zffs = s;
                    }
                    LinkedHashMap<String, String> zffsMap = managerMap.get(str_zffs);
                    /*if (zffsMap==null){
                        managerMap.put(str_zffs,new LinkedHashMap<String,String>(){{putAll(addMap);}});
                        zffsMap = managerMap.get(str_zffs);
                    }*/
                    String countNum = zffsMap.get(i_jyrq);
                    countNum = new BigDecimal(countNum).add(new BigDecimal(num1)).toString();
                    zffsMap.put(i_jyrq, countNum);
                }

            } else if ("2".equals(num)) {
                List<HashMap<Object, Object>> thirdList = transactionDetailService.findBankBillMoneyByTime(map);
                for (HashMap<Object, Object> hashMap : thirdList) {
                    String money = StringDUtil.changeNullToEmpty(hashMap.get("MONEY"));
                    log.info("hhuoqude money is :" + money);
                    String i_jyrq = StringDUtil.changeNullToEmpty(hashMap.get("TRADE_DATE"));
                    String i_zffs = StringDUtil.changeNullToEmpty(hashMap.get("I_JYQD"));
                    String str_zffs = "";
                    String s = payMethodMap.get(i_zffs);
                    if (s == null) {
                        str_zffs = "其他";
                    } else {
                        str_zffs = s;
                    }
                    LinkedHashMap<String, String> zffsMap = managerMap.get(str_zffs);
                    /*if (zffsMap==null){
                        managerMap.put(str_zffs,new LinkedHashMap<String,String>(){{putAll(addMap);}});
                        zffsMap = managerMap.get(str_zffs);
                    }*/
                    String countNum = zffsMap.get(i_jyrq);
                    countNum = new BigDecimal(countNum).add(new BigDecimal(money)).toString();
                    zffsMap.put(i_jyrq, countNum);
                }
            }

            //将linkedHashMap转为list<hashMap<>> hashMap 中 name 支付方式，data list集合 内容为计算的数据
            List<HashMap<String, Object>> resultList = new ArrayList<>();
            for (String key : managerMap.keySet()) {
                LinkedHashMap<String, String> linkedHashMap = managerMap.get(key);
                List<String> newList = new ArrayList<>();
                for (String key2 : linkedHashMap.keySet()) {
                    String s = linkedHashMap.get(key2);
                    newList.add(s);
                }
                HashMap<String, Object> newMap = new HashMap<>();
                newMap.put("name", key);
                newMap.put("data", newList);
                resultList.add(newMap);
            }
            responseMap.put("resultList", resultList);

        } catch (Exception e) {
            e.printStackTrace();
            errCode = "999";
            errMsg = "查询交易趋势失败,原因：" + e.getMessage();
        }
        responseMap.put("errCode", errCode);
        responseMap.put("errMsg", errMsg);
        return responseMap;
    }


    /**
     * @description: 查询交易占比
     * @author thuang
     * @date 2021/10/18 14:51
     * @version 1.0
     */
    @PostMapping("/findjyzbChartsData")
    @ResponseBody
    @ApiOperation(value = "查询交易占比")
    public HashMap<Object, Object> findjyzbChartsData(@RequestBody HashMap<Object, Object> map) {
        HashMap<Object, Object> responseMap = new HashMap<>();
        String errCode = "0";
        String errMsg = "";

        try {
            String startTime = StringDUtil.changeNullToEmpty(map.get("startTime"));
            String endTime = StringDUtil.changeNullToEmpty(map.get("endTime"));
            String num = StringDUtil.changeNullToEmpty(map.get("num"));//1笔数 2金额


            //查询字典表支付方式
            List<Dicinfo> pay_type = dicinfoService.findDicinfoTreeNodeList("THIRD_PAY");
            HashMap<String, String> payMethodMap = new HashMap<>();
            for (Dicinfo dicinfo : pay_type) {
                String dicname = dicinfo.getDicname();
                String dicvalue = dicinfo.getDicvalue();

                //微信支付支付宝支付 其他剩下的全算其他
                if (dicname.contains("微信") || dicname.contains("支付宝")) {
                    payMethodMap.put(dicvalue, dicname);
                }
            }

            //查询一段时间内每种支付方式的笔数或金额 以银行端为主要数据
            List<HashMap<Object, Object>> resultList = new ArrayList<>();
            String allDataNum = "";
            if ("1".equals(num)) {
                List<HashMap<Object, Object>> thirdList = transactionDetailService.findBankBillNumByTime(map);

                //循环记录 只分为支付宝和其他
                String oldZffs = "";
                HashMap<String, String> newMap = new HashMap<>();
                int jyNum = 0;
                int allNum = 0;
                for (int i = 0; i < thirdList.size(); i++) {
                    HashMap<Object, Object> hashMap = thirdList.get(i);
                    String num1 = StringDUtil.changeNullToEmpty(hashMap.get("NUM"));
                    String i_jyrq = StringDUtil.changeNullToEmpty(hashMap.get("TRADE_DATE"));
                    String i_zffs = StringDUtil.changeNullToEmpty(hashMap.get("I_JYQD"));

                    allNum = allNum + Integer.parseInt(num1);

                    String s = payMethodMap.get(i_zffs);
                    if (s == null) {
                        s = "其他";
                    }
                    String numStr = newMap.get(s);
                    if (numStr == null) {
                        newMap.put(s, "0");
                    }
                    numStr = newMap.get(s);
                    int thisNum = Integer.parseInt(numStr) + Integer.parseInt(num1);
                    newMap.put(s, "" + thisNum);

                }

                for (String key : newMap.keySet()) {
                    String s = newMap.get(key);

                    HashMap<Object, Object> addMap = new HashMap<>();
                    addMap.put("name", key);
                    addMap.put("value", s);

                    resultList.add(addMap);
                }

                allDataNum = "" + allNum;
            } else if ("2".equals(num)) {
                List<HashMap<Object, Object>> thirdList = transactionDetailService.findBankBillMoneyByTime(map);

                String oldZffs = "";
                HashMap<String, String> newMap = new HashMap<>();
                BigDecimal addMoney = new BigDecimal(0);
                BigDecimal allMoney = new BigDecimal(0);
                for (int i = 0; i < thirdList.size(); i++) {
                    HashMap<Object, Object> hashMap = thirdList.get(i);
                    String money = StringDUtil.changeNullToEmpty(hashMap.get("MONEY"));
                    String i_jyrq = StringDUtil.changeNullToEmpty(hashMap.get("TRADE_DATE"));
                    String i_zffs = StringDUtil.changeNullToEmpty(hashMap.get("I_JYQD"));

                    addMoney = addMoney.add(new BigDecimal(money));
                    allMoney = allMoney.add(new BigDecimal(money));

                    String s = payMethodMap.get(i_zffs);
                    if (s == null) {
                        s = "其他";
                    }
                    String moneyStr = newMap.get(s);
                    if (moneyStr == null) {
                        newMap.put(s, "0");
                    }
                    moneyStr = newMap.get(s);
                    BigDecimal thisMoney = new BigDecimal(moneyStr).add(new BigDecimal(money));
                    newMap.put(s, thisMoney.toString());
                }

                for (String key : newMap.keySet()) {
                    String s = newMap.get(key);

                    HashMap<Object, Object> addMap = new HashMap<>();
                    addMap.put("name", key);
                    addMap.put("value", s);
                    resultList.add(addMap);
                }

                allDataNum = allMoney.toString();
            }

            responseMap.put("resultList", resultList);
            responseMap.put("allDataNum", allDataNum);
            //厂商
//            List<HashMap<Object, Object>> firmlist = hisInterFaceConfigService.findAllconfig();
//            HashMap<String, String> firmMap = new HashMap<>();
//            for (HashMap<Object, Object> hashMap : firmlist) {
//                String id = StringDUtil.changeNullToEmpty(hashMap.get("ID"));
//                String his_interface_name = StringDUtil.changeNullToEmpty(hashMap.get("HIS_INTERFACE_NAME"));
//                firmMap.put(id, his_interface_name);
//            }
//
//            List<HashMap<Object, Object>> firmNumList = hisDetailService.findHisDetailFirmNumByTime(map);
//            List<HashMap<Object, Object>> firmNumResultList = new ArrayList<>();
//            for (HashMap<Object, Object> hashMap : firmNumList) {
//                String his_wsdl_id = StringDUtil.changeNullToEmpty(hashMap.get("HIS_WSDL_ID"));
//                String firmNum = StringDUtil.changeNullToEmpty(hashMap.get("FIRMNUM"));
//
//                HashMap<Object, Object> newMap = new HashMap<>();
//                newMap.put("name", firmMap.get(his_wsdl_id));
//                newMap.put("value", firmNum);
//                firmNumResultList.add(newMap);
//            }
//
//            responseMap.put("firmNumResultList", firmNumResultList);
        } catch (Exception e) {
            e.printStackTrace();
            errCode = "999";
            errMsg = "查询交易趋势失败,原因：" + e.getMessage();
        }
        responseMap.put("errCode", errCode);
        responseMap.put("errMsg", errMsg);
        return responseMap;
    }
}