6 Commits

Author SHA1 Message Date
GYJ
33b0c2bb10 员工账号重复校验 2024-11-22 10:10:52 +08:00
GYJ
d7ba8509d5 员工账号重复校验 2024-11-21 14:30:28 +08:00
谭凯凯
7a305e8901 交班bug修复 2024-11-21 11:11:06 +08:00
谭凯凯
6c25d89eb2 交班bug修复 2024-11-21 10:59:53 +08:00
谭凯凯
afed250715 jackson配置 2024-11-21 10:54:10 +08:00
谭凯凯
088d8037b8 jackson配置 2024-11-21 10:22:45 +08:00
12 changed files with 57 additions and 173 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.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -28,7 +29,9 @@ import java.util.List;
@EnableWebMvc
public class ConfigurerAdapter implements WebMvcConfigurer {
/** 文件配置 */
/**
* 文件配置
*/
private final FileProperties properties;
public ConfigurerAdapter(FileProperties properties) {
@@ -50,8 +53,8 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
FileProperties.ElPath path = properties.getPath();
String avatarUtl = "file:" + path.getAvatar().replace("\\","/");
String pathUtl = "file:" + path.getPath().replace("\\","/");
String avatarUtl = "file:" + path.getAvatar().replace("\\", "/");
String pathUtl = "file:" + path.getPath().replace("\\", "/");
registry.addResourceHandler("/avatar/**").addResourceLocations(avatarUtl).setCachePeriod(0);
registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).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);
FastJsonConfig config = new FastJsonConfig();
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue);
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
converter.setFastJsonConfig(config);
converter.setSupportedMediaTypes(supportMediaTypeList);
converter.setDefaultCharset(StandardCharsets.UTF_8);

View File

@@ -1,44 +1,16 @@
package cn.ysk.cashier.config.interceptor;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
/**
* @author lyf
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry){
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new UserInterceptor());
}
@Bean
public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper mapper = new ObjectMapper();
//忽略未知属性
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//日期格式转换
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
mapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
//Long类型转String类型
//SimpleModule simpleModule = new SimpleModule();
//simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
//simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
//mapper.registerModule(simpleModule);
converter.setObjectMapper(mapper);
return converter;
}
}

View File

@@ -137,7 +137,6 @@ 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,16 +73,6 @@ 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,19 +50,6 @@ 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,15 +1,11 @@
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;
@@ -19,15 +15,10 @@ 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;
/**
@@ -45,40 +36,14 @@ public class TbShopInfoController {
private final TbShopInfoService tbShopInfoService;
private final OnlineUserService onlineUserService;
private final TokenProvider tokenProvider;
private final SecurityProperties properties;
@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);
}
// @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);
// }
@GetMapping
@ApiOperation("查询/shop/list")

View File

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

View File

@@ -1,5 +1,6 @@
package cn.ysk.cashier.mybatis.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
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")
private Date cancelOrRefundTime;
/**
* 实际支付时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date payTime;
/**
* 创建时间(下单时间)
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* 更新时间(核销时间)
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;

View File

@@ -41,10 +41,6 @@ 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;
@@ -142,13 +138,9 @@ public class TbShopInfo implements Serializable {
private String city;
@Column(name = "`type`")
@ApiModelProperty(value = "店铺类型 单店--only 连锁店--chain--加盟店join")
@ApiModelProperty(value = "店铺类型 超市--MARKET---其它店SHOP")
private String type;
@Column(name = "`tube_type`")
@ApiModelProperty(value = "管理 0否 1是")
private Integer tubeType;
@Column(name = "`industry`")
@ApiModelProperty(value = "行业")
private String industry;

View File

@@ -104,27 +104,8 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
@Override
@Transactional(rollbackFor = Exception.class)
public TbPlussShopStaffDto create(TbPlussShopStaff resources) {
if (org.apache.commons.lang3.StringUtils.isBlank(resources.getAccount())) {
throw new BadRequestException("员工账号为空");
}
if (userRepository.findByUsername(resources.getShopId()+"@"+resources.getAccount()) != null) {
throw new BadRequestException("员工账号已存在");
}
if (!PhoneUtil.validator(resources.getPhone())){
throw new BadRequestException("手机号格式有误");
}
checkStaffParams(resources);
if (pattern.matcher(resources.getCode()).find()) {
throw new BadRequestException("员工编号不能包含中文");
}
if (resources.getRoleId()==null) {
throw new BadRequestException("请选择角色");
}
if (resources.getMaxDiscountAmount().compareTo(new BigDecimal(100000000L)) > 0) {
throw new BadRequestException("最大优惠金额过大");
}
resources.setCreatedAt(Instant.now().toEpochMilli());
//添加收银系统后台账号
@@ -175,6 +156,7 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
if (pattern.matcher(resources.getCode()).find()) {
throw new BadRequestException("员工编号不能包含中文");
}
TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffRepository.findById(resources.getId()).orElseGet(TbPlussShopStaff::new);
User sysUser = userRepository.findByUsername(resources.getShopId()+"@"+tbPlussShopStaff.getAccount());
if(!tbPlussShopStaff.getAccount().equals(resources.getAccount())){
@@ -207,6 +189,33 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
Integer.valueOf(resources.getShopId()), resources.getId(), resources.getPermissions());
}
private void checkStaffParams(TbPlussShopStaff resources) {
if (StringUtils.isBlank(resources.getAccount())) {
throw new BadRequestException("员工账号为空");
}
if (userRepository.findByUsername(resources.getShopId()+"@"+resources.getAccount()) != null) {
throw new BadRequestException("员工账号已存在");
}
if (!PhoneUtil.validator(resources.getPhone())){
throw new BadRequestException("手机号格式有误");
}
if (tbPlussShopStaffRepository.queryByAccount(resources.getAccount(),resources.getShopId()) != null) {
throw new BadRequestException("账号已存在");
}
if (pattern.matcher(resources.getCode()).find()) {
throw new BadRequestException("员工编号不能包含中文");
}
if (resources.getRoleId()==null) {
throw new BadRequestException("请选择角色");
}
if (resources.getMaxDiscountAmount().compareTo(new BigDecimal(100000000L)) > 0) {
throw new BadRequestException("最大优惠金额过大");
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateStatus(TbPlussShopStaff resources) {

View File

@@ -11,7 +11,6 @@ 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;
@@ -44,7 +43,6 @@ 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;
@@ -96,25 +94,6 @@ 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")
);
Predicate predicate = criteriaBuilder.or(
query1,
query2
);
criteriaBuilder.desc(root.get("tubeType"));
return predicate;
});
return list;
}
// @Override
// public List<TbShopInfoDto> queryAll(TbShopInfoQueryCriteria criteria){
// return tbShopInfoMapper.toDto(tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
@@ -141,6 +120,11 @@ 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) {
@@ -179,16 +163,6 @@ 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.setTubeType(1);
}
//增加商户详情
TbShopInfo save = tbShopInfoRepository.save(tbShopInfo);
if (resources.getRegisterCode() != null) {
@@ -277,14 +251,6 @@ 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);
tbShopInfo.setTubeType(1);
}
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,8 +39,6 @@ public interface TbShopInfoService {
*/
Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria);
List<TbShopInfo> queryChildShop(TbShopInfoQueryCriteria criteria);
/**
* 查询所有数据不分页
* @param criteria 条件参数
@@ -56,6 +54,7 @@ public interface TbShopInfoService {
TbShopInfoDto findById(Integer id);
TbShopInfo findByIdInfo(Integer id);
TbShopInfoDto finByAccount(String account);
/**
* 创建
* @param resources /