package com.yeejoin.amos.api.openapi.face.service;


import com.yeejoin.amos.api.openapi.constant.Constant;
import com.yeejoin.amos.api.openapi.face.model.BizTokenModel;
import com.yeejoin.amos.api.openapi.face.model.CylinderFillingRecordModel;
import com.yeejoin.amos.api.openapi.face.orm.dao.CylinderFillingRecordMapper;
import com.yeejoin.amos.api.openapi.face.orm.entity.CylinderFillingRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.component.cache.Redis;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.rdbms.service.BaseService;

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


/**
 * 
 * <pre>
 * 液化气体气瓶充装信息-充装记录 服务类
 * </pre>
 *
 * @author gwb
 * @version $Id: ElevatorService.java, v 0.1 2021年9月30日 下午3:28:55 gwb Exp $
 */
@Component
public class CylinderFillingRecordService extends BaseService<CylinderFillingRecordModel,CylinderFillingRecord,CylinderFillingRecordMapper> {
    @Autowired
    private RedisTemplate redisTemplate;
    @Transactional(rollbackFor= {Exception.class})
	public String createCylinderFilling(List<CylinderFillingRecordModel> model) {
		// TODO Auto-generated method stub
//		if (ValidationUtil.isEmpty(model))
//			throw new BadRequest("气瓶标签信息为空.");
    	
		for (CylinderFillingRecordModel cylinderFillingRecordModel : model) {
			cylinderFillingRecordModel.setRecDate(new Date());
			cylinderFillingRecordModel.setAppId(getAppId());
			this.createWithModel(cylinderFillingRecordModel);
		}
		return "OK";
	}

	private String getAppId() {
		String tokenKey = Redis.genKey(Constant.TOKEN_PREFIX,RequestContext.getToken());
    	BizTokenModel bizTokenModel = (BizTokenModel) redisTemplate.opsForValue().get(tokenKey);
    	return bizTokenModel.getAppId();
	}

	public List<String> getDateList() {
    	return baseMapper.getDateList();
	}
}	
