From 5858bf19a5e34f56c6d75394611a6c1b77fb6665 Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Fri, 29 Dec 2023 18:19:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E9=93=B6=E5=90=8E=E5=8F=B0=E8=B7=9F?= =?UTF-8?q?=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhengjie/interceptor/UserInterceptor.java | 20 ++++++++++ .../me/zhengjie/interceptor/WebConfig.java | 16 ++++++++ .../service/dto/TbOrderInfoQueryCriteria.java | 38 +++++++++---------- .../repository/TbProductGroupRepository.java | 4 ++ .../rest/TbProductGroupController.java | 7 ++-- .../service/TbProductGroupService.java | 2 +- .../impl/TbProductGroupServiceImpl.java | 34 +++++++++++++++-- .../mapstruct/TbProductGroupMapper.java | 5 +-- .../productGroup/service/vo/AddProduct.java | 3 ++ 9 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/interceptor/UserInterceptor.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/interceptor/WebConfig.java diff --git a/eladmin-system/src/main/java/me/zhengjie/interceptor/UserInterceptor.java b/eladmin-system/src/main/java/me/zhengjie/interceptor/UserInterceptor.java new file mode 100644 index 00000000..04228cc2 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/interceptor/UserInterceptor.java @@ -0,0 +1,20 @@ +package me.zhengjie.interceptor; + +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author lyf + */ +public class UserInterceptor implements HandlerInterceptor { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{ + String userName = request.getHeader("userName"); + request.setAttribute("userName", userName); + return true; + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/interceptor/WebConfig.java b/eladmin-system/src/main/java/me/zhengjie/interceptor/WebConfig.java new file mode 100644 index 00000000..c50e6f59 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/interceptor/WebConfig.java @@ -0,0 +1,16 @@ +package me.zhengjie.interceptor; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * @author lyf + */ +@Configuration +public class WebConfig implements WebMvcConfigurer { + @Override + public void addInterceptors(InterceptorRegistry registry){ + registry.addInterceptor(new UserInterceptor()); + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/orderInfo/service/dto/TbOrderInfoQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/orderInfo/service/dto/TbOrderInfoQueryCriteria.java index 1c1daa5f..4b933a9a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/orderInfo/service/dto/TbOrderInfoQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/orderInfo/service/dto/TbOrderInfoQueryCriteria.java @@ -28,79 +28,79 @@ import me.zhengjie.annotation.Query; @Data public class TbOrderInfoQueryCriteria{ - /** ¾«È· */ + /** 精确 */ @Query private Integer id; - /** ¾«È· */ + /** 精确 */ @Query private String orderNo; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal productAmount; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal payAmount; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal cashPaidAmount; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal wxPaidAmount; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal aliPaidAmount; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal depositPaidAmount; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal bankPaidAmount; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal virtualPaidAmount; - /** ¾«È· */ + /** 精确 */ @Query private BigDecimal otherPaidAmount; - /** ¾«È· */ + /** 精确 */ @Query private String sendType; - /** ¾«È· */ + /** 精确 */ @Query private String status; - /** ¾«È· */ + /** 精确 */ @Query private String shopId; - /** ¾«È· */ + /** 精确 */ @Query private String memberId; - /** ¾«È· */ + /** 精确 */ @Query private String userId; - /** ¾«È· */ + /** 精确 */ @Query private Long paidTime; - /** ¾«È· */ + /** 精确 */ @Query private Long createdAt; - /** ¾«È· */ + /** 精确 */ @Query private Integer isAccepted; } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/repository/TbProductGroupRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/repository/TbProductGroupRepository.java index cba52ff8..e7f63fb3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/repository/TbProductGroupRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/repository/TbProductGroupRepository.java @@ -18,6 +18,7 @@ package me.zhengjie.modules.productGroup.repository; import me.zhengjie.modules.productGroup.domain.TbProductGroup; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; /** * @website https://eladmin.vip @@ -25,4 +26,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; * @date 2023-12-16 **/ public interface TbProductGroupRepository extends JpaRepository, JpaSpecificationExecutor { + +// @Query("SELECT u FROM User u WHERE u.userName = :userName") +// User findByUserName(@Param("userName") String userName); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java index 6cd90865..433d144e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java @@ -104,9 +104,8 @@ public class TbProductGroupController { } @PostMapping("/addProductInfo") - public ResponseEntity addProductInfo(@RequestBody AddProduct addProduct){ - - - tbProductGroupService.updateProductIds(); + public ResponseEntity addProductInfo(@RequestBody AddProduct addProduct,@RequestAttribute(value = "userName", required = false) String userName){ + return new ResponseEntity<>(tbProductGroupService.updateProductIds(addProduct,userName),HttpStatus.OK); } + } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java index 2c5f4fdc..fc20eaf8 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java @@ -84,5 +84,5 @@ public interface TbProductGroupService { */ void download(List all, HttpServletResponse response) throws IOException; - ResponseEntity updateProductIds(AddProduct addProduct); + ResponseEntity updateProductIds(AddProduct addProduct,String userName); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java index 8d391ec2..f8867a5d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java @@ -17,6 +17,8 @@ package me.zhengjie.modules.productGroup.service.impl; import me.zhengjie.modules.productGroup.domain.TbProductGroup; import me.zhengjie.modules.productGroup.service.vo.AddProduct; +import me.zhengjie.modules.security.service.OnlineUserService; +import me.zhengjie.modules.security.service.dto.OnlineUserDto; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.FileUtil; import lombok.RequiredArgsConstructor; @@ -36,6 +38,7 @@ import me.zhengjie.utils.QueryHelp; import java.util.List; import java.util.Map; import java.io.IOException; +import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -53,9 +56,13 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { private final TbProductGroupRepository tbProductGroupRepository; private final TbProductGroupMapper tbProductGroupMapper; + @Resource + private OnlineUserService onlineUserService; + @Override public Map queryAll(TbProductGroupQueryCriteria criteria, Pageable pageable){ - Page page = tbProductGroupRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + Page page = tbProductGroupRepository.findAll((root, criteriaQuery, criteriaBuilder) -> + QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); return PageUtil.toPage(page.map(tbProductGroupMapper::toDto)); } @@ -115,17 +122,22 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { } @Override - public ResponseEntity updateProductIds(AddProduct addProduct) { + public ResponseEntity updateProductIds(AddProduct addProduct,String userName) { + OnlineUserDto onlineUser = onlineUserService.getOne(addProduct.getKey()); + + + if (addProduct.getIds().size()<1){ return new ResponseEntity<>("错误", HttpStatus.NOT_ACCEPTABLE); } - TbProductGroup productGroup = tbProductGroupMapper.queryById(addProduct.getProductId()); + TbProductGroupDto productGroup = this.findById(addProduct.getProductId()); if (productGroup == null){ return new ResponseEntity<>("没有找到改分类", HttpStatus.NOT_ACCEPTABLE); } TbProductGroup tbProductGroup = new TbProductGroup(); StringBuilder sb = new StringBuilder(); +// //如果没有 if (productGroup.getProductIds() == null) { for (String s : addProduct.getIds()) { sb.append(s); @@ -134,10 +146,24 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { tbProductGroup.setProductIds(sb.toString()); tbProductGroup.setId(addProduct.getProductId()); - tbProductGroupMapper.update(tbProductGroup); + this.update(tbProductGroup); + }else { + //如果有 + for (String s : addProduct.getIds()) { + sb.append(s); + sb.append(","); + } + sb.append(productGroup.getProductIds()); + + tbProductGroup.setProductIds(sb.toString()); + tbProductGroup.setId(addProduct.getProductId()); + this.update(tbProductGroup); } + return new ResponseEntity<>(HttpStatus.OK); + } + } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java index 2d0dc468..49abb9a6 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java @@ -18,7 +18,9 @@ package me.zhengjie.modules.productGroup.service.mapstruct; import me.zhengjie.base.BaseMapper; import me.zhengjie.modules.productGroup.domain.TbProductGroup; import me.zhengjie.modules.productGroup.service.dto.TbProductGroupDto; + import org.mapstruct.Mapper; + import org.mapstruct.ReportingPolicy; /** @@ -29,7 +31,4 @@ import org.mapstruct.ReportingPolicy; @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface TbProductGroupMapper extends BaseMapper { - int update(TbProductGroup tbProductGroup); - - TbProductGroup queryById(Integer id); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java index 67008b33..c05891eb 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java @@ -13,4 +13,7 @@ public class AddProduct { Integer productId; + String key; + + String userName; }