package com.saye.hospitalgd.service.impl;

import com.saye.hospitalgd.mapper.TransactionDetailMapper;
import com.saye.hospitalgd.service.TransactionDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author thuang
 * @version 1.0
 * @description: TODO
 * @date 2021/9/28 11:04
 */
@Service
@Transactional
public class TransactionDetailServiceImpl implements TransactionDetailService {

    @Autowired
    private TransactionDetailMapper transactionDetailMapper;

    @Override
    public List<HashMap<Object, Object>> findHisAndThirdJoinData(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findHisAndThirdJoinData(map);
    }

    @Override
    public List<HashMap<Object, Object>> findHisUnilateral() throws Exception {
        return transactionDetailMapper.findHisUnilateral();
    }

    @Override
    public List<HashMap<Object, Object>> findBankUnilateral() throws Exception {
        return transactionDetailMapper.findBankUnilateral();
    }

    @Override
    public List<HashMap<Object, Object>> findDiff() throws Exception {
        return transactionDetailMapper.findDiff();
    }

    @Override
    public List<HashMap<Object, Object>> findHisAndThirdJoinDataNumByTime(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findHisAndThirdJoinDataNumByTime(map);
    }

    @Override
    public void insertHisAndThirdJoinData(HashMap<Object, Object> map) throws Exception {
        //先删除原来的记录
        transactionDetailMapper.deleteHisAndThirdJoinData(map);

        //分别插入能关联的 //单边的  (非现金账 )   这里有个坑 假如银行端有空的账单过来，这里关联处理会出问题。 如果真有这情况 需要分开 his的‘其他’这类 同现金相似处理
        transactionDetailMapper.insertJoinDataToHisAndThird(map);
        transactionDetailMapper.insertHisUnilateral(map);
        transactionDetailMapper.insertThirdUnilateral(map);

//        //现金账
//        transactionDetailMapper.insertJoinDataToHisAndCash(map);
//        transactionDetailMapper.insertHisCashUnilateral(map);
//        transactionDetailMapper.insertCashUnilateral(map);

        //判断差错账 更新状态
        transactionDetailMapper.updateHisAndThirdError(map);

    }

    @Override
    public void insetHisAndCashJoinData(HashMap<Object, Object> map) {

    }

    @Override
    public List<HashMap<Object, Object>> findHisAndThirdJoinDataByParam(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findHisAndThirdJoinDataByParam(map);
    }

    @Override
    public void updateJoinDate(HashMap<Object, Object> map) throws Exception {
        transactionDetailMapper.updateJoinDate(map);
    }

    @Override
    public void updateJoinSetActiveByThird(HashMap<Object, Object> map) throws Exception {
        //判断是否现金账单
//        String c_zffs = StringDUtil.changeNullToEmpty(map.get("c_zffs"));
//        String cash_code = StringDUtil.changeNullToEmpty(map.get("cash_code"));

//        if (cash_code.equals(c_zffs)) {
//            transactionDetailMapper.updateJoinSetActiveByThirdCash(map);
//        } else {
        transactionDetailMapper.updateJoinSetActiveByThird(map);
//        }

    }

    @Override
    public void updateJoinSetActiveByHis(HashMap<Object, Object> map) throws Exception {
        //判断是否现金账单
//        String payType = StringDUtil.changeNullToEmpty(map.get("payType"));
//        String cash_code = StringDUtil.changeNullToEmpty(map.get("cash_code"));

//        if (cash_code.equals(payType)){
//        transactionDetailMapper.updateJoinSetActiveByHisCash(map);
//        }else {
        transactionDetailMapper.updateJoinSetActiveByHis(map);
//        }
    }

    @Override
    public List<HashMap<Object, Object>> findAllBankDetailNum(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findAllBankDetailNum(map);
    }

    @Override
    public List<HashMap<Object, Object>> findAllBankDetailSum(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findAllBankDetailSum(map);
    }

    @Override
    public List<HashMap<Object, Object>> findDBZNum(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findDBZNum(map);
    }

    @Override
    public List<HashMap<Object, Object>> findJoinDataNumByTime(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findJoinDataNumByTime(map);
    }

    @Override
    public List<HashMap<Object, Object>> findDBZFLNumByTime(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findDBZFLNumByTime(map);
    }

    @Override
    public List<HashMap<Object, Object>> findBankBillNumByTime(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findBankBillNumByTime(map);
    }

    @Override
    public List<HashMap<Object, Object>> findBankBillMoneyByTime(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findBankBillMoneyByTime(map);
    }

    @Override
    public void updateJoinSetActiveByZhiPiao(HashMap<Object, Object> map) throws Exception {
        transactionDetailMapper.updateJoinSetActiveByZhiPiao(map);
    }

    @Override
    public List<HashMap<Object, Object>> findHisAndThirdJoinDataByParamAndNotUnique(HashMap<Object, Object> map) throws Exception {
        return transactionDetailMapper.findHisAndThirdJoinDataByParamAndNotUnique(map);
    }

    @Override
    public void deleteHisAndThirdJoinDataByParamAndNotUnique(HashMap<Object, Object> map) throws Exception {
        transactionDetailMapper.deleteHisAndThirdJoinDataByParamAndNotUnique(map);
    }

    @Override
    public void addNotUniqueData(List<HashMap<Object, Object>> list) throws Exception {
        transactionDetailMapper.addNotUniqueData(list);
    }


}
