| | |
| | | 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
|
| | |
| | |
|
| | | @Resource
|
| | | private DeviceSexDao deviceSexDao;
|
| | | |
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | | |
| | |
|
| | | @Override
|
| | | public void save(String device, Integer sex) {
|
| | |
| | | deviceSex.setSex(sex);
|
| | | deviceSex.setCreateTime(new Date());
|
| | | deviceSexDao.save(deviceSex);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Integer getSex(String device) {
|
| | | DeviceSex deviceSex = deviceSexDao.get(device);
|
| | | if (deviceSex != null) {
|
| | | return deviceSex.getSex();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void deleteSex(String device) {
|
| | | deviceSexDao.delete(device);
|
| | | }
|
| | | |
| | | @Override
|
| | | public int changeDeviceSex(Integer sex, String device) {
|
| | | if (sex == null || sex < 0 || sex > 2) {
|
| | | sex = 0;
|
| | | }
|
| | |
|
| | | Integer sexDevice = getSex(device);
|
| | | if (sexDevice == null) {
|
| | | sexDevice = 0;
|
| | | }
|
| | | |
| | | if (sex == 0 && sexDevice != 0) {
|
| | | deleteSex(device);
|
| | | } |
| | | |
| | | if(sex > 0 && sex != sexDevice) {
|
| | | save(device, sex);
|
| | | }
|
| | | return sex;
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.deviceSex, device);
|
| | | redisManager.cacheCommonString(key, sex + "", 10);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public int getDeviceSex(String device) {
|
| | | Integer sexDevice = getSex(device);
|
| | | if (sexDevice == null) {
|
| | | sexDevice = 0;
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.deviceSex, device);
|
| | | String result = redisManager.getCommonString(key);
|
| | | if (!StringUtil.isNullOrEmpty(result)) {
|
| | | return Integer.parseInt(result);
|
| | | }
|
| | | return sexDevice;
|
| | | |
| | | DeviceSex deviceSex = deviceSexDao.get(device);
|
| | | if (deviceSex == null || deviceSex.getSex() == null) {
|
| | | return 0;
|
| | | }
|
| | | return deviceSex.getSex();
|
| | | }
|
| | | }
|