|
@@ -0,0 +1,85 @@
|
|
|
+package cn.rankin.userservice.service;
|
|
|
+
|
|
|
+import cn.rankin.data.api.user.entity.UserDevice;
|
|
|
+import cn.rankin.userservice.helper.RaStringHelper;
|
|
|
+import cn.rankin.userservice.repository.UserDeviceRepository;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class UserDeviceService
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private UserDeviceRepository userDeviceRepository;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Find user deceive
|
|
|
+ * @param uid the user id
|
|
|
+ * @param deviceCode the device code
|
|
|
+ * @param deviceType the device type
|
|
|
+ * @return the entity of user device
|
|
|
+ */
|
|
|
+ public UserDevice findDevice(String uid,String deviceCode,String deviceType)
|
|
|
+ {
|
|
|
+ if(RaStringHelper.isNull(uid))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(RaStringHelper.isNull(deviceCode))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(RaStringHelper.isNull(deviceType))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ UserDevice userDevice = userDeviceRepository.findUserDevice(uid,deviceCode,deviceType);
|
|
|
+ if(userDevice != null)
|
|
|
+ {
|
|
|
+ return userDevice;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ userDevice = new UserDevice();
|
|
|
+ userDevice.setUserId(uid);
|
|
|
+ userDevice.setGmtCreated(new Date());
|
|
|
+ userDevice.setDeviceCode(deviceCode);
|
|
|
+ userDevice.setDeviceType(deviceType);
|
|
|
+ userDevice.setBindingNum(1);
|
|
|
+ userDeviceRepository.save(userDevice);
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Find user deceive
|
|
|
+ * @param uid the user id
|
|
|
+ * @param deviceCode the device code
|
|
|
+ * @param deviceType the device type
|
|
|
+ * @return the entity of user device
|
|
|
+ */
|
|
|
+ public int updateDevice(String uid,String deviceCode,String deviceType,int bingdingNum)
|
|
|
+ {
|
|
|
+ if(RaStringHelper.isNull(uid))
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if(RaStringHelper.isNull(deviceCode))
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if(RaStringHelper.isNull(deviceType))
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ int updateRet = userDeviceRepository.updateDevice(uid,deviceCode,deviceType,bingdingNum);
|
|
|
+
|
|
|
+ return updateRet;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|