Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
张松 2024-11-21 14:17:56 +08:00
commit 4b5a4544d1
11 changed files with 132 additions and 34 deletions

View File

@ -14,6 +14,7 @@ import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,7 +29,9 @@ import java.util.List;
@EnableWebMvc @EnableWebMvc
public class ConfigurerAdapter implements WebMvcConfigurer { public class ConfigurerAdapter implements WebMvcConfigurer {
/** 文件配置 */ /**
* 文件配置
*/
private final FileProperties properties; private final FileProperties properties;
public ConfigurerAdapter(FileProperties properties) { public ConfigurerAdapter(FileProperties properties) {
@ -50,8 +53,8 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
FileProperties.ElPath path = properties.getPath(); FileProperties.ElPath path = properties.getPath();
String avatarUtl = "file:" + path.getAvatar().replace("\\","/"); String avatarUtl = "file:" + path.getAvatar().replace("\\", "/");
String pathUtl = "file:" + path.getPath().replace("\\","/"); String pathUtl = "file:" + path.getPath().replace("\\", "/");
registry.addResourceHandler("/avatar/**").addResourceLocations(avatarUtl).setCachePeriod(0); registry.addResourceHandler("/avatar/**").addResourceLocations(avatarUtl).setCachePeriod(0);
registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0); registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0);
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0); registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
@ -65,7 +68,7 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
supportMediaTypeList.add(MediaType.APPLICATION_JSON); supportMediaTypeList.add(MediaType.APPLICATION_JSON);
FastJsonConfig config = new FastJsonConfig(); FastJsonConfig config = new FastJsonConfig();
config.setDateFormat("yyyy-MM-dd HH:mm:ss"); config.setDateFormat("yyyy-MM-dd HH:mm:ss");
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue); config.setSerializerFeatures(SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
converter.setFastJsonConfig(config); converter.setFastJsonConfig(config);
converter.setSupportedMediaTypes(supportMediaTypeList); converter.setSupportedMediaTypes(supportMediaTypeList);
converter.setDefaultCharset(StandardCharsets.UTF_8); converter.setDefaultCharset(StandardCharsets.UTF_8);

View File

@ -10,7 +10,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry){ public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new UserInterceptor()); registry.addInterceptor(new UserInterceptor());
} }
} }

View File

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

View File

@ -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 获取鉴权信息
* *

View File

@ -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 /

View File

@ -1,12 +1,15 @@
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.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;
@ -20,6 +23,7 @@ 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 +47,39 @@ 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')") @PostMapping("changChildShop")
// public void exportTbShopInfo(HttpServletResponse response, TbShopInfoQueryCriteria criteria) throws IOException { @ApiOperation("切换子店铺")
// tbShopInfoService.download(tbShopInfoService.queryAll(criteria), response); 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("店铺信息不存在");
}
}
@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")

View File

@ -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;
/** 行业 */ /** 行业 */

View File

@ -1,5 +1,6 @@
package cn.ysk.cashier.mybatis.entity; package cn.ysk.cashier.mybatis.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
@ -106,21 +107,25 @@ public class TbPointsExchangeRecord {
/** /**
* 取消/退款时间 * 取消/退款时间
*/ */
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date cancelOrRefundTime; private Date cancelOrRefundTime;
/** /**
* 实际支付时间 * 实际支付时间
*/ */
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date payTime; private Date payTime;
/** /**
* 创建时间下单时间 * 创建时间下单时间
*/ */
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime; private Date createTime;
/** /**
* 更新时间核销时间 * 更新时间核销时间
*/ */
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime; private Date updateTime;

View File

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

View File

@ -1,8 +1,5 @@
package cn.ysk.cashier.service.impl.shopimpl; package cn.ysk.cashier.service.impl.shopimpl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.ysk.cashier.config.security.security.TokenProvider; import cn.ysk.cashier.config.security.security.TokenProvider;
import cn.ysk.cashier.config.security.service.UserCacheManager; import cn.ysk.cashier.config.security.service.UserCacheManager;
@ -12,13 +9,15 @@ import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
import cn.ysk.cashier.exception.BadRequestException; 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.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;
import cn.ysk.cashier.pojo.shop.TbShopInfo; import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.repository.TbShopPayTypeRepository; import cn.ysk.cashier.repository.TbShopPayTypeRepository;
import cn.ysk.cashier.repository.shop.*; import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository;
import cn.ysk.cashier.repository.shop.TbMerchantRegisterRepository;
import cn.ysk.cashier.repository.shop.TbPlussShopStaffRepository;
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
import cn.ysk.cashier.service.WxService; import cn.ysk.cashier.service.WxService;
import cn.ysk.cashier.service.shop.TbShopInfoService; import cn.ysk.cashier.service.shop.TbShopInfoService;
import cn.ysk.cashier.system.domain.Dept; import cn.ysk.cashier.system.domain.Dept;
@ -31,11 +30,8 @@ import cn.ysk.cashier.system.service.ParamsService;
import cn.ysk.cashier.system.service.UserService; import cn.ysk.cashier.system.service.UserService;
import cn.ysk.cashier.utils.*; import cn.ysk.cashier.utils.*;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -45,12 +41,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
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.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
@ -74,8 +67,6 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
private final UserService userService; private final UserService userService;
private final UserCacheManager userCacheManager;
private final TokenProvider tokenProvider;
private final ParamsService paramsService; private final ParamsService paramsService;
private final TbMerchantRegisterRepository merchantRegisterRepository; private final TbMerchantRegisterRepository merchantRegisterRepository;
@ -129,6 +120,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 +168,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 +206,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 +303,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());

View File

@ -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 /