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

import com.engine.core.impl.Service;
import com.engine.htsc.ReimbursementFlow.Dao.ReimbursementExcelDao;
import com.engine.htsc.ReimbursementFlow.Service.ReimbursementExcelService;
import com.engine.htsc.ReimbursementFlow.model.ExcelPayDetailZhiFu;
import com.engine.htsc.ReimbursementFlow.model.NewDepart;
import com.engine.htsc.ReimbursementFlow.model.NewUser;
import com.engine.htsc.payment.util.PayUtil;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.CellType;
import weaver.common.StringUtil;
import weaver.interfaces.htsc.GlobatTools.ConstUtil;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

public class ReimbursementExcelServiceImpl extends Service implements ReimbursementExcelService {
    private ReimbursementExcelDao reimbursementExcelDao = new ReimbursementExcelDao();

    @Override
    public String exportPaymentDetailExcel(Map<String, Object> params) {
        try {
            JAVATools.SetCmdwritelog("=======requestids=================" + params.get("requestids").toString());
            String[] reqids = params.get("requestids").toString().split(",");
            List<ExcelPayDetailZhiFu> data = new ArrayList<ExcelPayDetailZhiFu>();
            for (int i = 0; i < reqids.length; i++) {
                String entry = 1 + i + "";
                String reqid = reqids[i];
                String tablename = JAVATools.getMaintable(reqid);
                if ("formtable_main_".equals(tablename)) {
                    continue;
                }
                JAVATools.SetCmdwritelog("request:" + reqid + " 查询主表的表名:" + tablename);
                Map<String, Object> mainMap = reimbursementExcelDao.getMainMap(reqid, tablename);
                if (null == mainMap) {
                    continue;
                }
                String lcbh = ConstUtil.newNullString(mainMap.get("lcbh"));
                String lcbtSql = "select REQUESTNAME,workflowid from workflow_requestbase  where requestid= " + reqid;
                Map<String, Object> lcbtMap = JAVATools.GetTableToMap(lcbtSql, null);
                String workflowid = ConstUtil.newNullString(lcbtMap.get("workflowid"));
                String unNumber = PayUtil.getUnNumberByWorkFlowId(Integer.parseInt(workflowid));
                if (!("xgtyfk".equals(unNumber) || "xgtybx".equals(unNumber) || "xgclbx".equals(unNumber))) {
                    return "请导出正确的流程！";
                }
                if ("xgclbx".equals(unNumber)) {
                    getXGCLBX(data, reqid, tablename, entry, mainMap);
                } else {
                    String lcbt = checkKG(ConstUtil.newNullString(lcbtMap.get("requestname")));
                    List<Map<String, Object>> detailList8 = reimbursementExcelDao.getDetailList(reqid, tablename, "8");
                    List<Map<String, Object>> detailList11 = reimbursementExcelDao.getDetailList(reqid, tablename, "11");
                    List<Map<String, Object>> detailList12 = reimbursementExcelDao.getDetailList(reqid, tablename, "12");
                    for (int j = 0; j < detailList8.size(); j++) {
                        ExcelPayDetailZhiFu excelPayDetailZhiFu = new ExcelPayDetailZhiFu();

                        String ssjg = ConstUtil.newNullString(detailList8.get(j).get("ssjg"));
                        Map<String, String> map1 = new HashMap<>();
                        map1.put("jobcode", ssjg);
                        Map<String, Object> xgzgsjg = reimbursementExcelDao.getOtherMap("uf_xgzgsjg", map1);

                        NewUser bxr = new NewUser(ConstUtil.newNullString(detailList8.get(j).get("bxr")));
                        String sy = checkKG(ConstUtil.newNullString(detailList8.get(j).get("sy")));
                        String kjkm = "";
                        if (null != detailList12 && detailList12.size() > 0 && null != detailList12.get(j) && !"".equals(detailList12.get(j))) {
                            kjkm = ConstUtil.newNullString(detailList12.get(j).get("hjkm"));
                        }
                        String je = ConstUtil.newNullString(detailList8.get(j).get("je"));
                        String skdw = "";
                        if (null != detailList11 && detailList11.size() > 0 && null != detailList11.get(0) && !"".equals(detailList11.get(0))) {
                            skdw = checkKG(ConstUtil.newNullString(detailList11.get(0).get("skdw")));
                        }
                        NewDepart bxbm = new NewDepart(ConstUtil.newNullString(detailList8.get(j).get("bxbm")));
                        if ("xgtyfk".equals(unNumber)) {
                            bxbm = new NewDepart(ConstUtil.newNullString(detailList8.get(j).get("fysjcdbm")));
                        }
                        Map<String, String> map2 = new HashMap<>();
                        map2.put("jobcode", bxbm.getDepId());
                        Map<String, Object> xgbmgxb = reimbursementExcelDao.getOtherMap("uf_xgbmgxb", map2);

                        excelPayDetailZhiFu.setEntryNo(entry);
                        if (JAVATools.ismapisnotnull(xgzgsjg) && xgzgsjg.size() > 0) {
                            excelPayDetailZhiFu.setSubsidiary(ConstUtil.newNullString(xgzgsjg.get("jobname")));
                        }
                        if ("xgtyfk".equals(unNumber)) {
                            String sql = "select t.SELECTNAME from WORKFLOW_SELECTITEM t,WORKFLOW_BILLFIELD l where l.FIELDNAME='biz' and l.billid='-" + tablename.substring(15) + "' and t.FIELDID=l.id and t.SELECTVALUE='" + ConstUtil.newNullString(mainMap.get("biz")) + "'";
                            String bz = ConstUtil.newNullString(JAVATools.GetTableToMap(sql, null).get("selectname"));
                            Map<String, String> map = new HashMap<>();
                            map.put("jobcode", bz);
                            String currency = ConstUtil.newNullString(reimbursementExcelDao.getOtherMap("uf_zhsj", map).get("jobname"));
                            excelPayDetailZhiFu.setCurrency(currency);
                        } else {
                            String bz = ConstUtil.newNullString(detailList8.get(j).get("bz"));
                            Map<String, String> map = new HashMap<>();
                            map.put("jobcode", bz);
                            String currency = ConstUtil.newNullString(reimbursementExcelDao.getOtherMap("uf_zhsj", map).get("jobname"));
                            excelPayDetailZhiFu.setCurrency(currency);
                        }
                        if ("xgtyfk".equals(unNumber)) {
                            excelPayDetailZhiFu.setMemo(skdw + "|" + lcbt + "|" + lcbh);
                        } else {
                            excelPayDetailZhiFu.setMemo(bxr.getUserName() + "|" + lcbt + "|" + lcbh);
                        }
                        excelPayDetailZhiFu.setAccount(kjkm);
                        excelPayDetailZhiFu.setDebit(je);
                        String expenseDept = "";
                        if (JAVATools.ismapisnotnull(xgbmgxb) && xgbmgxb.size() > 0) {
                            expenseDept = ConstUtil.newNullString(xgbmgxb.get("jobname"));
                        }
                        if (expenseDept == null || expenseDept.length() == 0 || expenseDept == "") {
                            expenseDept = bxbm.getDepName();
                        }
                        excelPayDetailZhiFu.setDepartment(expenseDept);
                        excelPayDetailZhiFu.setLocation("HK");
                        if ("xgtyfk".equals(unNumber)) {
                            excelPayDetailZhiFu.setJournalEntryLine(skdw + "|" + lcbt);
                        } else {
                            excelPayDetailZhiFu.setJournalEntryLine(bxr.getUserName() + "|" + sy);
                        }
                        if ("ZZ323451".equals(bxbm.getDepCode())) {
                            excelPayDetailZhiFu.setEmployee(bxr.getUserName());
                        }
                        data.add(excelPayDetailZhiFu);
                    }
                    for (int j = 0; j < detailList11.size(); j++) {
                        ExcelPayDetailZhiFu excelPayDetailZhiFu1 = new ExcelPayDetailZhiFu();
                        NewUser ygxm1 = new NewUser();
                        if (null != detailList12 && detailList12.size() > 0 && null != detailList12.get(0) && !"".equals(detailList12.get(0))) {
                            ygxm1 = new NewUser(ConstUtil.newNullString(detailList12.get(0).get("ygxm")));
                        }
                        NewDepart bm1 = new NewDepart(ConstUtil.newNullString(detailList11.get(j).get("bm")));
                        String yxzfje1 = ConstUtil.newNullString(detailList11.get(j).get("yxzfje"));
                        String skdw = checkKG(ConstUtil.newNullString(detailList11.get(j).get("skdw")));
                        String khx = checkKG(ConstUtil.newNullString(detailList11.get(j).get("khx")));
                        String yxzh = checkKG(ConstUtil.newNullString(detailList11.get(j).get("yxzh")));
                        excelPayDetailZhiFu1.setBeneBankCode(khx);
                        excelPayDetailZhiFu1.setBeneType(yxzh);
                        excelPayDetailZhiFu1.setCreditAmount(yxzfje1);
                        excelPayDetailZhiFu1.setPaymentDetails(lcbt + "|" + lcbh);
                        excelPayDetailZhiFu1.setEntryNo(entry);
                        String ssjg1 = "";
                        if (null != detailList8 && detailList8.size() > 0 && null != detailList8.get(0) && !"".equals(detailList8.get(0))) {
                            ssjg1 = ConstUtil.newNullString(detailList8.get(0).get("ssjg"));
                        }
                        Map<String, String> map11 = new HashMap<>();
                        map11.put("jobcode", ssjg1);
                        Map<String, Object> xgzgsjg1 = reimbursementExcelDao.getOtherMap("uf_xgzgsjg", map11);
                        if (JAVATools.ismapisnotnull(xgzgsjg1) && xgzgsjg1.size() > 0) {
                            excelPayDetailZhiFu1.setSubsidiary(ConstUtil.newNullString(xgzgsjg1.get("jobname")));
                            if ("xgtyfk".equals(unNumber)) {
                                excelPayDetailZhiFu1.setSubsidiaryForPayment(ConstUtil.newNullString(xgzgsjg1.get("jobname")));
                            }
                        }
                        if ("xgtyfk".equals(unNumber)) {
                            String sql = "select t.SELECTNAME from WORKFLOW_SELECTITEM t,WORKFLOW_BILLFIELD l where l.FIELDNAME='biz' and l.billid='-" + tablename.substring(15) + "' and t.FIELDID=l.id and t.SELECTVALUE='" + ConstUtil.newNullString(mainMap.get("biz")) + "'";
                            String bz = checkKG(ConstUtil.newNullString(JAVATools.GetTableToMap(sql, null).get("selectname")));
                            Map<String, String> map = new HashMap<>();
                            map.put("jobcode", bz);
                            String currency = ConstUtil.newNullString(reimbursementExcelDao.getOtherMap("uf_zhsj", map).get("jobname"));
                            excelPayDetailZhiFu1.setCurrency(currency);
                            excelPayDetailZhiFu1.setChargePayCurrency(currency);
                            excelPayDetailZhiFu1.setBeneName(skdw);
                        } else {
                            String bz = "";
                            if (null != detailList8 && detailList8.size() > 0 && null != detailList8.get(0) && !"".equals(detailList8.get(0))) {
                                bz = checkKG(ConstUtil.newNullString(detailList8.get(0).get("bz")));
                            }
                            NewUser ygxm = new NewUser(ConstUtil.newNullString(detailList11.get(j).get("ygxm")));
                            Map<String, String> map = new HashMap<>();
                            map.put("jobcode", bz);
                            String currency = ConstUtil.newNullString(reimbursementExcelDao.getOtherMap("uf_zhsj", map).get("jobname"));
                            excelPayDetailZhiFu1.setCurrency(currency);
                            excelPayDetailZhiFu1.setBeneName(ygxm.getUserName());
                        }
                        if ("xgtyfk".equals(unNumber)) {
                            excelPayDetailZhiFu1.setMemo(skdw + "|" + lcbt + "|" + lcbh);
                        } else {
                            excelPayDetailZhiFu1.setMemo(ygxm1.getUserName() + "|" + lcbt + "|" + lcbh);
                        }
                        String account = "";
                        if (StringUtil.isNotNull(excelPayDetailZhiFu1.getSubsidiary())) {
                            Map<String, String> map12 = new HashMap<>();
                            map12.put("jobtype", "WBACCOUNT");
                            map12.put("jobname", excelPayDetailZhiFu1.getSubsidiary() + "-" + excelPayDetailZhiFu1.getCurrency());
                            if ("0".equals(yxzfje1)) {
                                map12.put("jobcode", "2");
                            } else {
                                map12.put("jobcode", "1");
                            }
                            Map<String, Object> zhsj = reimbursementExcelDao.getOtherMap("uf_zhsj", map12);
                            account = ConstUtil.newNullString(zhsj.get("account"));
                            excelPayDetailZhiFu1.setAccount(account);
                        }
                        excelPayDetailZhiFu1.setCredit(ConstUtil.newNullString(detailList11.get(j).get("dfkje")));
                        excelPayDetailZhiFu1.setDepartment("Back Office : Holding");
                        excelPayDetailZhiFu1.setLocation("HK");

                        if ("xgtyfk".equals(unNumber)) {
                            excelPayDetailZhiFu1.setJournalEntryLine(skdw + "|" + lcbt);
                        } else {
                            excelPayDetailZhiFu1.setJournalEntryLine(ygxm1.getUserName() + "|" + lcbt);
                        }
                        if ("ZZ323451".equals(bm1.getDepCode())) {
                            excelPayDetailZhiFu1.setEmployee(ygxm1.getUserName());
                        }
                        data.add(excelPayDetailZhiFu1);
                    }
                }
            }
            String filePath = crateExcelHongKong(data);
            return filePath;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public String crateExcelHongKong(List<ExcelPayDetailZhiFu> list) {
        try {
            if (null == list || 0 == list.size()) {
                return "";
            }
            ExcelPayDetailZhiFu detail = list.get(0);
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet("支付明细");
            HSSFRow row = sheet.createRow((short) 0);
            crateHead(workbook, row, 0, detail.cellName[0]);
            crateHead(workbook, row, 1, detail.cellName[1]);
            crateHead(workbook, row, 2, detail.cellName[2]);
            crateHead(workbook, row, 3, detail.cellName[3]);
            crateHead(workbook, row, 4, detail.cellName[4]);
            crateHead(workbook, row, 5, detail.cellName[5]);
            crateHead(workbook, row, 6, detail.cellName[6]);
            crateHead(workbook, row, 7, detail.cellName[7]);
            crateHead(workbook, row, 8, detail.cellName[8]);
            crateHead(workbook, row, 9, detail.cellName[9]);
            crateHead(workbook, row, 10, detail.cellName[10]);
            crateHead(workbook, row, 11, detail.cellName[11]);
            crateHead(workbook, row, 12, detail.cellName[12]);
            crateHead(workbook, row, 13, detail.cellName[13]);
            crateHead(workbook, row, 14, detail.cellName[14]);
            crateHead(workbook, row, 15, detail.cellName[15]);
            crateHead(workbook, row, 16, detail.cellName[16]);
            crateHead(workbook, row, 17, detail.cellName[17]);
            crateHead(workbook, row, 18, detail.cellName[18]);
            crateHead(workbook, row, 19, detail.cellName[19]);
            crateHead(workbook, row, 20, detail.cellName[20]);
            crateHead(workbook, row, 21, detail.cellName[21]);
            crateHead(workbook, row, 22, detail.cellName[22]);
            crateHead(workbook, row, 23, detail.cellName[23]);
            crateHead(workbook, row, 24, detail.cellName[24]);
            crateHead(workbook, row, 25, detail.cellName[25]);
            crateHead(workbook, row, 26, detail.cellName[26]);

            for (int i = 0; i < list.size(); i++) {
                HSSFRow row1 = sheet.createRow((short) (i + 1));
                ExcelPayDetailZhiFu costDetail = list.get(i);
                crateCell(workbook, row1, 0, costDetail.getConsolidationKey());
                crateCell(workbook, row1, 1, costDetail.getEntryNo());
                crateCell(workbook, row1, 2, costDetail.getSubsidiary());
                crateCell(workbook, row1, 3, costDetail.getCurrency());
                crateCell(workbook, row1, 4, costDetail.getExchangeRate());
                crateCell(workbook, row1, 5, costDetail.getPostingPeriod());
                crateCell(workbook, row1, 6, costDetail.getDate());
                crateCell(workbook, row1, 7, costDetail.getReversalDate());
                crateCell(workbook, row1, 8, costDetail.getDeferEntry());
                crateCell(workbook, row1, 9, costDetail.getMemo());
                crateCell(workbook, row1, 10, costDetail.getAccount());
                crateCell(workbook, row1, 11, costDetail.getDebit());
                crateCell(workbook, row1, 12, costDetail.getCredit());
                crateCell(workbook, row1, 13, costDetail.getDepartment());
                crateCell(workbook, row1, 14, costDetail.getLocation());
                crateCell(workbook, row1, 15, costDetail.getFinancialProduct());
                crateCell(workbook, row1, 16, costDetail.getClientCounterParty());
                crateCell(workbook, row1, 17, costDetail.getProjectName());
                crateCell(workbook, row1, 18, costDetail.getJournalEntryLine());
                crateCell(workbook, row1, 19, costDetail.getEmployee());
                crateCell(workbook, row1, 20, costDetail.getBeneBankCode());
                crateCell(workbook, row1, 21, costDetail.getBeneType());
                crateCell(workbook, row1, 22, costDetail.getBeneName());
                crateCell(workbook, row1, 23, costDetail.getCreditAmount());
                crateCell(workbook, row1, 24, costDetail.getPaymentDetails());
                crateCell(workbook, row1, 25, costDetail.getChargePayCurrency());
                crateCell(workbook, row1, 26, costDetail.getSubsidiaryForPayment());
            }
            int width = sheet.getColumnWidth(0);
            sheet.setColumnWidth(0, width);
            sheet.setColumnWidth(1, width * 2);
            sheet.setColumnWidth(2, width * 3);
            sheet.setColumnWidth(3, width * 2);
            sheet.setColumnWidth(4, width);
            sheet.setColumnWidth(5, width);
            sheet.setColumnWidth(6, width * 4);
            sheet.setColumnWidth(7, width);
            sheet.setColumnWidth(8, width);
            sheet.setColumnWidth(9, width * 4);
            sheet.setColumnWidth(10, width * 4);
            sheet.setColumnWidth(11, width * 2);
            sheet.setColumnWidth(12, width * 3);
            sheet.setColumnWidth(13, width * 4);
            sheet.setColumnWidth(14, width * 3);
            sheet.setColumnWidth(15, width * 3);
            sheet.setColumnWidth(16, width * 3);
            sheet.setColumnWidth(17, width * 3);
            sheet.setColumnWidth(18, width * 4);
            sheet.setColumnWidth(19, width * 3);
            sheet.setColumnWidth(20, width * 4);
            sheet.setColumnWidth(21, width * 4);
            sheet.setColumnWidth(22, width * 4);
            sheet.setColumnWidth(23, width * 4);
            sheet.setColumnWidth(24, width * 4);
            sheet.setColumnWidth(25, width * 4);
            sheet.setColumnWidth(26, width * 4);

//            String filePath = "D:\\nfs\\temp\\zs\\";
            String filePath = "/app/ecology/filesystem/reimbursementExcelTemp/";
            File dir = new File(filePath);
            if (dir.exists()) {
                dir.delete();
            }
            dir.setWritable(true, false);
            dir.mkdirs();
            Runtime.getRuntime().exec("chmod -R 777 " + filePath);
            SimpleDateFormat dsdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
            String nowdate = dsdf.format(new Date());
            filePath += "支付明细" + nowdate + ".xls";
            File file = new File(filePath);
            if (file.exists()) {
                file.delete();
            }
            FileOutputStream fOut = new FileOutputStream(filePath);
            workbook.write(fOut);
            fOut.flush();
            fOut.close();
            return filePath;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    private static void crateHead(HSSFWorkbook workbook, HSSFRow row, int col, String text) {
        HSSFCell cell = row.createCell((short) col);
        HSSFFont font = workbook.createFont();
        font.setFontHeightInPoints((short) 12);
        font.setBold(true);
        HSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFont(font);
        cell.setCellType(CellType.STRING);
        cell.setCellValue(text);
        cell.setCellStyle(cellStyle);
    }

    private static void crateCell(HSSFWorkbook workbook, HSSFRow row, int col, String text) {
        HSSFCell cell = row.createCell((short) col);
        HSSFFont font = workbook.createFont();
        font.setFontHeightInPoints((short) 12);
        cell.setCellType(CellType.STRING);
        cell.setCellValue(text);
    }

    private String checkKG(String text) {
        if ("" != text && null != text) {
            text = text.replaceAll("&nbsp;", " ");
        }
        return text;
    }

    public void getXGCLBX(List<ExcelPayDetailZhiFu> list, String reqid, String tablename, String entry, Map<String, Object> mainMap) {
        List<Map<String, Object>> detailList12 = reimbursementExcelDao.getDetailList(reqid, tablename, "12");
        List<Map<String, Object>> detailList13 = reimbursementExcelDao.getDetailList(reqid, tablename, "13");
        List<Map<String, Object>> detailList19 = reimbursementExcelDao.getDetailList(reqid, tablename, "19");
        List<Map<String, Object>> detailList10 = reimbursementExcelDao.getDetailList(reqid, tablename, "10");

        String lcbh = ConstUtil.newNullString(mainMap.get("lcbh"));
        String lcbtSql = "select REQUESTNAME,workflowid from workflow_requestbase  where requestid= " + reqid;
        Map<String, Object> lcbtMap = JAVATools.GetTableToMap(lcbtSql, null);
        String lcbt = checkKG(ConstUtil.newNullString(lcbtMap.get("requestname")));
        Map<String, String> map1 = new HashMap<>();
        map1.put("jobcode", "0");
        Map<String, Object> xgzgsjg = reimbursementExcelDao.getOtherMap("uf_xgzgsjg", map1);
        String sql = "select t.SELECTNAME from WORKFLOW_SELECTITEM t,WORKFLOW_BILLFIELD l where l.FIELDNAME='bz' and l.billid='-" + tablename.substring(15) + "' and t.FIELDID=l.id and t.SELECTVALUE='" + ConstUtil.newNullString(mainMap.get("bz")) + "'";
        String bz = ConstUtil.newNullString(JAVATools.GetTableToMap(sql, null).get("selectname"));
        Map<String, String> map = new HashMap<>();
        map.put("jobcode", bz);
        String currency = ConstUtil.newNullString(reimbursementExcelDao.getOtherMap("uf_zhsj", map).get("jobname"));

        for (int j = 0; j < detailList12.size(); j++) {
            ExcelPayDetailZhiFu excelPayDetailZhiFu = new ExcelPayDetailZhiFu();
            excelPayDetailZhiFu.setEntryNo(entry);
            excelPayDetailZhiFu.setCurrency(currency);
            if (JAVATools.ismapisnotnull(xgzgsjg) && xgzgsjg.size() > 0) {
                excelPayDetailZhiFu.setSubsidiary(ConstUtil.newNullString(xgzgsjg.get("jobname")));
            }
            NewUser ccr = new NewUser(ConstUtil.newNullString(detailList12.get(j).get("ccr")));
            excelPayDetailZhiFu.setMemo(ccr.getUserName() + "|" + lcbt + "|" + lcbh);
            excelPayDetailZhiFu.setAccount("900850000");
            excelPayDetailZhiFu.setDebit(ConstUtil.newNullString(mainMap.get("clfyhj")));
            NewDepart ccrszbm = new NewDepart(ConstUtil.newNullString(detailList12.get(j).get("ccrszbm")));
            Map<String, String> map2 = new HashMap<>();
            map2.put("jobcode", ccrszbm.getDepId());
            Map<String, Object> xgbmgxb = reimbursementExcelDao.getOtherMap("uf_xgbmgxb", map2);
            String expenseDept = "";
            if (JAVATools.ismapisnotnull(xgbmgxb) && xgbmgxb.size() > 0) {
                expenseDept = ConstUtil.newNullString(xgbmgxb.get("jobname"));
            }
            if (expenseDept == null || expenseDept.length() == 0 || expenseDept == "") {
                expenseDept = ccrszbm.getDepName();
            }
            excelPayDetailZhiFu.setDepartment(expenseDept);
            excelPayDetailZhiFu.setLocation("HK");
            Map<String, String> map3 = new HashMap<>();
            map3.put("code", checkKG(ConstUtil.newNullString(detailList12.get(j).get("gsxm"))));
            Map<String, Object> xggsxm = reimbursementExcelDao.getOtherMap("uf_xggsxm", map3);
            if (JAVATools.ismapisnotnull(xggsxm) && xggsxm.size() > 0) {
                excelPayDetailZhiFu.setProjectName(ConstUtil.newNullString(xgbmgxb.get("description")));
            }
            String xc = "";
            if (null != detailList13 && detailList13.size() > 0) {
                xc = PayUtil.getProvinceAndCityNameByCode(ConstUtil.newNullString(detailList13.get(j).get("mddd"))) + "|" + ConstUtil.newNullString(detailList13.get(j).get("cfrq"))
                        + "|" + ConstUtil.newNullString(detailList13.get(j).get("fhsj"));
            }
            excelPayDetailZhiFu.setJournalEntryLine(ccr.getUserName() + "|" + xc);
            if ("ZZ323451".equals(ccrszbm.getDepCode())) {
                excelPayDetailZhiFu.setEmployee(ccr.getUserName());
            }
            list.add(excelPayDetailZhiFu);
        }
        if (null != detailList19 && detailList19.size() > 0) {
            for (Map<String, Object> qita : detailList19) {
                ExcelPayDetailZhiFu excelPayDetailZhiFu2 = new ExcelPayDetailZhiFu();
                excelPayDetailZhiFu2.setEntryNo(entry);
                excelPayDetailZhiFu2.setCurrency(currency);
                if (JAVATools.ismapisnotnull(xgzgsjg) && xgzgsjg.size() > 0) {
                    excelPayDetailZhiFu2.setSubsidiary(ConstUtil.newNullString(xgzgsjg.get("jobname")));
                }
                NewUser ccr = new NewUser(ConstUtil.newNullString(qita.get("ccr")));
                excelPayDetailZhiFu2.setMemo(ccr.getUserName() + "|" + lcbt + "|" + lcbh);
                excelPayDetailZhiFu2.setAccount(ConstUtil.newNullString(qita.get("ysxm")));
                excelPayDetailZhiFu2.setDebit(ConstUtil.newNullString(qita.get("je")));
                NewDepart ccrbm = new NewDepart(ConstUtil.newNullString(qita.get("ccrbm")));
                Map<String, String> map2 = new HashMap<>();
                map2.put("jobcode", ccrbm.getDepId());
                Map<String, Object> xgbmgxb = reimbursementExcelDao.getOtherMap("uf_xgbmgxb", map2);
                String expenseDept = "";
                if (JAVATools.ismapisnotnull(xgbmgxb) && xgbmgxb.size() > 0) {
                    expenseDept = ConstUtil.newNullString(xgbmgxb.get("jobname"));
                }
                if (expenseDept == null || expenseDept.length() == 0 || expenseDept == "") {
                    expenseDept = ccrbm.getDepName();
                }
                excelPayDetailZhiFu2.setDepartment(expenseDept);
                excelPayDetailZhiFu2.setLocation("HK");
                excelPayDetailZhiFu2.setJournalEntryLine(checkKG(ConstUtil.newNullString(qita.get("bxsy"))));
                if ("ZZ323451".equals(ccrbm.getDepCode())) {
                    excelPayDetailZhiFu2.setEmployee(ccr.getUserName());
                }
                list.add(excelPayDetailZhiFu2);
            }
        }
        ExcelPayDetailZhiFu excelPayDetailZhiFu1 = new ExcelPayDetailZhiFu();
        excelPayDetailZhiFu1.setEntryNo(entry);
        excelPayDetailZhiFu1.setCurrency(currency);
        excelPayDetailZhiFu1.setPaymentDetails(lcbt + "|" + lcbh);
        if (JAVATools.ismapisnotnull(xgzgsjg) && xgzgsjg.size() > 0) {
            excelPayDetailZhiFu1.setSubsidiary(ConstUtil.newNullString(xgzgsjg.get("jobname")));
        }
        if (null != detailList10 && detailList10.size() > 0 && null != detailList10.get(0) && !"".equals(detailList10.get(0))) {
            NewUser bxr = new NewUser(ConstUtil.newNullString(detailList10.get(0).get("bxr")));
            excelPayDetailZhiFu1.setMemo(bxr.getUserName() + "|" + lcbt + "|" + lcbh);
            String account = "";
            if (StringUtil.isNotNull(excelPayDetailZhiFu1.getSubsidiary())) {
                Map<String, String> map12 = new HashMap<>();
                map12.put("jobtype", "WBACCOUNT");
                map12.put("jobname", excelPayDetailZhiFu1.getSubsidiary() + "-" + excelPayDetailZhiFu1.getCurrency());
                if ("0".equals(ConstUtil.newNullString(detailList10.get(0).get("yxzfje")))) {
                    map12.put("jobcode", "2");
                } else {
                    map12.put("jobcode", "1");
                }
                Map<String, Object> zhsj = reimbursementExcelDao.getOtherMap("uf_zhsj", map12);
                account = ConstUtil.newNullString(zhsj.get("account"));
                excelPayDetailZhiFu1.setAccount(account);
            }
            excelPayDetailZhiFu1.setBeneBankCode(ConstUtil.newNullString(detailList10.get(0).get("khx")));
            excelPayDetailZhiFu1.setBeneType(ConstUtil.newNullString(detailList10.get(0).get("yxzh")));
            excelPayDetailZhiFu1.setBeneName(bxr.getUserName());
            excelPayDetailZhiFu1.setCreditAmount(ConstUtil.newNullString(detailList10.get(0).get("yxzfje")));
            excelPayDetailZhiFu1.setCredit(ConstUtil.newNullString(detailList10.get(0).get("zfhj")));
            excelPayDetailZhiFu1.setDepartment("Back Office : Holding");
            excelPayDetailZhiFu1.setLocation("HK");
            if ("ZZ323451".equals(new NewDepart(ConstUtil.newNullString(detailList10.get(0).get("bm"))).getDepCode())) {
                excelPayDetailZhiFu1.setEmployee(bxr.getUserName());
            }
        }
        list.add(excelPayDetailZhiFu1);
    }
}
