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

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.common.util.AmountFormatUtil;
import com.dxhy.core.dao.TtFprzhzDao;
import com.dxhy.core.model.TtFprzhzRespVo;
import com.dxhy.core.service.export.TtFprzhzService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ld
 */
@Service("invoiceCertificationReportService")
public class TtFprzhzServiceImpl extends MpBaseServiceImpl<TtFprzhzDao, TtFprzhzRespVo> implements TtFprzhzService {

    @Override
    public JSONObject queryInvoiceCertification(Map<String, Object> params, int curr, int size) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push(params.get("dbName") + DbConstant.BUSINESS_READ);

        PageHelper.startPage(curr, size);
        List<TtFprzhzRespVo> pageList = this.baseMapper.queryInvoiceList(params);
        PageInfo<TtFprzhzRespVo> pageInfo = new PageInfo<>(pageList);
        json.put("hasNext", pageInfo.isHasNextPage());
        json.put("nextPage", pageInfo.getNextPage());
        List<String[]> returnList = new ArrayList<>();
        // 用于页面返回list对象
        if (pageList.size() > 0) {

            for (int i = 0; i < pageList.size(); i++) {
                String[] dataArray = new String[8];
                dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                dataArray[1] = pageList.get(i).getGfTaxNo();
                dataArray[2] = pageList.get(i).getGfName();
                dataArray[3] = pageList.get(i).getRzhBelongDate();
                dataArray[4] = pageList.get(i).getCount();
                dataArray[5] = AmountFormatUtil.fmtMicrometer(pageList.get(i).getAmount());
                dataArray[6] = AmountFormatUtil.fmtMicrometer(pageList.get(i).getTax());
                dataArray[7] = AmountFormatUtil.fmtMicrometer(pageList.get(i).getTotalAmount());
                returnList.add(dataArray);
            }
        }

        json.put("datalist", returnList);

        return json;

    }

}
