You've already forked FrameTour-BE
支持用户切换景区账号,单账号多景区权限
This commit is contained in:
@@ -26,9 +26,7 @@ public interface AppScenicService {
|
||||
|
||||
ApiResponse<ScenicLoginRespVO> login(ScenicLoginReq scenicLoginReq) throws Exception;
|
||||
|
||||
ApiResponse<ScenicRespVO> getMyScenic();
|
||||
|
||||
ApiResponse<List<DeviceRespVO>> getMyDevices();
|
||||
|
||||
List<ScenicAppVO> scenicListByLnLa(ScenicIndexVO scenicIndexVO);
|
||||
|
||||
ApiResponse<List<DeviceRespVO>> getDevices(Long scenicId);
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
|
||||
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
||||
import com.ycwl.basic.service.mobile.AppScenicService;
|
||||
import com.ycwl.basic.service.pc.ScenicAccountService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.utils.JwtTokenUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -25,6 +26,8 @@ import org.springframework.stereotype.Service;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import static com.ycwl.basic.constant.JwtRoleConstant.MERCHANT;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/6 10:23
|
||||
@@ -41,6 +44,8 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
private ScenicAccountMapper scenicAccountMapper;
|
||||
@Autowired
|
||||
private JwtTokenUtil jwtTokenUtil;
|
||||
@Autowired
|
||||
private ScenicAccountService scenicAccountService;
|
||||
|
||||
@Override
|
||||
public ApiResponse<PageInfo<ScenicAppVO>> pageQuery(ScenicReqQuery scenicReqQuery) {
|
||||
@@ -67,8 +72,7 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
|
||||
@Override
|
||||
public ApiResponse<ScenicLoginRespVO> login(ScenicLoginReq scenicLoginReq) throws Exception {
|
||||
|
||||
ScenicAccountEntity scenicAccount = scenicAccountMapper.getByAccount(scenicLoginReq.getAccount());
|
||||
ScenicAccountEntity scenicAccount = scenicAccountService.getScenicAccountByAccount(scenicLoginReq.getAccount());
|
||||
if (scenicAccount == null) {
|
||||
return ApiResponse.fail("账号不存在");
|
||||
}
|
||||
@@ -83,7 +87,7 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
jwtInfo.setName(scenicAccount.getName());
|
||||
jwtInfo.setAccount(scenicAccount.getAccount());
|
||||
jwtInfo.setUserId(scenicAccount.getId());
|
||||
jwtInfo.setScenicId(scenicAccount.getScenicId());
|
||||
jwtInfo.setRoleId(MERCHANT.type);
|
||||
String token = jwtTokenUtil.generateToken(jwtInfo);
|
||||
|
||||
ScenicLoginRespVO scenicLoginRespVO = new ScenicLoginRespVO();
|
||||
@@ -92,30 +96,15 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
return ApiResponse.success(scenicLoginRespVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<ScenicRespVO> getMyScenic() {
|
||||
String userId = BaseContextHandler.getUserId();
|
||||
ScenicAccountEntity account = scenicAccountMapper.findAccountById(userId);
|
||||
if (account == null) {
|
||||
return ApiResponse.fail("用户未绑定景区");
|
||||
}
|
||||
return getDetails(account.getScenicId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<DeviceRespVO>> getMyDevices() {
|
||||
String userId = BaseContextHandler.getUserId();
|
||||
ScenicAccountEntity account = scenicAccountMapper.findAccountById(userId);
|
||||
if (account == null) {
|
||||
return ApiResponse.fail("用户未绑定景区");
|
||||
}
|
||||
List<DeviceRespVO> deviceRespVOList = deviceMapper.listByScenicIdWithWVP(account.getScenicId());
|
||||
return ApiResponse.success(deviceRespVOList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ScenicAppVO> scenicListByLnLa(ScenicIndexVO scenicIndexVO) {
|
||||
List<ScenicAppVO> scenicAppVOS = scenicMapper.scenicListByLnLa(scenicIndexVO);
|
||||
return scenicAppVOS.stream().filter(scenic -> scenic.getDistance().compareTo(scenic.getRadius().multiply(BigDecimal.valueOf(1_000L))) < 0).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<DeviceRespVO>> getDevices(Long scenicId) {
|
||||
List<DeviceRespVO> deviceRespVOList = deviceMapper.listByScenicIdWithWVP(scenicId);
|
||||
return ApiResponse.success(deviceRespVOList);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user