package com.dxhy.core.service.export.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.core.dao.CoreMixedSignatureDao;
import com.dxhy.api.model.invoice.TDxInvoiceReimburse;
import com.dxhy.core.model.SmyqsWqsfpVO;
import com.dxhy.core.service.export.MixedSignService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

/**
 * 查验业务处理接口实现类
 *
 * @author user
 */
@SuppressWarnings("AlibabaMethodTooLong")
@Service("mixedSignService")
@Slf4j

public class MixedSignServiceImpl extends MpBaseServiceImpl<CoreMixedSignatureDao, TDxInvoiceReimburse>
    implements MixedSignService {

    @Override
    public JSONObject getMixedSignList(Map<String, Object> pramsMap, int curr, int size) {
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        // 需要设置返回列表标题时调用
        JSONObject json = new JSONObject();

        // 分页获取明细列表
        PageHelper.startPage(curr, size);
        List<SmyqsWqsfpVO> pageList = super.baseMapper.selectQsfpList(pramsMap);
        PageInfo<SmyqsWqsfpVO> pageInfo = new PageInfo<>(pageList);
        json.put("hasNext", pageInfo.isHasNextPage());
        json.put("nextPage", pageInfo.getNextPage());
        List<SmyqsWqsfpVO> resultList = pageInfo.getList();

        List<String[]> returnList = new ArrayList<>();

        if (resultList != null && resultList.size() > 0) {

            for (int i = 0; i < resultList.size(); i++) {
                String[] dataArray = new String[24];
                dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                dataArray[1] = resultList.get(i).getNotes();
                if ("0".equals(resultList.get(i).getFileType())) {
                    dataArray[2] = "封面";
                } else if ("1".equals(resultList.get(i).getFileType())) {
                    dataArray[2] = "票据";
                } else if ("2".equals(resultList.get(i).getFileType())) {
                    dataArray[2] = "附件";
                } else {
                    dataArray[2] = "其他";
                }
                if ("01".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "增值税专用发票";
                } else if ("03".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "机动车销售统一发票";
                } else if ("04".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "增值税普通发票";
                } else if ("10".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "增值税电子普通发票";
                } else if ("11".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "增值税普通发票(卷票)";
                } else if ("14".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "增值税电子普通发票(通行费)";
                } else if ("91".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "出租车票";
                } else if ("92".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "火车票";
                } else if ("94".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "汽车票";
                } else if ("95".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "定额发票";
                } else if ("96".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "长途汽车票";
                } else if ("97".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "通用机打发票";
                } else if ("98".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "过路过桥";
                } else if ("90".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "航空客运电子客票行程单";
                } else if ("89".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "公路运输客票(实名)";
                } else if ("88".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "水路运输客票(实名)";
                } else if ("87".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "其他运输客票(实名)";
                } else if ("00".equals(resultList.get(i).getInvoiceType())) {
                    dataArray[3] = "其他";
                } else {
                    dataArray[3] = "";
                }
                // 发票类型
                if ("1".equals(resultList.get(i).getQsStatus())) {
                    dataArray[4] = "已签收";
                    resultList.get(i).setQzStatus("1");
                } else if ("0".equals(resultList.get(i).getQsStatus())) {
                    dataArray[4] = "未签收";
                }
                if ("1".equals(resultList.get(i).getQzStatus())) {
                    dataArray[5] = "已确认";
                } else if ("0".equals(resultList.get(i).getQzStatus())) {
                    dataArray[5] = "未确认";
                }
                dataArray[6] = resultList.get(i).getCreateDate();
                dataArray[7] = resultList.get(i).getInvoiceCode();
                dataArray[8] = resultList.get(i).getInvoiceNo();
                dataArray[9] = resultList.get(i).getInvoiceDate();
                dataArray[10] = resultList.get(i).getGfName();
                dataArray[11] = resultList.get(i).getGfTaxNo();
                dataArray[12] = resultList.get(i).getXfName();
                dataArray[13] = resultList.get(i).getXfTaxNo();
                dataArray[14] = resultList.get(i).getInvoiceAmount();
                dataArray[15] = resultList.get(i).getTaxAmount();
                dataArray[16] = resultList.get(i).getTotalAmount() != null
                    ? resultList.get(i).getTotalAmount().toPlainString() : "";
                dataArray[17] = resultList.get(i).getTrainNumber();
                dataArray[18] = resultList.get(i).getDepartureCity();
                dataArray[19] = resultList.get(i).getReachingCity();
                dataArray[20] = resultList.get(i).getPassenger();
                dataArray[21] = resultList.get(i).getCheckCode();
                dataArray[22] = resultList.get(i).getRemark();
                dataArray[23] = resultList.get(i).getBusinessName();
                returnList.add(dataArray);
            }
        }
        json.put("datalist", returnList);
        return json;
    }
}
