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

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

import com.dxhy.common.constant.DictConstant;
import com.dxhy.common.service.DictdetaServcice;
import com.dxhy.common.vo.DictdetaModel;
import com.dxhy.core.service.export.IRzjgqdService;
import lombok.extern.slf4j.Slf4j;
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.enums.FplxEnum;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.common.util.AmountFormatUtil;
import com.dxhy.core.dao.RzjgqdDao;
import com.dxhy.core.model.RzjgqdRespVO;
import com.dxhy.core.util.InvoiceTypeUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.annotation.Resource;

/**
 * 认证结果
 * 
 * @author aa
 */
@Service("rzjgqdService")
@Slf4j

public class RzjgqdServiceImpl extends MpBaseServiceImpl<RzjgqdDao, RzjgqdRespVO> implements IRzjgqdService {
    @Resource
    private DictdetaServcice dictdetaServcice;
    @Override
    public JSONObject rzjgByGfshAndSkssq(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);

        PageHelper.startPage(curr, size);
        List<RzjgqdRespVO> pageList = super.baseMapper.rzjgByGfshAndSkssq(pramsMap);
        PageInfo<RzjgqdRespVO> pageInfo = new PageInfo<>(pageList);
        json.put("hasNext", pageInfo.isHasNextPage());
        json.put("nextPage", pageInfo.getNextPage());

        // 用于页面展示
        List<RzjgqdRespVO> 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[12];
                dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                dataArray[1] = resultList.get(i).getFpdm();
                dataArray[2] = resultList.get(i).getFphm();
                dataArray[3] = dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPE_VAT,resultList.get(i).getFplx());
                dataArray[4] = resultList.get(i).getKprq();
                dataArray[5] = resultList.get(i).getXfsh();
                dataArray[6] = resultList.get(i).getXfmc();
                if (!"".equals(resultList.get(i).getJe())) {
                    dataArray[7] = AmountFormatUtil.fmtMicrometer(resultList.get(i).getJe());
                }
                if (!"".equals(resultList.get(i).getSe())) {
                    dataArray[8] = AmountFormatUtil.fmtMicrometer(resultList.get(i).getSe());
                }
                if (!"".equals(resultList.get(i).getDkse())) {
                    dataArray[9] = AmountFormatUtil.fmtMicrometer(resultList.get(i).getDkse());
                }
                dataArray[10] = resultList.get(i).getRzrq();
                dataArray[11] = dictdetaServcice.queryDictName(DictConstant.FPDK_TYPE,resultList.get(i).getDklx());
                returnList.add(dataArray);
            }

        }

        json.put("datalist", returnList);

        return json;
    }

    /**
     * 发票类型码统一放入map中
     */
    public static final Map<String, String> FPLX_MAP = new HashMap<String, String>(16) {
        {
            for (FplxEnum en : FplxEnum.values()) {
                this.put(en.getFplxDm(), en.getFplxMc(en.getIndex()));
            }
        }
    };

}
