package cn.superdesk.uniorder.dubbo.consumer.order._leaveover;

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.JwtUtil;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.order.BankRecord;
import cn.superdesk.uniorder.dubbo.facade.order._leaveover.DubboBankRecordService;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;


@Slf4j
@Component
public class BankRecordDubboConsumerService {

	@Reference(version = "1.0.0", timeout = 30000, retries = -1)
	private DubboBankRecordService bankRecordService;

	public Boolean addObj(String token, BankRecord item) throws ParseException {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		item.setCreateUserId(loginSysUser.getSysUserId());
		item.setOffStatus(Byte.valueOf("0"));
		item.setCreateTime(DateUtil.date());
		//5/6/19
		SimpleDateFormat sdf = new SimpleDateFormat("M/d/y");
		item.setRecDate(sdf.parse(item.getRecDateStr()));

		return bankRecordService.addObj(item);
	}

	public R<List<BankRecord>> findAllByPage(String token, Map<String, Object> params, int pageNum, int pageSize) {

		return bankRecordService.findAllByPage(params, pageNum, pageSize);
	}

	public List<String> findBank() {

		return bankRecordService.findBank();
	}
}
