package com.neusoft.smart.pos.trade.task;

import com.neusoft.smart.pos.constants.DictionaryConstant;
import com.neusoft.smart.pos.framework.task.RedisTask;
import com.neusoft.smart.pos.framework.utils.SpringUtils;
import com.neusoft.smart.pos.trade.persistent.domain.BillSettlementTask;
import com.neusoft.smart.pos.trade.service.BillTaskService;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Slf4j
public class BillTask extends RedisTask {

	private final static Logger logger = LoggerFactory.getLogger(BillTask.class);
	
	@Setter
	public Integer orgId;
	@Setter
	public List<Integer> shopIds;
	@Setter
	public String billNumber;
	
	@Autowired
	private BillTaskService billTaskService = SpringUtils.getBean(BillTaskService.class);
	
	@Override
	public void executeTask() {
		log.info("账单结算任务开始执行");
		billTaskService.generateBillByBillNumber(orgId,shopIds,billNumber);
		BillSettlementTask billSettlementTask = new BillSettlementTask();
		billSettlementTask.setTaskStatus(DictionaryConstant.BILL_TASK_STATUS_2.getCode());
		billSettlementTask.setEndTime(new Date());
		billTaskService.updateBillSettlementTask(billSettlementTask,orgId,billNumber);
		log.info("账单结算任务执行完成");
	}
	
	
}
