From 107d1ad3794894f1284e50a3dc4c4dc0ded03efa Mon Sep 17 00:00:00 2001 From: xiehonglong <599179587@qq.com> Date: Sat, 8 Jul 2017 18:09:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ifish/bean/Tbl_Vender.java | 270 ++++++++++++++++++ .../java/com/ifish/helper/DeviceHelper.java | 149 ++++++++++ .../java/com/ifish/helper/RedisHelper.java | 172 +++++++++++ .../java/com/ifish/helper/RedisHelperI.java | 69 +++++ .../java/com/ifish/helper/UserHelper.java | 75 +++++ .../com/ifish/mapper/Tbl_Device_Mapper.java | 190 ++++++++++++ .../ifish/mapper/Tbl_Device_MapperSql.java | 269 +++++++++++++++++ .../mapper/Tbl_Hardware_Type_Mapper.java | 38 +++ .../ifish/mapper/Tbl_Push_List_Mapper.java | 74 +++++ .../ifish/mapper/Tbl_Push_List_MapperSql.java | 30 ++ .../com/ifish/mapper/Tbl_User_Mapper.java | 80 ++++++ .../com/ifish/mapper/Tbl_User_MapperSql.java | 101 +++++++ src/main/resources/property.properties | 3 +- 13 files changed, 1519 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/ifish/bean/Tbl_Vender.java create mode 100644 src/main/java/com/ifish/helper/DeviceHelper.java create mode 100644 src/main/java/com/ifish/helper/RedisHelper.java create mode 100644 src/main/java/com/ifish/helper/RedisHelperI.java create mode 100644 src/main/java/com/ifish/helper/UserHelper.java create mode 100644 src/main/java/com/ifish/mapper/Tbl_Device_Mapper.java create mode 100644 src/main/java/com/ifish/mapper/Tbl_Device_MapperSql.java create mode 100644 src/main/java/com/ifish/mapper/Tbl_Hardware_Type_Mapper.java create mode 100644 src/main/java/com/ifish/mapper/Tbl_Push_List_Mapper.java create mode 100644 src/main/java/com/ifish/mapper/Tbl_Push_List_MapperSql.java create mode 100644 src/main/java/com/ifish/mapper/Tbl_User_Mapper.java create mode 100644 src/main/java/com/ifish/mapper/Tbl_User_MapperSql.java diff --git a/src/main/java/com/ifish/bean/Tbl_Vender.java b/src/main/java/com/ifish/bean/Tbl_Vender.java new file mode 100644 index 0000000..da691c8 --- /dev/null +++ b/src/main/java/com/ifish/bean/Tbl_Vender.java @@ -0,0 +1,270 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.bean; + +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * 鱼缸场详情表(tbl_vender_list) + * + * @author bianj + * @version 1.0.0 2017-06-27 + */ +@Entity +@Table(name = "tbl_vender_list") +public class Tbl_Vender implements java.io.Serializable { + + /** + * 版本号 + */ + private static final long serialVersionUID = -487543106603936914L; + + /** + * 鱼缸厂编号 + */ + @Id + @Column(name = "brand_code", unique = true, nullable = false, length = 20) + private String brandCode; + + /** + * 电子厂代码 + */ + @Id + @Column(name = "factory_code", unique = true, nullable = false, length = 20) + private String factoryCode; + + /** + * logo + */ + @Column(name = "brand_logo", nullable = true, length = 100) + private String brandLogo; + + /** + * 鱼缸厂名称 + */ + @Column(name = "brand_name", nullable = false, length = 20) + private String brandName; + + /** + * 品牌介绍 + */ + @Column(name = "brand_introduce", nullable = true, length = 100) + private String brandIntroduce; + + /** + * app展示 + */ + @Column(name = "app_show", nullable = true, length = 1) + private String appShow; + + /** + * 联系电话 + */ + @Column(name = "contact_phone", nullable = true, length = 30) + private String contactPhone; + + /** + * 联系地址 + */ + @Column(name = "contact_address", nullable = true, length = 50) + private String contactAddress; + + /** + * 更新时间 + */ + @Column(name = "update_time", nullable = true) + private Date updateTime; + + /** + * 创建时间 + */ + @Column(name = "create_time", nullable = true) + private Date createTime; + + /** + * 获取鱼缸厂编号 + * + * @return 鱼缸厂编号 + */ + public String getBrandCode() { + return this.brandCode; + } + + /** + * 设置鱼缸厂编号 + * + * @param brandCode 鱼缸厂编号 + */ + public void setBrandCode(String brandCode) { + this.brandCode = brandCode; + } + + /** + * 获取电子厂代码 + * + * @return 电子厂代码 + */ + public String getFactoryCode() { + return this.factoryCode; + } + + /** + * 设置电子厂代码 + * + * @param factoryCode 电子厂代码 + */ + public void setFactoryCode(String factoryCode) { + this.factoryCode = factoryCode; + } + + /** + * 获取logo + * + * @return logo + */ + public String getBrandLogo() { + return this.brandLogo; + } + + /** + * 设置logo + * + * @param brandLogo logo + */ + public void setBrandLogo(String brandLogo) { + this.brandLogo = brandLogo; + } + + /** + * 获取鱼缸厂名称 + * + * @return 鱼缸厂名称 + */ + public String getBrandName() { + return this.brandName; + } + + /** + * 设置鱼缸厂名称 + * + * @param brandName 鱼缸厂名称 + */ + public void setBrandName(String brandName) { + this.brandName = brandName; + } + + /** + * 获取品牌介绍 + * + * @return 品牌介绍 + */ + public String getBrandIntroduce() { + return this.brandIntroduce; + } + + /** + * 设置品牌介绍 + * + * @param brandIntroduce 品牌介绍 + */ + public void setBrandIntroduce(String brandIntroduce) { + this.brandIntroduce = brandIntroduce; + } + + /** + * 获取app展示 + * + * @return app展示 + */ + public String getAppShow() { + return this.appShow; + } + + /** + * 设置app展示 + * + * @param appShow app展示 + */ + public void setAppShow(String appShow) { + this.appShow = appShow; + } + + /** + * 获取联系电话 + * + * @return 联系电话 + */ + public String getContactPhone() { + return this.contactPhone; + } + + /** + * 设置联系电话 + * + * @param contactPhone 联系电话 + */ + public void setContactPhone(String contactPhone) { + this.contactPhone = contactPhone; + } + + /** + * 获取联系地址 + * + * @return 联系地址 + */ + public String getContactAddress() { + return this.contactAddress; + } + + /** + * 设置联系地址 + * + * @param contactAddress 联系地址 + */ + public void setContactAddress(String contactAddress) { + this.contactAddress = contactAddress; + } + + /** + * 获取更新时间 + * + * @return 更新时间 + */ + public Date getUpdateTime() { + return this.updateTime; + } + + /** + * 设置更新时间 + * + * @param updateTime 更新时间 + */ + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + /** + * 获取创建时间 + * + * @return 创建时间 + */ + public Date getCreateTime() { + return this.createTime; + } + + /** + * 设置创建时间 + * + * @param createTime 创建时间 + */ + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } +} diff --git a/src/main/java/com/ifish/helper/DeviceHelper.java b/src/main/java/com/ifish/helper/DeviceHelper.java new file mode 100644 index 0000000..9c7fae1 --- /dev/null +++ b/src/main/java/com/ifish/helper/DeviceHelper.java @@ -0,0 +1,149 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.helper; + +import com.ifish.bean.LoginRecord; +import com.ifish.bean.Tbl_Device; +import com.ifish.bean.Tbl_Device_User; +import com.ifish.bean.Tbl_Factory_List; +import com.ifish.bean.Tbl_HardWare_Type; +import com.ifish.mapper.Tbl_Device_Mapper; +import com.ifish.mapper.Tbl_Hardware_Type_Mapper; +import com.ifish.socket.model.send.DeviceLoginContextLength24; +import com.ifish.util.IfishUtil; +import com.ifish.util.RedisKey; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * + * @author Administrator + */ +@Component +public class DeviceHelper implements DeviceHelperI { + + /** + * 所有tbl_Hardware_Type表的操作方法接口 + */ + @Autowired + private Tbl_Hardware_Type_Mapper tbl_Hardware_Type_Mapper; + + @Autowired + private RedisHelperI redisHelperI; + + @Autowired + private Tbl_Device_Mapper tbl_Device_Mapper; + + @Override + public Tbl_Device update(Tbl_Device device) { + try { + int i = tbl_Device_Mapper.updateTbl_Device(device); + if (i > 0) { + return device; + } else { + return null; + } + } catch (Exception e) { + return null; + } + } + + @Override + public Tbl_Device update(DeviceLoginContextLength24 model) { + return null; + } + + @Override + public void updateWarnOnoff(String macAddress, String onOff) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Tbl_Device getUniqueByProperty(String property, Object value) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public List getByProperty(String property, Object value) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Tbl_Device_User getUniqueByProperty(String macAddress) { + Tbl_Device device = getDeviceByMacAddress(macAddress); + Tbl_Device_User deviceUser = null; + try { +// String key = RedisKey.DeviceUser_Key + "m" + macAddress; +// String redisString = redisHelperI.getRedis(key); +// if (StringUtils.isNotBlank(redisString)) { +// deviceUser = (Tbl_Device_User) IfishUtil.JsonToBean(redisString, Tbl_Device_User.class); +// } else { +// device = tbl_Device_Mapper.getDeviceUsersByUserIdAndDeviceId(device.get, deviceId); +// if (device != null && device.getDeviceId() > 0) { +// redisHelperI.setRedis(key, IfishUtil.ObjectToJson(device)); +// } +// } + } catch (Exception e) { + } + return deviceUser; + } + + @Override + public List getListByProperty(Integer deviceId) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public LoginRecord save(LoginRecord loginRecord) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Tbl_Factory_List getFactoryListById(String factoryCode) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Tbl_HardWare_Type getHardwareTypeById(String typeCode) { + + Tbl_HardWare_Type hardwareType = null; + try { + String key = RedisKey.HardWareType_key + typeCode; + String redisString = redisHelperI.getRedis(key); + if (StringUtils.isNotBlank(redisString)) { + hardwareType = (Tbl_HardWare_Type) IfishUtil.JsonToBean(redisString, Tbl_HardWare_Type.class); + } else { + hardwareType = tbl_Hardware_Type_Mapper.getHardwareTypeByTypeCode(typeCode); + if (hardwareType != null && StringUtils.isNotBlank(hardwareType.getHardwareType())) { + redisHelperI.setRedis(key, IfishUtil.ObjectToJson(hardwareType)); + } + } + } catch (Exception e) { + } + return hardwareType; + } + + public Tbl_Device getDeviceByMacAddress(String macAddress) { + Tbl_Device device = null; + try { + String key = RedisKey.Device_key + macAddress; + String redisString = redisHelperI.getRedis(key); + if (StringUtils.isNotBlank(redisString)) { + device = (Tbl_Device) IfishUtil.JsonToBean(redisString, Tbl_Device.class); + } else { + device = tbl_Device_Mapper.getDeviceByMacAddress(macAddress); + if (device != null && device.getDeviceId() > 0) { + redisHelperI.setRedis(key, IfishUtil.ObjectToJson(device)); + } + } + } catch (Exception e) { + } + return device; + } + +} diff --git a/src/main/java/com/ifish/helper/RedisHelper.java b/src/main/java/com/ifish/helper/RedisHelper.java new file mode 100644 index 0000000..5f8f512 --- /dev/null +++ b/src/main/java/com/ifish/helper/RedisHelper.java @@ -0,0 +1,172 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.helper; + +import com.ifish.util.IfishUtil; +import java.util.Iterator; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +/** + * redis缓存服务器所有接口方法 + * + * @author Administrator + */ +@Component +public class RedisHelper implements RedisHelperI { + + @Autowired + private StringRedisTemplate redis; + + /* + *获取缓存值 + */ + @Override + public String getRedis(String key) { + try { + String result = redis.opsForValue().get(key.toLowerCase()); + return result; + } catch (Exception e) { + return null; + } + } + + /* + *设置缓存(默认时间为1天) + */ + @Override + public void setRedis(String key, String value) { + if (value == null) { + return; + } + try { + redis.opsForValue().set(key.toLowerCase(), value, IfishUtil.CacheTime_DAYS, TimeUnit.DAYS); + } catch (Exception e) { + } + } + + /*设置自定义时效缓存 + *key 缓存名称,value缓存值(string),time(保存时间),unit(时间类型) + */ + @Override + public void setRedis(String key, String value, int time, TimeUnit unit) { + if (value == null) { + return; + } + try { + redis.opsForValue().set(key.toLowerCase(), value, time, unit); + } catch (Exception e) { + } + } + + /* + *设置按天时效缓存 + */ + @Override + public void setRedisToDAYS(String key, String value) { + if (value == null) { + return; + } + try { + redis.opsForValue().set(key.toLowerCase(), value, IfishUtil.CacheTime_DAYS, TimeUnit.DAYS); + } catch (Exception e) { + } + } + + /* + *设置按时时效缓存 + */ + @Override + public void setRedisToHOURS(String key, String value) { + if (value == null) { + return; + } + try { + redis.opsForValue().set(key.toLowerCase(), value, IfishUtil.CacheTime_HOURS, TimeUnit.HOURS); + } catch (Exception e) { + } + } + + /* + *设置按分时效缓存 + */ + @Override + public void setRedisToMINUTES(String key, String value) { + if (value == null) { + return; + } + try { + redis.opsForValue().set(key.toLowerCase(), value, IfishUtil.CacheTime_MINUTES, TimeUnit.MINUTES); + } catch (Exception e) { + } + } + + /* + *设置按秒时效缓存 + */ + @Override + public void setRedisToSECONDS(String key, String value) { + if (value == null) { + return; + } + try { + redis.opsForValue().set(key.toLowerCase(), value, IfishUtil.CacheTime_SECONDS, TimeUnit.SECONDS); + } catch (Exception e) { + } + } + + /* + *删除缓存值 + */ + @Override + public void deleteRedis(String key) { + try { + redis.delete(key.toLowerCase()); + } catch (Exception e) { + } + } + + /* + *删除带前缀的批量缓存 + *tagkey 缓存前缀 + *如省份缓存 province:10,前缀为province + */ + @Override + public void delRedisByTagKey(String tagkey) { + try { + Set set = redis.keys(tagkey.toLowerCase() + "*"); + Iterator it = set.iterator(); + while (it.hasNext()) { + String keyStr = it.next(); + redis.delete(keyStr); + } + } catch (Exception e) { + } + } + + /* + * 删除当前缓存数据库所有的key + * 排除系数设置缓存 + */ + @Override + public void deleteDBRedis() { + try { + Set set = redis.keys("*"); + Iterator it = set.iterator(); + while (it.hasNext()) { + String keyStr = it.next(); + //排除系数设置缓存 + if (!keyStr.contains("recommendsetting:")) { + redis.delete(keyStr); + } + } + } catch (Exception e) { + } + } +} diff --git a/src/main/java/com/ifish/helper/RedisHelperI.java b/src/main/java/com/ifish/helper/RedisHelperI.java new file mode 100644 index 0000000..0faa9cb --- /dev/null +++ b/src/main/java/com/ifish/helper/RedisHelperI.java @@ -0,0 +1,69 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.helper; + +import java.util.concurrent.TimeUnit; + +/** + * redis缓存服务器所有接口方法 + * + * @author Administrator + */ +public interface RedisHelperI { + + /* + *删除带前缀的批量缓存 + *tagkey 缓存前缀 + *如省份缓存 province:10,前缀为province + */ + void delRedisByTagKey(String tagkey); + + /* + *删除缓存值 + */ + void deleteRedis(String key); + + /* + *删除当前缓存数据库所有的key + */ + void deleteDBRedis(); + + /* + *获取缓存值 + */ + String getRedis(String key); + + /* + *设置缓存(有效时间默认为1天) + */ + void setRedis(String key, String value); + + /*设置自定义时效缓存 + *key 缓存名称,value缓存值(string),time(保存时间),unit(时间类型) + */ + void setRedis(String key, String value, int time, TimeUnit unit); + + /* + *设置按天时效缓存 + */ + void setRedisToDAYS(String key, String value); + + /* + *设置按时时效缓存 + */ + void setRedisToHOURS(String key, String value); + + /* + *设置按分时效缓存 + */ + void setRedisToMINUTES(String key, String value); + + /* + *设置按秒时效缓存 + */ + void setRedisToSECONDS(String key, String value); + +} diff --git a/src/main/java/com/ifish/helper/UserHelper.java b/src/main/java/com/ifish/helper/UserHelper.java new file mode 100644 index 0000000..bd7a33d --- /dev/null +++ b/src/main/java/com/ifish/helper/UserHelper.java @@ -0,0 +1,75 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.helper; + +import com.ifish.bean.Tbl_Push_List; +import com.ifish.bean.Tbl_User; +import com.ifish.mapper.Tbl_Push_List_Mapper; +import com.ifish.mapper.Tbl_User_Mapper; +import com.ifish.util.IfishUtil; +import com.ifish.util.RedisKey; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * + * @author Administrator + */ +@Component +public class UserHelper implements UserHelperI { + + @Autowired + private RedisHelperI redisHelperI; + + @Autowired + private Tbl_User_Mapper tbl_User_Mapper; + + @Autowired + private Tbl_Push_List_Mapper tbl_Push_List_Mapper; + + @Override + public Tbl_User findById(Integer userId) { + Tbl_User tmpUser = null; + try { + String userKey = RedisKey.User_Key + userId; + String userString = redisHelperI.getRedis(userKey); + //1.从数据库或缓存中读取用户对象 + if (StringUtils.isNotBlank(userString)) { + tmpUser = (Tbl_User) IfishUtil.JsonToBean(userString, Tbl_User.class); + } else { + tmpUser = tbl_User_Mapper.getUserByUserId(userId + ""); + saveUserToRedis(tmpUser); + } + } catch (Exception e) { + } + return tmpUser; + } + + @Override + public Tbl_Push_List save(Tbl_Push_List pushList) { + try { + int i = tbl_Push_List_Mapper.saveTbl_Push_List(pushList); + if (i > 0) { + return pushList; + } else { + return null; + } + } catch (Exception e) { + return null; + } + } + + /** + * 将用户对象保存至redis缓存中,有效期1天 + * + * @param user + */ + private void saveUserToRedis(Tbl_User user) throws Exception { + String key = RedisKey.User_Key + user.getUserId(); + redisHelperI.setRedis(key, IfishUtil.ObjectToJson(user)); + } +} diff --git a/src/main/java/com/ifish/mapper/Tbl_Device_Mapper.java b/src/main/java/com/ifish/mapper/Tbl_Device_Mapper.java new file mode 100644 index 0000000..5fc6a38 --- /dev/null +++ b/src/main/java/com/ifish/mapper/Tbl_Device_Mapper.java @@ -0,0 +1,190 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.mapper; + +import com.ifish.bean.Tbl_Device; +import com.ifish.bean.Tbl_Device_Statistics; +import com.ifish.bean.Tbl_Device_User; +import java.util.List; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.InsertProvider; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.SelectKey; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.annotations.UpdateProvider; + +/** + * + * @author Administrator + */ +public interface Tbl_Device_Mapper { + + /** + * 根据设备ID获取设备详情 + * + * @param deviceid + * @return + */ + @Select("SELECT device_id,server_ip,device_ip,is_camera,mac_address,login_time,is_blacklist,hardware_type,on_off," + + "today_remind,water_remind,remind_cycle,remind_date,factory_code,brand_code,create_time,active_code,active_time,update_time,camera_id from tbl_device WHERE device_id= #{deviceid}") + Tbl_Device getDeviceById(@Param("deviceid") Integer deviceid); + + /** + * 根据摄像头ID获取设备详情 + * + * @param deviceid + * @return + */ + @Select("SELECT device_id,server_ip,device_ip,is_camera,mac_address,login_time,is_blacklist,hardware_type,on_off," + + "today_remind,water_remind,remind_cycle,remind_date,factory_code,brand_code,create_time,active_code,active_time,update_time,camera_id from tbl_device WHERE camera_id= #{cameraID}") + Tbl_Device getDeviceByCameraId(@Param("cameraID") String cameraID); + + /** + * 根据设备ID获取设备详情 + * + * @param deviceid + * @return + */ + @Select("SELECT device_id,server_ip,device_ip,is_camera,mac_address,login_time,is_blacklist,hardware_type,on_off," + + "today_remind,water_remind,remind_cycle,remind_date,factory_code,brand_code,create_time,active_code,active_time,update_time,camera_id from tbl_device WHERE mac_address= #{mac_address}") + Tbl_Device getDeviceByMacAddress(@Param("mac_address") String macAddress); + + /** + * 根据用户ID获取用户绑定设备集合 + * + * @param userid + * @param deviceId + * @return + */ + @Select("SELECT id,user_id,device_id,is_master,show_name,create_time,update_time,custom_icon_name,custom_show_name,is_look,is_live from tbl_device_user WHERE user_id = #{userid}") + List getDeviceUsersByUserId(@Param("userid") Integer userid); + + /** + * 根据设备ID和用户ID获取设备与其他用户的关系 + * + * @param userid + * @param deviceId + * @return + */ + @Select("SELECT id,user_id,device_id,is_master,show_name,create_time,update_time,custom_icon_name,custom_show_name,is_look,is_live from tbl_device_user WHERE user_id <> ${userid} AND device_id = #{deviceid}") + List getOtherDeviceUsersByOtherUserIdAndDeviceId(@Param("userid") Integer userid, @Param("deviceid") Integer deviceId); + + /** + * 根据设备ID和用户ID获取设备与用户的关系 + * + * @param userid + * @param deviceId + * @return + */ + @Select("SELECT id,user_id,device_id,is_master,show_name,create_time,update_time,custom_icon_name,custom_show_name,is_look,is_live from tbl_device_user WHERE user_id = #{userid} AND device_id = #{deviceid}") + Tbl_Device_User getDeviceUsersByUserIdAndDeviceId(@Param("userid") Integer userid, @Param("deviceid") Integer deviceId); + + /** + * 根据设备ID查询此设备关联的所有用户 + * + * @param deviceId + * @return + */ + @Select("SELECT id,user_id,device_id,is_master,show_name,create_time,update_time,custom_icon_name,custom_show_name,is_look,is_live from tbl_device_user WHERE device_id = #{deviceid}") + List getDeviceUsersByDeviceId(@Param("deviceid") Integer deviceId); + + /** + * 修改用户和设备关系表数据 + * + * @param device_User + * @return + */ + @UpdateProvider(method = "updateTblDeviceUser", type = Tbl_Device_MapperSql.class) + int updateTblDeviceUser(@Param("deviceUser") Tbl_Device_User device_User); + + /** + * 删除设备和用户的关系 + * + * @param id + * @return + */ + @Delete("DELETE from tbl_device_user where id = #{id}") + int deleteDeviceUserById(@Param("id") Integer id); + + /** + * 根据设备ID查询设备统计信息 + * + * @param deviceid + * @return + */ + @Select("SELECT id,device_id,mac_address,login_count,login_time,first_activate,create_time,is_charge,sdk_version,sdk_time,create_date,is_upgrade,upgrade_version," + + "upgrade_time,authorize_time,create_code,MCU_count,module_count,router_count,server_count,server_try_count,software_version,hardware_type,factory_code,brand_code FROM tbl_device_statistics WHERE device_id=#{deviceid}") + Tbl_Device_Statistics getDevStatisticsByDeviceId(@Param("deviceid") Integer deviceid); + + /** + * 插入一条设备统计信息 + * + * @param device_Statistics + * @return + */ + @InsertProvider(type = Tbl_Device_MapperSql.class, method = "insertDeviceStatistics") + @SelectKey(statement = "select @@IDENTITY as id", keyProperty = "deviceStatistics.id", keyColumn = "id", before = false, resultType = int.class) + Integer insertDeviceStatistics(@Param("deviceStatistics") Tbl_Device_Statistics device_Statistics); + + /** + * 修改设备统计信息表 + * + * @param device_Statistics + * @return + */ + @UpdateProvider(type = Tbl_Device_MapperSql.class, method = "updateDeviceStatistics") + Integer updateDeviceStatistics(@Param("deviceStatistics") Tbl_Device_Statistics device_Statistics); + + /** + * 插入一条设备信息 + * + * @param device + * @return + */ + @InsertProvider(type = Tbl_Device_MapperSql.class, method = "insertDevice") + @SelectKey(statement = "select @@IDENTITY as device_id", keyProperty = "device.deviceId", keyColumn = "device_id", before = false, resultType = int.class) + Integer insertDevice(@Param("device") Tbl_Device device); + + /** + * 插入一套设备与用户关系数据 + * + * @param deviceUser + * @return + */ + @InsertProvider(type = Tbl_Device_MapperSql.class, method = "insertDeviceUser") + @SelectKey(statement = "select @@IDENTITY as id", keyProperty = "deviceUser.id", keyColumn = "id", before = false, resultType = int.class) + Integer insertDeviceUser(@Param("deviceUser") Tbl_Device_User deviceUser); + + /** + * 根据ID删除设备信息数据(摄像头) + * + * @param id + * @return + */ + @Delete("DELETE from tbl_device where id = #{id}") + int deleteDeviceById(@Param("id") Integer id); + + + /** + * 修改设备信息 + * + * @param device + * @return + */ + @UpdateProvider(type = Tbl_Device_MapperSql.class, method = "updateTbl_Device") + Integer updateTbl_Device(@Param("device") Tbl_Device device); + + /** + * 修改摄像头激活码信息为已使用 + * + * @param activa_Code + * @return + */ + @Update("UPDATE tbl_activa_code set is_used='1' WHERE active_code = #{code}") + Integer updateTblActivaCodeIsUse(@Param("code") String activa_Code); + +} diff --git a/src/main/java/com/ifish/mapper/Tbl_Device_MapperSql.java b/src/main/java/com/ifish/mapper/Tbl_Device_MapperSql.java new file mode 100644 index 0000000..77eb599 --- /dev/null +++ b/src/main/java/com/ifish/mapper/Tbl_Device_MapperSql.java @@ -0,0 +1,269 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.mapper; + +import com.ifish.bean.Tbl_Device; +import com.ifish.bean.Tbl_Device_Statistics; +import com.ifish.bean.Tbl_Device_User; +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.annotations.Param; + +/** + * + * @author Administrator + */ +public class Tbl_Device_MapperSql { + + /** + * 修改设备和用户的表 + * + * @param device_User + * @return + */ + public String updateTblDeviceUser(@Param("deviceUser") Tbl_Device_User device_User) { + StringBuilder sb = new StringBuilder(); + + sb.append("UPDATE tbl_device_user SET "); + + if (device_User.getUserId() != null && device_User.getUserId() > 0) { + sb.append("user_id = #{deviceUser.userId}, "); + } + if (device_User.getDeviceId() != null && device_User.getDeviceId() > 0) { + sb.append("device_id = #{deviceUser.deviceId}, "); + } + if (StringUtils.isNotBlank(device_User.getIsMaster())) { + sb.append("is_master = #{deviceUser.isMaster}, "); + } + if (StringUtils.isNotBlank(device_User.getShowName())) { + sb.append("show_name = #{deviceUser.showName}, "); + } + if (device_User.getCreateTime() != null && StringUtils.isNotBlank(device_User.getCreateTime().toString())) { + sb.append("create_time = #{deviceUser.createTime}, "); + } + if (StringUtils.isNotBlank(device_User.getCustomIconName())) { + sb.append("custom_icon_name = #{deviceUser.customIconName}, "); + } + if (StringUtils.isNotBlank(device_User.getCustomShowName())) { + sb.append("custom_show_name = #{deviceUser.customShowName}, "); + } + if (StringUtils.isNotBlank(device_User.getIsLook())) { + sb.append("is_look = #{deviceUser.isLook}, "); + } + if (StringUtils.isNotBlank(device_User.getIsLive())) { + sb.append("is_live = #{deviceUser.isLive}, "); + } + sb.append("update_time = now() "); + sb.append(" WHERE id = #{deviceUser.id}"); + return sb.toString(); + } + + /** + * 插入一条设备统计信息表 + * + * @param device_Statistics + * @return + */ + public String insertDeviceStatistics(@Param("deviceStatistics") Tbl_Device_Statistics device_Statistics) { + StringBuilder sb = new StringBuilder(); + + sb.append("INSERT tbl_device_statistics(device_id,mac_address,login_count,login_time,first_activate,create_time,is_charge,sdk_version,sdk_time,create_date,authorize_time,create_code,hardware_type,factory_code,brand_code)"); + sb.append("values(#{deviceStatistics.deviceId},#{deviceStatistics.macAddress},#{deviceStatistics.loginCount},#{deviceStatistics.loginTime},#{deviceStatistics.firstActivate},#{deviceStatistics.createTime},"); + sb.append("#{deviceStatistics.isCharge},#{deviceStatistics.sdkVersion},#{deviceStatistics.sdkTime},#{deviceStatistics.createDate},#{deviceStatistics.authorizeTime},#{deviceStatistics.createCode},"); + sb.append("#{deviceStatistics.hardwareType},#{deviceStatistics.factoryCode},#{deviceStatistics.brandCode})"); + return sb.toString(); + } + + /** + * 修改设备统计信息表 + * + * @param device_Statistics + * @return + */ + public String updateDeviceStatistics(@Param("deviceStatistics") Tbl_Device_Statistics device_Statistics) { + StringBuilder sb = new StringBuilder(); + + sb.append("UPDATE tbl_device_statistics SET "); + + if (device_Statistics.getDeviceId() > 0) { + sb.append("device_id = #{deviceStatistics.deviceId}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getMacAddress())) { + sb.append("mac_address = #{deviceStatistics.macAddress}, "); + } + if (device_Statistics.getLoginCount() > 0) { + sb.append("login_count = #{deviceStatistics.loginCount}, "); + } + if (device_Statistics.getLoginTime() != null && StringUtils.isNotBlank(device_Statistics.getLoginTime().toString())) { + sb.append("login_time= #{deviceStatistics.loginTime}, "); + } + if (device_Statistics.getFirstActivate() != null && StringUtils.isNotBlank(device_Statistics.getFirstActivate().toString())) { + sb.append("first_activate= #{deviceStatistics.firstActivate}, "); + } + if (device_Statistics.getCreateTime() != null && StringUtils.isNotBlank(device_Statistics.getCreateTime().toString())) { + sb.append("create_time= #{deviceStatistics.createTime}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getIsCharge())) { + sb.append("is_charge = #{deviceStatistics.isCharge}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getSdkVersion())) { + sb.append("sdk_version = #{deviceStatistics.sdkVersion}, "); + } + if (device_Statistics.getSdkTime() != null && StringUtils.isNotBlank(device_Statistics.getSdkTime().toString())) { + sb.append("sdk_time= #{deviceStatistics.sdkTime}, "); + } + if (device_Statistics.getCreateDate() != null && StringUtils.isNotBlank(device_Statistics.getCreateDate().toString())) { + sb.append("create_date= #{deviceStatistics.createDate}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getIsUpgrade())) { + sb.append("is_upgrade = #{deviceStatistics.isUpgrade}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getUpgradeVersion())) { + sb.append("upgrade_version = #{deviceStatistics.upgradeVersion}, "); + } + if (device_Statistics.getUpgradeTime() != null && StringUtils.isNotBlank(device_Statistics.getUpgradeTime().toString())) { + sb.append("upgrade_time= #{deviceStatistics.upgradeTime}, "); + } + if (device_Statistics.getAuthorizeTime() != null && StringUtils.isNotBlank(device_Statistics.getAuthorizeTime().toString())) { + sb.append("authorize_time= #{deviceStatistics.authorizeTime}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getCreateCode())) { + sb.append("create_code = #{deviceStatistics.createCode}, "); + } + if (device_Statistics.getMcuCount() != null && device_Statistics.getMcuCount() > 0) { + sb.append("mcu_count = #{deviceStatistics.mcuCount}, "); + } + if (device_Statistics.getModuleCount() != null && device_Statistics.getModuleCount() > 0) { + sb.append("module_count = #{deviceStatistics.moduleCount}, "); + } + if (device_Statistics.getRouterCount() != null && device_Statistics.getRouterCount() > 0) { + sb.append("router_count = #{deviceStatistics.routerCount}, "); + } + if (device_Statistics.getServerCount() != null && device_Statistics.getServerCount() > 0) { + sb.append("server_count = #{deviceStatistics.serverCount}, "); + } + if (device_Statistics.getServerTryCount() != null && device_Statistics.getServerTryCount() > 0) { + sb.append("server_try_count = #{deviceStatistics.serverTryCount}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getSoftwareVersion())) { + sb.append("software_version = #{deviceStatistics.softwareVersion}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getHardwareType())) { + sb.append("hardware_type = #{deviceStatistics.hardwareType}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getFactoryCode())) { + sb.append("factory_code = #{deviceStatistics.factoryCode}, "); + } + if (StringUtils.isNotBlank(device_Statistics.getBrandCode())) { + sb.append("brand_code = #{deviceStatistics.brandCode}, "); + } + if (sb.lastIndexOf(",") == sb.length() - 2) { + sb.deleteCharAt(sb.length() - 2); + } + sb.append(" WHERE id = #{deviceStatistics.id}"); + return sb.toString(); + } + + /** + * 插入一条设备信息 + * + * @param device + * @return + */ + public String insertDevice(@Param("device") Tbl_Device device) { + StringBuilder sb = new StringBuilder(); + + sb.append("INSERT INTO tbl_device(server_ip,device_ip,is_camera,mac_address,login_time,is_blacklist,hardware_type,on_off,today_remind,water_remind,remind_date,remind_cycle,factory_code,brand_code,"); + sb.append("create_time,active_code,active_time,update_time,camera_id) VALUES(#{device.serverIp},#{device.deviceIp},#{device.isCamera},#{device.macAddress},#{device.loginTime},#{device.isBlacklist},#{device.hardwareType},#{device.onOff},"); + sb.append("#{device.todayRemind},#{device.waterRemind},#{device.remindDate},#{device.remindCycle},#{device.factoryCode},#{device.brandCode},#{device.createTime},#{device.activeCode},#{device.activeTime},#{device.updateTime},#{device.cameraId})"); + + return sb.toString(); + } + + /** + * 插入设备和用户信息 + * + * @param deviceUser + * @return + */ + public String insertDeviceUser(@Param("deviceUser") Tbl_Device_User deviceUser) { + StringBuilder sb = new StringBuilder(); + + sb.append("INSERT INTO tbl_device_user (user_id,device_id,is_master,show_name,create_time,update_time,custom_icon_name,custom_show_name,is_look,is_live) VALUES("); + sb.append("#{deviceUser.userId},#{deviceUser.deviceId},#{deviceUser.isMaster},#{deviceUser.showName},#{deviceUser.createTime},#{deviceUser.updateTime},#{deviceUser.customIconName},#{deviceUser.customShowName},#{deviceUser.isLook},#{deviceUser.isLive})"); + + return sb.toString(); + } + + /** + * 修改设备信息 + * + * @param device + * @return + */ + public String updateTbl_Device(@Param("device") Tbl_Device device) { + StringBuilder sb = new StringBuilder(); + + sb.append("UPDATE tbl_device SET "); + if (StringUtils.isNotBlank(device.getServerIp())) { + sb.append("server_ip = #{device.serverIp}, "); + } + if (StringUtils.isNotBlank(device.getDeviceIp())) { + sb.append("device_ip = #{device.deviceIp}, "); + } + if (StringUtils.isNotBlank(device.getIsCamera())) { + sb.append("is_camera = #{device.isCamera}, "); + } + if (StringUtils.isNotBlank(device.getMacAddress())) { + sb.append("mac_address = #{device.macAddress}, "); + } + if (device.getLoginTime() != null && StringUtils.isNotBlank(device.getLoginTime().toString())) { + sb.append("login_time = #{device.loginTime}, "); + } + if (device.getRemindDate() != null && StringUtils.isNotBlank(device.getRemindDate().toString())) { + sb.append("remind_date = #{device.loginTime}, "); + } + if (StringUtils.isNotBlank(device.getIsBlacklist())) { + sb.append("is_blacklist = #{device.isBlacklist}, "); + } + if (StringUtils.isNotBlank(device.getHardwareType())) { + sb.append("hardware_type = #{device.hardwareType}, "); + } + if (StringUtils.isNotBlank(device.getOnOff())) { + sb.append("on_off = #{device.onOff}, "); + } + if (StringUtils.isNotBlank(device.getTodayRemind())) { + sb.append("today_remind = #{device.todayRemind}, "); + } + if (StringUtils.isNotBlank(device.getWaterRemind())) { + sb.append("water_remind = #{device.waterRemind}, "); + } + if (device.getRemindCycle() != null && device.getRemindCycle() > 0) { + sb.append("remind_cycle = #{device.remindCycle}, "); + } + if (StringUtils.isNotBlank(device.getFactoryCode())) { + sb.append("factory_code = #{device.factoryCode}, "); + } + if (StringUtils.isNotBlank(device.getBrandCode())) { + sb.append("brand_code = #{device.brandCode}, "); + } + if (StringUtils.isNotBlank(device.getCameraId())) { + sb.append("camera_id = #{device.cameraId}, "); + } + if (device.getCreateTime() != null && StringUtils.isNotBlank(device.getCreateTime().toString())) { + sb.append("create_time = #{device.createTime}, "); + } + if (device.getActiveTime() != null && StringUtils.isNotBlank(device.getActiveTime().toString())) { + sb.append("active_time = #{device.activeTime}, "); + } + + if (StringUtils.isNotBlank(device.getActiveCode())) { + sb.append("active_code = #{device.activeCode}, "); + } + sb.append("update_time = now() "); + sb.append(" WHERE device_id = #{device.deviceId}"); + return sb.toString(); + } +} diff --git a/src/main/java/com/ifish/mapper/Tbl_Hardware_Type_Mapper.java b/src/main/java/com/ifish/mapper/Tbl_Hardware_Type_Mapper.java new file mode 100644 index 0000000..47f7bd2 --- /dev/null +++ b/src/main/java/com/ifish/mapper/Tbl_Hardware_Type_Mapper.java @@ -0,0 +1,38 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.mapper; + +import com.ifish.bean.Tbl_HardWare_Type; +import com.ifish.bean.Tbl_Vender; +import java.util.Map; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +/** + * + * @author Administrator + */ +public interface Tbl_Hardware_Type_Mapper { + + /** + * 根据设备类型Code获取厂家设备类型详情 + * + * @param type + * @return + */ + @Select("select hardware_type,hardware_name,control_amount,timer_amount,is_work_model,is_custom_icon,all_icon_name,all_show_name,default_icon_name,default_show_name," + + "icon_link,is_lightness,is_sark_lamp,hardware_desc,update_time,create_time from tbl_hardware_type where hardware_type=#{type}") + Tbl_HardWare_Type getHardwareTypeByTypeCode(@Param("type") String type); + + /** + * 根据code获取厂家信息 + * + * @param code + * @return + */ + @Select("select brand_code,brand_name,brand_introduce,brand_logo from tbl_vender_list where brand_code=#{code}") + Tbl_Vender getVenderListByBrandCode(@Param("code") String code); +} diff --git a/src/main/java/com/ifish/mapper/Tbl_Push_List_Mapper.java b/src/main/java/com/ifish/mapper/Tbl_Push_List_Mapper.java new file mode 100644 index 0000000..1677338 --- /dev/null +++ b/src/main/java/com/ifish/mapper/Tbl_Push_List_Mapper.java @@ -0,0 +1,74 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.mapper; + +import com.ifish.bean.Tbl_Push_List; +import java.util.List; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.SelectProvider; + +/** + * + * @author Administrator + */ +public interface Tbl_Push_List_Mapper { + + /** + * 分页获取用户推送消息 + * + * @param userId + * @param pushType + * @param pageSize + * @param firstResult + * @return + */ + @SelectProvider(type = Tbl_Push_List_MapperSql.class, method = "getPushList") + List getPushList(@Param("userid") Integer userId, @Param("pushtype") String pushType, @Param("pagesize") Integer pageSize, @Param("first") Integer firstResult); + + /** + * 根据ID查询推送消息对象 + * + * @param pushId + * @return + */ + @Select("SELECT push_id,user_id,device_id,show_name,phone_type,push_type,push_title,push_context,create_time,push_link,jpush_status,google_status FROM TBL_PUSH_LIST WHERE push_id = #{pushid}") + Tbl_Push_List getPush_ListById(@Param("pushid") Integer pushId); + + /** + * 插入一条推送信息 + * + * @param tbl_Push_List + * @return + */ + @Insert("INSERT INTO TBL_PUSH_LIST(user_id,device_id,show_name,phone_type,push_type,push_title,push_context,create_time,push_link,jpush_status,google_status,report_id,mcu_count,modular_count,router_count,server_count,server_try_count) VALUES (#{push.userId},#{push.deviceId},#{push.showName},#{push.phoneType}," + + "#{push.pushType},#{push.pushTitle},#{push.pushContext},NOW(),#{push.pushLink},#{push.jpushStatus},#{push.googleStatus},#{push.reportId},#{push.mcuCount},#{push.modularCount},#{push.routerCount},#{push.serverCount},#{push.serverTryCount})") + Integer saveTbl_Push_List(@Param("push") Tbl_Push_List tbl_Push_List); + + /** + * 根据ID删除推送消息 + * + * @param pushId + * @return + */ + @Delete("DELETE FROM TBL_PUSH_LIST WHERE push_id = #{id}") + Integer deletePushListById(@Param("id") Integer pushId); + + /** + * 分页获取用户推送消息 + * + * @param userId + * @param pushType + * @param pageSize + * @param firstResult + * @return + */ + @Select("SELECT COUNT(1) FROM TBL_PUSH_LIST WHERE user_id = #{userid} AND push_type = #{pushtype} LIMIT ${first},${pagesize}") + Integer getPushListCount(@Param("userid") Integer userId, @Param("pushtype") String pushType, @Param("pagesize") Integer pageSize, @Param("first") Integer firstResult); + +} diff --git a/src/main/java/com/ifish/mapper/Tbl_Push_List_MapperSql.java b/src/main/java/com/ifish/mapper/Tbl_Push_List_MapperSql.java new file mode 100644 index 0000000..e4e8e5f --- /dev/null +++ b/src/main/java/com/ifish/mapper/Tbl_Push_List_MapperSql.java @@ -0,0 +1,30 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.mapper; + +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.annotations.Param; + +/** + * + * @author Administrator + */ +public class Tbl_Push_List_MapperSql { + + public String getPushList(@Param("userid") Integer userId, @Param("pushtype") String pushType, @Param("pagesize") Integer pageSize, @Param("first") Integer firstResult) { + StringBuilder sb = new StringBuilder(); + + sb.append("SELECT push_id,user_id,device_id,show_name,phone_type,push_type,push_title,push_context,create_time,push_link,jpush_status,google_status FROM TBL_PUSH_LIST WHERE "); + sb.append("user_id = #{userid} "); + if (StringUtils.isNotBlank(pushType)) { + sb.append("AND push_type = #{pushtype} "); + } + sb.append("ORDER BY push_id DESC LIMIT ").append(firstResult).append(",").append(pageSize); + + return sb.toString(); + } + +} diff --git a/src/main/java/com/ifish/mapper/Tbl_User_Mapper.java b/src/main/java/com/ifish/mapper/Tbl_User_Mapper.java new file mode 100644 index 0000000..41fe5fa --- /dev/null +++ b/src/main/java/com/ifish/mapper/Tbl_User_Mapper.java @@ -0,0 +1,80 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.mapper; + +import com.ifish.bean.Tbl_User; +import org.apache.ibatis.annotations.InsertProvider; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.SelectKey; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.annotations.UpdateProvider; + +/** + * + * @author Administrator + */ +public interface Tbl_User_Mapper { + + /** + * 根据手机号获取用户对象 + * + * @return + */ + @Select("select user_id,nick_name,user_password,phone_number,user_email,user_type,user_img,user_sex,login_count,update_time,login_time,create_time,login_type,remarks,address,P2PVerify_code1,P2PVerify_code2," + + "gwell_userID,is_register_gwell,jiguang_userID,longitude,latitude from tbl_user where phone_number=#{phoneNumber}") + Tbl_User getUserByPhoneNumber(@Param("phoneNumber") String phoneNumber); + + /** + * 根据用户邮箱获取用户对象 + * + * @param userid + * @return + */ + @Select("select user_id,nick_name,user_password,phone_number,user_email,user_type,user_img,user_sex,login_count,update_time,login_time,create_time,login_type,remarks,address,P2PVerify_code1,P2PVerify_code2," + + "gwell_userID,is_register_gwell,jiguang_userID,longitude,latitude from tbl_user where user_email=#{user_email}") + Tbl_User getUserByUserEmail(@Param("user_email") String userEmail); + + /** + * 根据用户ID获取用户对象 + * + * @param userid + * @return + */ + @Select("select user_id,nick_name,user_password,phone_number,user_email,user_type,user_img,user_sex,login_count,update_time,login_time,create_time,login_type,remarks,address,P2PVerify_code1,P2PVerify_code2," + + "gwell_userID,is_register_gwell,jiguang_userID,longitude,latitude from tbl_user where user_id=#{userid}") + Tbl_User getUserByUserId(@Param("userid") String userid); + + /** + * 每次登陆后修改登陆时间、次数和手机类型 + * + * @param userId + * @param loginType + * @return + */ + @Update("update tbl_user set login_count=if(login_count is null,1,login_count+1),login_type=#{logintype},login_time=current_timestamp() where user_id=#{userid}") + Integer executeLoginUpdate(@Param("userid") Integer userId, @Param("logintype") String loginType); + + /** + * 修改用户账号信息 + * + * @param user + * @return + */ + @UpdateProvider(type = Tbl_User_MapperSql.class, method = "updateUser") + Integer updateUser(@Param("user") Tbl_User user); + + /** + * 注册用户 + * + * @param user + * @return + */ + @InsertProvider(type = Tbl_User_MapperSql.class, method = "registerUser") + @SelectKey(statement = "select @@IDENTITY as user_id", keyProperty = "user.userId", keyColumn = "userId", before = false, resultType = int.class) + Integer insertUser(@Param("user") Tbl_User user); + +} diff --git a/src/main/java/com/ifish/mapper/Tbl_User_MapperSql.java b/src/main/java/com/ifish/mapper/Tbl_User_MapperSql.java new file mode 100644 index 0000000..ec264cd --- /dev/null +++ b/src/main/java/com/ifish/mapper/Tbl_User_MapperSql.java @@ -0,0 +1,101 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.ifish.mapper; + +import com.ifish.bean.Tbl_User; +import org.apache.ibatis.annotations.Param; +import org.apache.commons.lang3.StringUtils; + +/** + * + * @author Administrator + */ +public class Tbl_User_MapperSql { + + public String updateUser(@Param("user") Tbl_User user) { + StringBuilder sb = new StringBuilder(); + + sb.append("Update tbl_User SET "); + if (user.getNickName() != null && StringUtils.isNotBlank(user.getNickName())) { + sb.append("nick_name = #{user.nickName}, "); + } + if (user.getUserPassword() != null && StringUtils.isNotBlank(user.getUserPassword())) { + sb.append("user_password = #{user.userPassword}, "); + } + if (user.getPhoneNumber() != null && StringUtils.isNotBlank(user.getPhoneNumber())) { + sb.append("phone_number = #{user.phoneNumber}, "); + } + if (user.getUserEmail() != null && StringUtils.isNotBlank(user.getUserEmail())) { + sb.append("user_email = #{user.userEmail}, "); + } +// if (user.getUserType() != null && StringUtils.isNotBlank(user.getUserType())) { +// sb.append("user_type = #{user.userType}, "); +// } + if (user.getUserImg() != null && StringUtils.isNotBlank(user.getUserImg())) { + sb.append("user_img = #{user.userImg}, "); + } + if (user.getUserSex() != null && StringUtils.isNotBlank(user.getUserSex())) { + sb.append("user_sex = #{user.userSex}, "); + } + //登陆次数有另外的Sql语句 + if (user.getUpdateTime() != null) { + sb.append("update_time = #{user.updateTime}, "); + } + if (user.getLoginTime() != null) { + sb.append("login_time = #{user.loginTime}, "); + } + //注册时间不予修改 + if (user.getLoginType() != null && StringUtils.isNotBlank(user.getLoginType())) { + sb.append("login_type = #{user.loginType}, "); + } + if (user.getRemarks() != null && StringUtils.isNotBlank(user.getRemarks())) { + sb.append("remarks = #{user.remarks}, "); + } + if (user.getAddress() != null && StringUtils.isNotBlank(user.getAddress())) { + sb.append("address = #{user.address}, "); + } + if (user.getP2pverifyCode1() != null && StringUtils.isNotBlank(user.getP2pverifyCode1())) { + sb.append("p2pverify_code1 = #{user.p2pverifyCode1}, "); + } + if (user.getP2pverifyCode2() != null && StringUtils.isNotBlank(user.getP2pverifyCode2())) { + sb.append("p2pverify_code2 = #{user.p2pverifyCode2}, "); + } + if (user.getGwellUserid() != null && StringUtils.isNotBlank(user.getGwellUserid())) { + sb.append("gwell_userid = #{user.gwellUserid}, "); + } + if (user.getIsRegisterGwell() != null && StringUtils.isNotBlank(user.getIsRegisterGwell())) { + sb.append("is_register_gwell = #{user.isRegisterGwell}, "); + } + if (user.getJiguangUserid() != null && StringUtils.isNotBlank(user.getJiguangUserid())) { + sb.append("jiguang_userID = #{user.jiguangUserid}, "); + } + if (user.getLatitude() != null && user.getLatitude() > 0) { + sb.append("latitude = #{user.latitude}, "); + } + if (user.getLongitude() != null && user.getLongitude() > 0) { + sb.append("longitude = #{iser.longitude}, "); + } + if (sb.lastIndexOf(",") == sb.length() - 2) { + sb.deleteCharAt(sb.length() - 2); + } + sb.append(" WHERE user_id = #{user.userId}"); + return sb.toString(); + } + + /** + * 游客注册接口 + * + * @param user + * @return + */ + public String registerUser(@Param("user") Tbl_User user) { + StringBuilder sb = new StringBuilder(); + + sb.append("INSERT tbl_user (user_type) value ('0')"); + + return sb.toString(); + } +} diff --git a/src/main/resources/property.properties b/src/main/resources/property.properties index 8518ef0..8465d57 100644 --- a/src/main/resources/property.properties +++ b/src/main/resources/property.properties @@ -35,7 +35,8 @@ check_style=GIF,PNG,BMP,JPG,JPEG #\u662f\u5426\u5f00\u53d1\u6a21\u5f0f\uff0cfalse\u5219\u4ee3\u8868\u8981\u53d1\u5e03\u5230\u6d4b\u8bd5\u6216\u8005\u6b63\u5f0f\u73af\u5883\uff0c\u4f1a\u8fdb\u884c\u5168\u5c40\u5934\u90e8\u9a8c\u8bc1\uff0ctrue\u4ee3\u8868\u5728\u672c\u5730\u8fdb\u884c\u4ee3\u7801\u7f16\u5199\uff0c\u4e0d\u4f1a\u8fdb\u884c\u9a8c\u8bc1 devModel=true #\u672c\u5730 -ifiship=192.168.199.129 +#ifiship=192.168.199.129 +ifiship=192.168.2.146 #\u6d4b\u8bd5\u4e91 #ifiship=139.196.24.156 #\u6b63\u5f0f\u4e91