From 59997acf8fe89392ac03ae9514fdb35404e4070a Mon Sep 17 00:00:00 2001 From: bynt Date: Mon, 29 May 2023 16:41:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E5=8D=95=E6=8F=90=E4=BA=A4=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/zhengjie/base/BaseEntity.java | 3 + .../zhengjie/utils/enums/AmountScopeEnum.java | 69 +++++++++++++++++++ .../service/mapstruct/LogErrorMapperImpl.java | 2 +- .../service/mapstruct/LogSmallMapperImpl.java | 2 +- .../modules/loan/domain/LoanUser.java | 4 +- .../modules/loan/dto/LoanUserDTO.java | 6 +- .../loan/dto/LoanUserQueryCriteria.java | 34 +++++++++ .../modules/loan/rest/LoanUserController.java | 23 +++++-- .../modules/loan/service/LoanUserService.java | 11 +++ .../service/impl/LoanUserServiceImpl.java | 29 ++++++++ 10 files changed, 174 insertions(+), 9 deletions(-) create mode 100644 eladmin-common/src/main/java/me/zhengjie/utils/enums/AmountScopeEnum.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/loan/dto/LoanUserQueryCriteria.java diff --git a/eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java b/eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java index 5f6fbfb..90afa66 100644 --- a/eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java +++ b/eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java @@ -15,6 +15,8 @@ */ package me.zhengjie.base; +import cn.hutool.core.date.DatePattern; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; @@ -55,6 +57,7 @@ public class BaseEntity implements Serializable { @CreationTimestamp @Column(name = "create_time", updatable = false) @ApiModelProperty(value = "创建时间", hidden = true) + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8") private Timestamp createTime; @UpdateTimestamp diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/enums/AmountScopeEnum.java b/eladmin-common/src/main/java/me/zhengjie/utils/enums/AmountScopeEnum.java new file mode 100644 index 0000000..56c81cb --- /dev/null +++ b/eladmin-common/src/main/java/me/zhengjie/utils/enums/AmountScopeEnum.java @@ -0,0 +1,69 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.zhengjie.utils.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + *

+ * 数据权限枚举 + *

+ * + * @author Zheng Jie + * @date 2020-05-07 + */ +@Getter +@AllArgsConstructor +public enum AmountScopeEnum { + + /** + * 1-10万 + */ + ONE_TO_TEN(1, "1-10万"), + + /** + * 10-20万 + */ + TEN_TO_TWENTY(2, "10-20万"), + + /** + * 20-30 + */ + TWENTY_TO_THIRTY(3, "20-30万"), + /** + * 30-60 + */ + THIRTY_TO_SIXTY(4, "30-60万"), + + /** + * 大于60 + */ + GREATER_SIXTY(5, "60+"); + + private final Integer value; + private final String description; + + public static AmountScopeEnum find(Integer val) { + for (AmountScopeEnum dataScopeEnum : AmountScopeEnum.values()) { + if (val.equals(dataScopeEnum.getValue())) { + return dataScopeEnum; + } + } + return null; + } + +} diff --git a/eladmin-logging/target/generated-sources/annotations/me/zhengjie/service/mapstruct/LogErrorMapperImpl.java b/eladmin-logging/target/generated-sources/annotations/me/zhengjie/service/mapstruct/LogErrorMapperImpl.java index c58560a..1c66da5 100644 --- a/eladmin-logging/target/generated-sources/annotations/me/zhengjie/service/mapstruct/LogErrorMapperImpl.java +++ b/eladmin-logging/target/generated-sources/annotations/me/zhengjie/service/mapstruct/LogErrorMapperImpl.java @@ -9,7 +9,7 @@ import org.springframework.stereotype.Component; @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2023-05-29T13:21:00+0800", + date = "2023-05-29T16:32:36+0800", comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_251 (Oracle Corporation)" ) @Component diff --git a/eladmin-logging/target/generated-sources/annotations/me/zhengjie/service/mapstruct/LogSmallMapperImpl.java b/eladmin-logging/target/generated-sources/annotations/me/zhengjie/service/mapstruct/LogSmallMapperImpl.java index d0c7655..7f874e8 100644 --- a/eladmin-logging/target/generated-sources/annotations/me/zhengjie/service/mapstruct/LogSmallMapperImpl.java +++ b/eladmin-logging/target/generated-sources/annotations/me/zhengjie/service/mapstruct/LogSmallMapperImpl.java @@ -9,7 +9,7 @@ import org.springframework.stereotype.Component; @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2023-05-29T13:21:01+0800", + date = "2023-05-29T16:32:36+0800", comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_251 (Oracle Corporation)" ) @Component diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/loan/domain/LoanUser.java b/eladmin-system/src/main/java/me/zhengjie/modules/loan/domain/LoanUser.java index da93365..d00dcc7 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/loan/domain/LoanUser.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/loan/domain/LoanUser.java @@ -6,7 +6,6 @@ import lombok.Setter; import me.zhengjie.base.BaseEntity; import javax.persistence.*; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; @@ -48,6 +47,9 @@ public class LoanUser extends BaseEntity implements Serializable { @ApiModelProperty(value = "额度类型 1:5-10万 2:10-20万 3:20-30万 4:30-50万 5:50万以上") private Integer quotaType; + @Column(name = "remarks") + @ApiModelProperty(value = "备注") + private String remarks; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/loan/dto/LoanUserDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/loan/dto/LoanUserDTO.java index 7000873..14c3c0d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/loan/dto/LoanUserDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/loan/dto/LoanUserDTO.java @@ -24,11 +24,13 @@ public class LoanUserDTO { @ApiModelProperty(value = "地址") private String address; - @NotNull @ApiModelProperty(value = "借款类别 1:信用卡 2:网贷 3:信用卡+网贷") private Integer borrowingType; @NotNull - @ApiModelProperty(value = "额度类型 1:5-10万 2:10-20万 3:20-30万 4:30-50万 5:50万以上") + @ApiModelProperty(value = "额度类型 1:1-10万 2:10-20万 3:20-30万 4:30-60万 5:60万以上") private Integer quotaType; + + @ApiModelProperty(value = "备注") + private String remarks; } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/loan/dto/LoanUserQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/loan/dto/LoanUserQueryCriteria.java new file mode 100644 index 0000000..3bbab15 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/loan/dto/LoanUserQueryCriteria.java @@ -0,0 +1,34 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.loan.dto; + +import lombok.Data; +import me.zhengjie.annotation.Query; + +import java.sql.Timestamp; +import java.util.List; + +/** +* @website https://el-admin.vip +* @author x +* @date 2021-08-05 +**/ +@Data +public class LoanUserQueryCriteria { + + @Query(type = Query.Type.BETWEEN) + private List createTime; +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/loan/rest/LoanUserController.java b/eladmin-system/src/main/java/me/zhengjie/modules/loan/rest/LoanUserController.java index 0b41e15..12ebb84 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/loan/rest/LoanUserController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/loan/rest/LoanUserController.java @@ -1,21 +1,26 @@ package me.zhengjie.modules.loan.rest; +import cn.hutool.core.collection.CollUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import me.zhengjie.annotation.Log; import me.zhengjie.annotation.NoRepeatSubmit; import me.zhengjie.common.http.CommonResponse; import me.zhengjie.common.http.ResponseCode; import me.zhengjie.modules.loan.dto.LoanUserDTO; +import me.zhengjie.modules.loan.dto.LoanUserQueryCriteria; import me.zhengjie.modules.loan.service.LoanUserService; +import me.zhengjie.service.dto.LogQueryCriteria; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * @author Enzo @@ -40,4 +45,14 @@ public class LoanUserController { new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK) : new ResponseEntity<>(CommonResponse.createByError(ResponseCode.ERROR), HttpStatus.INTERNAL_SERVER_ERROR); } + + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + public void download(HttpServletResponse response, LoanUserQueryCriteria criteria) throws IOException { + if (CollUtil.isNotEmpty(criteria.getCreateTime())) { + loanUserService.download(criteria, response); + } + } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/loan/service/LoanUserService.java b/eladmin-system/src/main/java/me/zhengjie/modules/loan/service/LoanUserService.java index 2159c9c..5421749 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/loan/service/LoanUserService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/loan/service/LoanUserService.java @@ -1,6 +1,10 @@ package me.zhengjie.modules.loan.service; import me.zhengjie.modules.loan.dto.LoanUserDTO; +import me.zhengjie.modules.loan.dto.LoanUserQueryCriteria; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * @author Enzo @@ -13,4 +17,11 @@ public interface LoanUserService { * @return */ Boolean userSubmit(LoanUserDTO loanUserDTO); + + /** + * 导出文件 + * @param criteria + * @param response + */ + void download(LoanUserQueryCriteria criteria, HttpServletResponse response) throws IOException; } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/loan/service/impl/LoanUserServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/loan/service/impl/LoanUserServiceImpl.java index afb3180..b713f4a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/loan/service/impl/LoanUserServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/loan/service/impl/LoanUserServiceImpl.java @@ -3,14 +3,26 @@ package me.zhengjie.modules.loan.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import lombok.RequiredArgsConstructor; +import me.zhengjie.domain.Log; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.loan.domain.LoanUser; import me.zhengjie.modules.loan.dto.LoanUserDTO; +import me.zhengjie.modules.loan.dto.LoanUserQueryCriteria; import me.zhengjie.modules.loan.repository.LoanUserRepository; import me.zhengjie.modules.loan.service.LoanUserService; +import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.MobileUtil; +import me.zhengjie.utils.QueryHelp; +import me.zhengjie.utils.enums.AmountScopeEnum; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + /** * @author Enzo * @date : 2022/6/6 @@ -38,4 +50,21 @@ public class LoanUserServiceImpl implements LoanUserService { } return Boolean.FALSE; } + + @Override + public void download(LoanUserQueryCriteria criteria, HttpServletResponse response) throws IOException { + List all = loanUserRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb))); + List> list = new ArrayList<>(); + for (LoanUser user : all) { + AmountScopeEnum amountScopeEnum = AmountScopeEnum.find(user.getQuotaType()); + Map map = new LinkedHashMap<>(); + map.put("用户名", user.getUsername()); + map.put("手机号码", user.getPhone()); + map.put("额度类型", amountScopeEnum != null ? amountScopeEnum.getDescription() : "未知"); + map.put("创建日期", user.getCreateTime().toString()); + map.put("备注", user.getRemarks()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } }