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);
|
||||
}
|
||||
}
|
||||
|
@@ -16,4 +16,6 @@ public interface ScenicAccountService {
|
||||
List<ScenicAccountEntity> pageQuery(ScenicAccountReqQuery req);
|
||||
|
||||
int updateStatus(Long id);
|
||||
|
||||
ScenicAccountEntity getScenicAccountByAccount(String account);
|
||||
}
|
@@ -130,7 +130,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
}
|
||||
LoginRespVO loginRespVO = new LoginRespVO();
|
||||
String token = jwtTokenUtil.generateToken(new JwtInfo(login.getStaffName(), login.getStaffId(), roleId, login.getAccount(), login.getAccount(), null,null));
|
||||
String token = jwtTokenUtil.generateToken(new JwtInfo(login.getStaffName(), login.getStaffId(), roleId, login.getAccount(), login.getAccount(), null));
|
||||
loginRespVO.setToken(token);
|
||||
loginRespVO.setName(login.getStaffName());
|
||||
loginRespVO.setTypeName(login.getTypeName());
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.ycwl.basic.service.pc.impl;
|
||||
|
||||
import com.ycwl.basic.exception.BaseException;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicAccountReqQuery;
|
||||
import com.ycwl.basic.service.pc.ScenicAccountService;
|
||||
@@ -30,12 +31,23 @@ public class ScenicAccountServiceImpl implements ScenicAccountService {
|
||||
|
||||
@Override
|
||||
public int updateScenicAccount(ScenicAccountEntity entity) {
|
||||
return mapper.update(entity);
|
||||
if (entity.getId() == null) {
|
||||
throw new BaseException("参数错误");
|
||||
}
|
||||
int update = mapper.update(entity);
|
||||
mapper.deleteRelationById(entity.getId());
|
||||
entity.getScenicId().forEach(scenicId -> {
|
||||
mapper.addAccountScenicRelation(entity.getId(), scenicId, entity.getIsSuper());
|
||||
});
|
||||
return update;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScenicAccountEntity getScenicAccountById(Long id) {
|
||||
return mapper.findAccountById(String.valueOf(id));
|
||||
ScenicAccountEntity account = mapper.findAccountById(String.valueOf(id));
|
||||
List<Long> scenicList = mapper.getAccountRelations(id);
|
||||
account.setScenicId(scenicList);
|
||||
return account;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,4 +65,12 @@ public class ScenicAccountServiceImpl implements ScenicAccountService {
|
||||
public int updateStatus(Long id) {
|
||||
return mapper.updateStatus(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScenicAccountEntity getScenicAccountByAccount(String account) {
|
||||
ScenicAccountEntity accountEntity = mapper.getByAccount(account);
|
||||
List<Long> scenicList = mapper.getAccountRelations(accountEntity.getId());
|
||||
accountEntity.setScenicId(scenicList);
|
||||
return accountEntity;
|
||||
}
|
||||
}
|
@@ -71,21 +71,20 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiResponse<Boolean> add(ScenicAddOrUpdateReq scenicAddReq) {
|
||||
ScenicAccountEntity scenicAccount = scenicAccountMapper.getByAccount(scenicAddReq.getAccount());
|
||||
if (scenicAccount != null) {
|
||||
return ApiResponse.fail("账号已存在");
|
||||
}
|
||||
Long scenicId = SnowFlakeUtil.getLongId();
|
||||
scenicAddReq.setId(scenicId);
|
||||
int add = scenicMapper.add(scenicAddReq);
|
||||
ScenicAccountEntity account = new ScenicAccountEntity();
|
||||
account.setId(SnowFlakeUtil.getLongId());
|
||||
account.setScenicId(scenicId);
|
||||
account.setName(scenicAddReq.getName() + "管理员");
|
||||
account.setAccount(scenicAddReq.getAccount());
|
||||
account.setPassword(scenicAddReq.getPassword());
|
||||
account.setIsSuper(1);
|
||||
scenicAccountMapper.add(account);
|
||||
ScenicAccountEntity scenicAccount = scenicAccountMapper.getByAccount(scenicAddReq.getAccount());
|
||||
if (scenicAccount == null) {
|
||||
scenicAccount = new ScenicAccountEntity();
|
||||
scenicAccount.setId(SnowFlakeUtil.getLongId());
|
||||
scenicAccount.setName(scenicAddReq.getName() + "管理员");
|
||||
scenicAccount.setAccount(scenicAddReq.getAccount());
|
||||
scenicAccount.setPassword(scenicAddReq.getPassword());
|
||||
scenicAccount.setIsSuper(1);
|
||||
scenicAccountMapper.add(scenicAccount);
|
||||
}
|
||||
scenicAccountMapper.addAccountScenicRelation(scenicAccount.getId(), scenicId, 1);
|
||||
if (add > 0) {
|
||||
return ApiResponse.success(true);
|
||||
} else {
|
||||
@@ -98,7 +97,7 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
public ApiResponse<Boolean> deleteById(Long id) {
|
||||
int i = scenicMapper.deleteById(id);
|
||||
if (i > 0) {
|
||||
scenicAccountMapper.deleteByScenicId(id);
|
||||
scenicAccountMapper.deleteRelationByScenicId(id);
|
||||
IFaceBodyAdapter adapter = getScenicFaceBodyAdapter(id);
|
||||
Thread.ofVirtual().start(() -> {
|
||||
adapter.deleteFaceDb(id.toString());
|
||||
@@ -117,6 +116,9 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
|
||||
@Override
|
||||
public ApiResponse<Boolean> update(ScenicAddOrUpdateReq scenicUpdateReq) {
|
||||
if (scenicUpdateReq.getId() == null) {
|
||||
return ApiResponse.fail("参数错误");
|
||||
}
|
||||
if (StringUtils.isNotBlank(scenicUpdateReq.getAccount()) && StringUtils.isNotBlank(scenicUpdateReq.getPassword())) {
|
||||
ScenicAccountEntity scenicAccount = scenicAccountMapper.getByAccount(scenicUpdateReq.getAccount());
|
||||
if (scenicAccount != null) {
|
||||
@@ -132,13 +134,13 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
} else {
|
||||
account = new ScenicAccountEntity();
|
||||
account.setId(SnowFlakeUtil.getLongId());
|
||||
account.setScenicId(scenicUpdateReq.getId());
|
||||
account.setName(scenicUpdateReq.getName() + "管理员");
|
||||
account.setAccount(scenicUpdateReq.getAccount());
|
||||
account.setPassword(scenicUpdateReq.getPassword());
|
||||
account.setIsSuper(1);
|
||||
scenicAccountMapper.add(account);
|
||||
}
|
||||
scenicAccountMapper.addAccountScenicRelation(account.getId(), scenicUpdateReq.getId(), 1);
|
||||
}
|
||||
int i = scenicMapper.update(scenicUpdateReq);
|
||||
if (i > 0) {
|
||||
|
Reference in New Issue
Block a user