package com.neusoft.smart.pos;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import javax.annotation.PostConstruct;

@SpringCloudApplication
@EnableFeignClients
//@MapperScan({"com.neusoft.smart.pos.order.persistent.mapper","com.neusoft.smart.pos.payorder.persistent.mapper", "com.neusoft.smart.pos.payment.persistent.mapper"})
@MapperScan({"com.neusoft.smart.pos.*.persistent.mapper","com.neusoft.smart.pos.*.persistent.ext.mapper"})
public class ServiceOrderApplication {

	@Autowired
	private RedisTemplate redisTemplate;

	public static void main(String[] args) {
		SpringApplication.run(ServiceOrderApplication.class, args);
	}

	@Bean("deviceConfigMap")
	public BoundHashOperations initBoundHashOperations2() {
		return redisTemplate.boundHashOps("deviceConfigMap");
	}

	@PostConstruct
	public RedisTemplate init() {
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		redisTemplate.setHashKeySerializer(new StringRedisSerializer());
		redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
		redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
		return redisTemplate;
	}
}
