package com.example.his.api.mis.service;

import com.example.his.api.db.dao.SystemDao;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;

@Service
public class SystemService {
    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private SystemDao systemDao;

    public String getItemValue(String item) {
        String value = redisTemplate.opsForValue().get("setting#" + item).toString();
        return value;
    }

    @Transactional
    public boolean setItemValue(String item, String value) {
        HashMap param = new HashMap<>() {{
            put("item", item);
            put("value", value);
        }};
        int rows = systemDao.update(param);
        if (rows == 1) {
            redisTemplate.opsForValue().set("setting#" + item, value);
            return true;
        } else {
            return false;
        }
    }
}
