package cn.superdesk.uniorder.dubbo.provider.unified;

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.unified.UnifiedDrowMoney;
import cn.superdesk.uniorder.dao.entity.unified.UnifiedEncourage;
import cn.superdesk.uniorder.dao.entity.unified.UnifiedServiceGroup;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedDrowMoneyPage;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedDrowMoneyParam;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedEncouragePage;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedEncourageParam;
import cn.superdesk.uniorder.dto.vo.wechat.WxChannelItemList;
import cn.superdesk.uniorder.dubbo.facade.unified.DubboUnifiedEncourageService;
import cn.superdesk.uniorder.service.setting.UnifiedServiceService;
import cn.superdesk.uniorder.service.unified.UnifiedDrowMoneyService;
import cn.superdesk.uniorder.service.unified.UnifiedEncourageService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

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

@Service(version = "1.0.0", retries = -1, timeout = 10000)
public class DubboUnifiedEncourageServiceImpl implements DubboUnifiedEncourageService {


	@Autowired
	private UnifiedEncourageService unifiedEncourageService;
	@Autowired
	private UnifiedDrowMoneyService unifiedDrowMoneyService;
	@Autowired
	private UnifiedServiceService   unifiedServiceService;

//	@Autowired
//	private UnifiedChannelSyncService        unifiedChannelSyncService;
//	@Autowired
//	private UnifiedChannelProfitSyncService  unifiedChannelProfitSyncService;
//	@Autowired
//	private UnifiedChannelProfitXVirtService unifiedChannelProfitXVirtService;

	@Override
	public Map<String, Object> addObj(UnifiedEncourageParam param, LoginSysUser loginSysUser) {

		Map<String, Object> resMap           = new HashMap<>();
		UnifiedEncourage    unifiedEncourage = new UnifiedEncourage();
		BeanUtils.copyProperties(param, unifiedEncourage);
		unifiedEncourage.setCreateTime(DateUtil.date());
		unifiedEncourage.setCreateUserId(loginSysUser.getSysUserId());
		unifiedEncourageService.insertSelective(unifiedEncourage);
		resMap.put("code", "1");
		resMap.put("data", unifiedEncourage);
		return resMap;
	}

	@Override
	public Map<String, Object> updateObj(UnifiedEncourageParam param, LoginSysUser loginSysUser) {

		Map<String, Object> resMap           = new HashMap<>();
		UnifiedEncourage    unifiedEncourage = new UnifiedEncourage();

		BeanUtils.copyProperties(param, unifiedEncourage);

		unifiedEncourage.setUpdateTime(DateUtil.date());
		unifiedEncourage.setUpdateUserId(loginSysUser.getSysUserId());

		unifiedEncourageService.updateByPrimaryKeySelective(unifiedEncourage);

		resMap.put("code", "1");
		resMap.put("data", unifiedEncourage);
		return resMap;
	}

	@Override
	public R<List<UnifiedEncouragePage>> getPage(Map<String, Object> params, int pageNum, int pageSize) {
		return unifiedEncourageService.getPage(params, pageNum, pageSize);
	}


	@Override
	public UnifiedServiceGroup findServiceGroupByCode(String businessCode) {
		return unifiedEncourageService.findServiceGroupByCode(businessCode);
	}

	@Override
	public Map<String, Object> profitAdd(UnifiedDrowMoneyParam param, Long userId) {

		Map<String, Object> resMap           = new HashMap<>();
		UnifiedDrowMoney    unifiedDrowMoney = new UnifiedDrowMoney();

		BeanUtils.copyProperties(param, unifiedDrowMoney);

		unifiedDrowMoney.setCreateTime(DateUtil.date());
		unifiedDrowMoney.setCreateUserId(userId);

		unifiedDrowMoneyService.insertSelective(unifiedDrowMoney);

		resMap.put("code", "1");
		resMap.put("data", unifiedDrowMoney);
		return resMap;
	}

	@Override
	public R<List<UnifiedDrowMoneyPage>> getPageProfit(Map<String, Object> params, int pageNum, int pageSize) {
		return unifiedDrowMoneyService.getPageProfit(params, pageNum, pageSize);
	}


	@Override
	public BigDecimal getAmountProfit(Map<String, Object> amountProfitQuery) {
		return unifiedEncourageService.getAmountProfit(amountProfitQuery);
	}

	@Override
	public BigDecimal getAmountEncourage(Map<String, Object> amountProfitQuery) {
		return unifiedEncourageService.getAmountEncourage(amountProfitQuery);
	}

	@Override
	public BigDecimal getOrderAmount(Map<String, Object> amountQuery) {
		return unifiedEncourageService.getOrderAmount(amountQuery);
	}

	@Override
	public Integer getVirtCountByChannelId(Map<String, Object> virtCountQuery) {
		return unifiedEncourageService.getVirtCountByChannelId(virtCountQuery);
	}

	@Override
	public BigDecimal getAmountBack(Map<String, Object> amountProfitQuery) {
		return unifiedEncourageService.getAmountBack(amountProfitQuery);
	}

	@Override
	public BigDecimal getAmountGetCash(Map<String, Object> amountGetCashQuery) {
		return unifiedEncourageService.getAmountGetCash(amountGetCashQuery);
	}

	@Override
	public List<WxChannelItemList> getChannelItemList(Map<String, Object> channelListQuery) {
		return unifiedEncourageService.getChannelItemList(channelListQuery);
	}

	@Override
	public List<UnifiedEncouragePage> getEncourageList(Map<String, Object> amountGetCashQuery) {
		return unifiedEncourageService.getEncourageList(amountGetCashQuery);
	}

	@Override
	public List<UnifiedServiceGroup> getServiceGroupAll(Map<String, Object> params) {
		return unifiedServiceService.findAllByGroup(params);
	}


}
