package com.dxhy.sign.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.aspect.SysLog;
import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.enums.FplxEnum;
import com.dxhy.common.util.FileUtils;
import com.dxhy.common.util.InvoiceUtil;
import com.dxhy.common.util.UserInfoUtil;
import com.dxhy.common.util.ZipUtil;
import com.dxhy.common.utils.DateUtils;
import com.dxhy.common.utils.R;
import com.dxhy.common.vo.UserInfo;
import com.dxhy.sign.service.elec.SignElecInvoiceService;
import com.dxhy.sign.service.invoicequery.SignInvoiceQueryService;
import com.dxhy.sign.util.DateTimeHelper;

import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 发票查验模块接口类
 *
 * @author ld
 * @date today
 */
@SuppressWarnings({"AlibabaUndefineMagicConstant", "AlibabaMethodTooLong"})
@RestController
@Slf4j

public class SignCheckInvoiceQueryController extends AbstractController {
    @Resource
    private SignInvoiceQueryService signInvoiceQueryService;
    @Resource
    private SignElecInvoiceService signElecInvoiceService;
    @Value("${ftp.connection.size}")
    private String size;
    /**
     * 上传时本地文件暂存路径
     */
    @Value("${ftp.connection.tempPath}")
    private String tempPath;
    /**
     * 上传时本地文件存放路径
     */
    @Value("${ftp.connection.depositPath}")
    private String depositPath;

    @PostMapping("/elecCheck/uploadFile")
    @SysLog("上传电子发票")
    public ResponseEntity<R> uploadFile(MultipartFile file) {
        try {
            UserInfo userInfo = getUserInfo();
            boolean checkFileSize = FileUtils.checkFileSize(file.getSize(), Integer.parseInt(size), "M");
            if (!checkFileSize) {
                return ResponseEntity.ok(R.error("上传文件大于 " + size + "M"));
            }
            String filename = file.getOriginalFilename();
            String prefix = filename != null ? filename.substring(filename.lastIndexOf(".") + 1) : null;
            if (!"zip".equals(prefix) && !"pdf".equals(prefix) && !"ZIP".equals(prefix) && !"PDF".equals(prefix)
                && !"ofd".equals(prefix) && !"OFD".equals(prefix)) {
                return ResponseEntity.ok(R.error("请上传pdf、ofd文件或者pdf、ofd的压缩文件(.zip)！"));
            }
            List<String> gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
            String taxNo = "";
            if (gfshAll.size() > 0) {
                taxNo = gfshAll.get(0);

            }
            // 文件名称
            String fileName = signElecInvoiceService.getOriginalFilename(file.getOriginalFilename());
            // 上传文件重新命名
            String pdfFileName = userInfo.getUsername() + "_" + DateTimeHelper.formatNowDate("yyyyMMddHHmmss")
                + fileName.substring(fileName.indexOf("."));
            // 创建临时存储文件夹
            String tempPathPdf =
                tempPath + userInfo.getUsername() + "_" + DateTimeHelper.formatNowDate("yyyyMMddHHmmss") + "/";
            signElecInvoiceService.createFileDir(tempPathPdf);
            File newFile = new File(tempPathPdf + pdfFileName);
            try {
                file.transferTo(newFile.getAbsoluteFile());
                if (fileName.contains("zip") || fileName.contains("ZIP")) {
                    // 若用户上传的是zip压缩文件,对文件进行解压
                    ZipUtil.unzip(tempPathPdf + pdfFileName);
                    // 对上传的文件进行移动保存
                    FileUtil.move(newFile, new File(depositPath), true);
                } else if (fileName.contains("ofd") || fileName.contains("OFD")) {
                    // 对用ofd上传，压缩ofd文件，然后保存
                    ZipUtil.zip(newFile, Boolean.FALSE);
                    List<File> zipFiles = FileUtils.findFile(tempPathPdf, "zip");
                    for (File zipFile : zipFiles) {
                        // 对上传的文件进行移动保存
                        FileUtil.move(zipFile, new File(depositPath), true);
                    }
                } else {
                    // 对用pdf上传，压缩pdf文件，然后保存
                    ZipUtil.zip(newFile, Boolean.FALSE);
                    List<File> zipFiles = FileUtils.findFile(tempPathPdf, "zip");
                    for (File zipFile : zipFiles) {
                        // 对上传的文件进行移动保存
                        FileUtil.move(zipFile, new File(depositPath), true);
                    }
                }
                // 获取临时文件夹里的所有pdf文件
                List<File> files = null;
                if (fileName.contains("pdf") || fileName.contains("zip") || fileName.contains("PDF")
                    || fileName.contains("ZIP") || fileName.contains("ofd") || fileName.contains("OFD")) {
                    files = FileUtils.findFile(tempPathPdf, "");
                }
                List<File> pdfFile = new ArrayList<>();
                List<File> ofdFile = new ArrayList<>();
                if (files != null && files.size() > 0) {
                    for (File fi : files) {
                        String name = fi.getName();
                        if (!name.contains("pdf") && !name.contains("PDF") && !name.contains("ZIP")
                            && !name.contains("zip") && !name.contains("ofd") && !name.contains("OFD")) {
                            return ResponseEntity.ok(R.error("请上传pdf、ofd文件或者pdf、ofd的压缩文件(.zip)！"));
                        }
                        if (name.contains("pdf") || name.contains("PDF")) {
                            pdfFile.add(fi);
                        }
                        if (name.contains("ofd") || name.contains("OFD")) {
                            ofdFile.add(fi);
                        }
                    }

                    JSONObject saveUploadElecFile = signInvoiceQueryService.saveUploadElecFile(pdfFile, ofdFile,
                        userInfo, pdfFileName, tempPathPdf, "Y", taxNo);
                    return ResponseEntity.ok(R.ok().put("data", saveUploadElecFile));
                } else {
                    return ResponseEntity.ok(R.error("请上传pdf、ofd文件或者pdf、ofd的压缩文件(.zip)！"));
                }
            } catch (Exception e) {
                e.printStackTrace();
                return ResponseEntity.ok(R.error("请上传pdf、ofd文件或者pdf、ofd的压缩文件(.zip)！"));
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error("上传失败，请查看上传文件是否正确。"));
        }
    }

    /**
     * 扫码查验发票
     */
    @PostMapping("/smcy/info")
    @ResponseBody
    @SysLog("发票扫码查验")
    public ResponseEntity<?> smQueryInvoice(@RequestBody Map<String, String> pramsMap) {
        // 入参统一在入口处理
        String userid = getLoginName();
        pramsMap.put("userid", userid);
        String dbName = getUserInfo().getDbName();
        pramsMap.put("dbName", dbName);

        pramsMap.put("company", getUserInfo().getCompany());

        List<String> gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
        if (gfshAll.size() > 0) {
            pramsMap.put("taxNo", gfshAll.get(0));

        }
        InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode"));
        if(FplxEnum.QDZZP.getFplxDm().equals(pramsMap.get("invoiceType"))
                || FplxEnum.QDPP.getFplxDm().equals(pramsMap.get("invoiceType"))){
            pramsMap.put("invoiceType", pramsMap.get("invoiceType"));
        }else {
            if (pramsMap.get("invoiceCode").isEmpty()) {

                return ResponseEntity.ok(R.error("发票代码不能为空！"));
            }
            pramsMap.put("invoiceType", iu.getFplxdm());
        }

        if (pramsMap.get("invoiceNo").isEmpty()) {
            return ResponseEntity.ok(R.error("发票号码不能为空！"));
        }

        if (pramsMap.get("saveHistory") == null || pramsMap.get("saveHistory").isEmpty()) {
            pramsMap.put("saveHistory", "Y");
        }

        if (!pramsMap.get("invoiceDate").isEmpty()) {
            iu.setKprq(pramsMap.get("invoiceDate"));
            if (!iu.kprqValid(null)) {
                pramsMap.put("invoiceDate", "开票日期格式错误！");
            }
        } else {
            return ResponseEntity.ok(R.error("开票日期不能为空！"));
        }

        if (FplxEnum.ZP.getFplxDm().equals(pramsMap.get("invoiceType"))
            || FplxEnum.JDC.getFplxDm().equals(pramsMap.get("invoiceType"))
            || FplxEnum.DZZP.getFplxDm().equals(pramsMap.get("invoiceType"))
            || FplxEnum.ESC.getFplxDm().equals(pramsMap.get("invoiceType"))
            || FplxEnum.QDZZP.getFplxDm().equals(pramsMap.get("invoiceType"))
            || FplxEnum.QDPP.getFplxDm().equals(pramsMap.get("invoiceType"))) {
            if (pramsMap.get("invoiceAmount").isEmpty()) {
                return ResponseEntity.ok(R.error("金额不能为空！"));
            }
        } else {
            if (pramsMap.get("checkCode").isEmpty()) {
                return ResponseEntity.ok(R.error("校验码不能为空！"));
            }
        }
        if ("Y".equals(pramsMap.get("saveHistory"))) {
            String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode"))?"":pramsMap.get("invoiceCode"))+ pramsMap.get("invoiceNo");
            String notes = signInvoiceQueryService.checkingInvoiceInfo(dbName,
                    uuid, getUserInfo());
            if (notes != null) {
                return ResponseEntity.ok(R.error(notes));
            }
        }

        try {
            return ResponseEntity.ok(R.ok().put("data", signInvoiceQueryService.smQueryInvoice(pramsMap)));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 票面信息查询接口
     *
     * @return 返回结果
     *
     */
    @RequestMapping("/fpmx/info")
    @ResponseBody
    @SysLog("明细查看")
    public ResponseEntity<?> getFpmx(@RequestBody Map<String, String> pramsMap) {
        // Map<String,Object> pramsMap = new HashMap<String,Object>(16);
        pramsMap.put("dbName", getUserInfo().getDbName());

        String invoiceCode = pramsMap.get("invoiceCode");
        String invoiceNo = pramsMap.get("invoiceNo");

        try {
            String msg = signInvoiceQueryService.getFpmx(invoiceCode, invoiceNo, getUserInfo().getDbName());
            if (msg == null) {
                return ResponseEntity.ok(R.error("未获取到发票信息！"));
            } else {
                return ResponseEntity.ok(R.ok().put("data", msg));
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 扫描仪查验发票
     *
     *
     */
    @PostMapping("/smycy/info")
    @ResponseBody
    @SysLog("扫描仪查验")
    public ResponseEntity<?> smyQueryInvoice(@RequestBody Map<String, String> pramsMap) {
        pramsMap.put("userid", getLoginName());
        pramsMap.put("dbName", getUserInfo().getDbName());
        pramsMap.put("company", getUserInfo().getCompany());

        List<String> gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
        if (gfshAll.size() > 0) {
            pramsMap.put("taxNo", gfshAll.get(0));

        }
        if (pramsMap.get("scanPch").isEmpty()) {
            return ResponseEntity.ok(R.error("扫描识别批次号不能为空！"));
        } else {
            pramsMap.put("pch", pramsMap.get("scanPch"));
        }

        if (pramsMap.get("saveHistory") == null || pramsMap.get("saveHistory").isEmpty()) {
            pramsMap.put("saveHistory", "Y");
        }

        try {
            return ResponseEntity.ok(R.ok().put("data",
                signInvoiceQueryService.smyQueryInvoice(pramsMap, pramsMap.get("saveHistory"), getUserInfo())));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 修改- 扫描仪查验发票
     *
     * @return 返回结果
     *
     */
    @PostMapping("/smycy/updateInfo")
    @ResponseBody
    @SysLog("扫描仪查验--修改")
    public ResponseEntity<?> smyUpdateQueryInvoice(@RequestBody Map<String, String> pramsMap) {

        String userid = getLoginName();
        pramsMap.put("userid", userid);
        String dbName = getUserInfo().getDbName();
        pramsMap.put("dbName", dbName);
        pramsMap.put("company", getUserInfo().getCompany());
        List<String> gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
        if (gfshAll.size() > 0) {
            pramsMap.put("taxNo", gfshAll.get(0));

        }
//        if (pramsMap.get("invoiceCode").isEmpty()) {
//
//            return ResponseEntity.ok(R.error("发票代码不能为空！"));
//        }
        String invoiceType = "";
        InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode"));
        if(StringUtils.isNotBlank(pramsMap.get("invoiceType"))){
             invoiceType = pramsMap.get("invoiceType");
            if(FplxEnum.QDZZP.getFplxDm().equals(invoiceType) || FplxEnum.QDPP.getFplxDm().equals(invoiceType)){
                pramsMap.put("invoiceType", invoiceType);
            }else {
                pramsMap.put("invoiceType", iu.getFplxdm());
            }
        }



        if (pramsMap.get("invoiceNo").isEmpty()) {
            return ResponseEntity.ok(R.error("发票号码不能为空！"));
        }

        if (!pramsMap.get("invoiceDate").isEmpty()) {
            iu.setKprq(pramsMap.get("invoiceDate"));
            if (!iu.kprqValid(null)) {
                pramsMap.put("invoiceDate", "开票日期格式错误！");
            }
        } else {
            return ResponseEntity.ok(R.error("开票日期不能为空！"));
        }

        if (FplxEnum.ZP.getFplxDm().equals(pramsMap.get("invoiceType"))
                || FplxEnum.JDC.getFplxDm().equals(pramsMap.get("invoiceType"))
                || FplxEnum.DZZP.getFplxDm().equals(pramsMap.get("invoiceType"))
                || FplxEnum.ESC.getFplxDm().equals(pramsMap.get("invoiceType"))) {
            if (pramsMap.get("invoiceAmount").isEmpty()) {
                return ResponseEntity.ok(R.error("金额不能为空！"));
            }
        } else if (FplxEnum.QDZZP.getFplxDm().equals(pramsMap.get("invoiceType"))
                || FplxEnum.QDPP.getFplxDm().equals(pramsMap.get("invoiceType"))) {
            if (pramsMap.get("totalAmount").isEmpty()) {
                return ResponseEntity.ok(R.error("价税合计不能为空！"));
            }
            pramsMap.put("invoiceAmount",pramsMap.get("totalAmount"));
        } else {
            if (pramsMap.get("checkCode").isEmpty()) {
                return ResponseEntity.ok(R.error("校验码不能为空！"));
            }
        }

        if (pramsMap.get("saveHistory") == null || pramsMap.get("saveHistory").isEmpty()) {
            pramsMap.put("saveHistory", "Y");
        }

        try {
            return ResponseEntity.ok(R.ok().put("data", signInvoiceQueryService.smyUpdateQueryInvoice(pramsMap)));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 签收excel导入的发票
     *
     * @return 返回结果
     *
     */
    @PostMapping("/excelcy/info")
    @ResponseBody
    @SysLog("导入查验")
    public ResponseEntity<?> excelQsfp(@RequestBody Map<String, Object> pramsMap) {
        try {

            if (pramsMap.get("zsl") == null || "".equals(pramsMap.get("zsl"))) {
                return ResponseEntity.ok(R.error("查验发票总数不能为空！"));
            }
            JSONArray detailArray;
            if (pramsMap.get("invoices") == null || "".equals(pramsMap.get("invoices"))) {
                return ResponseEntity.ok(R.error("查验发票信息不能为空！"));
            } else {
                detailArray = (JSONArray)pramsMap.get("invoices");
                if (detailArray == null || detailArray.size() != (Integer)pramsMap.get("zsl")) {
                    return ResponseEntity.ok(R.error("发票明细数量和总数量不一致！"));
                }
            }
            List<String> gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
            String userId = getLoginName();
            String userName = getLoginName();
            String dbName = getUserInfo().getDbName();
            String company = getUserInfo().getCompany();
            String menuId = (String)pramsMap.get("menuId");
            if (pramsMap.get("saveHistory") == null || "".equals(pramsMap.get("saveHistory"))) {
                pramsMap.put("saveHistory", "Y");
            }
            String msg = signInvoiceQueryService.checkExcelFp(detailArray, getUserInfo(), dbName);
            if (StringUtils.isNotBlank(msg)) {
                return ResponseEntity.ok(R.error(msg));
            } else {
                List<Map<String, String>> detailList =
                    signInvoiceQueryService.convertExcelFp(detailArray, userId, userName, dbName);
                return ResponseEntity.ok(R.ok().put("data", signInvoiceQueryService.cyExcelfp(detailList,
                    pramsMap.get("saveHistory").toString(), company, gfshAll.get(0), menuId)));
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 查询查验历史记录
     *
     *
     */
    @RequestMapping("/cyls/list")
    @ResponseBody
    @SysLog("查验历史列表")
    public ResponseEntity<?> checkHistoryList(@RequestBody Map<String, Object> pramsMap) {
        // 入参统一在入口处理
        Map<String, String> data = new HashMap<>(16);

        data.put("userid", getLoginName());
        data.put("dbName", getUserInfo().getDbName());

        if (pramsMap.get("invoiceCode") != null && !"".equals(pramsMap.get("invoiceCode"))) {
            data.put("invoiceCode", pramsMap.get("invoiceCode").toString());
        }

        if (pramsMap.get("invoiceNo") != null && !"".equals(pramsMap.get("invoiceNo"))) {
            data.put("invoiceNo", pramsMap.get("invoiceNo").toString());
        }

        if (pramsMap.get("cyrqq") != null && !"".equals(pramsMap.get("cyrqq"))) {
            data.put("cyrqq", DateUtils.getMorning(DateUtils.strToDate(pramsMap.get("cyrqq").toString())));
        }
        if (pramsMap.get("cyrqz") != null && !"".equals(pramsMap.get("cyrqz"))) {
            data.put("cyrqz", DateUtils.getNight(DateUtils.strToDate(pramsMap.get("cyrqz").toString())));
        }

        if (pramsMap.get("kprqq") != null && !"".equals(pramsMap.get("kprqq"))) {
            data.put("kprqq", DateUtils.getMorning(DateUtils.strToDate(pramsMap.get("kprqq").toString())));
        }
        if (pramsMap.get("kprqz") != null && !"".equals(pramsMap.get("kprqz"))) {
            data.put("kprqz", DateUtils.getNight(DateUtils.strToDate(pramsMap.get("kprqz").toString())));
        }

        int curr = (int)pramsMap.get("curr");
        int size = (int)pramsMap.get("size");
        data.put("company", (String)pramsMap.get("company"));
        data.put("menuId", (String)pramsMap.get("menuId"));
        try {
            return ResponseEntity.ok(R.ok().put("data", signInvoiceQueryService.getCheckHistory(data, curr, size)));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 删除查验历史
     *
     *
     */
    @PostMapping("/cyls/del")
    @ResponseBody
    @SysLog("删除查验历史")
    public ResponseEntity<?> delCheckHistory(@RequestBody Map<String, String> pramsMap) {

        pramsMap.put("userid", getLoginName());
        pramsMap.put("dbName", getUserInfo().getDbName());
        pramsMap.put("uuid",  (StringUtils.isBlank(pramsMap.get("invoiceCode"))?"":pramsMap.get("invoiceCode"))+ pramsMap.get("invoiceNo"));
        try {
            signInvoiceQueryService.delCheckHistory(pramsMap);
            return ResponseEntity.ok(R.ok().put("data", "删除成功"));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error("删除失败"));
        }
    }

    /**
     * 查验历史记录统计
     *
     *
     */
    @RequestMapping("/cytj/list")
    @ResponseBody
    @SysLog("查验历史统计")
    public ResponseEntity<?> checkHistoryStatistics(@RequestBody Map<String, String> pramsMap) {
        // 入参统一在入口处理
        pramsMap.put("userid", getLoginName());
        pramsMap.put("dbName", getUserInfo().getDbName());
        try {
            return ResponseEntity.ok(R.ok().put("data", signInvoiceQueryService.checkHistoryStatistics(pramsMap)));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 查询查验历史-历史记录
     */
    @RequestMapping("/cyls/detail")
    @ResponseBody
    @SysLog("查验历史记录")
    public ResponseEntity<?> checkHistoryListDetail(@RequestBody Map<String, Object> pramsMap) {
        // 入参统一在入口处理
        Map<String, String> data = new HashMap<>(16);

        data.put("userid", getLoginName());
        data.put("dbName", getUserInfo().getDbName());
        data.put("curr", String.valueOf(pramsMap.get("curr")));
        data.put("size", String.valueOf(pramsMap.get("size")));
        if(StringUtils.isNotBlank(String.valueOf(pramsMap.get("invoiceCode")))){
            data.put("invoiceCode", String.valueOf(pramsMap.get("invoiceCode")));
        }
        data.put("invoiceNo", String.valueOf(pramsMap.get("invoiceNo")));
        try {
            return ResponseEntity.ok(R.ok().put("data", signInvoiceQueryService.getCheckHistoryDetail(data)));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    @RequestMapping("/cyzhcx/list")
    @ResponseBody
    @SysLog("查验综合查询")
    public ResponseEntity<?> checkList(@RequestBody Map<String, Object> pramsMap) {
        // 入参统一在入口处理
        Map<String, Object> data = new HashMap<>(16);

        data.put("userid", pramsMap.get("checkUser"));
        data.put("dbName", getUserInfo().getDbName());

        data.put("company", pramsMap.get("company"));
        data.put("menuId", pramsMap.get("menuId"));

        List<String> gfshList = new ArrayList<>();
        if (!"99".equals(pramsMap.get("gfsh")) && pramsMap.get("gfsh") != null && !"".equals(pramsMap.get("gfsh"))) {
            gfshList.add(pramsMap.get("gfsh").toString());
        }
        data.put("gfsh", gfshList);
        if (pramsMap.get("invoiceNo") != null && !"".equals(pramsMap.get("invoiceNo"))) {
            data.put("invoiceNo", pramsMap.get("invoiceNo"));
        }

        if (pramsMap.get("invoiceType") != null && !"".equals(pramsMap.get("invoiceType"))
            && !"99".equals(pramsMap.get("invoiceType"))) {
            data.put("invoiceType", pramsMap.get("invoiceType"));
        }

        if (pramsMap.get("cyrqq") != null && !"".equals(pramsMap.get("cyrqq"))) {
            data.put("cyrqq", DateUtils.getMorning(DateUtils.strToDate(pramsMap.get("cyrqq").toString())));
        }
        if (pramsMap.get("cyrqz") != null && !"".equals(pramsMap.get("cyrqz"))) {
            data.put("cyrqz", DateUtils.getNight(DateUtils.strToDate(pramsMap.get("cyrqz").toString())));
        }

        if (pramsMap.get("kprqq") != null && !"".equals(pramsMap.get("kprqq"))) {
            data.put("kprqq", DateUtils.getMorning(DateUtils.strToDate(pramsMap.get("kprqq").toString())));
        }
        if (pramsMap.get("kprqz") != null && !"".equals(pramsMap.get("kprqz"))) {
            data.put("kprqz", DateUtils.getNight(DateUtils.strToDate(pramsMap.get("kprqz").toString())));
        }
        data.put("invoiceSource",pramsMap.get("invoiceSource"));
        int curr = (int)pramsMap.get("curr");
        int size = (int)pramsMap.get("size");

        try {
            return ResponseEntity.ok(R.ok().put("data", signInvoiceQueryService.getCheckList(data, curr, size)));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

}
