yujian
2019-06-25 491f5c8e304f2ad4d26e261f536ae98f1705772b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.yeshi.fanli.service.impl.homemodule;
 
import java.util.Date;
 
import javax.annotation.Resource;
 
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.StringUtil;
 
@Service
public class DeviceSexServiceImpl implements DeviceSexService {
 
    @Resource
    private DeviceSexDao deviceSexDao;
 
    @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);
    }
 
    @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;
    }
    
 
    @Override
    public int getDeviceSex(String device) {
        Integer sexDevice = getSex(device);
        if (sexDevice == null) {
            sexDevice = 0;
        }
        return sexDevice;
    }
}