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.MathUtil;
import com.dxhy.core.dao.CoreJxsemxbbDao;
import com.dxhy.core.model.JxsemxbbRespVO;
import com.dxhy.core.service.export.JxsemxbbcxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

/**
 * 进项税额明细报表是实现类
 *
 * @author user
 */
@Service("corejxsemxbbcxService")
@Slf4j

public class JxsemxbbcxServiceImpl extends MpBaseServiceImpl<CoreJxsemxbbDao, JxsemxbbRespVO> implements JxsemxbbcxService {

    @Override
    public JSONObject selectByPramsMap(Map<String, Object> pramsMap) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);

        try {

            String[] titlelist = {"购方名称", "税款所属期", "份数", "金额", "税额", "本期进项税额转出额", "14", "15", "16", "17", "18", "19",
                "20", "21", "22", "23"};
            String[] titleprop = {"gfmc", "skssq", "TotalCount", "totalAmount", "totalTax", "totalOutTax", "outTax1",
                "outTax2", "outTax3", "outTax4", "outTax5", "outTax6", "outTax7", "outTax8"};

            // 需要设置返回列表标题时调用
            json = super.setTitleList(titlelist, titleprop);

            String skssq = pramsMap.get("skssq").toString().substring(0, 4) + "年"
                + pramsMap.get("skssq").toString().substring(4, 6) + "月";
            json.put("skssq", skssq);

            List<JxsemxbbRespVO> zpList = super.baseMapper.selectzp(pramsMap);
            List<JxsemxbbRespVO> name = super.baseMapper.selectname(pramsMap);
            JxsemxbbRespVO vo = zpList.get(0);
            // 转化为展示对象
            vo.setGfmc(name.get(0).getGfmc());
            vo.setTotalAmount(MathUtil.round(vo.getTotalAmount()));
            vo.setTotalTax(MathUtil.round(vo.getTotalTax()));
            vo.setAmount17(MathUtil.round(vo.getAmount17()));
            vo.setAmount13(MathUtil.round(vo.getAmount13()));
            vo.setAmount10(MathUtil.round(vo.getAmount10()));
            vo.setAmount5(MathUtil.round(vo.getAmount5()));
            vo.setAmount3(MathUtil.round(vo.getAmount3()));
            vo.setTax17(MathUtil.round(vo.getTax17()));
            vo.setTax13(MathUtil.round(vo.getTax13()));
            vo.setTax10(MathUtil.round(vo.getTax10()));
            vo.setTax6(MathUtil.round(vo.getTax6()));
            vo.setTax5(MathUtil.round(vo.getTax5()));
            vo.setTax3(MathUtil.round(vo.getTax3()));

            json.put("datalist", vo);

        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }

}
