支持用户切换景区账号,单账号多景区权限

This commit is contained in:
2025-06-28 13:29:24 +08:00
parent e8488d081f
commit 206696deb8
19 changed files with 259 additions and 88 deletions

View File

@ -0,0 +1,13 @@
package com.ycwl.basic.constant;
public enum JwtRoleConstant {
MERCHANT("merchant"),
ADMIN("admin"),
APP_USER("app_user");
public final String type;
JwtRoleConstant(String type) {
this.type = type;
}
}

View File

@ -1,25 +1,36 @@
package com.ycwl.basic.controller.mobile.manage;
import com.ycwl.basic.annotation.IgnoreToken;
import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginReq;
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginRespVO;
import com.ycwl.basic.model.mobile.weChat.DTO.WeChatUserInfoDTO;
import com.ycwl.basic.model.pc.device.resp.DeviceRespVO;
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.service.pc.ScenicService;
import com.ycwl.basic.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.ycwl.basic.constant.JwtRoleConstant.MERCHANT;
/**
* @Author:longbinbin
* @Date:2024/12/12 18:28
@ -28,9 +39,12 @@ import java.util.List;
@RequestMapping("/api/mobile/scenicAccount/v1")
@Api(tags = "景区账号相关接口")
public class AppScenicAccountController {
@Autowired
private ScenicAccountService accountService;
@Autowired
private AppScenicService scenicService;
@Autowired
private ScenicService adminScenicService;
@ApiOperation("登录")
@PostMapping("/login")
@ -39,13 +53,68 @@ public class AppScenicAccountController {
return scenicService.login(scenicLoginReq);
}
@GetMapping("/myScenicList")
public ApiResponse<List<ScenicRespVO>> myScenicList() {
List<ScenicRespVO> list = Collections.emptyList();
if (StringUtils.equals(BaseContextHandler.getRoleId(), MERCHANT.type)) {
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = accountService.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
list = account.getScenicId().stream().map(id -> {
return scenicService.getDetails(id).getData();
}).toList();
} else {
list = adminScenicService.list(new ScenicReqQuery()).getData();
}
return ApiResponse.success(list);
}
@GetMapping("/getScenic")
public ApiResponse<ScenicRespVO> getMyScenic() {
return scenicService.getMyScenic();
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = accountService.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
return scenicService.getDetails(account.getScenicId().getFirst());
}
@GetMapping("/{scenicId}")
public ApiResponse<ScenicRespVO> getScenic(@PathVariable Long scenicId) {
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = accountService.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
if (!account.getScenicId().contains(scenicId)) {
return ApiResponse.fail("无权限");
}
return scenicService.getDetails(scenicId);
}
@GetMapping("/devices")
public ApiResponse<List<DeviceRespVO>> getDeviceList() {
return scenicService.getMyDevices();
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = accountService.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
return scenicService.getDevices(account.getScenicId().getFirst());
}
@GetMapping("/{scenicId}/devices")
public ApiResponse<List<DeviceRespVO>> getDeviceList(@PathVariable Long scenicId) {
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = accountService.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
if (!account.getScenicId().contains(scenicId)) {
return ApiResponse.fail("无权限");
}
return scenicService.getDevices(scenicId);
}
}

View File

@ -7,9 +7,11 @@ import com.ycwl.basic.model.pc.order.req.OrderReqQuery;
import com.ycwl.basic.model.pc.order.resp.OrderRespVO;
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
import com.ycwl.basic.service.pc.OrderService;
import com.ycwl.basic.service.pc.ScenicAccountService;
import com.ycwl.basic.utils.ApiResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -24,27 +26,57 @@ public class AppScenicOrderController {
@Autowired
private OrderService orderService;
@Autowired
private ScenicAccountMapper scenicAccountMapper;
private ScenicAccountService service;
@PostMapping("/list")
@Deprecated
public ApiResponse<List<OrderRespVO>> list(@RequestBody OrderReqQuery query) {
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = scenicAccountMapper.findAccountById(userId);
if (account == null) {
return ApiResponse.fail("用户未绑定景区");
ScenicAccountEntity account = service.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
query.setScenicId(account.getScenicId());
query.setScenicId(account.getScenicId().getFirst());
return orderService.list(query);
}
@PostMapping("/{scenicId}/list")
public ApiResponse<List<OrderRespVO>> list(@PathVariable Long scenicId, @RequestBody OrderReqQuery query) {
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = service.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
if (!account.getScenicId().contains(scenicId)) {
return ApiResponse.fail("无权限查看该景区订单");
}
query.setScenicId(scenicId);
return orderService.list(query);
}
@PostMapping("/page")
@Deprecated
public ApiResponse<PageInfo<OrderRespVO>> page(@RequestBody OrderReqQuery query) {
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = scenicAccountMapper.findAccountById(userId);
if (account == null) {
return ApiResponse.fail("用户未绑定景区");
ScenicAccountEntity account = service.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
query.setScenicId(account.getScenicId());
query.setScenicId(account.getScenicId().getFirst());
return orderService.pageQueryDetail(query);
}
@PostMapping("/{scenicId}/page")
public ApiResponse<PageInfo<OrderRespVO>> page(@PathVariable Long scenicId, @RequestBody OrderReqQuery query) {
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = service.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
if (!account.getScenicId().contains(scenicId)) {
return ApiResponse.fail("无权限查看该景区订单");
}
query.setScenicId(scenicId);
return orderService.pageQueryDetail(query);
}
}

View File

@ -2,6 +2,7 @@ package com.ycwl.basic.controller.pc;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycwl.basic.mapper.ScenicAccountMapper;
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;
@ -16,6 +17,8 @@ import java.util.List;
public class ScenicAccountController {
@Autowired
private ScenicAccountService service;
@Autowired
private ScenicAccountMapper scenicAccountMapper;
// 添加景区账号
@PostMapping("/add")
@ -62,6 +65,10 @@ public class ScenicAccountController {
public ApiResponse<PageInfo<ScenicAccountEntity>> pageQuery(@RequestBody ScenicAccountReqQuery req) {
PageHelper.startPage(req.getPageNum(), req.getPageSize());
List<ScenicAccountEntity> list = service.pageQuery(req);
list.forEach(entity -> {
entity.setPassword("");
entity.setScenicId(scenicAccountMapper.getAccountRelations(entity.getId()));
});
PageInfo<ScenicAccountEntity> pageInfo = new PageInfo<>(list);
return ApiResponse.success(pageInfo);
}

View File

@ -1,12 +1,16 @@
package com.ycwl.basic.controller.pc;
import com.github.pagehelper.PageInfo;
import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.model.mobile.statistic.req.CommonQueryReq;
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
import com.ycwl.basic.model.pc.scenic.req.ScenicAddOrUpdateReq;
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.mobile.AppStatisticsService;
import com.ycwl.basic.service.pc.ScenicAccountService;
import com.ycwl.basic.service.pc.ScenicService;
import com.ycwl.basic.storage.StorageFactory;
import com.ycwl.basic.storage.adapters.IStorageAdapter;
@ -17,12 +21,16 @@ import com.ycwl.basic.repository.ScenicRepository;
import com.ycwl.basic.model.pc.mp.MpConfigEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.util.Collections;
import java.util.List;
import static com.ycwl.basic.constant.JwtRoleConstant.MERCHANT;
/**
* @Author:longbinbin
* @Date:2024/12/3 15:20
@ -34,11 +42,15 @@ public class ScenicController {
@Autowired
private ScenicService scenicService;
@Autowired
private AppScenicService appScenicService;
@Autowired
private ScenicRepository scenicRepository;
@Autowired
private AppStatisticsService appStatisticsService;
@Autowired
private ScenicAccountService accountService;
@ApiOperation("分页查询景区")
@PostMapping("/page")
@ -155,4 +167,22 @@ public class ScenicController {
query.setScenicId(scenicId);
return appStatisticsService.orderChart(query);
}
@GetMapping("/myScenicList")
public ApiResponse<List<ScenicRespVO>> myScenicList() {
List<ScenicRespVO> list = Collections.emptyList();
if (StringUtils.equals(BaseContextHandler.getRoleId(), MERCHANT.type)) {
String userId = BaseContextHandler.getUserId();
ScenicAccountEntity account = accountService.getScenicAccountById(Long.valueOf(userId));
if (account == null || account.getScenicId().isEmpty()) {
return ApiResponse.fail("景区账号未绑定景区");
}
list = account.getScenicId().stream().map(id -> {
return appScenicService.getDetails(id).getData();
}).toList();
} else {
list = scenicService.list(new ScenicReqQuery()).getData();
}
return ApiResponse.success(list);
}
}

View File

@ -19,4 +19,11 @@ public interface ScenicAccountMapper {
ScenicAccountEntity findAccountById(String id);
List<ScenicAccountEntity> pageQuery(ScenicAccountReqQuery req);
int addAccountScenicRelation(Long accountId, Long scenicId, int isAdmin);
int deleteRelationByScenicId(Long scenicId);
List<Long> getAccountRelations(Long accountId);
int deleteRelationById(Long accountId);
}

View File

@ -44,11 +44,6 @@ public class JwtInfo implements Serializable {
private String phone;
/**
* 景区id
*/
private Long scenicId;
/**
* 生成 token 的时间

View File

@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author:longbinbin
* @Date:2024/12/13 9:44
@ -13,7 +15,7 @@ import lombok.Data;
public class ScenicLoginRespVO {
private Long id;
@ApiModelProperty("景区id")
private Long scenicId;
private List<Long> scenicId;
@ApiModelProperty("是否是超级管理员")
private Integer isSuper;
@ApiModelProperty("账号名称")

View File

@ -4,12 +4,13 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
@TableName("scenic_account")
public class ScenicAccountEntity {
private Long id;
private Long scenicId;
private List<Long> scenicId;
private Integer isSuper;
private String name;
private String phone;

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -16,4 +16,6 @@ public interface ScenicAccountService {
List<ScenicAccountEntity> pageQuery(ScenicAccountReqQuery req);
int updateStatus(Long id);
ScenicAccountEntity getScenicAccountByAccount(String account);
}

View File

@ -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());

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -6,11 +6,13 @@ import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.apache.commons.lang3.StringUtils;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
import java.util.Objects;
/**
* @author yangchen
@ -73,15 +75,13 @@ public class JwtAnalysisUtil {
}
Long userId = null;
if (body.get("userId")!=null) {
String strUserId = StringUtil.a(body.get("userId"));
userId= Long.parseLong(strUserId);
userId= Long.parseLong(Objects.requireNonNullElse(body.get("userId"), "").toString());
}
return new JwtInfo(StringUtil.a(body.get("name")),
return new JwtInfo(Objects.requireNonNullElse(body.get("name"), "").toString(),
userId,
StringUtil.a(body.get("roleId")),
Objects.requireNonNullElse(body.get("roleId"), "").toString(),
body.getSubject(),
StringUtil.a(body.get("phone")),
body.get("scenicId") == null ? null : Long.valueOf(body.get("scenicId").toString()),
Objects.requireNonNullElse(body.get("phone"), "").toString(),
expireTime);
}
}

View File

@ -1,11 +0,0 @@
package com.ycwl.basic.utils;
public final class StringUtil {
public StringUtil() {
}
public static String a(Object obj) {
return obj == null ? "" : obj.toString();
}
}

View File

@ -3,19 +3,19 @@
<mapper namespace="com.ycwl.basic.mapper.PermissionMapper">
<!-- 新增插入语句 -->
<insert id="insertPermission">
INSERT INTO permission (user_id, perm_str, create_time, update_time)
INSERT INTO account_permission (user_id, perm_str, create_time, update_time)
VALUES (#{userId}, #{permString}, NOW(), NOW())
</insert>
<!-- 新增更新语句 -->
<update id="updatePermission">
UPDATE permission
UPDATE account_permission
SET perm_str = #{permString}, update_time = NOW()
WHERE user_id = #{userId}
</update>
<select id="selectByUserId" resultType="com.ycwl.basic.model.pc.permission.entity.PermissionEntity">
SELECT id, user_id, perm_str as permString, create_time, update_time
FROM permission
FROM account_permission
WHERE user_id = #{userId}
limit 1
</select>

View File

@ -5,6 +5,10 @@
insert into scenic_account(id, scenic_id, is_super, name, phone, account, password, create_time, update_time)
values (#{id}, #{scenicId}, #{isSuper}, #{name}, #{phone}, #{account}, #{password}, now(), now())
</insert>
<insert id="addAccountScenicRelation">
insert into account_scenic(account_id, scenic_id, is_admin)
values (#{accountId}, #{scenicId}, #{isAdmin})
</insert>
<update id="update">
update scenic_account
<set>
@ -41,11 +45,17 @@
<delete id="deleteByScenicId">
delete from scenic_account where scenic_id = #{scenicId}
</delete>
<delete id="deleteRelationByScenicId">
delete from account_scenic where scenic_id = #{scenicId}
</delete>
<delete id="deleteRelationById">
delete from account_scenic where account_id = #{accountId}
</delete>
<select id="getSuperAccountOfScenic"
resultType="com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity">
select id, scenic_id, is_super, name, phone, account, password, create_time, update_time
from scenic_account
where scenic_id = #{scenicId} and is_super = 1
select a.id, b.scenic_id, b.is_admin as isSuper, a.name, a.phone, a.account, a.password, a.create_time, a.update_time
from scenic_account a left join account_scenic b on a.id = b.account_id
where b.scenic_id = #{scenicId} and b.is_admin = 1
</select>
<select id="getByAccount" resultType="com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity">
select id, scenic_id, is_super, name, phone, account, password, status,create_time, update_time
@ -61,7 +71,7 @@
SELECT * FROM scenic_account
<where>
<if test="scenicId != null">
AND scenic_id = #{scenicId}
AND id in (select account_id from account_scenic where scenic_id = #{scenicId})
</if>
<if test="account != null and account != ''">
AND account LIKE CONCAT('%', #{account}, '%')
@ -84,4 +94,9 @@
</where>
ORDER BY create_time DESC
</select>
<select id="getAccountRelations" resultType="java.lang.Long">
SELECT scenic_id
FROM account_scenic
WHERE account_id = #{scenicId}
</select>
</mapper>