增加根据管理员id查询门店接口
This commit is contained in:
@ -1,9 +1,19 @@
|
|||||||
package com.sczx.store.controller;
|
package com.sczx.store.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.sczx.store.common.Result;
|
||||||
|
import com.sczx.store.dto.CompanyStoreDTO;
|
||||||
|
import com.sczx.store.dto.SimpleUserInfoDTO;
|
||||||
|
import com.sczx.store.dto.req.StoreDistanceReq;
|
||||||
|
import com.sczx.store.service.StoreService;
|
||||||
|
import com.sczx.store.util.JwtUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -15,7 +25,23 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
*/
|
*/
|
||||||
@Api(value = "门店管理端接口", produces = "管理端接口")
|
@Api(value = "门店管理端接口", produces = "管理端接口")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/client")
|
@RequestMapping("/store")
|
||||||
public class StoreManageController {
|
public class StoreManageController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StoreService storeService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JwtUtil jwtUtil;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "根据管理员信息获取门店列表")
|
||||||
|
@PostMapping("/listStoresByManage")
|
||||||
|
public Result<List<CompanyStoreDTO>> listStoresByManage(@RequestParam(value = "managerId", required = false) Integer managerId){
|
||||||
|
if (managerId == null ) {
|
||||||
|
SimpleUserInfoDTO simpleUserInfoDTO = jwtUtil.getUserInfoFromToken();
|
||||||
|
managerId = simpleUserInfoDTO.getUserId();
|
||||||
|
}
|
||||||
|
return Result.ok(storeService.listStoresByManage(managerId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/main/java/com/sczx/store/dto/SimpleUserInfoDTO.java
Normal file
29
src/main/java/com/sczx/store/dto/SimpleUserInfoDTO.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.sczx.store.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@ApiModel(value = "基本用户信息")
|
||||||
|
@Data
|
||||||
|
public class SimpleUserInfoDTO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户id")
|
||||||
|
private Integer userId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户姓名")
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "手机号")
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色id")
|
||||||
|
private Integer roleId;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "小程序类型")
|
||||||
|
private String miniProgramType;
|
||||||
|
|
||||||
|
@ApiModelProperty("头像")
|
||||||
|
private String avatarUrl;
|
||||||
|
}
|
||||||
@ -20,4 +20,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface CompanyStoreMapper extends BaseMapper<CompanyStorePO> {
|
public interface CompanyStoreMapper extends BaseMapper<CompanyStorePO> {
|
||||||
IPage<CompanyStoreDTO> listStoresByBBoxWithDistance(Page<CompanyStoreDTO> page, @Param("storeDistanceReq") StoreDistanceReq storeDistanceReq);
|
IPage<CompanyStoreDTO> listStoresByBBoxWithDistance(Page<CompanyStoreDTO> page, @Param("storeDistanceReq") StoreDistanceReq storeDistanceReq);
|
||||||
|
|
||||||
|
List<CompanyStoreDTO> listStoresByManage(@Param("managerId") Integer managerId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,4 +19,6 @@ import java.util.List;
|
|||||||
public interface CompanyStoreRepo extends IService<CompanyStorePO> {
|
public interface CompanyStoreRepo extends IService<CompanyStorePO> {
|
||||||
|
|
||||||
IPage<CompanyStoreDTO> listStoresByBBoxWithDistance(StoreDistanceReq storeDistanceReq,Integer pageNo, Integer pageSize);
|
IPage<CompanyStoreDTO> listStoresByBBoxWithDistance(StoreDistanceReq storeDistanceReq,Integer pageNo, Integer pageSize);
|
||||||
|
|
||||||
|
List<CompanyStoreDTO> listStoresByManage(Integer managerId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,4 +30,9 @@ public class CompanyStoreRepoImpl extends ServiceImpl<CompanyStoreMapper, Compan
|
|||||||
Page<CompanyStoreDTO> page = new Page<>(pageNo, pageSize);
|
Page<CompanyStoreDTO> page = new Page<>(pageNo, pageSize);
|
||||||
return this.getBaseMapper().listStoresByBBoxWithDistance(page, storeDistanceReq);
|
return this.getBaseMapper().listStoresByBBoxWithDistance(page, storeDistanceReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CompanyStoreDTO> listStoresByManage(Integer managerId) {
|
||||||
|
return this.getBaseMapper().listStoresByManage(managerId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.sczx.store.dto.CompanyStoreDTO;
|
import com.sczx.store.dto.CompanyStoreDTO;
|
||||||
import com.sczx.store.dto.req.StoreDistanceReq;
|
import com.sczx.store.dto.req.StoreDistanceReq;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public interface StoreService {
|
public interface StoreService {
|
||||||
/**
|
/**
|
||||||
@ -21,4 +23,12 @@ public interface StoreService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
CompanyStoreDTO getStoreById(Integer id);
|
CompanyStoreDTO getStoreById(Integer id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据管理员id获取门店信息
|
||||||
|
* @param managerId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<CompanyStoreDTO> listStoresByManage(Integer managerId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,16 +3,23 @@ package com.sczx.store.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.sczx.store.convert.StoreConvert;
|
import com.sczx.store.convert.StoreConvert;
|
||||||
import com.sczx.store.dto.CompanyStoreDTO;
|
import com.sczx.store.dto.CompanyStoreDTO;
|
||||||
|
import com.sczx.store.dto.SimpleUserInfoDTO;
|
||||||
import com.sczx.store.dto.req.StoreDistanceReq;
|
import com.sczx.store.dto.req.StoreDistanceReq;
|
||||||
import com.sczx.store.po.CompanyStorePO;
|
import com.sczx.store.po.CompanyStorePO;
|
||||||
import com.sczx.store.repository.CompanyStoreRepo;
|
import com.sczx.store.repository.CompanyStoreRepo;
|
||||||
import com.sczx.store.service.StoreService;
|
import com.sczx.store.service.StoreService;
|
||||||
|
import com.sczx.store.util.JwtUtil;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class StoreServiceImpl implements StoreService {
|
public class StoreServiceImpl implements StoreService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CompanyStoreRepo companyStoreRepo;
|
private CompanyStoreRepo companyStoreRepo;
|
||||||
@Override
|
@Override
|
||||||
@ -28,4 +35,10 @@ public class StoreServiceImpl implements StoreService {
|
|||||||
|
|
||||||
return StoreConvert.INSTANCE.poToDTO(companyStorePO);
|
return StoreConvert.INSTANCE.poToDTO(companyStorePO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CompanyStoreDTO> listStoresByManage(Integer managerId) {
|
||||||
|
|
||||||
|
return companyStoreRepo.listStoresByManage(managerId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package com.sczx.store.util;
|
package com.sczx.store.util;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.sczx.store.dto.SimpleUserInfoDTO;
|
||||||
import io.jsonwebtoken.JwtException;
|
import io.jsonwebtoken.JwtException;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
@ -7,9 +10,13 @@ import io.jsonwebtoken.security.Keys;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 张黎
|
* @Author: 张黎
|
||||||
@ -31,15 +38,37 @@ public class JwtUtil {
|
|||||||
log.info("JWT 密钥:{}", secretKey);
|
log.info("JWT 密钥:{}", secretKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateToken(String username, String role) {
|
public String generateToken(SimpleUserInfoDTO simpleUserInfoDTO, String subject){
|
||||||
|
Map<String, Object> claims = Maps.newHashMap();
|
||||||
|
claims.put("userInfo", simpleUserInfoDTO.getUserId());
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.setSubject(username)
|
.setClaims(claims) // 设置自定义 claims
|
||||||
.claim("role", role)
|
.setSubject(subject)
|
||||||
.setExpiration(new Date(System.currentTimeMillis() + expiration))
|
.setExpiration(new Date(System.currentTimeMillis() + expiration))
|
||||||
.signWith(key, SignatureAlgorithm.HS512)
|
.signWith(key, SignatureAlgorithm.HS512)
|
||||||
.compact();
|
.compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从 token 中提取某个字段
|
||||||
|
public <T> T getClaim(String token, String claimKey, Class<T> clazz) {
|
||||||
|
return Jwts.parserBuilder()
|
||||||
|
.setSigningKey(key)
|
||||||
|
.build()
|
||||||
|
.parseClaimsJws(token)
|
||||||
|
.getBody()
|
||||||
|
.get(claimKey, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从 token 中提取某个对象类型的字段(支持复杂对象)
|
||||||
|
public <T> T getClaimFromToken(String token, String claimKey, Class<T> targetClass) {
|
||||||
|
return Jwts.parserBuilder()
|
||||||
|
.setSigningKey(key)
|
||||||
|
.build()
|
||||||
|
.parseClaimsJws(token)
|
||||||
|
.getBody()
|
||||||
|
.get(claimKey, targetClass);
|
||||||
|
}
|
||||||
|
|
||||||
public String extractUsername(String token) {
|
public String extractUsername(String token) {
|
||||||
return Jwts.parserBuilder()
|
return Jwts.parserBuilder()
|
||||||
.setSigningKey(key)
|
.setSigningKey(key)
|
||||||
@ -60,4 +89,35 @@ public class JwtUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HttpServletRequest getCurrentRequest() {
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
return attributes != null ? attributes.getRequest() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前请求的Authorization头内容
|
||||||
|
* @return Authorization头的值,如果不存在则返回null
|
||||||
|
*/
|
||||||
|
public String getAuthorizationHeader() {
|
||||||
|
HttpServletRequest request = getCurrentRequest();
|
||||||
|
return request != null ? request.getHeader("Authorization") : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从token中获取用户信息
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
public SimpleUserInfoDTO getUserInfoFromToken() {
|
||||||
|
String authHeader = getAuthorizationHeader();
|
||||||
|
log.info("token:{}",authHeader);
|
||||||
|
if (authHeader != null && authHeader.startsWith("Bearer ")) {
|
||||||
|
String token = authHeader.substring(7);
|
||||||
|
String userInfoJson = getClaim(token, "userInfo", String.class);
|
||||||
|
// 进行token验证等操作
|
||||||
|
return JSONObject.parseObject(userInfoJson, SimpleUserInfoDTO.class);
|
||||||
|
}else {
|
||||||
|
throw new RuntimeException("token不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,4 +58,37 @@
|
|||||||
|
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="listStoresByManage" resultType="com.sczx.store.dto.CompanyStoreDTO">
|
||||||
|
SELECT
|
||||||
|
t.id,
|
||||||
|
t.name,
|
||||||
|
t.contact_person,
|
||||||
|
t.phone,
|
||||||
|
t.contact_person2,
|
||||||
|
t.phone2,
|
||||||
|
t.province_id,
|
||||||
|
t.province_name,
|
||||||
|
t.city_id,
|
||||||
|
t.city_name,
|
||||||
|
t.area_id,
|
||||||
|
t.area_name,
|
||||||
|
t.address,
|
||||||
|
t.detailed_address,
|
||||||
|
t.image,
|
||||||
|
t.latitude,
|
||||||
|
t.longitude,
|
||||||
|
t.day_time,
|
||||||
|
t.start_time,
|
||||||
|
t.end_time,
|
||||||
|
t.label,
|
||||||
|
t.status
|
||||||
|
FROM
|
||||||
|
zc_company_store t
|
||||||
|
JOIN
|
||||||
|
zc_base_user_store s
|
||||||
|
ON t.id = s.store_id
|
||||||
|
WHERE
|
||||||
|
s.user_id = #{managerId}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user