Merge branch 'dev-门店切换-应用中心' into test
# Conflicts: # eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java
This commit is contained in:
commit
eb6336aa41
|
|
@ -137,6 +137,7 @@ public class AuthorizationController {
|
||||||
put("user", jwtUserDto);
|
put("user", jwtUserDto);
|
||||||
if (byAccount != null) {
|
if (byAccount != null) {
|
||||||
put("shopId", byAccount.getId());
|
put("shopId", byAccount.getId());
|
||||||
|
put("mainId", byAccount.getId());
|
||||||
put("loginType", org.apache.commons.lang3.StringUtils.isNotBlank(authUser.getLoginType())?authUser.getLoginType():"merchant");
|
put("loginType", org.apache.commons.lang3.StringUtils.isNotBlank(authUser.getLoginType())?authUser.getLoginType():"merchant");
|
||||||
put("shopName", byAccount.getShopName());
|
put("shopName", byAccount.getShopName());
|
||||||
put("logo", byAccount.getLogo());
|
put("logo", byAccount.getLogo());
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,16 @@ public class TokenProvider implements InitializingBean {
|
||||||
.compact();
|
.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 获取鉴权信息
|
* 依据Token 获取鉴权信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,19 @@ public class OnlineUserService {
|
||||||
redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000);
|
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 /
|
* @param filter /
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
package cn.ysk.cashier.controller.shop;
|
package cn.ysk.cashier.controller.shop;
|
||||||
|
|
||||||
import cn.ysk.cashier.annotation.Log;
|
import cn.ysk.cashier.annotation.Log;
|
||||||
|
import cn.ysk.cashier.annotation.rest.AnonymousGetMapping;
|
||||||
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
|
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.security.TokenProvider;
|
||||||
import cn.ysk.cashier.config.security.service.OnlineUserService;
|
import cn.ysk.cashier.config.security.service.OnlineUserService;
|
||||||
import cn.ysk.cashier.dto.BindingDto;
|
import cn.ysk.cashier.dto.BindingDto;
|
||||||
|
import cn.ysk.cashier.config.security.service.dto.JwtUserDto;
|
||||||
import cn.ysk.cashier.dto.shop.TbShopInfoDto;
|
import cn.ysk.cashier.dto.shop.TbShopInfoDto;
|
||||||
import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
|
import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
|
||||||
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
||||||
import cn.ysk.cashier.service.shop.TbShopInfoService;
|
import cn.ysk.cashier.service.shop.TbShopInfoService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
|
@ -16,10 +20,15 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
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.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,13 +52,41 @@ public class TbShopInfoController {
|
||||||
public ResponseEntity<Object> binding(@RequestBody BindingDto bindingDto){
|
public ResponseEntity<Object> binding(@RequestBody BindingDto bindingDto){
|
||||||
return new ResponseEntity<>(tbShopInfoService.binding(bindingDto), HttpStatus.OK);
|
return new ResponseEntity<>(tbShopInfoService.binding(bindingDto), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
// @Log("导出数据")
|
|
||||||
// @ApiOperation("导出数据")
|
private final SecurityProperties properties;
|
||||||
// @GetMapping(value = "/download")
|
|
||||||
// @PreAuthorize("@el.check('tbShopInfo:list')")
|
@AnonymousPostMapping("changChildShop")
|
||||||
// public void exportTbShopInfo(HttpServletResponse response, TbShopInfoQueryCriteria criteria) throws IOException {
|
@PostMapping("changChildShop")
|
||||||
// tbShopInfoService.download(tbShopInfoService.queryAll(criteria), response);
|
@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
|
@GetMapping
|
||||||
@ApiOperation("查询/shop/list")
|
@ApiOperation("查询/shop/list")
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ public class TbShopInfoDto implements Serializable {
|
||||||
|
|
||||||
/** 自增id */
|
/** 自增id */
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
private String mainId;
|
||||||
|
|
||||||
/** 店铺帐号 */
|
/** 店铺帐号 */
|
||||||
@NotBlank(message = "店铺账号不能为空")
|
@NotBlank(message = "店铺账号不能为空")
|
||||||
|
|
@ -101,6 +102,8 @@ public class TbShopInfoDto implements Serializable {
|
||||||
/** 未用 */
|
/** 未用 */
|
||||||
private String mchId;
|
private String mchId;
|
||||||
|
|
||||||
|
private Integer tubeType;
|
||||||
|
|
||||||
private String registerType;
|
private String registerType;
|
||||||
|
|
||||||
/** 是否独立的微信小程序 */
|
/** 是否独立的微信小程序 */
|
||||||
|
|
@ -112,7 +115,7 @@ public class TbShopInfoDto implements Serializable {
|
||||||
/** 类似于这种规则51.51.570 */
|
/** 类似于这种规则51.51.570 */
|
||||||
private String city;
|
private String city;
|
||||||
|
|
||||||
/** 店铺类型 超市--MARKET---其它店SHOP */
|
/** 店铺类型 单店--only 连锁店--chain--加盟店join*/
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
/** 行业 */
|
/** 行业 */
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,10 @@ public class TbShopInfo implements Serializable {
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "`main_id`")
|
||||||
|
@ApiModelProperty(value = "总店铺帐号")
|
||||||
|
private String mainId;
|
||||||
|
|
||||||
@Column(name = "`account`")
|
@Column(name = "`account`")
|
||||||
@ApiModelProperty(value = "店铺帐号")
|
@ApiModelProperty(value = "店铺帐号")
|
||||||
private String account;
|
private String account;
|
||||||
|
|
@ -138,9 +142,13 @@ public class TbShopInfo implements Serializable {
|
||||||
private String city;
|
private String city;
|
||||||
|
|
||||||
@Column(name = "`type`")
|
@Column(name = "`type`")
|
||||||
@ApiModelProperty(value = "店铺类型 超市--MARKET---其它店SHOP")
|
@ApiModelProperty(value = "店铺类型 单店--only 连锁店--chain--加盟店join")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
@Column(name = "`tube_type`")
|
||||||
|
@ApiModelProperty(value = "管理 0否 1是")
|
||||||
|
private Integer tubeType;
|
||||||
|
|
||||||
@Column(name = "`industry`")
|
@Column(name = "`industry`")
|
||||||
@ApiModelProperty(value = "行业")
|
@ApiModelProperty(value = "行业")
|
||||||
private String industry;
|
private String industry;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import cn.ysk.cashier.exception.BadRequestException;
|
||||||
import cn.ysk.cashier.exception.EntityNotFoundException;
|
import cn.ysk.cashier.exception.EntityNotFoundException;
|
||||||
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
|
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
|
||||||
import cn.ysk.cashier.mybatis.mapper.MpShopInfoMapper;
|
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.TbMerchantAccount;
|
||||||
import cn.ysk.cashier.pojo.shop.TbMerchantRegister;
|
import cn.ysk.cashier.pojo.shop.TbMerchantRegister;
|
||||||
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
|
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
|
||||||
|
|
@ -46,6 +47,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
@ -129,6 +131,28 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
||||||
return PageUtil.toPage(page);
|
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
|
// @Override
|
||||||
// public List<TbShopInfoDto> queryAll(TbShopInfoQueryCriteria criteria){
|
// public List<TbShopInfoDto> queryAll(TbShopInfoQueryCriteria criteria){
|
||||||
// return tbShopInfoMapper.toDto(tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
// return tbShopInfoMapper.toDto(tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||||
|
|
@ -155,11 +179,6 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
||||||
return tbShopInfo;
|
return tbShopInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TbShopInfoDto finByAccount(String account) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public TbShopInfoDto create(TbShopInfoDto resources) {
|
public TbShopInfoDto create(TbShopInfoDto resources) {
|
||||||
|
|
@ -198,6 +217,15 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
||||||
//向redis中存入key
|
//向redis中存入key
|
||||||
redisUtils.set(CacheKey.ACT_CODE+resources.getAccount(),"1",tbShopInfo.getExpireAt()-Instant.now().toEpochMilli());
|
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);
|
TbShopInfo save = tbShopInfoRepository.save(tbShopInfo);
|
||||||
if (resources.getRegisterCode() != null) {
|
if (resources.getRegisterCode() != null) {
|
||||||
|
|
@ -286,6 +314,13 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(TbShopInfo resources) {
|
public void update(TbShopInfo resources) {
|
||||||
TbShopInfo tbShopInfo = tbShopInfoRepository.findById(resources.getId()).orElseGet(TbShopInfo::new);
|
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())) {
|
if (StringUtils.isNotBlank(resources.getShopName()) && !resources.getShopName().equals(tbShopInfo.getShopName())) {
|
||||||
shopStaffRepository.updateNameById(resources.getShopName(),resources.getId().toString());
|
shopStaffRepository.updateNameById(resources.getShopName(),resources.getId().toString());
|
||||||
userRepository.updateNickName(resources.getAccount(),resources.getShopName());
|
userRepository.updateNickName(resources.getAccount(),resources.getShopName());
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ public interface TbShopInfoService {
|
||||||
*/
|
*/
|
||||||
Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria);
|
Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria);
|
||||||
|
|
||||||
|
List<TbShopInfo> queryChildShop(TbShopInfoQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有数据不分页
|
* 查询所有数据不分页
|
||||||
* @param criteria 条件参数
|
* @param criteria 条件参数
|
||||||
|
|
@ -63,7 +65,6 @@ public interface TbShopInfoService {
|
||||||
TbShopInfoDto findById(Integer id);
|
TbShopInfoDto findById(Integer id);
|
||||||
TbShopInfo findByIdInfo(Integer id);
|
TbShopInfo findByIdInfo(Integer id);
|
||||||
|
|
||||||
TbShopInfoDto finByAccount(String account);
|
|
||||||
/**
|
/**
|
||||||
* 创建
|
* 创建
|
||||||
* @param resources /
|
* @param resources /
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue