diff --git a/nxhs-service/src/main/java/cc/yunxi/controller/DeviceController.java b/nxhs-service/src/main/java/cc/yunxi/controller/DeviceController.java index 69e6d46..ad87487 100644 --- a/nxhs-service/src/main/java/cc/yunxi/controller/DeviceController.java +++ b/nxhs-service/src/main/java/cc/yunxi/controller/DeviceController.java @@ -297,50 +297,46 @@ public class DeviceController { return JSONUtil.toJsonStr(list); } - //手机号登录 - @PostMapping("/customerLogin") - @ApiOperation("投递员手机号登录") - public CommonResult customerLogin(@RequestBody LoginReqVO loginReqVO) { - CommonResult result = new CommonResult<>(); - Client client = clientService.getLastestClientByPhone(loginReqVO.getPhone()); - if (client == null) { - throw new BizIllegalException("登录失败:您还未注册,请先扫码注册!"); - } + @PostMapping("/login") + @ApiOperation("清运员手机号登录") + public CommonResult login(@RequestBody LoginReqVO loginReqVO) { RecycleDevice device = deviceService.getByDeviceCode(loginReqVO.getDeviceCode()); if (device == null) { throw new BizIllegalException("登录失败:未查询到对应设备信息!"); } - UserDTO userDTO = commonService.loginDeviceByClient(client); - LoginRespVO respVO = new LoginRespVO(); - respVO.setUserId(client.getId()); - respVO.setOpenId(client.getWxOpenid()); - respVO.setUserName(client.getNickName()); - respVO.setStatus(client.getEnabledMark()); - respVO.setToken(userDTO.getToken()); - respVO.setTimeExpire(userDTO.getTimeExpire()); - respVO.setRole(1); - result.setData(respVO); - result.setCode(200); - result.setMsg("登录成功"); - return result; - } - - @PostMapping("/cleanerLogin") - @ApiOperation("清运员手机号登录") - public CommonResult cleanerLogin(@RequestBody LoginReqVO loginReqVO) { Recycler recycler = recyclerService.getRecyclerByPhoneNumber(loginReqVO.getPhone()); - if (recycler == null) { - throw new BizIllegalException("登录失败:你还不是清运员,请先注册!"); - } - RecycleDevice device = deviceService.getByDeviceCode(loginReqVO.getDeviceCode()); - if (device == null) { - throw new BizIllegalException("登录失败:未查询到对应设备信息!"); + CommandVO command = new CommandVO(); + command.setDeviceCode(loginReqVO.getDeviceCode()); + command.setCmd(CMDEnum.login); + command.setOptTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + command.setRemark("登录成功"); + if (null != recycler) { + RecycleStaffDevice staffDevice = staffDeviceService.getByDeviceCode(loginReqVO.getDeviceCode(), loginReqVO.getPhone()); + if (null == staffDevice) { + throw new BizIllegalException("登录失败:你不是当前设备的管理人员!"); + } } - RecycleStaffDevice staffDevice = staffDeviceService.getByDeviceCode(loginReqVO.getDeviceCode(), loginReqVO.getPhone()); - if (null == staffDevice) { - throw new BizIllegalException("登录失败:你不是当前设备的管理人员!"); + //如果不是回收员 则走 投递员登录 + else { + Client client = clientService.getLastestClientByPhone(loginReqVO.getPhone()); + if (client == null) { + throw new BizIllegalException("登录失败:您还未注册,请先扫码注册!"); + } + UserDTO userInfo = commonService.loginDeviceByClient(client); + LoginRespVO respVO = new LoginRespVO(); + respVO.setUserId(client.getId()); + respVO.setOpenId(client.getWxOpenid()); + respVO.setUserName(client.getNickName()); + respVO.setStatus(client.getEnabledMark()); + respVO.setToken(userInfo.getToken()); + respVO.setBalance(client.getBanlance()); + respVO.setPhone(client.getMobilePhone()); + respVO.setTimeExpire(userInfo.getTimeExpire()); + respVO.setRole(1); + command.setData(respVO); + mqttClient.publish(loginReqVO.getDeviceCode() + "/command", JSONUtil.toJsonStr(command)); + return CommonResult.success("登录成功!", "success"); } - //登录成功 UserDTO userDTO = commonService.loginDeviceByRecycler(recycler); LoginRespVO respVO = new LoginRespVO(); @@ -349,9 +345,12 @@ public class DeviceController { respVO.setUserName(recycler.getStaffsName()); respVO.setStatus(recycler.getStatus()); respVO.setToken(userDTO.getToken()); + respVO.setPhone(recycler.getMobilePhone()); + respVO.setBalance(BigDecimal.ZERO); respVO.setTimeExpire(userDTO.getTimeExpire()); respVO.setRole(2); - return CommonResult.success(respVO); + mqttClient.publish(loginReqVO.getDeviceCode() + "/command", JSONUtil.toJsonStr(respVO)); + return CommonResult.success("登录成功!", "success"); } @@ -515,8 +514,8 @@ public class DeviceController { RecycleDeviceEvent event = new RecycleDeviceEvent(); event.setDeviceCode(deviceCode); event.setBucketCode("");//桶编码 - if (StrUtil.isNotEmpty(cmd.getData())) { - event.setBucketCode(cmd.getData());//桶编码 + if (null != cmd.getData() && StrUtil.isNotEmpty(cmd.getData().toString())) { + event.setBucketCode(cmd.getData().toString());//桶编码 } event.setEventType(deviceCode); diff --git a/nxhs-service/src/main/java/cc/yunxi/domain/vo/device/CommandVO.java b/nxhs-service/src/main/java/cc/yunxi/domain/vo/device/CommandVO.java index 173038f..b424a66 100644 --- a/nxhs-service/src/main/java/cc/yunxi/domain/vo/device/CommandVO.java +++ b/nxhs-service/src/main/java/cc/yunxi/domain/vo/device/CommandVO.java @@ -18,7 +18,7 @@ public class CommandVO { @NotNull(message = "命令不能为空") private CMDEnum cmd; @ApiModelProperty(value = "命令参数") - private String data; + private Object data; @ApiModelProperty(value = "操作时间", required = true, example = "admin") @NotNull(message = "操作时间不能为空") private String optTime; diff --git a/nxhs-service/src/main/java/cc/yunxi/domain/vo/device/LoginRespVO.java b/nxhs-service/src/main/java/cc/yunxi/domain/vo/device/LoginRespVO.java index 766ca88..8293522 100644 --- a/nxhs-service/src/main/java/cc/yunxi/domain/vo/device/LoginRespVO.java +++ b/nxhs-service/src/main/java/cc/yunxi/domain/vo/device/LoginRespVO.java @@ -6,6 +6,7 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.math.BigDecimal; import java.util.List; //设备手机号登录成功 @@ -19,9 +20,13 @@ public class LoginRespVO { private String openId; @ApiModelProperty("用户名") private String userName;//用户名 + @ApiModelProperty("手机号") + private String phone;//用户名 @ApiModelProperty(value = "用户状态", required = true) @NotNull(message = "用户状态不能为空") private Integer status; + @ApiModelProperty(value = "账户余额") + private BigDecimal balance; @ApiModelProperty(value = "用户状态", required = true) @NotBlank(message = "令牌不能为空") private String token; diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/CommonService.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/CommonService.java index 29f7448..ad37681 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/CommonService.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/CommonService.java @@ -30,6 +30,7 @@ import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Date; /** @@ -158,14 +159,15 @@ public class CommonService implements ICommonService { respVO.setStatus(recycler.getStatus()); respVO.setToken(userDTO.getToken()); respVO.setUserId(userDTO.getId()); + respVO.setPhone(recycler.getMobilePhone()); respVO.setUserName(userDTO.getUsername()); respVO.setOpenId(userDTO.getOpenid()); + respVO.setBalance(BigDecimal.ZERO); respVO.setTimeExpire(userDTO.getTimeExpire()); - String data = JSONUtil.toJsonStr(respVO); CommandVO command = new CommandVO(); command.setCmd(CMDEnum.login); command.setDeviceCode(wxLoginDTO.getDevCode()); - command.setData(data); + command.setData(respVO); command.setOptTime(DateUtil.now()); command.setRemark("登录成功"); boolean connected = mqttClient.isConnected(); @@ -200,13 +202,14 @@ public class CommonService implements ICommonService { respVO.setUserName(userDTO.getUsername()); respVO.setStatus(client.getEnabledMark()); respVO.setToken(userDTO.getToken()); + respVO.setBalance(client.getBanlance()); + respVO.setPhone(client.getMobilePhone()); respVO.setTimeExpire(userDTO.getTimeExpire()); respVO.setRole(1); - String data = JSONUtil.toJsonStr(respVO); CommandVO command = new CommandVO(); command.setCmd(CMDEnum.login); command.setDeviceCode(wxLoginDTO.getDevCode()); - command.setData(data); + command.setData(respVO); command.setOptTime(DateUtil.now()); command.setRemark("登录成功"); boolean connected = mqttClient.isConnected();