From ab6a4a5279135c61dd7e2e6bb525dac903ac5523 Mon Sep 17 00:00:00 2001 From: cun-nan <19819293608@163.com> Date: Thu, 19 Oct 2023 18:47:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/FileUpload/index.vue | 11 +- fuintAdmin/src/views/member/index.vue | 138 +++++-- fuintAdmin/src/views/member/userInfo.vue | 376 +++++++++++++++++- fuintAdmin/src/views/userGrade/index.vue | 8 +- fuintBackend/fuint-application/pom.xml | 17 + ...StoreMapper.xml => ExportExcelService.xml} | 0 .../controller/ExportController.java | 94 +++++ .../business/userManager/entity/LJUser.java | 37 ++ .../listener/EasyExcelListener.java | 38 ++ .../userManager/mapper/xml/LJUserMapper.xml | 3 +- .../java/com/fuint/common/util/ExcelUtil.java | 2 +- 11 files changed, 664 insertions(+), 60 deletions(-) rename fuintBackend/fuint-application/src/main/java/com/fuint/business/store/mapper/xml/{MtStoreMapper.xml => ExportExcelService.xml} (100%) create mode 100644 fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/controller/ExportController.java create mode 100644 fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/listener/EasyExcelListener.java diff --git a/fuintAdmin/src/components/FileUpload/index.vue b/fuintAdmin/src/components/FileUpload/index.vue index 472db7699..f41befa4f 100644 --- a/fuintAdmin/src/components/FileUpload/index.vue +++ b/fuintAdmin/src/components/FileUpload/index.vue @@ -2,7 +2,7 @@
新增 + >新增会员 @@ -173,10 +173,6 @@ @@ -193,25 +189,11 @@ @@ -222,13 +204,6 @@ @@ -242,14 +217,6 @@ - - - - - - - - @@ -288,6 +255,44 @@ /> + + + +

+ {{item}} +

+
+
+ 录入单个会员 + 批量导入会员 +
+
+ + + + + + + + + + + + + + +
+
+ @@ -391,6 +396,28 @@
+ + +
+
第一步: 下载示例模板,按照模板填写会员数据,手机号为必填项
+ 会员示例模板.xlsx +
+
+
第二步: 选择用户数据上传并导入会员
+ + 点击上传 +
只能上传xls/xlsx文件,单次最大5000行会员数据且不超过1M 超出请分文件处理
+
+ +
+
+ @@ -406,12 +433,21 @@ import pointRecharge from "./pointRecharge"; import {addUser, delUser, getUser, listStatistic, listUser, updateUser} from "@/api/staff/user/user"; import {listUserGrade} from "@/api/staff/user/usergrade"; import {ljStoreList} from "@/api/staff/store"; +import {getSysConfig} from "@/api/staff/user/sysconfig"; +import { getToken } from "@/utils/auth"; export default { name: "MemberIndex", components: { balanceRecharge, pointRecharge }, dicts: ['official','zhzt'], data() { return { + headers: { + 'Access-Token': getToken(), + }, + // 文件上传信息 + fileList: [], + + addMember:[], // 余额 balance:'', // 积分 @@ -438,6 +474,8 @@ export default { total: 0, // 表格数据 list: [], + // 会员表格数据 + userList: [], // 会员等级列表 userGradeList: [], // 店铺列表 @@ -445,6 +483,8 @@ export default { storeIds: [], // 是否显示修改对话框 open: false, + openUser: false, + openUpload: false, // 当前操作用户 userId: '', // 是否弹层充值 @@ -487,6 +527,7 @@ export default { created() { this.getList(); this.getStatistic(); + this.getConfig(); }, methods: { // 跳转详情页 @@ -583,6 +624,10 @@ export default { handleBalance(userId) { this.openBalance = true; this.userId = userId.toString(); + }, + // 导入会员信息 + importUser(){ + }, // 积分变更操作 handlePoint(userId) { @@ -602,9 +647,24 @@ export default { }, // 新增按钮操作 handleAdd() { + this.openUser = true; + this.title = "新增会员"; + }, + // 新增按钮操作 + addOne() { this.reset(); this.open = true; - this.title = "新增会员"; + this.title = "录入会员"; + }, + addMult(){ + this.openUpload = true; + this.title = "批量导入会员"; + }, + // 获取配置信息 + getConfig(){ + getSysConfig('addMember').then(response => { + this.addMember = response.data.split(";") + }); }, // 表单重置 reset() { @@ -659,6 +719,9 @@ export default { this.getList(); this.$modal.msgSuccess("删除成功"); }).catch(() => {}); + }, + handleChange(file, fileList) { + this.fileList = fileList.slice(-3); } } }; @@ -676,4 +739,9 @@ export default { background: #f6f8f9; padding-top: 30px; } + .el-upload, .el-upload--text { + width: 150px; + height: 60px !important; + line-height: 60px !important; + } diff --git a/fuintAdmin/src/views/member/userInfo.vue b/fuintAdmin/src/views/member/userInfo.vue index decdcbf1b..7a5cff03a 100644 --- a/fuintAdmin/src/views/member/userInfo.vue +++ b/fuintAdmin/src/views/member/userInfo.vue @@ -1,11 +1,12 @@ @@ -318,18 +600,32 @@ import {getUser, updateUser} from "@/api/staff/user/user"; import {ljStoreInfo} from "@/api/staff/store"; import {getUserGrade} from "@/api/staff/user/usergrade"; +import {getSysConfig} from "@/api/staff/user/sysconfig"; export default { - dicts: ['official','zhzt'], + dicts: ['official','zhzt','zcrzdj'], data(){ return{ + // 每日交易介绍 + transaction:"", + config:'-1', + num:1, + // 操作类型 + type:'add', title:'', // 是否显示修改对话框 openMobile: false, + openSecondCard:false, + openUserGrade:false, + openSubCard:false, + openConfig:false, + openLevel:false, growthValue:'whole', cardList:'notUse', tabPosition: 'giftCard', balanceRecord: 'first', + // 关于副卡信息 + aboutSecondCard:[], // 遮罩层 loading: false, id:'', @@ -340,8 +636,9 @@ export default { // 会员等级信息 grade:'', activeName: 'refuelOrder', + subCardActive:'subCardManage', tableData:[], - total:'', + total:0, queryParams: { page: 1, pageSize: 10, @@ -350,16 +647,19 @@ export default { name: '', status: '', }, + subCardList:[], list: [], // 表单校验 rules: { mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }], + type: [{ required: true, message: "请选择操作类型", trigger: "blur" }], } } }, created() { this.id = this.$route.query.id; this.getUserInfo(); + this.getInformation(); }, methods: { // 更换手机号 @@ -367,6 +667,40 @@ export default { this.openMobile = true; this.title = '更换手机号' }, + // 副卡管理 + secondCard(){ + this.openSecondCard = true; + this.title = this.form.secondCard+'-副卡账户管理' + }, + // 会员等级成长值 + userGrade(){ + this.openUserGrade = true; + this.title = '更换手机号' + }, + // 子卡管理 + subCard(){ + this.openSubCard = true; + this.title = '子卡管理' + }, + // 每日笔数 + configuration(){ + this.openConfig = true; + this.title = '每日交易次数' + }, + // 固定等级 + level(){ + this.openLevel = true; + this.title = '固定等级(原专车认证)' + }, + // 获取副卡信息 + getInformation(){ + getSysConfig('second_card').then(response => { + this.aboutSecondCard = response.data.split(";") + }); + getSysConfig('transaction').then(response => { + this.transaction = response.data + }); + }, getList(){ }, @@ -416,10 +750,16 @@ export default { // 取消按钮 cancel() { this.openMobile = false; + this.openUserGrade = false; + this.openConfig = false; + this.openLevel = false; }, handleClick(tab, event) { console.log(tab, event); }, + handleChange(value) { + console.log(value); + }, // 返回 goBack() { this.$router.back(-1); diff --git a/fuintAdmin/src/views/userGrade/index.vue b/fuintAdmin/src/views/userGrade/index.vue index 6969de6d6..aa80b264f 100644 --- a/fuintAdmin/src/views/userGrade/index.vue +++ b/fuintAdmin/src/views/userGrade/index.vue @@ -259,7 +259,7 @@ - + @@ -281,7 +281,7 @@ - + @@ -291,7 +291,7 @@ - + @@ -301,7 +301,7 @@ - + diff --git a/fuintBackend/fuint-application/pom.xml b/fuintBackend/fuint-application/pom.xml index d6ba80849..8f79f90bb 100644 --- a/fuintBackend/fuint-application/pom.xml +++ b/fuintBackend/fuint-application/pom.xml @@ -135,6 +135,23 @@ org.springframework.boot spring-boot-starter-validation + + + + com.alibaba + easyexcel + 2.1.4 + + + org.apache.poi + poi + 3.17 + + + org.apache.poi + poi-ooxml + 3.17 + diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/mapper/xml/MtStoreMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/mapper/xml/ExportExcelService.xml similarity index 100% rename from fuintBackend/fuint-application/src/main/java/com/fuint/business/store/mapper/xml/MtStoreMapper.xml rename to fuintBackend/fuint-application/src/main/java/com/fuint/business/store/mapper/xml/ExportExcelService.xml diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/controller/ExportController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/controller/ExportController.java new file mode 100644 index 000000000..804a37299 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/controller/ExportController.java @@ -0,0 +1,94 @@ +package com.fuint.business.userManager.controller; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.EasyExcelFactory; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.fuint.business.userManager.entity.LJUser; +import com.fuint.business.userManager.listener.EasyExcelListener; +import com.fuint.business.userManager.mapper.LJUserMapper; +import com.fuint.business.userManager.service.LJUserService; +import com.fuint.framework.web.BaseController; +import com.fuint.framework.web.ResponseObject; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.net.URLEncoder; +import java.util.List; + +@RestController +@RequestMapping("/excel") +public class ExportController extends BaseController{ + @Autowired + private EasyExcelListener listener; + @Autowired + private LJUserService service; + @Autowired + private LJUserMapper mapper; + + @RequestMapping("/import") + public ResponseObject myImport(MultipartFile file) throws IOException { + try { + //获取文件名 + String filename = file.getOriginalFilename(); + //获取文件流 + InputStream inputStream = file.getInputStream(); + //实例化实现了AnalysisEventListener接口的类 + EasyExcelListener listener = new EasyExcelListener(); + + EasyExcelFactory.read(inputStream, LJUser.class, listener).headRowNumber(1).build().readAll(); + //获取数据 + List list = listener.getDatas(); + if (list.size() > 1) { + for (int i = 0; i < list.size(); i++) { + LJUser user = (LJUser) list.get(i); + //使用mybatis-plus添加到数据库 + service.insertUser(user); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return getSuccessResult("OK"); + } + + + @RequestMapping("/export") + public void export(HttpServletResponse response, HttpServletRequest request) { + + try { + String filenames = "会员信息导入示列"; + String userAgent = request.getHeader("User-Agent"); + if (userAgent.contains("MSIE") || userAgent.contains("Trident")) { + filenames = URLEncoder.encode(filenames, "UTF-8"); + } else { + filenames = new String(filenames.getBytes("UTF-8"), "ISO-8859-1"); + } + response.setContentType("application/json.ms-exce"); + response.setCharacterEncoding("utf-8"); + response.addHeader("Content-Disposition", "filename=" + filenames + ".xlsx"); + + // Step1:创建一个 QueryWrapper 对象 + QueryWrapper queryWrapper = new QueryWrapper<>(); + + // Step2: 构造查询条件 + queryWrapper + .select("*"); + + // Step3:执行查询 + List userList = mapper.selectList(queryWrapper); + + EasyExcel.write(response.getOutputStream(), LJUser.class).sheet("sheet").doWrite(userList); + } catch (Exception e) { + e.printStackTrace(); + } + + + } +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/entity/LJUser.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/entity/LJUser.java index 30be2d080..71d7001d2 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/entity/LJUser.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/entity/LJUser.java @@ -1,5 +1,8 @@ package com.fuint.business.userManager.entity; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.format.DateTimeFormat; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.annotation.*; import com.fasterxml.jackson.annotation.JsonFormat; @@ -23,6 +26,7 @@ import java.util.List; @Getter @Setter @TableName("mt_user") +@ExcelIgnoreUnannotated @ApiModel(value = "MtUser对象", description = "会员个人信息") public class LJUser extends BaseEntity implements Serializable { @@ -30,93 +34,126 @@ public class LJUser extends BaseEntity implements Serializable { @ApiModelProperty("会员ID") @TableId(value = "ID", type = IdType.AUTO) + @ExcelProperty(index = 0,value = "id") private Integer id; @ApiModelProperty("会员号") + @ExcelProperty(index = 1,value = "会员号") private String userNo; @ApiModelProperty("头像") + @ExcelProperty(index = 2,value = "头像") private String avatar; @ApiModelProperty("称呼") + @ExcelProperty(index = 3,value = "称呼") private String name; @ApiModelProperty("微信open_id") + @ExcelProperty(index = 4,value = "微信open_id") private String openId; @ApiModelProperty("手机号码") + @ExcelProperty(index = 5,value = "手机号码") private String mobile; @ApiModelProperty("证件号码") + @ExcelProperty(index = 6,value = "证件号码") private String idcard; @ApiModelProperty("等级ID") + @ExcelProperty(index = 7,value = "等级ID") private String gradeId; @ApiModelProperty("会员开始时间") @TableField(strategy = FieldStrategy.IGNORED) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ExcelProperty(index = 8,value = "会员开始时间") private Date startTime; @ApiModelProperty("会员结束时间") @TableField(strategy=FieldStrategy.IGNORED) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ExcelProperty(index = 9,value = "会员结束时间") private Date endTime; @ApiModelProperty("余额") + @ExcelProperty(index = 10,value = "余额") private BigDecimal balance; @ApiModelProperty("积分") + @ExcelProperty(index = 11,value = "积分") private Integer point; @ApiModelProperty("性别 1男;0女") + @ExcelProperty(index = 12,value = "性别 1男;0女") private Integer sex; @ApiModelProperty("出生日期") + @ExcelProperty(index = 13,value = "出生日期") private String birthday; @ApiModelProperty("车牌号") + @ExcelProperty(index = 14,value = "车牌号") private String carNo; @ApiModelProperty("来源渠道") + @ExcelProperty(index = 15,value = "来源渠道") private String source; @ApiModelProperty("密码") + @ExcelProperty(index = 16,value = "密码") private String password; @ApiModelProperty("salt") + @ExcelProperty(index = 17,value = "salt") private String salt; @ApiModelProperty("地址") + @ExcelProperty(index = 18,value = "地址") private String address; @ApiModelProperty("所属商户ID") + @ExcelProperty(index = 19,value = "所属商户ID") private Integer merchantId; @ApiModelProperty("默认店铺") + @ExcelProperty(index = 20,value = "默认店铺") private Integer storeId; @ApiModelProperty("状态,A:激活;N:禁用;D:删除") + @ExcelProperty(index = 21,value = "状态") private String status; @ApiModelProperty("备注信息") + @ExcelProperty(index = 22,value = "备注信息") private String description; @ApiModelProperty("最后操作人") + @ExcelProperty(index = 23,value = "最后操作人") private String operator; @ApiModelProperty("升数卡") + @ExcelProperty(index = 24,value = "升数卡") private BigDecimal literCard; @ApiModelProperty("公众号") + @ExcelProperty(index = 25,value = "公众号") private String official; @ApiModelProperty("加油金") + @ExcelProperty(index = 26,value = "加油金") private BigDecimal refuelMoney; @ApiModelProperty("加油次数") + @ExcelProperty(index = 27,value = "加油次数") private BigDecimal consumeNum; @ApiModelProperty("副卡信息") + @ExcelProperty(index = 28,value = "副卡信息") private String secondCard; + + @ApiModelProperty("固定等级") + @ExcelProperty(index = 29,value = "固定等级") + private String fixingLevel; } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/listener/EasyExcelListener.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/listener/EasyExcelListener.java new file mode 100644 index 000000000..ae4c94334 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/listener/EasyExcelListener.java @@ -0,0 +1,38 @@ +package com.fuint.business.userManager.listener; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +public class EasyExcelListener extends AnalysisEventListener { + //可以通过实例获取该值 + private List datas = new ArrayList(); + + @Override + public void invoke(Object o, AnalysisContext analysisContext) { + datas.add(o);//数据存储到list,供批量处理,或后续自己业务逻辑处理。 + doSomething(o);//根据自己业务做处理 + } + + private void doSomething(Object object) { + //1、入库调用接口 + } + + public List getDatas() { + return datas; + } + + public void setDatas(List datas) { + this.datas = datas; + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + // datas.clear();//解析结束销毁不用的资源 + } +} + diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/mapper/xml/LJUserMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/mapper/xml/LJUserMapper.xml index dd970d7b8..4269f7dcd 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/mapper/xml/LJUserMapper.xml +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/mapper/xml/LJUserMapper.xml @@ -31,6 +31,7 @@ + @@ -40,7 +41,7 @@ select id, mobile, user_no, avatar, name, open_id, idcard, grade_id, start_time, end_time, balance, point, sex, birthday, car_no, source, password, salt, address, merchant_id, store_id, create_time, update_time, - status, description, operator,official,liter_card,refuel_money,consume_num,second_card from mt_user + status, description, operator,official,liter_card,refuel_money,consume_num,second_card,fixing_level from mt_user