日志增加shopId,改动打印机,增加注册时默认四种支付方式
This commit is contained in:
@@ -17,10 +17,10 @@ package cn.ysk.cashier.aspect;
|
||||
|
||||
import cn.ysk.cashier.domain.Log;
|
||||
import cn.ysk.cashier.service.LogService;
|
||||
import cn.ysk.cashier.utils.RequestHolder;
|
||||
import cn.ysk.cashier.utils.SecurityUtils;
|
||||
import cn.ysk.cashier.utils.StringUtils;
|
||||
import cn.ysk.cashier.utils.ThrowableUtil;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@@ -28,6 +28,8 @@ import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -41,6 +43,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
public class LogAspect {
|
||||
|
||||
private final LogService logService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
ThreadLocal<Long> currentTime = new ThreadLocal<>();
|
||||
|
||||
@@ -69,7 +74,16 @@ public class LogAspect {
|
||||
Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get());
|
||||
currentTime.remove();
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log);
|
||||
|
||||
Object o = redisUtils.get("online-token-"+getToken(request));
|
||||
JSONObject jsonObject = null;
|
||||
Integer shopId = null;
|
||||
if (o!= null){
|
||||
String jsonString = JSON.toJSONString(o);
|
||||
jsonObject = JSONObject.parseObject(jsonString);
|
||||
shopId = (Integer)jsonObject.get("shopId");
|
||||
}
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log, shopId);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -85,7 +99,15 @@ public class LogAspect {
|
||||
currentTime.remove();
|
||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log);
|
||||
Object o = redisUtils.get("online-token-"+getToken(request));
|
||||
JSONObject jsonObject = null;
|
||||
Integer shopId = null;
|
||||
if (o!= null){
|
||||
String jsonString = JSON.toJSONString(o);
|
||||
jsonObject = JSONObject.parseObject(jsonString);
|
||||
shopId = (Integer)jsonObject.get("shopId");
|
||||
}
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log, shopId);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@@ -95,4 +117,11 @@ public class LogAspect {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public String getToken(HttpServletRequest request) {
|
||||
final String requestHeader = request.getHeader("Authorization");
|
||||
if (requestHeader != null && requestHeader.startsWith("Bearer")) {
|
||||
return requestHeader.substring(7);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ public class Log implements Serializable {
|
||||
/** 异常详细 */
|
||||
private byte[] exceptionDetail;
|
||||
|
||||
private Integer shopId;
|
||||
|
||||
/** 创建日期 */
|
||||
@CreationTimestamp
|
||||
private Timestamp createTime;
|
||||
|
||||
@@ -63,7 +63,7 @@ public interface LogService {
|
||||
* @param log 日志实体
|
||||
*/
|
||||
@Async
|
||||
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log);
|
||||
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log,Integer shopId);
|
||||
|
||||
/**
|
||||
* 查询异常详情
|
||||
|
||||
@@ -77,7 +77,7 @@ public class LogServiceImpl implements LogService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log) {
|
||||
public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log,Integer shopId) {
|
||||
if (log == null) {
|
||||
throw new IllegalArgumentException("Log 不能为 null!");
|
||||
}
|
||||
@@ -103,6 +103,7 @@ public class LogServiceImpl implements LogService {
|
||||
log.setParams(JSONUtil.toJsonStr(Dict.create().set("username", log.getUsername())));
|
||||
}
|
||||
log.setBrowser(browser);
|
||||
log.setShopId(shopId);
|
||||
logRepository.save(log);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class AuthorizationController {
|
||||
|
||||
}};
|
||||
// 保存在线信息
|
||||
onlineUserService.save(jwtUserDto, token, request);
|
||||
onlineUserService.save(jwtUserDto, token, request,byAccount.getId());
|
||||
|
||||
if (loginProperties.isSingleLogin()) {
|
||||
//踢掉之前已经登录的token
|
||||
@@ -142,7 +142,7 @@ public class AuthorizationController {
|
||||
String token = tokenProvider.createToken(authentication);
|
||||
final JwtUserDto jwtUserDto = (JwtUserDto) authentication.getPrincipal();
|
||||
// 保存在线信息
|
||||
onlineUserService.save(jwtUserDto, token,request);
|
||||
onlineUserService.save(jwtUserDto, token,request,null);
|
||||
// 返回 token 与 用户信息
|
||||
TbShopInfo byAccount = tbShopInfoRepository.findByAccount(jwtUserDto.getUsername());
|
||||
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
|
||||
|
||||
@@ -50,14 +50,14 @@ public class OnlineUserService {
|
||||
* @param token /
|
||||
* @param request /
|
||||
*/
|
||||
public void save(JwtUserDto jwtUserDto, String token, HttpServletRequest request){
|
||||
public void save(JwtUserDto jwtUserDto, String token, HttpServletRequest request,Integer shopId){
|
||||
String dept = jwtUserDto.getUser().getDept().getName();
|
||||
String ip = StringUtils.getIp(request);
|
||||
String browser = StringUtils.getBrowser(request);
|
||||
String address = StringUtils.getCityInfo(ip);
|
||||
OnlineUserDto onlineUserDto = null;
|
||||
try {
|
||||
onlineUserDto = new OnlineUserDto(jwtUserDto.getUsername(), jwtUserDto.getUser().getNickName(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
|
||||
onlineUserDto = new OnlineUserDto(shopId,jwtUserDto.getUsername(), jwtUserDto.getUser().getNickName(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
|
||||
@@ -24,10 +24,13 @@ import java.util.Date;
|
||||
* 在线用户
|
||||
* @author Zheng Jie
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class OnlineUserDto {
|
||||
/**
|
||||
* shopId
|
||||
*/
|
||||
private Integer shopId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
@@ -69,5 +72,80 @@ public class OnlineUserDto {
|
||||
*/
|
||||
private Date loginTime;
|
||||
|
||||
public Integer getShopId() {
|
||||
return shopId;
|
||||
}
|
||||
|
||||
public void setShopId(Integer shopId) {
|
||||
this.shopId = shopId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getDept() {
|
||||
return dept;
|
||||
}
|
||||
|
||||
public void setDept(String dept) {
|
||||
this.dept = dept;
|
||||
}
|
||||
|
||||
public String getBrowser() {
|
||||
return browser;
|
||||
}
|
||||
|
||||
public void setBrowser(String browser) {
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public Date getLoginTime() {
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime(Date loginTime) {
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ public class TbShopCurrencyController {
|
||||
@GetMapping
|
||||
@Log("查询/shop/currency")
|
||||
@ApiOperation("查询/shop/currency")
|
||||
@PreAuthorize("@el.check('tbShopCurrency:list')")
|
||||
public ResponseEntity<Object> queryTbShopCurrency(TbShopCurrencyQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(tbShopCurrencyService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
@@ -62,7 +61,6 @@ public class TbShopCurrencyController {
|
||||
@GetMapping("/{shopId}")
|
||||
@Log("查询/shop/currency/info")
|
||||
@ApiOperation("查询/shop/currency/info")
|
||||
@PreAuthorize("@el.check('tbShopCurrency:info')")
|
||||
public Object queryTbShopCurrencyInfo(@PathVariable("shopId") String shopId){
|
||||
return tbShopCurrencyService.findByShopId(shopId);
|
||||
}
|
||||
@@ -70,7 +68,6 @@ public class TbShopCurrencyController {
|
||||
@PostMapping
|
||||
@Log("新增/shop/currency")
|
||||
@ApiOperation("新增/shop/currency")
|
||||
@PreAuthorize("@el.check('tbShopCurrency:add')")
|
||||
public ResponseEntity<Object> createTbShopCurrency(@Validated @RequestBody TbShopCurrency resources){
|
||||
return new ResponseEntity<>(tbShopCurrencyService.create(resources),HttpStatus.CREATED);
|
||||
}
|
||||
@@ -78,7 +75,6 @@ public class TbShopCurrencyController {
|
||||
@PutMapping
|
||||
@Log("修改/shop/currency")
|
||||
@ApiOperation("修改/shop/currency")
|
||||
@PreAuthorize("@el.check('tbShopCurrency:edit')")
|
||||
public ResponseEntity<Object> updateTbShopCurrency(@Validated @RequestBody TbShopCurrency resources){
|
||||
tbShopCurrencyService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
@@ -87,7 +83,6 @@ public class TbShopCurrencyController {
|
||||
@DeleteMapping
|
||||
@Log("删除/shop/currency")
|
||||
@ApiOperation("删除/shop/currency")
|
||||
@PreAuthorize("@el.check('tbShopCurrency:del')")
|
||||
public ResponseEntity<Object> deleteTbShopCurrency(@RequestBody Integer[] ids) {
|
||||
tbShopCurrencyService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class TbPrintMachineQueryCriteria{
|
||||
|
||||
/** 精确 */
|
||||
@Query
|
||||
private String type;
|
||||
private String contentType;
|
||||
|
||||
@Query
|
||||
private String shopId;
|
||||
|
||||
@@ -18,6 +18,9 @@ package cn.ysk.cashier.repository;
|
||||
import cn.ysk.cashier.pojo.TbShopPayType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
@@ -25,4 +28,41 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
* @date 2023-11-03
|
||||
**/
|
||||
public interface TbShopPayTypeRepository extends JpaRepository<TbShopPayType, Integer>, JpaSpecificationExecutor<TbShopPayType> {
|
||||
@Modifying
|
||||
@Query(value = "INSERT INTO `tb_shop_pay_type` ( shop_id, `pay_type`, `pay_name`, `is_show_shortcut`, `is_refundable`, `is_open_cash_drawer`, `is_system`, `is_ideal`, `is_display`, `icon` )\n" +
|
||||
"VALUES\n" +
|
||||
"\t( :shopId, 'cash', '现金', 1, 0, 1, 0, 1, 1, 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240302/2dab947729d640fba7709b7c0b42bfef.png' ),(\n" +
|
||||
"\t\t:shopId,\n" +
|
||||
"\t\t'bank',\n" +
|
||||
"\t\t'银行卡',\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t0,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t0,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240302/14b20cf721304b7fa2f01e6e75fab403.png' \n" +
|
||||
"\t\t),(:shopId,\n" +
|
||||
"\t\t'scanCode',\n" +
|
||||
"\t\t'扫码支付',\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t0,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t0,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240302/9ff08224680446c8b3978844da99bbaa.png' \n" +
|
||||
"\t\t),(:shopId,\n" +
|
||||
"\t\t'deposit',\n" +
|
||||
"\t\t'储值卡',\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t0,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t0,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t\t1,\n" +
|
||||
"\t'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240302/18d40f471a924d55b4eb13e5f553734d.png' \n" +
|
||||
"\t)",nativeQuery = true)
|
||||
Integer creatPayType(@Param("shopId") String shopId);
|
||||
|
||||
}
|
||||
@@ -26,10 +26,8 @@ import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantRegister;
|
||||
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
||||
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.repository.TbShopPayTypeRepository;
|
||||
import cn.ysk.cashier.repository.shop.*;
|
||||
import cn.ysk.cashier.service.shop.TbShopInfoService;
|
||||
import cn.ysk.cashier.system.domain.Dept;
|
||||
import cn.ysk.cashier.system.domain.Job;
|
||||
@@ -85,6 +83,8 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
||||
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
private final TbShopPayTypeRepository tbShopPayTypeRepository;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria){
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
||||
@@ -215,8 +215,11 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
||||
tbPlussShopStaff.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
tbPlussShopStaff.setCode(save.getPhone());
|
||||
shopStaffRepository.save(tbPlussShopStaff);
|
||||
|
||||
|
||||
//增加默认支付方式
|
||||
Integer integer = tbShopPayTypeRepository.creatPayType(save.getId().toString());
|
||||
if (integer<4){
|
||||
throw new BadRequestException("请重试");
|
||||
}
|
||||
|
||||
return tbShopInfoMapper.toDto(new TbShopInfo());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user