| | |
| | | package com.yeshi.fanli.service.impl.homemodule;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.user.DeviceSexDao;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.DeviceSex;
|
| | | import com.yeshi.fanli.service.inter.homemodule.DeviceSexService;
|
| | | import com.yeshi.fanli.util.RedisKeyEnum;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | | public class DeviceSexServiceImpl implements DeviceSexService {
|
| | |
|
| | | @Resource
|
| | | private DeviceSexDao deviceSexDao;
|
| | | |
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | | |
| | |
|
| | | @Override
|
| | | public void save(String device, Integer sex) {
|
| | | if (StringUtil.isNullOrEmpty(device) || sex == null) {
|
| | | return;
|
| | | }
|
| | | DeviceSex deviceSex = new DeviceSex();
|
| | | deviceSex.setId(device);
|
| | | deviceSex.setSex(sex);
|
| | | deviceSex.setCreateTime(new Date());
|
| | | deviceSexDao.save(deviceSex);
|
| | | |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.deviceSex, device);
|
| | | redisManager.cacheCommonString(key, sex + "", 10);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getDeviceSex(String device) {
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.deviceSex, device);
|
| | | String result = redisManager.getCommonString(key);
|
| | | if (!StringUtil.isNullOrEmpty(result)) {
|
| | | return Integer.parseInt(result);
|
| | | }
|
| | | |
| | | DeviceSex deviceSex = deviceSexDao.get(device);
|
| | | if (deviceSex == null || deviceSex.getSex() == null) {
|
| | | return 0;
|
| | | }
|
| | | return deviceSex.getSex();
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.homemodule; |
| | | |
| | | import java.util.Date; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.yeshi.fanli.dao.user.DeviceSexDao; |
| | | import com.yeshi.fanli.entity.bus.homemodule.DeviceSex; |
| | | import com.yeshi.fanli.service.inter.homemodule.DeviceSexService; |
| | | import com.yeshi.fanli.util.RedisKeyEnum; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | @Service |
| | | public class DeviceSexServiceImpl implements DeviceSexService { |
| | | |
| | | @Resource |
| | | private DeviceSexDao deviceSexDao; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | |
| | | @Override |
| | | public void save(String device, Integer sex) { |
| | | if (StringUtil.isNullOrEmpty(device) || sex == null) { |
| | | return; |
| | | } |
| | | DeviceSex deviceSex = new DeviceSex(); |
| | | deviceSex.setId(device); |
| | | deviceSex.setSex(sex); |
| | | deviceSex.setCreateTime(new Date()); |
| | | deviceSexDao.save(deviceSex); |
| | | |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.deviceSex, device); |
| | | redisManager.cacheCommonString(key, sex + "", 10); |
| | | } |
| | | |
| | | @Override |
| | | public int getDeviceSex(String device, SystemEnum system) { |
| | | if (system != SystemEnum.blks) |
| | | return 0; |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.deviceSex, device); |
| | | String result = redisManager.getCommonString(key); |
| | | if (!StringUtil.isNullOrEmpty(result)) { |
| | | return Integer.parseInt(result); |
| | | } |
| | | |
| | | DeviceSex deviceSex = deviceSexDao.get(device); |
| | | if (deviceSex == null || deviceSex.getSex() == null) { |
| | | return 0; |
| | | } |
| | | return deviceSex.getSex(); |
| | | } |
| | | } |