手机号登录

master
guochaojie 4 months ago
parent ef85e73a46
commit 23ce976a38

@ -297,50 +297,46 @@ public class DeviceController {
return JSONUtil.toJsonStr(list); return JSONUtil.toJsonStr(list);
} }
//手机号登录 @PostMapping("/login")
@PostMapping("/customerLogin") @ApiOperation("清运员手机号登录")
@ApiOperation("投递员手机号登录") public CommonResult<String> login(@RequestBody LoginReqVO loginReqVO) {
public CommonResult<LoginRespVO> customerLogin(@RequestBody LoginReqVO loginReqVO) {
CommonResult<LoginRespVO> result = new CommonResult<>();
Client client = clientService.getLastestClientByPhone(loginReqVO.getPhone());
if (client == null) {
throw new BizIllegalException("登录失败:您还未注册,请先扫码注册!");
}
RecycleDevice device = deviceService.getByDeviceCode(loginReqVO.getDeviceCode()); RecycleDevice device = deviceService.getByDeviceCode(loginReqVO.getDeviceCode());
if (device == null) { if (device == null) {
throw new BizIllegalException("登录失败:未查询到对应设备信息!"); throw new BizIllegalException("登录失败:未查询到对应设备信息!");
} }
UserDTO userDTO = commonService.loginDeviceByClient(client); Recycler recycler = recyclerService.getRecyclerByPhoneNumber(loginReqVO.getPhone());
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("登录失败:你不是当前设备的管理人员!");
}
}
//如果不是回收员 则走 投递员登录
else {
Client client = clientService.getLastestClientByPhone(loginReqVO.getPhone());
if (client == null) {
throw new BizIllegalException("登录失败:您还未注册,请先扫码注册!");
}
UserDTO userInfo = commonService.loginDeviceByClient(client);
LoginRespVO respVO = new LoginRespVO(); LoginRespVO respVO = new LoginRespVO();
respVO.setUserId(client.getId()); respVO.setUserId(client.getId());
respVO.setOpenId(client.getWxOpenid()); respVO.setOpenId(client.getWxOpenid());
respVO.setUserName(client.getNickName()); respVO.setUserName(client.getNickName());
respVO.setStatus(client.getEnabledMark()); respVO.setStatus(client.getEnabledMark());
respVO.setToken(userDTO.getToken()); respVO.setToken(userInfo.getToken());
respVO.setTimeExpire(userDTO.getTimeExpire()); respVO.setBalance(client.getBanlance());
respVO.setPhone(client.getMobilePhone());
respVO.setTimeExpire(userInfo.getTimeExpire());
respVO.setRole(1); respVO.setRole(1);
result.setData(respVO); command.setData(respVO);
result.setCode(200); mqttClient.publish(loginReqVO.getDeviceCode() + "/command", JSONUtil.toJsonStr(command));
result.setMsg("登录成功"); return CommonResult.success("登录成功!", "success");
return result;
} }
@PostMapping("/cleanerLogin")
@ApiOperation("清运员手机号登录")
public CommonResult<LoginRespVO> 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("登录失败:未查询到对应设备信息!");
}
RecycleStaffDevice staffDevice = staffDeviceService.getByDeviceCode(loginReqVO.getDeviceCode(), loginReqVO.getPhone());
if (null == staffDevice) {
throw new BizIllegalException("登录失败:你不是当前设备的管理人员!");
}
//登录成功 //登录成功
UserDTO userDTO = commonService.loginDeviceByRecycler(recycler); UserDTO userDTO = commonService.loginDeviceByRecycler(recycler);
LoginRespVO respVO = new LoginRespVO(); LoginRespVO respVO = new LoginRespVO();
@ -349,9 +345,12 @@ public class DeviceController {
respVO.setUserName(recycler.getStaffsName()); respVO.setUserName(recycler.getStaffsName());
respVO.setStatus(recycler.getStatus()); respVO.setStatus(recycler.getStatus());
respVO.setToken(userDTO.getToken()); respVO.setToken(userDTO.getToken());
respVO.setPhone(recycler.getMobilePhone());
respVO.setBalance(BigDecimal.ZERO);
respVO.setTimeExpire(userDTO.getTimeExpire()); respVO.setTimeExpire(userDTO.getTimeExpire());
respVO.setRole(2); 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(); RecycleDeviceEvent event = new RecycleDeviceEvent();
event.setDeviceCode(deviceCode); event.setDeviceCode(deviceCode);
event.setBucketCode("");//桶编码 event.setBucketCode("");//桶编码
if (StrUtil.isNotEmpty(cmd.getData())) { if (null != cmd.getData() && StrUtil.isNotEmpty(cmd.getData().toString())) {
event.setBucketCode(cmd.getData());//桶编码 event.setBucketCode(cmd.getData().toString());//桶编码
} }
event.setEventType(deviceCode); event.setEventType(deviceCode);

@ -18,7 +18,7 @@ public class CommandVO {
@NotNull(message = "命令不能为空") @NotNull(message = "命令不能为空")
private CMDEnum cmd; private CMDEnum cmd;
@ApiModelProperty(value = "命令参数") @ApiModelProperty(value = "命令参数")
private String data; private Object data;
@ApiModelProperty(value = "操作时间", required = true, example = "admin") @ApiModelProperty(value = "操作时间", required = true, example = "admin")
@NotNull(message = "操作时间不能为空") @NotNull(message = "操作时间不能为空")
private String optTime; private String optTime;

@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
//设备手机号登录成功 //设备手机号登录成功
@ -19,9 +20,13 @@ public class LoginRespVO {
private String openId; private String openId;
@ApiModelProperty("用户名") @ApiModelProperty("用户名")
private String userName;//用户名 private String userName;//用户名
@ApiModelProperty("手机号")
private String phone;//用户名
@ApiModelProperty(value = "用户状态", required = true) @ApiModelProperty(value = "用户状态", required = true)
@NotNull(message = "用户状态不能为空") @NotNull(message = "用户状态不能为空")
private Integer status; private Integer status;
@ApiModelProperty(value = "账户余额")
private BigDecimal balance;
@ApiModelProperty(value = "用户状态", required = true) @ApiModelProperty(value = "用户状态", required = true)
@NotBlank(message = "令牌不能为空") @NotBlank(message = "令牌不能为空")
private String token; private String token;

@ -30,6 +30,7 @@ import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
/** /**
@ -158,14 +159,15 @@ public class CommonService implements ICommonService {
respVO.setStatus(recycler.getStatus()); respVO.setStatus(recycler.getStatus());
respVO.setToken(userDTO.getToken()); respVO.setToken(userDTO.getToken());
respVO.setUserId(userDTO.getId()); respVO.setUserId(userDTO.getId());
respVO.setPhone(recycler.getMobilePhone());
respVO.setUserName(userDTO.getUsername()); respVO.setUserName(userDTO.getUsername());
respVO.setOpenId(userDTO.getOpenid()); respVO.setOpenId(userDTO.getOpenid());
respVO.setBalance(BigDecimal.ZERO);
respVO.setTimeExpire(userDTO.getTimeExpire()); respVO.setTimeExpire(userDTO.getTimeExpire());
String data = JSONUtil.toJsonStr(respVO);
CommandVO command = new CommandVO(); CommandVO command = new CommandVO();
command.setCmd(CMDEnum.login); command.setCmd(CMDEnum.login);
command.setDeviceCode(wxLoginDTO.getDevCode()); command.setDeviceCode(wxLoginDTO.getDevCode());
command.setData(data); command.setData(respVO);
command.setOptTime(DateUtil.now()); command.setOptTime(DateUtil.now());
command.setRemark("登录成功"); command.setRemark("登录成功");
boolean connected = mqttClient.isConnected(); boolean connected = mqttClient.isConnected();
@ -200,13 +202,14 @@ public class CommonService implements ICommonService {
respVO.setUserName(userDTO.getUsername()); respVO.setUserName(userDTO.getUsername());
respVO.setStatus(client.getEnabledMark()); respVO.setStatus(client.getEnabledMark());
respVO.setToken(userDTO.getToken()); respVO.setToken(userDTO.getToken());
respVO.setBalance(client.getBanlance());
respVO.setPhone(client.getMobilePhone());
respVO.setTimeExpire(userDTO.getTimeExpire()); respVO.setTimeExpire(userDTO.getTimeExpire());
respVO.setRole(1); respVO.setRole(1);
String data = JSONUtil.toJsonStr(respVO);
CommandVO command = new CommandVO(); CommandVO command = new CommandVO();
command.setCmd(CMDEnum.login); command.setCmd(CMDEnum.login);
command.setDeviceCode(wxLoginDTO.getDevCode()); command.setDeviceCode(wxLoginDTO.getDevCode());
command.setData(data); command.setData(respVO);
command.setOptTime(DateUtil.now()); command.setOptTime(DateUtil.now());
command.setRemark("登录成功"); command.setRemark("登录成功");
boolean connected = mqttClient.isConnected(); boolean connected = mqttClient.isConnected();

Loading…
Cancel
Save