设备对接 接口优化

master
guochaojie 4 months ago
parent 7121d9d077
commit bf5205b029

@ -8,6 +8,7 @@ import cc.yunxi.domain.po.*;
import cc.yunxi.domain.vo.device.*; import cc.yunxi.domain.vo.device.*;
import cc.yunxi.domain.vo.file.FileUploadRespVO; import cc.yunxi.domain.vo.file.FileUploadRespVO;
import cc.yunxi.service.*; import cc.yunxi.service.*;
import cc.yunxi.service.impl.CommonService;
import cc.yunxi.utils.DeviceStatusManager; import cc.yunxi.utils.DeviceStatusManager;
import cc.yunxi.utils.UserContext; import cc.yunxi.utils.UserContext;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -56,6 +57,13 @@ public class DeviceController {
private IRecycleCleanOrderService cleanOrderService; private IRecycleCleanOrderService cleanOrderService;
@Resource @Resource
private IRecycleDeliveryOrderService deliveryOrderService; private IRecycleDeliveryOrderService deliveryOrderService;
@Resource
private IRecyclerService recyclerService;
@Resource
private IClientService clientService;
@Resource
private ICommonService commonService;
@Resource @Resource
private IFileService fileService; private IFileService fileService;
@ -213,15 +221,61 @@ public class DeviceController {
} }
//手机号登录 //手机号登录
@PostMapping("/login") @PostMapping("/customerLogin")
@ApiModelProperty("手机号登录") @ApiModelProperty("投递员手机号登录")
public CommonResult<LoginRespVO> login(@RequestBody LoginReqVO loginReqVO) { public CommonResult<LoginRespVO> customerLogin(@RequestBody LoginReqVO loginReqVO) {
CommonResult<LoginRespVO> result = new CommonResult<>(); CommonResult<LoginRespVO> result = new CommonResult<>();
//todo Client client = clientService.getLastestClientByPhone(loginReqVO.getPhone());
if (client == null) {
throw new BizIllegalException("登录失败:您还未注册,请先扫码注册!");
}
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);
return result; return result;
} }
@PostMapping("/customerLogin")
@ApiModelProperty("清运员手机号登录")
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("登录失败:未查询到对应设备信息!");
}
String recyclerPhone = device.getBeLongRecyclerPhone();
if (StrUtil.isEmpty(recyclerPhone) || !recyclerPhone.equals(loginReqVO.getPhone())) {
throw new BizIllegalException("登录失败:你不是当前设备的清运员或当前设备未分配清运员!");
}
//登录成功
UserDTO userDTO = commonService.loginDeviceByRecycler(recycler);
LoginRespVO respVO = new LoginRespVO();
respVO.setUserId(recycler.getId());
respVO.setOpenId(recycler.getOpenid());
respVO.setUserName(recycler.getStaffsName());
respVO.setStatus(recycler.getStatus());
respVO.setToken(userDTO.getToken());
respVO.setTimeExpire(userDTO.getTimeExpire());
respVO.setRole(1);
return CommonResult.success(respVO);
}
//投递重量上传 //投递重量上传
@PostMapping("/delivery") @PostMapping("/delivery")
@ApiModelProperty("投递订单上传") @ApiModelProperty("投递订单上传")
@ -411,8 +465,7 @@ public class DeviceController {
@ApiModelProperty("获取设备状态") @ApiModelProperty("获取设备状态")
@PostMapping("/status") @PostMapping("/status")
public CommonResult<String> command(@RequestBody DeviceVO deviceVO) public CommonResult<String> command(@RequestBody DeviceVO deviceVO) {
{
String deviceCode = deviceVO.getDeviceCode(); String deviceCode = deviceVO.getDeviceCode();
CommandVO cmd = new CommandVO(); CommandVO cmd = new CommandVO();
cmd.setCmd(CMDEnum.status); cmd.setCmd(CMDEnum.status);

@ -50,6 +50,10 @@ public class RecycleDevice {
@TableField(value = "BE_LONG_COMPANY_ID") @TableField(value = "BE_LONG_COMPANY_ID")
@ApiModelProperty("所属商户") @ApiModelProperty("所属商户")
private String beLongCompanyId; private String beLongCompanyId;
@TableField(value = "BE_LONG_RECYCLER_PHONE")
@ApiModelProperty("回收员手机号")
private String beLongRecyclerPhone;
@TableField(value = "LATITUDE") @TableField(value = "LATITUDE")
@ApiModelProperty("纬度") @ApiModelProperty("纬度")
private String latitude; private String latitude;

@ -65,6 +65,10 @@ public class Recycler {
@TableField(value = "auto_enabled") @TableField(value = "auto_enabled")
private Integer autoEnabled; private Integer autoEnabled;
@ApiModelProperty("管理设备")
@TableField("manage_device")
private String manageDevice;
@ApiModelProperty("状态 (0-禁用1-启用)") @ApiModelProperty("状态 (0-禁用1-启用)")
@TableField("enabled_mark") @TableField("enabled_mark")
private Integer status; private Integer status;

@ -19,5 +19,4 @@ public class LoginReqVO {
@ApiModelProperty(value = "手机号", required = true, example = "13800138000") @ApiModelProperty(value = "手机号", required = true, example = "13800138000")
@NotBlank(message = "手机号不能为空") @NotBlank(message = "手机号不能为空")
private String phone; private String phone;
} }

@ -4,21 +4,31 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
//设备手机号登录成功 //设备手机号登录成功
@Data @Data
@ApiModel("设备手机号登录成功") @ApiModel("设备手机号登录成功")
public class LoginRespVO { public class LoginRespVO {
@ApiModelProperty("用户id") @ApiModelProperty(value = "用户id", required = true, example = "1")
@NotBlank(message = "用户id不能为空")
private String userId;//用户id private String userId;//用户id
@ApiModelProperty(value = "wx_openid")
private String openId;
@ApiModelProperty("用户名") @ApiModelProperty("用户名")
private String userName;//用户名 private String userName;//用户名
@ApiModelProperty("用户状态") @ApiModelProperty(value = "用户状态", required = true)
private String status;//用户状态 @NotNull(message = "用户状态不能为空")
private String phone;//手机号 private Integer status;
private String token;//手机号 @ApiModelProperty(value = "用户状态", required = true)
@NotBlank(message = "令牌不能为空")
private String token;
@ApiModelProperty(value = "令牌过期时间", required = true)
@NotNull(message = "令牌过期时间不能为空")
private Long timeExpire; private Long timeExpire;
private String deviceCode;//设备编码 @ApiModelProperty(value = "用户角色", required = true)
private List<Integer> roles;//用户角色 @NotNull(message = "用户角色不能为空")
private Integer role;
} }

@ -3,6 +3,8 @@ package cc.yunxi.service;
import cc.yunxi.domain.dto.UserDTO; import cc.yunxi.domain.dto.UserDTO;
import cc.yunxi.domain.dto.WxLoginDTO; import cc.yunxi.domain.dto.WxLoginDTO;
import cc.yunxi.domain.po.Client;
import cc.yunxi.domain.po.Recycler;
import javax.validation.Valid; import javax.validation.Valid;
@ -40,4 +42,20 @@ public interface ICommonService {
* @param token * @param token
*/ */
UserDTO checkStation(String token); UserDTO checkStation(String token);
/**
*
* @param recycler
* @return UserDTO
* @return
*/
UserDTO loginDeviceByRecycler(Recycler recycler);
/**
*
* @param client
* @return UserDTO
*/
UserDTO loginDeviceByClient(Client client);
} }

@ -197,6 +197,28 @@ public class CommonService implements ICommonService {
return userDTO; return userDTO;
} }
@Override
public UserDTO loginDeviceByRecycler(Recycler recycler) {
UserDTO userDTO = new UserDTO();
userDTO.setUserType(UserTypeEnum.RECYCLER);
userDTO.setId(recycler.getId());
userDTO.setUsername(recycler.getStaffsName());
userDTO.setCompanyId(recycler.getCompanyId());
userDTO.setStationId(recycler.getStationId());
userDTO.setToken(this.createToken(userDTO));
return userDTO;
}
@Override
public UserDTO loginDeviceByClient(Client client) {
UserDTO userDTO = new UserDTO();
userDTO.setId(client.getId());
userDTO.setUserType(UserTypeEnum.CLIENT);
userDTO.setUsername(client.getNickName());
userDTO.setToken(this.createToken(userDTO));
return userDTO;
}
/** /**
* token * token

@ -4,7 +4,7 @@
<!-- 查询单位指定的回收垃圾散户 --> <!-- 查询单位指定的回收垃圾散户 -->
<select id="isClientUnit" resultType="String"> <select id="isClientUnit" resultType="String">
SELECT idname FROM nx_manager where mobile_phone = #{phoneNumber}; SELECT id,name FROM nx_manager where mobile_phone = #{phoneNumber};
</select> </select>
<select id="getLatestClientByPhone" resultType="Client"> <select id="getLatestClientByPhone" resultType="Client">

Loading…
Cancel
Save