package cn.superdesk.uniorder.dubbo.consumer.accounting;

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.accounting.AccountingAppeal;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dto.param.accounting.AccountingAppealParam;
import cn.superdesk.uniorder.dubbo.facade.accounting.DubboAccountingAppealService;
import cn.superdesk.uniorder.common.security.JwtUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * @Description: 对账单-申诉
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2020-10-23 17:19:13
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020-10-23 17:19:13
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
public class AccountingAppealDubboConsumerService {

	@Reference(version = "1.0.0", timeout = 10000, retries = -1)
	private DubboAccountingAppealService dubboAccountingAppealService;


	/****************************************** extends BaseService 部分 start ******************************************/

	public void addObj(AccountingAppealParam param) {

		dubboAccountingAppealService.addObj(param);

	}

	public void updateObj(AccountingAppealParam param) {

		dubboAccountingAppealService.updateObj(param);
	}

	public void deleteObj(Long id) {

		dubboAccountingAppealService.deleteObj(id);
	}

	public AccountingAppeal findById(Long id) {

		return dubboAccountingAppealService.findById(id);
	}

	public PageInfo<AccountingAppeal> findByPaging(Map<String, Object> conditions, Integer pageNun, Integer pageSize) {

		return dubboAccountingAppealService.findByPaging(conditions, pageNun, pageSize);
	}

	public List<AccountingAppeal> findAll(Map<String, Object> queryMap) {

		return dubboAccountingAppealService.findAll(queryMap);
	}

	/****************************************** extends BaseService 部分   end ******************************************/


	public void addAccountingAppeal(AccountingAppealParam param, String token) {

		log.info("\n\n\n\n{}\n\n\n\n", AnJsonUtils.toPrettyJson(param));

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		param.setCreateTime(DateUtil.date());
		param.setCreateUserId(loginSysUser.getSysUserId());

		dubboAccountingAppealService.addAccountingAppeal(param);
	}


	public void updateAccountingAppeal(AccountingAppealParam param, String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

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

		dubboAccountingAppealService.updateAccountingAppeal(param);
	}


	public void deleteAccountingAppeal(Long id) {
		dubboAccountingAppealService.deleteAccountingAppeal(id);
	}


	public AccountingAppeal findAccountingAppealById(Long id) {

		return dubboAccountingAppealService.findAccountingAppealById(id);
	}

	public AccountingAppeal findAccountingAppealByAccountingOrderId(Long accountingOrderId) {
		return dubboAccountingAppealService.findAccountingAppealByAccountingOrderId(accountingOrderId);
	}

	public R<List<AccountingAppeal>> pageQuery(Map<String, Object> conditions, int pageNun, int pageSize) {

		return dubboAccountingAppealService.pageQuery(conditions, pageNun, pageSize);
	}
}
