Explorar o código

第二版,频安宝小程序,清理垃圾代码

suntianwu %!s(int64=3) %!d(string=hai) anos
pai
achega
31883d7575

+ 3 - 1
src/main/java/com/care/bms/controller/SysUserController.java

@@ -101,8 +101,10 @@ public class SysUserController {
             int flag = this.bmsSysUserService.createCareSysUser(vo,loginUser);
             if (flag == 1) {
                 return  Result.error("电话已存在!");
-            } else {
+            } else if (flag == 0) {
                 return  Result.success("新增成功!");
+            } else {
+                return  Result.success("新增失败!");
             }
 
         }catch (BDException e) {

+ 199 - 0
src/main/java/com/care/client/controller/DevApiController.java

@@ -0,0 +1,199 @@
+package com.care.client.controller;
+
+import com.care.client.service.PassportService;
+import com.care.client.service.PinanbaoDeviceService;
+import com.care.client.vo.HouseContactVO;
+import com.care.client.vo.MemberInfoVO;
+import com.care.client.vo.DeviceVO;
+import com.care.client.vo.OlderVO;
+import com.care.common.exception.BDException;
+import com.care.common.util.Result;
+import com.care.common.vo.device.StationVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+/**
+ * @Author: lilt
+ * @Date: 2021/5/26
+ * @Desc:
+ */
+@RestController
+@Api(value = "DevApiController", tags = { "我的设备" })
+@Slf4j
+@RequestMapping("/pinanbao/device")
+public class DevApiController {
+
+    @Resource
+    private PinanbaoDeviceService pinanbaoDeviceService;
+    @Resource
+    private PassportService passportService;
+
+    /**
+     * 查询空闲设备列表
+     * @return
+     */
+    @GetMapping("/my/queryFreeDeviceList")
+    @ApiOperation(tags = {"我的设备"},value = "选择要添加设备列表(查询空闲设备列表)--二期新增")
+    public Result<List<DeviceVO>> queryFreeDeviceList(@RequestHeader(value = "token") String token){
+        try {
+            MemberInfoVO current = passportService.checkToken(token);
+            List<DeviceVO> datas = pinanbaoDeviceService.queryFreeDeviceList(current.getId());
+            return Result.success(datas);
+        }catch (BDException e) {
+            return  Result.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("设备: 列表查询出现异常",e);
+            return Result.error( "获取失败");
+        }
+    }
+
+    /**
+     * 选择空闲设备保存绑定
+     * @return
+     */
+    @PostMapping("/my/bindDevice")
+    @ApiOperation(tags = {"我的设备"},value = "选择空闲设备保存绑定 --二期新增")
+    public Result<Object> bindDevice(HttpServletRequest request, @RequestHeader("token") String token,
+                                   @RequestParam("id") Long id) {
+        MemberInfoVO current = passportService.checkToken(token);
+        if (this.pinanbaoDeviceService.bindDevice(current.getId(),id)) {
+            return  Result.success("绑定成功");
+        } else{
+            return  Result.error("绑定失败");
+        }
+    }
+
+    @DeleteMapping("/my/removeMyDevice/{id}")
+    @ApiOperation(tags = {"我的设备"},value = "移除设备(解除绑定) -- 二期新增")
+    public Result<Object> removeMyDevice(HttpServletRequest request,@RequestHeader("token") String token,
+                                         @PathVariable("id") Long id) {
+        try {
+            MemberInfoVO current = passportService.checkToken(token);
+            this.pinanbaoDeviceService.removeMyDevice(current.getId(),id);
+            return Result.success("移除成功!");
+        } catch (Exception e) {
+            log.error("设备: 移除设备出现异常", e);
+            return Result.error("移除失败!");
+        }
+    }
+
+    /**
+     * 我的设备列表
+     * @return
+     */
+    @GetMapping("/my/myDeviceList")
+    @ApiOperation(tags = {"我的设备"},value = "我的设备列表")
+    public Result<List<DeviceVO>> myDeviceList(@RequestHeader(value = "token") String token){
+        try {
+            MemberInfoVO current = passportService.checkToken(token);
+            List<DeviceVO> datas = pinanbaoDeviceService.queryDeviceByMemberId(current.getId());
+            return Result.success(datas);
+        }catch (BDException e) {
+            return  Result.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("设备: 列表查询出现异常",e);
+            return Result.error( "获取失败");
+        }
+    }
+
+    /**
+     * 我的设备详情
+     * @return
+     */
+    @GetMapping("/my/getMyDeviceInfo")
+    @ApiOperation(tags = {"我的设备"},value = "设备详情 (包括设备名、场景、响应时间、服务信息等) -- 二期新增")
+    public Result<DeviceVO> getMyDeviceInfo(@RequestHeader(value = "token") String token,
+                                                @RequestParam("id") Long id){
+        try {
+            return Result.success(this.pinanbaoDeviceService.getDeviceInfo(id));
+        }catch (BDException e) {
+            return  Result.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("设备: 查询详情出现异常",e);
+            return Result.error( "获取失败");
+        }
+    }
+
+    /**
+     * 我的设备-服务站简介
+     * @return
+     */
+    @GetMapping("/my/getMyDevStationInfo")
+    @ApiOperation(tags = {"我的设备"},value = "服务站简介 -- 二期新增")
+    public Result<StationVO> getMyDevStationInfo(@RequestHeader(value = "token") String token,
+                                                 @RequestParam("stationId") Long stationId){
+        try {
+            return Result.success(this.pinanbaoDeviceService.getMyDevStationInfo(stationId));
+        }catch (BDException e) {
+            return  Result.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("服务站: 查询详情出现异常",e);
+            return Result.error( "获取失败");
+        }
+    }
+
+    @PostMapping("/my/updateMyDevice")
+    @ApiOperation(tags = {"我的设备"},value = "设备修改(设备名,场景、响应时间) -- 二期新增")
+    public Result<Object> updateMyDevice(@RequestHeader("token") String token,
+                                 @RequestBody DeviceVO vo){
+        try {
+            if(this.pinanbaoDeviceService.updateMyDevice(vo)){
+                return  Result.success("修改成功!");
+            } else {
+                return Result.error("修改失败!");
+            }
+
+        }catch (BDException e) {
+            log.error("修改设备-出现异常",e);
+            return Result.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("设备: 修改设备出现异常",e);
+            return Result.error("修改失败!");
+        }
+    }
+
+
+    /**
+     * 查询我的设备拥有的被监护人列表
+     * @return
+     */
+    @GetMapping("/my/queryMyOlderListByDeviceId")
+    @ApiOperation(tags = {"我的设备"},value = "查询我的设备拥有的被监护人列表")
+    public Result<List<OlderVO>> queryMyOlderListByDeviceId(@RequestHeader(value = "token") String token,
+                                                   @RequestParam("id") Long id){
+        try {
+            List<OlderVO> datas = pinanbaoDeviceService.queryMyOlderListByDeviceId(id);
+            return Result.success(datas);
+        }catch (BDException e) {
+            return  Result.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("老人: 列表查询出现异常",e);
+            return Result.error( "获取失败");
+        }
+    }
+
+    /**
+     * 查询我的设备拥有的紧急联系人列表
+     * @return
+     */
+    @GetMapping("/my/queryMyContactListByDeviceId")
+    @ApiOperation(tags = {"我的设备"},value = "查询我的设备拥有的紧急联系人列表")
+    public Result<List<HouseContactVO>> queryMyContactListByDeviceId(@RequestHeader(value = "token") String token,
+                                                            @RequestParam("id") Long id){
+        try {
+            List<HouseContactVO> datas = pinanbaoDeviceService.queryMyContactListByDeviceId(id);
+            return Result.success(datas);
+        }catch (BDException e) {
+            return  Result.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("联系人: 列表查询出现异常",e);
+            return Result.error( "获取失败");
+        }
+    }
+}

+ 1 - 1
src/main/java/com/care/client/controller/DevInstallApiController.java

@@ -48,7 +48,7 @@ public class DevInstallApiController {
     }
 
     /**
-     * 验证设备(是否存在,是否被别人绑定了)
+     * 绑定用户
      * @param devCode
      * @return
      */

+ 1 - 1
src/main/java/com/care/client/controller/HouseApiController.java

@@ -28,7 +28,7 @@ import java.util.List;
  * @Desc:
  */
 @RestController
-@Api(value = "EventHandleController", tags = { "房屋信息" })
+@Api(value = "HouseApiController", tags = { "房屋信息" })
 @Slf4j
 @RequestMapping("/pinanbao/house")
 public class HouseApiController {

+ 1 - 1
src/main/java/com/care/client/controller/OlderApiController.java

@@ -21,7 +21,7 @@ import java.util.List;
  * @Desc:
  */
 @RestController
-@Api(value = "ContactApiController", tags = { "我的被监护人" })
+@Api(value = "OlderApiController", tags = { "我的被监护人" })
 @Slf4j
 @RequestMapping("/pinanbao/older")
 public class OlderApiController {

+ 223 - 0
src/main/java/com/care/client/service/PinanbaoDeviceService.java

@@ -0,0 +1,223 @@
+package com.care.client.service;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.care.client.vo.DeviceVO;
+import com.care.client.vo.HouseContactVO;
+import com.care.client.vo.OlderVO;
+import com.care.common.entity.*;
+import com.care.common.enums.OlderLiveTypeEnum;
+import com.care.common.enums.RelationTypeEnum;
+import com.care.common.service.*;
+import com.care.common.vo.device.StationVO;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.compress.utils.Lists;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Author: lilt
+ * @Date: 2021/6/7
+ * @Desc:
+ */
+@Slf4j
+@Service
+public class PinanbaoDeviceService {
+
+    @Resource
+    private CareMemberInfoService careMemberInfoService;
+    @Resource
+    private CareDeviceService careDeviceService;
+    @Resource
+    private CareSysUserService careSysUserService;
+    @Resource
+    private CareStationService careStationService;
+    @Resource
+    private CareHouseOlderRelService careHouseOlderRelService;
+    @Resource
+    private CareOlderService careOlderService;
+    @Resource
+    private CareHouseContactRelService careHouseContactRelService;
+    @Resource
+    private CareHouseContactService careHouseContactService;
+
+    /**
+     * 查询空闲设备列表
+     * @param memberId
+     * @return
+     */
+    public List<DeviceVO> queryFreeDeviceList(Long memberId){
+        List<DeviceVO> vos = Lists.newArrayList();
+        CareMemberInfo memberInfo = this.careMemberInfoService.getById(memberId);
+        QueryWrapper<CareDevice> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().ne(CareDevice::getMemberId, memberInfo.getId())
+                .and(wrapper ->wrapper.isNull(CareDevice::getMemberId).or().eq(CareDevice::getMemberId,'0'))
+                .orderByAsc(CareDevice::getDevCode);
+        List<CareDevice> devices = this.careDeviceService.list(queryWrapper);
+        if (CollUtil.isNotEmpty(devices)){
+            devices.forEach(item -> {
+                DeviceVO vo = new DeviceVO();
+                BeanUtil.copyProperties(item,vo);
+                vos.add(vo);
+            });
+        }
+        return vos;
+    }
+
+
+    /**
+     * 绑定设备
+     * @return
+     */
+    public boolean bindDevice(Long memberId,Long devId){
+        CareDevice careDevice = this.careDeviceService.getById(devId);
+        careDevice.setMemberId(memberId);
+        careDevice.setMemberPhone(this.careMemberInfoService.getById(memberId).getPhone());
+        return this.careDeviceService.updateById(careDevice);
+    }
+
+    /**
+     * 移除设备
+     * @return
+     */
+    public Boolean removeMyDevice(Long memberId,Long devId) {
+        CareDevice careDevice = new CareDevice();
+        careDevice.setMemberId(null);
+        careDevice.setMemberPhone(null);
+
+        QueryWrapper<CareDevice> updateWrapper = new QueryWrapper<>();
+        updateWrapper.lambda().eq(CareDevice::getMemberId,memberId).eq(CareDevice::getId,devId);
+        return careDeviceService.update(careDevice,updateWrapper);
+    }
+
+    /**
+     * 查询设备列表
+     * @param memberId
+     * @return
+     */
+    public List<DeviceVO> queryDeviceByMemberId(Long memberId){
+        List<DeviceVO> vos = Lists.newArrayList();
+        CareMemberInfo memberInfo = this.careMemberInfoService.getById(memberId);
+        QueryWrapper<CareDevice> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(CareDevice::getMemberId, memberInfo.getId());
+        List<CareDevice> devices = this.careDeviceService.list(queryWrapper);
+        if (CollUtil.isNotEmpty(devices)){
+            devices.forEach(item -> {
+                DeviceVO vo = new DeviceVO();
+                BeanUtil.copyProperties(item,vo);
+                vos.add(vo);
+            });
+        }
+        return vos;
+    }
+
+    /**
+     * 新增设备
+     * @param memberId
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean createMyDevice(Long memberId,DeviceVO vo){
+        //保存被监护人
+        CareDevice careDevice = new CareDevice();
+        BeanUtil.copyProperties(vo,careDevice);
+        careDevice.setMemberId(memberId);
+        careDevice.setCreateTime(new Date());
+        return this.careDeviceService.save(careDevice);
+    }
+
+    /**
+     * 查询设备详情
+     * @param id
+     * @return
+     */
+    public DeviceVO getDeviceInfo(Long id){
+        CareDevice careDevice = this.careDeviceService.getById(id);
+        DeviceVO vo = new DeviceVO();
+        BeanUtil.copyProperties(careDevice,vo);
+        CareSysUser chamb = this.careSysUserService.getById(vo.getChambId());
+        vo.setChambName(chamb.getName());
+        vo.setChambPhone(chamb.getPhone());
+        vo.setStationName(this.careStationService.getById(vo.getStationId()).getShortName());
+        return vo;
+    }
+    /**
+     * 查询服务站简介
+     * @param stationId
+     * @return
+     */
+    public StationVO getMyDevStationInfo(Long stationId){
+        CareStation careStation = this.careStationService.getById(stationId);
+        StationVO vo = new StationVO();
+        BeanUtil.copyProperties(careStation,vo);
+        return vo;
+    }
+
+    /**
+     * 修改设备
+     * @param vo
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean updateMyDevice(DeviceVO vo){
+        //修改设备
+        CareDevice careDevice = this.careDeviceService.getById(vo.getId());
+        BeanUtil.copyProperties(vo,careDevice);
+        careDevice.setModifyTime(new Date());
+        return this.careDeviceService.updateById(careDevice);
+    }
+
+    /**
+     * 查询我的设备拥有的被监护人列表
+     * @param devId
+     * @return
+     */
+    public List<OlderVO> queryMyOlderListByDeviceId(Long devId){
+        List<OlderVO> vos = Lists.newArrayList();
+        CareDevice careDevice = this.careDeviceService.getById(devId);
+
+        QueryWrapper<CareHouseOlderRel> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(CareHouseOlderRel::getHouseId, careDevice.getHouseId());
+        List<CareHouseOlderRel> rels = this.careHouseOlderRelService.list(queryWrapper);
+        if (CollUtil.isNotEmpty(rels)){
+            rels.forEach(item -> {
+                OlderVO vo = new OlderVO();
+                CareOlder careOlder = this.careOlderService.getById(item.getOlderId());
+                BeanUtil.copyProperties(careOlder,vo);
+                vo.setLiveTypeDesc(OlderLiveTypeEnum.getCodeToName(vo.getLiveType()));
+                vos.add(vo);
+            });
+        }
+        return vos;
+    }
+
+    /**
+     * 查询我的设备拥有的紧急联系人列表
+     * @param devId
+     * @return
+     */
+    public List<HouseContactVO> queryMyContactListByDeviceId(Long devId){
+        List<HouseContactVO> vos = Lists.newArrayList();
+        CareDevice careDevice = this.careDeviceService.getById(devId);
+
+        QueryWrapper<CareHouseContactRel> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(CareHouseContactRel::getHouseId, careDevice.getHouseId());
+        List<CareHouseContactRel> rels = this.careHouseContactRelService.list(queryWrapper);
+        if (CollUtil.isNotEmpty(rels)){
+            rels.forEach(item -> {
+                HouseContactVO vo = new HouseContactVO();
+                CareHouseContact careHouseContact = this.careHouseContactService.getById(item.getContactId());
+                BeanUtil.copyProperties(careHouseContact,vo);
+                vo.setRelationTypeDesc(RelationTypeEnum.getCodeToName(vo.getRelationType()));
+                vos.add(vo);
+            });
+        }
+        List<HouseContactVO> vosNew = CollUtil.sortByProperty(vos,"contactLevel");
+        return vosNew;
+    }
+
+}

+ 106 - 0
src/main/java/com/care/client/vo/DeviceVO.java

@@ -0,0 +1,106 @@
+package com.care.client.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+
+/**
+ * @Author: lilt
+ * @Date: 2021/6/7
+ * @Desc:
+ */
+@Data
+public class DeviceVO {
+
+    private Long id;
+
+
+    @ApiModelProperty("机构ID")
+    private Long orgId;
+
+
+    @ApiModelProperty("服务站ID")
+    private Long stationId;
+
+    private String stationName;
+
+    @ApiModelProperty("房屋ID")
+    private Long houseId;
+    @ApiModelProperty("房屋地址")
+    private String houseAddr;
+
+    @ApiModelProperty("关联管家ID")
+    private Long chambId;
+
+    @ApiModelProperty("关联管家号码")
+    private String chambPhone;
+
+    @ApiModelProperty("关联管家姓名")
+    private String chambName;
+
+    @ApiModelProperty("设备名称")
+    private String devName;
+
+    @ApiModelProperty("设备编码")
+    private String devCode;
+
+
+    @ApiModelProperty("设备场景:1客厅,2卫生间,3卧室,4其他")
+    private String devScene;
+
+    private String devSceneName;
+
+    @ApiModelProperty("状态:1在线;2:离线")
+    private String status;
+
+    private String statusName;
+
+    @ApiModelProperty("激活状态:0未激活,1已激活")
+    private String activeStatus;
+
+    private String activeStatusName;
+
+    @ApiModelProperty("经度")
+    private Double longitude;
+
+
+    @ApiModelProperty("纬度")
+    private Double latitude;
+
+    @ApiModelProperty("跌到响应时间(分)")
+    private Integer fallResponseTime;
+
+    @ApiModelProperty("久滞响应时间(分)")
+    private Integer longlagResponseTime;
+
+    @ApiModelProperty("坠床响应时间(分)")
+    private Integer fallingbedResponseTime;
+
+    @ApiModelProperty("激活时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
+    private Date activeTime;
+
+    @ApiModelProperty("createTime")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
+    private Date createTime;
+
+
+    @ApiModelProperty("modifyTime")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
+    private Date modifyTime;
+
+
+    @ApiModelProperty("备注")
+    private String remark;
+
+    @ApiModelProperty("关联用户ID")
+    private Long memberId;
+
+    @ApiModelProperty("关联用户号码")
+    private String memberPhone;
+
+
+}

+ 3 - 0
src/main/java/com/care/common/entity/CareStation.java

@@ -71,6 +71,9 @@ public class CareStation implements Serializable {
     @TableField("LATITUDE")
     private Double latitude;
 
+    @ApiModelProperty("简介")
+    @TableField("INTRODUCTION")
+    private String introduction;
 
     @ApiModelProperty("createTime")
     @TableField("CREATE_TIME")

+ 2 - 0
src/main/java/com/care/common/vo/device/StationVO.java

@@ -54,6 +54,8 @@ public class StationVO implements Serializable {
     @ApiModelProperty("纬度")
     private Double latitude;
 
+    @ApiModelProperty("简介")
+    private String introduction;
 
     @ApiModelProperty("createTime")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")