用终端操作 接口

master
guochaojie 3 months ago
parent f57b718b1c
commit 4d341712d3

@ -399,6 +399,11 @@ public class DeviceController {
throw new BizIllegalException("上传失败:根据桶编号,未查询到桶信息!!");
}
Client client = clientService.getClientByMobile(orderVO.getPhone());
if (null == client) {
throw new BizIllegalException("上传失败:根据手机号未找到对应的客户信息!");
}
String companyId = device.getBeLongCompanyId();
//查询配置
RecycleDeviceConfig config = configService.getByCompanyId(companyId);
@ -430,7 +435,7 @@ public class DeviceController {
order.setAdjustPrice(BigDecimal.ZERO);
order.setAdjustComm("");
}
order.setDeliverId(orderVO.getUserId());
order.setDeliverId(client.getId());
order.setPhone(orderVO.getPhone());
// 上传照片
List<Snap> images = orderVO.getImages();
@ -501,6 +506,11 @@ public class DeviceController {
if (null == bucket) {
throw new BizIllegalException("上传失败:根据桶编号,未查询到桶信息!!");
}
Recycler recycle = recyclerService.getLatestRecycleByPhone(orderVO.getPhone());
if (null == recycle) {
throw new BizIllegalException("上传失败:根据手机号,未查询到回收员信息!!");
}
//查询配置
RecycleDeviceConfig config = configService.getByCompanyId(device.getBeLongCompanyId());
String adjustSet = config.getCleanAdjustSet();//审核配置
@ -517,7 +527,7 @@ public class DeviceController {
order.setPrice(orderVO.getPrice());
order.setWeight(orderVO.getTotalWeight());
order.setTotalPrice(orderVO.getTotalPrice());
order.setCleanUserId(orderVO.getUserId());
order.setCleanUserId(recycle.getId());
order.setPhone(orderVO.getPhone());
order.setBagNo(orderVO.getBagNo());
order.setLoginType("2");
@ -553,7 +563,7 @@ public class DeviceController {
order.setReportTime(DateUtil.parse(orderVO.getReportTime(), "yyyy-MM-dd HH:mm:ss"));
}
order.setCreatorUserId(orderVO.getUserId());
order.setCreatorUserId(recycle.getId());
order.setCreatorTime(new Date());
order.setPhone(orderVO.getPhone());
order.setCompanyId(device.getBeLongCompanyId());
@ -1016,4 +1026,69 @@ public class DeviceController {
}
return CommonResult.error(400, "桶内桶内无重量!");
}
@ApiOperation("小程序接口 用终端操作")
@PostMapping("/loginDevice")
public CommonResult loginDevice(CommandVO commandVO) {
UserDTO user = UserContext.getUser();
if (null == user) {
throw new BizIllegalException("登录已过期,请先登录!");
}
String phone = user.getPhone();
String deviceCode = commandVO.getDeviceCode();
int role = 0;
LoginRespVO respVO = new LoginRespVO();
Recycler recycler = recyclerService.getRecyclerByPhoneNumber(phone);
Client client = clientService.getLastestClientByPhone(phone);
if (client == null) {
throw new BizIllegalException("登录失败:您还未注册,请先扫码注册!");
} else {
role = 1;
}
if (null != recycler) {
RecycleStaffDevice staffDevice = staffDeviceService.getByDeviceCode(deviceCode, phone);
if (null != staffDevice) {
if (role == 1) role = 3;
}
}
UserDTO userInfo = null;
if (role == 1) {
userInfo = commonService.loginDeviceByClient(client);
respVO.setUserId(client.getId());
respVO.setOpenId(client.getWxOpenid());
respVO.setUserName(client.getNickName());
respVO.setStatus(client.getEnabledMark());
respVO.setPhone(client.getMobilePhone());
respVO.setBalance(client.getBanlance());
} else if (role == 3) {
userInfo = commonService.loginDeviceByRecycler(recycler);
respVO.setUserId(recycler.getId());
respVO.setOpenId(recycler.getOpenid());
respVO.setUserName(recycler.getStaffsName());
respVO.setStatus(recycler.getStatus());
respVO.setPhone(recycler.getMobilePhone());
respVO.setBalance(BigDecimal.ZERO);
}
respVO.setToken(userInfo.getToken());
respVO.setTimeExpire(userInfo.getTimeExpire());
respVO.setRole(role);
CommandVO command = new CommandVO();
command.setCmd(CMDEnum.login);
command.setDeviceCode(deviceCode);
command.setData(respVO);
command.setOptTime(DateUtil.now());
command.setRemark("登录成功");
boolean connected = mqttClient.isConnected();
if (connected) {
mqttClient.publish(deviceCode + "/command", JSONUtil.toJsonStr(command));
log.info("扫描登录 ===> 通知设备 code:{}", deviceCode);
} else {
log.error("扫描登录失败 ===> mqtt未连接 code:{}", deviceCode);
}
return null;
}
}

@ -152,32 +152,6 @@ public class CommonService implements ICommonService {
userDTO.setUsername(recycler.getStaffsName());
userDTO.setToken(this.createToken(userDTO));
userDTO.setCompanyId(recycler.getCompanyId());
if (StrUtil.isNotEmpty(wxLoginDTO.getDevCode())) {
// 通知设备登录成功
LoginRespVO respVO = new LoginRespVO();
respVO.setRole(2);
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());
CommandVO command = new CommandVO();
command.setCmd(CMDEnum.login);
command.setDeviceCode(wxLoginDTO.getDevCode());
command.setData(respVO);
command.setOptTime(DateUtil.now());
command.setRemark("登录成功");
boolean connected = mqttClient.isConnected();
if (connected) {
mqttClient.publish(wxLoginDTO.getDevCode() + "/command", JSONUtil.toJsonStr(command));
log.info("扫描登录 回收员 ===> 通知设备 code:{}", wxLoginDTO.getDevCode());
} else {
log.error("扫描登录失败 回收员 ===> mqtt未连接 code:{}", wxLoginDTO.getDevCode());
}
}
return userDTO;
}
@ -194,33 +168,6 @@ public class CommonService implements ICommonService {
userDTO.setUserType(UserTypeEnum.CLIENT);
userDTO.setUsername(client.getNickName());
userDTO.setToken(this.createToken(userDTO));
if (StrUtil.isNotEmpty(wxLoginDTO.getDevCode())) {
// 通知设备登录成功
LoginRespVO respVO = new LoginRespVO();
respVO.setUserId(userDTO.getId());
respVO.setOpenId(userDTO.getOpenid());
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);
CommandVO command = new CommandVO();
command.setCmd(CMDEnum.login);
command.setDeviceCode(wxLoginDTO.getDevCode());
command.setData(respVO);
command.setOptTime(DateUtil.now());
command.setRemark("登录成功");
boolean connected = mqttClient.isConnected();
if (connected) {
mqttClient.publish(wxLoginDTO.getDevCode() + "/command", JSONUtil.toJsonStr(command));
log.info("扫描登录 散户 ===> 通知设备 code:{}", wxLoginDTO.getDevCode());
} else {
log.error("扫描登录失败 散户 ===> mqtt未连接 code:{}", wxLoginDTO.getDevCode());
}
}
return userDTO;
}

@ -35,7 +35,8 @@ public class RecycleBucketServiceImpl extends ServiceImpl<RecycleBucketMapper, R
public List<RecycleBucket> getByDeviceCode(String deviceCode) {
QueryWrapper<RecycleBucket> query = new QueryWrapper<>();
query.lambda().isNull(RecycleBucket::getDeleteMark)
.eq(RecycleBucket::getDeviceCode, deviceCode);
.eq(RecycleBucket::getDeviceCode, deviceCode)
.orderByAsc(RecycleBucket::getShowOrd);
return recycleBucketMapper.selectList(query);
}

Loading…
Cancel
Save