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

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

import javax.annotation.Resource;

import com.dxhy.common.constant.DictConstant;
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.FpqsjgEnum;
import com.dxhy.common.enums.QsfsEnum;
import com.dxhy.common.service.DictdetaServcice;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.common.util.MathUtil;
import com.dxhy.common.vo.DictdetaModel;
import com.dxhy.core.dao.QssbDao;
import com.dxhy.core.model.QssbRespVO;
import com.dxhy.core.service.export.IQssbService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

/**
 * 签收失败统计业务实现类
 *
 * @author user
 */
@SuppressWarnings("DuplicatedCode")
@Service("qssbService")
@Slf4j

public class QssbServiceImpl extends MpBaseServiceImpl<QssbDao, QssbRespVO> implements IQssbService {
    @Resource
    private DictdetaServcice dictdetaServcice;

    @Override
    public JSONObject selectQssbBySmb(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<QssbRespVO> pageList = super.baseMapper.selectQssbBySmb(pramsMap);
        PageInfo<QssbRespVO> pageInfo = new PageInfo<>(pageList);
        json.put("hasNext", pageInfo.isHasNextPage());
        json.put("nextPage", pageInfo.getNextPage());

        // 用于页面展示
        List<QssbRespVO> resultList = pageInfo.getList();
        if (resultList != null && resultList.size() > 0) {
            for (int i = 0; i < resultList.size(); i++) {
                resultList.get(i).setXh(String.valueOf((curr - 1) * size + i + 1));
                resultList.get(i).setJe(MathUtil.round(resultList.get(i).getJe()));
                resultList.get(i).setSe(MathUtil.round(resultList.get(i).getSe()));

                //字典值转换
                resultList.get(i).setQsfs(dictdetaServcice.queryDictName(DictConstant.QS_TYPE,resultList.get(i).getQsfs()));
                resultList.get(i).setInvoiceType(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPE_VAT,resultList.get(i).getInvoiceType()));

            }
        }

        json.put("datalist", resultList);

        return json;
    }

}
