yshop1.6.1发布:新增移动端浏览记录,下单增加简单ReentrantLock锁

This commit is contained in:
hupeng
2019-12-26 16:06:09 +08:00
parent 517249e0e1
commit f8a6703dfa
22 changed files with 179 additions and 3501 deletions

File diff suppressed because one or more lines are too long

View File

@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.http.HttpUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.param.IdParam;
@ -93,6 +94,7 @@ public class StoreBargainController extends BaseController {
/**
* 砍价详情
*/
@Log(value = "查看砍价产品",type = 1)
@GetMapping("/bargain/detail/{id}")
@ApiOperation(value = "砍价详情",notes = "砍价详情",response = YxStoreBargainQueryVo.class)
public ApiResult<YxStoreBargainQueryVo> getYxStoreBargain(@PathVariable Integer id){
@ -326,7 +328,7 @@ public class StoreBargainController extends BaseController {
//第一步标题
Font font = Font.createFont(Font.TRUETYPE_FONT, newFileT);
Font f= font.deriveFont(Font.PLAIN,40);
Font f= font.deriveFont(Font.PLAIN,30);
//font.
ImgUtil.pressText(//
newFile,
@ -444,6 +446,7 @@ public class StoreBargainController extends BaseController {
/**
* 砍价取消
*/
@Log(value = "取消砍价产品",type = 1)
@PostMapping("/bargain/user/cancel")
@ApiOperation(value = "砍价取消",notes = "砍价取消")
public ApiResult<Object> bargainCancel(@RequestBody String jsonStr){

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.http.HttpUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.param.IdParam;
@ -81,6 +82,7 @@ public class StoreCombinationController extends BaseController {
/**
* 拼团产品详情
*/
@Log(value = "查看拼团产品",type = 1)
@GetMapping("/combination/detail/{id}")
@ApiOperation(value = "拼团产品详情",notes = "拼团产品详情",response = YxStoreCombinationQueryVo.class)
public ApiResult<Object> detail(@PathVariable Integer id){
@ -268,6 +270,7 @@ public class StoreCombinationController extends BaseController {
/**
* 取消开团
*/
@Log(value = "取消开团",type = 1)
@PostMapping("/combination/remove")
@ApiOperation(value = "取消开团",notes = "取消开团")
public ApiResult<Object> remove(@RequestBody String jsonStr){

View File

@ -3,6 +3,7 @@ package co.yixiang.modules.activity.web.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.modules.activity.service.YxStoreSeckillService;
import co.yixiang.modules.activity.web.dto.SeckillConfigDTO;
import co.yixiang.modules.activity.web.dto.SeckillTimeDTO;

View File

@ -2,6 +2,7 @@ package co.yixiang.modules.order.web.controller;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.param.IdParam;
@ -45,6 +46,8 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* <p>
@ -73,6 +76,8 @@ public class StoreOrderController extends BaseController {
private final ExpressService expressService;
private final YxStoreBargainUserService storeBargainUserService;
private static Lock lock = new ReentrantLock(false);
/**
* 订单确认
@ -204,7 +209,14 @@ public class StoreOrderController extends BaseController {
if(param.getFrom().equals("weixin")) param.setIsChannel(0);
//创建订单
YxStoreOrder order = storeOrderService.createOrder(uid,key,param);
YxStoreOrder order = null;
try{
lock.lock();
order = storeOrderService.createOrder(uid,key,param);
}finally {
lock.unlock();
}
if(ObjectUtil.isNull(order)) throw new ErrorRequestException("订单生成失败");
@ -262,6 +274,7 @@ public class StoreOrderController extends BaseController {
/**
* 订单支付
*/
@Log(value = "订单支付",type = 1)
@PostMapping("/order/pay")
@ApiOperation(value = "订单支付",notes = "订单支付")
public ApiResult<ConfirmOrderDTO> pay(@Valid @RequestBody PayParam param){
@ -333,6 +346,7 @@ public class StoreOrderController extends BaseController {
/**
* 订单列表
*/
@Log(value = "查看订单列表",type = 1)
@GetMapping("/order/list")
@ApiOperation(value = "订单列表",notes = "订单列表")
public ApiResult<List<YxStoreOrderQueryVo>> orderList(@RequestParam(value = "type",defaultValue = "0") int type,
@ -347,6 +361,7 @@ public class StoreOrderController extends BaseController {
/**
* 订单详情
*/
@Log(value = "查看订单详情",type = 1)
@GetMapping("/order/detail/{key}")
@ApiOperation(value = "订单详情",notes = "订单详情")
public ApiResult<YxStoreOrderQueryVo> detail(@PathVariable String key){
@ -430,6 +445,7 @@ public class StoreOrderController extends BaseController {
/**
* 订单收货
*/
@Log(value = "订单收货",type = 1)
@PostMapping("/order/take")
@ApiOperation(value = "订单收货",notes = "订单收货")
public ApiResult<Object> orderTake(@RequestBody String jsonStr){
@ -490,6 +506,7 @@ public class StoreOrderController extends BaseController {
/**
* 订单评价
*/
@Log(value = "评价商品",type = 1)
@PostMapping("/order/comment")
@ApiOperation(value = "订单评价",notes = "订单评价")
public ApiResult<Object> comment(@Valid @RequestBody YxStoreProductReply productReply){
@ -561,6 +578,7 @@ public class StoreOrderController extends BaseController {
/**
* 订单退款审核
*/
@Log(value = "提交订单退款",type = 1)
@PostMapping("/order/refund/verify")
@ApiOperation(value = "订单退款审核",notes = "订单退款审核")
public ApiResult<Object> refundVerify(@RequestBody RefundParam param){
@ -572,6 +590,7 @@ public class StoreOrderController extends BaseController {
/**
* 订单取消 未支付的订单回退积分,回退优惠券,回退库存
*/
@Log(value = "取消订单",type = 1)
@PostMapping("/order/cancel")
@ApiOperation(value = "订单取消",notes = "订单取消")
public ApiResult<Object> cancelOrder(@RequestBody String jsonStr){

View File

@ -1,6 +1,7 @@
package co.yixiang.modules.shop.web.controller;
import cn.hutool.core.util.ObjectUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.vo.Paging;
@ -43,6 +44,7 @@ public class CouponController extends BaseController {
/**
* 可领取优惠券列表
*/
@Log(value = "查看优惠券",type = 1)
@GetMapping("/coupons")
@ApiOperation(value = "可领取优惠券列表",notes = "可领取优惠券列表")
public ApiResult<Object> getList(
@ -57,6 +59,7 @@ public class CouponController extends BaseController {
/**
* 领取优惠券
*/
@Log(value = "领取优惠券",type = 1)
@PostMapping("/coupon/receive")
@ApiOperation(value = "领取优惠券",notes = "领取优惠券")
public ApiResult<Object> receive(@RequestBody String jsonStr){

View File

@ -1,6 +1,7 @@
package co.yixiang.modules.shop.web.controller;
import cn.hutool.core.util.ObjectUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.param.IdParam;
@ -59,6 +60,7 @@ public class StoreCartController extends BaseController {
/**
* 购物车 添加
*/
@Log(value = "添加购物车",type = 1)
@PostMapping("/cart/add")
@ApiOperation(value = "添加购物车",notes = "添加购物车")
public ApiResult<Map<String,Object>> add(@RequestBody String jsonStr){
@ -112,6 +114,7 @@ public class StoreCartController extends BaseController {
/**
* 购物车列表
*/
@Log(value = "查看购物车",type = 1)
@GetMapping("/cart/list")
@ApiOperation(value = "购物车列表",notes = "购物车列表")
public ApiResult<Map<String,Object>> getList(){

View File

@ -1,5 +1,6 @@
package co.yixiang.modules.shop.web.controller;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.param.IdParam;
@ -37,7 +38,7 @@ import java.util.Map;
*/
@Slf4j
@RestController
@Api("商品表 API")
@Api(value = "产品模块", tags = "产品模块", description = "产品模块")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StoreProductController extends BaseController {
@ -92,6 +93,7 @@ public class StoreProductController extends BaseController {
/**
* 普通商品详情
*/
@Log(value = "查看商品详情",type = 1)
@GetMapping("/product/detail/{id}")
@ApiOperation(value = "普通商品详情",notes = "普通商品详情")
public ApiResult<ProductDTO> detail(@PathVariable Integer id){
@ -102,6 +104,7 @@ public class StoreProductController extends BaseController {
/**
* 添加收藏
*/
@Log(value = "添加收藏",type = 1)
@PostMapping("/collect/add")
@ApiOperation(value = "添加收藏",notes = "添加收藏")
public ApiResult<Object> collectAdd(@Validated @RequestBody YxStoreProductRelationQueryParam param){
@ -113,6 +116,7 @@ public class StoreProductController extends BaseController {
/**
* 取消收藏
*/
@Log(value = "取消收藏",type = 1)
@PostMapping("/collect/del")
@ApiOperation(value = "取消收藏",notes = "取消收藏")
public ApiResult<Object> collectDel(@Validated @RequestBody YxStoreProductRelationQueryParam param){

View File

@ -1,6 +1,7 @@
package co.yixiang.modules.user.web.controller;
import cn.hutool.core.util.StrUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.param.IdParam;
@ -44,6 +45,7 @@ public class UserAddressController extends BaseController {
/**
* 添加或修改地址
*/
@Log(value = "编辑地址",type = 1)
@PostMapping("/address/edit")
@ApiOperation(value = "添加或修改地址",notes = "添加或修改地址",response = ApiResult.class)
public ApiResult<Map<String,Object>> addYxUserAddress(@Valid @RequestBody AddressParam param){
@ -98,6 +100,7 @@ public class UserAddressController extends BaseController {
/**
* 删除用户地址
*/
@Log(value = "删除地址",type = 1)
@PostMapping("/address/del")
@ApiOperation(value = "删除用户地址",notes = "删除用户地址",response = ApiResult.class)
public ApiResult<Boolean> deleteYxUserAddress(@Valid @RequestBody IdParam idParam){
@ -112,6 +115,7 @@ public class UserAddressController extends BaseController {
/**
* 用户地址列表
*/
@Log(value = "查看地址",type = 1)
@GetMapping("/address/list")
@ApiOperation(value = "用户地址列表",notes = "用户地址列表",response = YxUserAddressQueryVo.class)
public ApiResult<Paging<YxUserAddressQueryVo>> getYxUserAddressPageList(

View File

@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.modules.shop.service.YxSystemConfigService;
@ -100,6 +101,7 @@ public class UserBillController extends BaseController {
/**
* 积分记录
*/
@Log(value = "查看积分流水",type = 1)
@GetMapping("/integral/list")
@ApiOperation(value = "积分记录",notes = "积分记录")
public ApiResult<Object> userInfo(@RequestParam(value = "page",defaultValue = "1") int page,
@ -224,6 +226,7 @@ public class UserBillController extends BaseController {
* sort childCount ASC/DESC 团队排序 numberCount ASC/DESC
* 金额排序 orderCount ASC/DESC 订单排序
*/
@Log(value = "查看分销人",type = 1)
@PostMapping("/spread/people")
@ApiOperation(value = "推荐用户",notes = "推荐用户")
public ApiResult<Object> spreadPeople(@Valid @RequestBody PromParam param){
@ -242,6 +245,7 @@ public class UserBillController extends BaseController {
* type 0 全部 1 消费 2 充值 3 返佣 4 提现
* @return mixed
*/
@Log(value = "查看佣金",type = 1)
@GetMapping("/spread/commission/{type}")
@ApiOperation(value = "推广佣金明细",notes = "推广佣金明细")
public ApiResult<Object> spreadCommission(@RequestParam(value = "page",defaultValue = "1") int page,

View File

@ -1,5 +1,6 @@
package co.yixiang.modules.user.web.controller;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.param.IdParam;
@ -68,6 +69,7 @@ public class UserController extends BaseController {
/**
* 获取个人中心菜单
*/
@Log(value = "进入用户中心",type = 1)
@GetMapping("/menu/user")
@ApiOperation(value = "获取个人中心菜单",notes = "获取个人中心菜单")
public ApiResult<Map<String,Object>> userMenu(){

View File

@ -1,5 +1,6 @@
package co.yixiang.modules.user.web.controller;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.common.web.param.IdParam;
@ -42,6 +43,7 @@ public class UserLevelController extends BaseController {
/**
* 会员等级列表
*/
@Log(value = "进入会员中心",type = 1)
@GetMapping("/user/level/grade")
@ApiOperation(value = "会员等级列表",notes = "会员等级列表")
public ApiResult<Object> getLevelInfo(){

View File

@ -6,7 +6,7 @@ spring:
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://localhost:3306/yshop?serverTimezone=Asia/Shanghai&useSSL=false
username: yshop
password:
password:
# 初始化配置
initial-size: 3
@ -48,7 +48,7 @@ spring:
database: 0
host: 127.0.0.1
port: 6379
password:
password:
#连接超时时间
timeout: 5000

View File

@ -13,4 +13,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface Log {
String value() default "";
int type() default 0;
}

View File

@ -49,7 +49,9 @@ public class LogAspect {
currentTime = System.currentTimeMillis();
result = joinPoint.proceed();
Log log = new Log("INFO",System.currentTimeMillis() - currentTime);
logService.save(getUsername(), StringUtils.getIP(RequestHolder.getHttpServletRequest()),joinPoint, log);
logService.save(getUsername(),
StringUtils.getIP(RequestHolder.getHttpServletRequest()),joinPoint,
log,getUid());
return result;
}
@ -63,7 +65,9 @@ public class LogAspect {
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime);
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
logService.save(getUsername(), StringUtils.getIP(RequestHolder.getHttpServletRequest()), (ProceedingJoinPoint)joinPoint, log);
logService.save(getUsername(),
StringUtils.getIP(RequestHolder.getHttpServletRequest()),
(ProceedingJoinPoint)joinPoint, log,getUid());
}
public String getUsername() {
@ -73,4 +77,12 @@ public class LogAspect {
return "";
}
}
public Long getUid(){
try {
return SecurityUtils.getUserId();
}catch (Exception e){
return 0L;
}
}
}

View File

@ -62,6 +62,10 @@ public class Log implements Serializable {
*/
private Long time;
private Long uid;
private Integer type;
/**
* 异常详细
*/

View File

@ -1,11 +1,15 @@
package co.yixiang.repository;
import co.yixiang.domain.Log;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.Map;
/**
* @author Zheng Jie
* @date 2018-11-24
@ -13,6 +17,18 @@ import org.springframework.stereotype.Repository;
@Repository
public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecificationExecutor {
@Query(nativeQuery = true,
value = "select l.id,l.create_time as createTime,l.description," +
"l.request_ip as requestIp,l.address," +
"u.nickname from log l left join yx_user u on u.uid=l.uid " +
" where l.type=1" +
" and if(?1 !='',u.nickname LIKE CONCAT('%',?1,'%'),1=1) order by l.id desc",
countQuery = "select count(*) from log l left join yx_user u on u.uid=l.uid" +
" where l.type=1 " +
"and if(?1 !='',u.nickname LIKE CONCAT('%',?1,'%'),1=1)")
Page<Map> findAllByPageable(String nickname,
Pageable pageable);
/**
* 获取一个时间段的IP记录
* @param date1

View File

@ -28,9 +28,18 @@ public class LogController {
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity getLogs(LogQueryCriteria criteria, Pageable pageable){
criteria.setLogType("INFO");
criteria.setType(0);
return new ResponseEntity(logService.queryAll(criteria,pageable), HttpStatus.OK);
}
@GetMapping(value = "/mlogs")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity getApiLogs(LogQueryCriteria criteria, Pageable pageable){
criteria.setLogType("INFO");
criteria.setType(1);
return new ResponseEntity(logService.findAllByPageable(criteria.getBlurry(),pageable), HttpStatus.OK);
}
@GetMapping(value = "/logs/user")
public ResponseEntity getUserLogs(LogQueryCriteria criteria, Pageable pageable){
criteria.setLogType("INFO");

View File

@ -12,6 +12,8 @@ import org.springframework.scheduling.annotation.Async;
*/
public interface LogService {
Object findAllByPageable(String nickname, Pageable pageable);
/**
* queryAll
* @param criteria
@ -36,7 +38,7 @@ public interface LogService {
* @param log
*/
@Async
void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log);
void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log,Long uid);
/**
* 查询异常详情

View File

@ -17,4 +17,8 @@ public class LogQueryCriteria {
@Query
private String logType;
@Query
private Integer type;
}

View File

@ -20,6 +20,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author Zheng Jie
@ -40,6 +42,15 @@ public class LogServiceImpl implements LogService {
private final String LOGINPATH = "login";
@Override
public Object findAllByPageable(String nickname, Pageable pageable) {
Page<Map> page = logRepository.findAllByPageable(nickname,pageable);
Map<String,Object> map = new LinkedHashMap<>(2);
map.put("content",page.getContent());
map.put("totalElements",page.getTotalElements());
return map;
}
@Override
public Object queryAll(LogQueryCriteria criteria, Pageable pageable){
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
@ -57,7 +68,8 @@ public class LogServiceImpl implements LogService {
@Override
@Transactional(rollbackFor = Exception.class)
public void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log){
public void save(String username, String ip, ProceedingJoinPoint joinPoint,
Log log,Long uid){
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
@ -67,6 +79,12 @@ public class LogServiceImpl implements LogService {
if (log != null) {
log.setDescription(aopLog.value());
}
//类型 0-后台 1-前台
log.setType(aopLog.type());
if(uid != null) {
log.setUid(uid);
}
// 方法路径
String methodName = joinPoint.getTarget().getClass().getName()+"."+signature.getName()+"()";

View File

@ -32,7 +32,7 @@ public class DeptController {
private static final String ENTITY_NAME = "dept";
// @Log("查询部门")
@Log("查询部门")
@GetMapping(value = "/dept")
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT','DEPT_ALL','DEPT_SELECT')")
public ResponseEntity getDepts(DeptQueryCriteria criteria){
@ -42,7 +42,7 @@ public class DeptController {
return new ResponseEntity(deptService.buildTree(deptDTOS),HttpStatus.OK);
}
//@Log("新增部门")
@Log("新增部门")
@PostMapping(value = "/dept")
@PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_CREATE')")
public ResponseEntity create(@Validated @RequestBody Dept resources){
@ -52,7 +52,7 @@ public class DeptController {
return new ResponseEntity(deptService.create(resources),HttpStatus.CREATED);
}
//@Log("修改部门")
@Log("修改部门")
@PutMapping(value = "/dept")
@PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_EDIT')")
public ResponseEntity update(@Validated(Dept.Update.class) @RequestBody Dept resources){
@ -60,7 +60,7 @@ public class DeptController {
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
//@Log("删除部门")
@Log("删除部门")
@DeleteMapping(value = "/dept/{id}")
@PreAuthorize("hasAnyRole('ADMIN','DEPT_ALL','DEPT_DELETE')")
public ResponseEntity delete(@PathVariable Long id){