package com.dxhy.extend.service.bb.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.common.util.StringHelper;
import com.dxhy.extend.dao.ExtJxsemxbbDao;
import com.dxhy.extend.model.ExtJxsemxbbRespVO;
import com.dxhy.extend.service.bb.ExtJxsemxbbcxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

/**
 * 进项税额明细报表是实现类
 *
 * @author kangzq
 * @date 2019年5月20日
 * @version 1.0
 */
@Service("extendjxsemxbbcxService")
@Slf4j

public class ExtJxsemxbbcxServiceImpl extends MpBaseServiceImpl<ExtJxsemxbbDao, ExtJxsemxbbRespVO>
    implements ExtJxsemxbbcxService {

    @Override
    public String selectByPramsMap(Map<String, Object> pramsMap) {
        JSONObject json;
        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<ExtJxsemxbbRespVO> zpList = super.baseMapper.selectzp(pramsMap);
            List<ExtJxsemxbbRespVO> name = super.baseMapper.selectname(pramsMap);
            ExtJxsemxbbRespVO vo = zpList.get(0);
            // 转化为展示对象
            vo.setGfmc(name.get(0).getGfmc());
            if (!StringHelper.isBlank(vo.getTotalAmount())) {
                vo.setTotalAmount(MathUtil.round(vo.getTotalAmount()));
            }
            if (!StringHelper.isBlank(vo.getTotalTax())) {
                vo.setTotalTax(MathUtil.round(vo.getTotalTax()));
            }
            if (!StringHelper.isBlank(vo.getAmount17())) {
                vo.setAmount17(MathUtil.round(vo.getAmount17()));
            }
            if (!StringHelper.isBlank(vo.getAmount13())) {
                vo.setAmount13(MathUtil.round(vo.getAmount13()));
            }
            if (!StringHelper.isBlank(vo.getAmount10())) {
                vo.setAmount10(MathUtil.round(vo.getAmount10()));
            }
            if (!StringHelper.isBlank(vo.getAmount5())) {
                vo.setAmount5(MathUtil.round(vo.getAmount5()));
            }
            if (!StringHelper.isBlank(vo.getAmount3())) {
                vo.setAmount3(MathUtil.round(vo.getAmount3()));
            }
            if (!StringHelper.isBlank(vo.getTax17())) {
                vo.setTax17(MathUtil.round(vo.getTax17()));
            }
            if (!StringHelper.isBlank(vo.getTax13())) {
                vo.setTax13(MathUtil.round(vo.getTax13()));
            }
            if (!StringHelper.isBlank(vo.getTax10())) {
                vo.setTax10(MathUtil.round(vo.getTax10()));
            }
            if (!StringHelper.isBlank(vo.getTax6())) {
                vo.setTax6(MathUtil.round(vo.getTax6()));
            }
            if (!StringHelper.isBlank(vo.getTax5())) {
                vo.setTax5(MathUtil.round(vo.getTax5()));
            }
            if (!StringHelper.isBlank(vo.getTax3())) {
                vo.setTax3(MathUtil.round(vo.getTax3()));
            }

            json.put("datalist", vo);

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

        return super.responseResult(json);
    }

}
