多门店 列表/切换

This commit is contained in:
2024-11-21 14:12:35 +08:00
parent b74e455f5d
commit b233f6ea21
8 changed files with 121 additions and 15 deletions

View File

@@ -137,6 +137,7 @@ public class AuthorizationController {
put("user", jwtUserDto);
if (byAccount != null) {
put("shopId", byAccount.getId());
put("mainId", byAccount.getId());
put("loginType", org.apache.commons.lang3.StringUtils.isNotBlank(authUser.getLoginType())?authUser.getLoginType():"merchant");
put("shopName", byAccount.getShopName());
put("logo", byAccount.getLogo());

View File

@@ -73,6 +73,16 @@ public class TokenProvider implements InitializingBean {
.compact();
}
public String createToken(String name,String shopId) {
return jwtBuilder
// 加入ID确保生成的 Token 都不一致
.setId(IdUtil.simpleUUID())
.claim(AUTHORITIES_KEY, name)
.claim("shopId",shopId)
.setSubject(name)
.compact();
}
/**
* 依据Token 获取鉴权信息
*

View File

@@ -50,6 +50,19 @@ public class OnlineUserService {
redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000);
}
public void save(String username, String nickName, String token, HttpServletRequest request,Integer shopId){
String ip = StringUtils.getIp(request);
String browser = StringUtils.getBrowser(request);
String address = StringUtils.getCityInfo(ip);
OnlineUserDto onlineUserDto = null;
try {
onlineUserDto = new OnlineUserDto(shopId,username, nickName, null, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
} catch (Exception e) {
log.error(e.getMessage(),e);
}
redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000);
}
/**
* 查询全部数据
* @param filter /

View File

@@ -1,11 +1,15 @@
package cn.ysk.cashier.controller.shop;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.annotation.rest.AnonymousGetMapping;
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.config.security.config.bean.SecurityProperties;
import cn.ysk.cashier.config.security.security.TokenProvider;
import cn.ysk.cashier.config.security.service.OnlineUserService;
import cn.ysk.cashier.config.security.service.dto.JwtUserDto;
import cn.ysk.cashier.dto.shop.TbShopInfoDto;
import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.service.shop.TbShopInfoService;
import io.swagger.annotations.Api;
@@ -15,10 +19,15 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
@@ -36,14 +45,40 @@ public class TbShopInfoController {
private final TbShopInfoService tbShopInfoService;
private final OnlineUserService onlineUserService;
private final TokenProvider tokenProvider;
private final SecurityProperties properties;
// @Log("导出数据")
// @ApiOperation("导出数据")
// @GetMapping(value = "/download")
// @PreAuthorize("@el.check('tbShopInfo:list')")
// public void exportTbShopInfo(HttpServletResponse response, TbShopInfoQueryCriteria criteria) throws IOException {
// tbShopInfoService.download(tbShopInfoService.queryAll(criteria), response);
// }
@AnonymousPostMapping("changChildShop")
@PostMapping("changChildShop")
@ApiOperation("切换子店铺")
public ResponseEntity<Object> changChildShop(@RequestBody TbShopInfoQueryCriteria criteria, HttpServletRequest request) {
TbShopInfoDto shopInfo = tbShopInfoService.findById(criteria.getId());
if (shopInfo != null) {
//生成token
String token = tokenProvider.createToken(shopInfo.getAccount(), criteria.getId().toString());
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
put("token", properties.getTokenStartWith() + token);
if (shopInfo != null) {
put("shopId", shopInfo.getId());
put("mainId", shopInfo.getMainId());
put("loginType", "merchant");
put("shopName", shopInfo.getShopName());
put("logo", shopInfo.getLogo());
}
}};
// 保存在线信息
onlineUserService.save(shopInfo.getAccount(), shopInfo.getShopName(), token, request, shopInfo.getId());
return ResponseEntity.ok(authInfo);
} else {
throw new BadRequestException("店铺信息不存在");
}
}
@AnonymousGetMapping("queryChildShop")
@GetMapping("queryChildShop")
@ApiOperation("查询子店铺")
public ResponseEntity<Object> queryChildShop(TbShopInfoQueryCriteria criteria){
return new ResponseEntity<>(tbShopInfoService.queryChildShop(criteria),HttpStatus.OK);
}
@GetMapping
@ApiOperation("查询/shop/list")

View File

@@ -37,6 +37,7 @@ public class TbShopInfoDto implements Serializable {
/** 自增id */
private Integer id;
private String mainId;
/** 店铺帐号 */
@NotBlank(message = "店铺账号不能为空")
@@ -101,6 +102,8 @@ public class TbShopInfoDto implements Serializable {
/** 未用 */
private String mchId;
private Integer tubeType;
private String registerType;
/** 是否独立的微信小程序 */
@@ -112,7 +115,7 @@ public class TbShopInfoDto implements Serializable {
/** 类似于这种规则51.51.570 */
private String city;
/** 店铺类型 超市--MARKET---其它店SHOP */
/** 店铺类型 单店--only 连锁店--chain--加盟店join*/
private String type;
/** 行业 */

View File

@@ -41,6 +41,10 @@ public class TbShopInfo implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "`main_id`")
@ApiModelProperty(value = "总店铺帐号")
private String mainId;
@Column(name = "`account`")
@ApiModelProperty(value = "店铺帐号")
private String account;
@@ -138,9 +142,13 @@ public class TbShopInfo implements Serializable {
private String city;
@Column(name = "`type`")
@ApiModelProperty(value = "店铺类型 超市--MARKET---其它店SHOP")
@ApiModelProperty(value = "店铺类型 单店--only 连锁店--chain--加盟店join")
private String type;
@Column(name = "`tube_type`")
@ApiModelProperty(value = "管理 0否 1是")
private Integer tubeType;
@Column(name = "`industry`")
@ApiModelProperty(value = "行业")
private String industry;

View File

@@ -11,6 +11,7 @@ import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.exception.EntityNotFoundException;
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
import cn.ysk.cashier.mybatis.mapper.MpShopInfoMapper;
import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
import cn.ysk.cashier.pojo.shop.TbMerchantRegister;
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
@@ -43,6 +44,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -94,6 +96,28 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
return PageUtil.toPage(page);
}
@Override
public List<TbShopInfo> queryChildShop(TbShopInfoQueryCriteria criteria){
List<TbShopInfo> list = tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
Predicate query1 = criteriaBuilder.equal(root.get("id"), criteria.getId());
Predicate query2 = criteriaBuilder.and(
criteriaBuilder.equal(root.get("mainId"), criteria.getId()),
criteriaBuilder.notEqual(root.get("type"), "only"),
criteriaBuilder.equal(root.get("tubeType"), 1)
);
// 再将两个子条件进行或运算组合成最终条件
Predicate predicate = criteriaBuilder.or(
query1,
query2
);
return predicate;
});
return list;
}
// @Override
// public List<TbShopInfoDto> queryAll(TbShopInfoQueryCriteria criteria){
// return tbShopInfoMapper.toDto(tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
@@ -120,11 +144,6 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
return tbShopInfo;
}
@Override
public TbShopInfoDto finByAccount(String account) {
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public TbShopInfoDto create(TbShopInfoDto resources) {
@@ -163,6 +182,15 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
//向redis中存入key
redisUtils.set(CacheKey.ACT_CODE+resources.getAccount(),"1",tbShopInfo.getExpireAt()-Instant.now().toEpochMilli());
}
if(org.apache.commons.lang3.StringUtils.isNotBlank(resources.getType()) && !"only".equals(resources.getType())){
if(resources.getMainId() == null){
throw new BadRequestException("连锁店或者扩展店 主店铺不能为空");
}
}else {
tbShopInfo.setMainId(null);
}
//增加商户详情
TbShopInfo save = tbShopInfoRepository.save(tbShopInfo);
if (resources.getRegisterCode() != null) {
@@ -251,6 +279,13 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
@Transactional(rollbackFor = Exception.class)
public void update(TbShopInfo resources) {
TbShopInfo tbShopInfo = tbShopInfoRepository.findById(resources.getId()).orElseGet(TbShopInfo::new);
if(org.apache.commons.lang3.StringUtils.isNotBlank(resources.getType()) && !"only".equals(resources.getType())){
if(resources.getMainId() == null){
throw new BadRequestException("连锁店或者扩展店 主店铺不能为空");
}
}else {
tbShopInfo.setMainId(null);
}
if (StringUtils.isNotBlank(resources.getShopName()) && !resources.getShopName().equals(tbShopInfo.getShopName())) {
shopStaffRepository.updateNameById(resources.getShopName(),resources.getId().toString());
userRepository.updateNickName(resources.getAccount(),resources.getShopName());

View File

@@ -39,6 +39,8 @@ public interface TbShopInfoService {
*/
Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria);
List<TbShopInfo> queryChildShop(TbShopInfoQueryCriteria criteria);
/**
* 查询所有数据不分页
* @param criteria 条件参数
@@ -54,7 +56,6 @@ public interface TbShopInfoService {
TbShopInfoDto findById(Integer id);
TbShopInfo findByIdInfo(Integer id);
TbShopInfoDto finByAccount(String account);
/**
* 创建
* @param resources /