From e13ea7939e897e41ab4608e105a68ffde168dcbb Mon Sep 17 00:00:00 2001 From: wangliwen Date: Thu, 16 Jun 2022 11:45:44 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=B1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renren-admin/src/main/resources/application-prod.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/renren-admin/src/main/resources/application-prod.yml b/renren-admin/src/main/resources/application-prod.yml index 5c9bd2aa..ae3f77fd 100644 --- a/renren-admin/src/main/resources/application-prod.yml +++ b/renren-admin/src/main/resources/application-prod.yml @@ -34,9 +34,9 @@ spring: wall: config: multi-statement-allow: true -# 生产环境默认关掉flyway + # 生产环境默认关掉flyway flyway: - enable: false + enabled: false #上传的静态资源配置 resource: root_url: 15.72.183.90 @@ -51,7 +51,7 @@ big_date: hisense: gateway: url: http://15.72.184.7:8080 - + qdyjj: ipAndPort: 15.72.178.136:9494 \ No newline at end of file From 6b5f35e283ed970e6a0adcaff24e1fa1d7542a9d Mon Sep 17 00:00:00 2001 From: wangliwen Date: Thu, 16 Jun 2022 14:54:12 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=83=BD=E5=8A=9B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/resource/entity/AttrEntity.java | 304 +++++++-------- .../excel/ResourceExcelImportListener.java | 345 ++++++++++++++++++ 2 files changed, 499 insertions(+), 150 deletions(-) create mode 100644 renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java diff --git a/renren-admin/src/main/java/io/renren/modules/resource/entity/AttrEntity.java b/renren-admin/src/main/java/io/renren/modules/resource/entity/AttrEntity.java index 296d03ec..5b5ed667 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/entity/AttrEntity.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/entity/AttrEntity.java @@ -10,188 +10,192 @@ import java.util.Date; /** * 资源属性表 * - * @author dg + * @author dg * @since 1.0 2022-04-13 */ @Data -@EqualsAndHashCode(callSuper=false) +@EqualsAndHashCode(callSuper = false) @TableName("tb_data_attr") -public class AttrEntity implements Serializable{ - private static final long serialVersionUID = 1L; +public class AttrEntity implements Serializable { + private static final long serialVersionUID = 1L; - @TableId - private Long id; - /** - * 资源ID,表tb_data_resource主键 - */ - private Long dataResourceId; - /** - * 属性类型 - */ - private String attrType; - /** - * 属性值 - */ - private String attrValue; - /** - * 删除标志:0:正常使用;1:已删除;9:其他 - */ - private Integer delFlag; - /** - * 创建人 - */ - @TableField(fill = FieldFill.INSERT) - private Long creator; - /** - * 创建时间 - */ - @TableField(fill = FieldFill.INSERT) - private Date createDate; - /** - * 修改人 - */ - @TableField(fill = FieldFill.INSERT_UPDATE) - private Long updater; - /** - * 更新时间 - */ - @TableField(fill = FieldFill.INSERT_UPDATE) - private Date updateDate; - private String note1; - private String note2; - private String note3; - private String note4; - private String note5; + @TableId + private Long id; + /** + * 资源ID,表tb_data_resource主键 + */ + private Long dataResourceId; + /** + * 属性类型 + */ + private String attrType; + /** + * 属性值 + */ + private String attrValue; + /** + * 删除标志:0:正常使用;1:已删除;9:其他 + */ + private Integer delFlag; + /** + * 创建人 + */ + @TableField(fill = FieldFill.INSERT) + private Long creator; + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + private Date createDate; + /** + * 修改人 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; + private String note1; + private String note2; + private String note3; + private String note4; + private String note5; - public Long getId() { - return id; - } + public AttrEntity() { + this.delFlag = 0; + } - public void setId(Long id) { - this.id = id; - } + public Long getId() { + return id; + } - public Long getDataResourceId() { - return dataResourceId; - } + public void setId(Long id) { + this.id = id; + } - public void setDataResourceId(Long dataResourceId) { - this.dataResourceId = dataResourceId; - } + public Long getDataResourceId() { + return dataResourceId; + } - public String getAttrType() { - return attrType; - } + public void setDataResourceId(Long dataResourceId) { + this.dataResourceId = dataResourceId; + } - public void setAttrType(String attrType) { - this.attrType = attrType; - } + public String getAttrType() { + return attrType; + } - public String getAttrValue() { - return attrValue; - } + public void setAttrType(String attrType) { + this.attrType = attrType; + } - public void setAttrValue(String attrValue) { - this.attrValue = attrValue; - } + public String getAttrValue() { + return attrValue; + } - public Integer getDelFlag() { - return delFlag; - } + public void setAttrValue(String attrValue) { + this.attrValue = attrValue; + } - public void setDelFlag(Integer delFlag) { - this.delFlag = delFlag; - } + public Integer getDelFlag() { + return delFlag; + } - public Long getCreator() { - return creator; - } + public void setDelFlag(Integer delFlag) { + this.delFlag = delFlag; + } - public void setCreator(Long creator) { - this.creator = creator; - } + public Long getCreator() { + return creator; + } - public Date getCreateDate() { - return createDate; - } + public void setCreator(Long creator) { + this.creator = creator; + } - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } + public Date getCreateDate() { + return createDate; + } - public Long getUpdater() { - return updater; - } + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } - public void setUpdater(Long updater) { - this.updater = updater; - } + public Long getUpdater() { + return updater; + } - public Date getUpdateDate() { - return updateDate; - } + public void setUpdater(Long updater) { + this.updater = updater; + } - public void setUpdateDate(Date updateDate) { - this.updateDate = updateDate; - } + public Date getUpdateDate() { + return updateDate; + } - public String getNote1() { - return note1; - } + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } - public void setNote1(String note1) { - this.note1 = note1; - } + public String getNote1() { + return note1; + } - public String getNote2() { - return note2; - } + public void setNote1(String note1) { + this.note1 = note1; + } - public void setNote2(String note2) { - this.note2 = note2; - } + public String getNote2() { + return note2; + } - public String getNote3() { - return note3; - } + public void setNote2(String note2) { + this.note2 = note2; + } - public void setNote3(String note3) { - this.note3 = note3; - } + public String getNote3() { + return note3; + } - public String getNote4() { - return note4; - } + public void setNote3(String note3) { + this.note3 = note3; + } - public void setNote4(String note4) { - this.note4 = note4; - } + public String getNote4() { + return note4; + } - public String getNote5() { - return note5; - } + public void setNote4(String note4) { + this.note4 = note4; + } - public void setNote5(String note5) { - this.note5 = note5; - } + public String getNote5() { + return note5; + } - @Override - public String toString() { - return "AttrEntity{" + - "id=" + id + - ", dataResourceId=" + dataResourceId + - ", attrType='" + attrType + '\'' + - ", attrValue='" + attrValue + '\'' + - ", delFlag=" + delFlag + - ", creator=" + creator + - ", createDate=" + createDate + - ", updater=" + updater + - ", updateDate=" + updateDate + - ", note1='" + note1 + '\'' + - ", note2='" + note2 + '\'' + - ", note3='" + note3 + '\'' + - ", note4='" + note4 + '\'' + - ", note5='" + note5 + '\'' + - '}'; - } + public void setNote5(String note5) { + this.note5 = note5; + } + + @Override + public String toString() { + return "AttrEntity{" + + "id=" + id + + ", dataResourceId=" + dataResourceId + + ", attrType='" + attrType + '\'' + + ", attrValue='" + attrValue + '\'' + + ", delFlag=" + delFlag + + ", creator=" + creator + + ", createDate=" + createDate + + ", updater=" + updater + + ", updateDate=" + updateDate + + ", note1='" + note1 + '\'' + + ", note2='" + note2 + '\'' + + ", note3='" + note3 + '\'' + + ", note4='" + note4 + '\'' + + ", note5='" + note5 + '\'' + + '}'; + } } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java b/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java new file mode 100644 index 00000000..1eb6ecd8 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java @@ -0,0 +1,345 @@ +package io.renren.modules.resource.excel; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.fastjson.JSON; +import io.renren.modules.resource.dto.ResourceDTO; +import io.renren.modules.resource.entity.AttrEntity; +import io.renren.modules.resource.service.ResourceService; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + + +/** + * 导入资源 + */ +public class ResourceExcelImportListener extends AnalysisEventListener> { + private static final Logger logger = LoggerFactory.getLogger(ResourceExcelImportListener.class); + private int BATCH_COUNT = Runtime.getRuntime().availableProcessors() * 10; + + private int sheet = 1; // 读取excel sheet + + private List> deptList; // 部门信息 + + private ResourceService resourceService; + + private List> list = new ArrayList<>(); + + Map headMap = null; + + /** + * When analysis one row trigger invoke function. + * + * @param data one row value. Is is same as {@link AnalysisContext#readRowHolder()} + * @param context analysis context + */ + @Override + public void invoke(Map data, AnalysisContext context) { + list.add(data); + if (list.size() > BATCH_COUNT) { + dealDate(); + list.clear(); + } + } + + /** + * if have something to do after all analysis + * + * @param context + */ + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + dealDate(); + } + + @Override + public void invokeHeadMap(Map headMap, AnalysisContext context) { + if (this.headMap == null) { + this.headMap = headMap; + } + logger.info("sheet:" + sheet + "解析到一条头数据:{}", JSON.toJSONString(headMap)); + } + + + /** + * 处理数据 + */ + private void dealDate() { + list.stream().map(index -> { + Optional> deptOptional = + deptList.stream().filter(dept -> index.values().contains(dept.getOrDefault("name", "").toString())).findAny(); + if (!deptOptional.isPresent()) { + logger.info("找不到部门:{}", index.toString()); + return null; + } + ResourceDTO resourceDTO = new ResourceDTO(); + switch (sheet) { + case 0: // 需要跳过前6行 + resourceDTO = getResourceDTO(resourceDTO, index, 0, Long.valueOf(deptOptional.get().get("id").toString())); + break; + case 1: + resourceDTO = getResourceDTO(resourceDTO, index, 1, Long.valueOf(deptOptional.get().get("id").toString())); + break; + case 2: + resourceDTO = getResourceDTO(resourceDTO, index, 2, Long.valueOf(deptOptional.get().get("id").toString())); + break; + case 3: + resourceDTO = getResourceDTO(resourceDTO, index, 3, Long.valueOf(deptOptional.get().get("id").toString())); + break; + default: + logger.error("不支持该sheet"); + } + return resourceDTO; + }).filter(index -> index != null && StringUtils.isNotEmpty(index.getName())).forEach(index -> { + resourceService.insertWithAttrs(index); + logger.info("完成导入:{}", index.getName()); + }); + } + + /** + * @param resourceDTO + * @return 获取导入对应参数 + */ + private ResourceDTO getResourceDTO(ResourceDTO resourceDTO, Map date, int sheet, Long deptId) { + List infoList = new ArrayList<>(); + resourceDTO.setCreateDate(new Date()); + + switch (sheet) { + case 0: { + resourceDTO.setType("应用资源"); + resourceDTO.setName(date.get(1)); + + AttrEntity attrEntity1 = new AttrEntity(); + attrEntity1.setAttrType("应用状态"); + attrEntity1.setAttrValue(date.get(2)); + infoList.add(attrEntity1); // 应用状态 + + AttrEntity attrEntity2 = new AttrEntity(); + attrEntity2.setAttrType("应用类型"); + attrEntity2.setAttrValue(date.get(3)); + infoList.add(attrEntity2); // 应用类型 + + AttrEntity attrEntity3 = new AttrEntity(); + attrEntity3.setAttrType("应用领域"); + attrEntity3.setAttrValue(date.get(4)); + infoList.add(attrEntity3); // 应用领域 + + resourceDTO.setDescription(date.get(5)); // 描述 + + AttrEntity attrEntity4 = new AttrEntity(); + attrEntity4.setAttrType("发布端"); + attrEntity4.setAttrValue(date.get(6)); + infoList.add(attrEntity4); // 发布端 + + resourceDTO.setDeptName(date.get(7)); + resourceDTO.setDeptContacts(date.get(8)); // 部门联系人 + resourceDTO.setDeptPhone(date.get(9)); // 部门联系人电话 + + AttrEntity attrEntity5 = new AttrEntity(); + attrEntity5.setAttrType("应用展示视频"); + attrEntity5.setAttrValue(date.get(10)); + infoList.add(attrEntity5); // 应用展示视频 + + AttrEntity attrEntity6 = new AttrEntity(); + attrEntity6.setAttrType("应用图片"); + attrEntity6.setAttrValue(date.get(11)); + infoList.add(attrEntity6); // 应用图片 + + AttrEntity attrEntity7 = new AttrEntity(); + attrEntity7.setAttrType("功能介绍"); + attrEntity7.setAttrValue(date.get(12)); + infoList.add(attrEntity7); // 功能介绍 + + AttrEntity attrEntity8 = new AttrEntity(); + attrEntity8.setAttrType("部署区域"); + attrEntity8.setAttrValue(date.get(13)); + infoList.add(attrEntity8); // 部署区域 + + AttrEntity attrEntity9 = new AttrEntity(); + attrEntity9.setAttrType("是否统一登录"); + attrEntity9.setAttrValue(date.get(14)); + infoList.add(attrEntity9); // 是否统一登录 + + resourceDTO.setLink(date.get(15)); // 访问地址 + resourceDTO.setShareCondition(date.get(16)); // 共享条件 + resourceDTO.setShareMode(date.get(17)); // 共享类型 + resourceDTO.setShareType(null); + + AttrEntity attrEntity10 = new AttrEntity(); + attrEntity10.setAttrType("等保定级"); + attrEntity10.setAttrValue(date.get(18)); + infoList.add(attrEntity10); // 等保定级 + + AttrEntity attrEntity11 = new AttrEntity(); + attrEntity11.setAttrType("是否等保备案"); + attrEntity11.setAttrValue(date.get(19)); + infoList.add(attrEntity11); // 是否等保备案 + + AttrEntity attrEntity12 = new AttrEntity(); + attrEntity12.setAttrType("服务商"); + attrEntity12.setAttrValue(date.get(20)); + infoList.add(attrEntity12); // 服务商 + + AttrEntity attrEntity13 = new AttrEntity(); + attrEntity13.setAttrType("服务商联系人"); + attrEntity13.setAttrValue(date.get(21)); + infoList.add(attrEntity13); // 服务商联系人 + + AttrEntity attrEntity14 = new AttrEntity(); + attrEntity14.setAttrType("服务商联系电话"); + attrEntity14.setAttrValue(date.get(22)); + infoList.add(attrEntity14); // 服务商联系人 + + AttrEntity attrEntity15 = new AttrEntity(); + attrEntity15.setAttrType("常见问题"); + attrEntity15.setAttrValue(date.get(23)); + infoList.add(attrEntity15); // 常见问题 + + } + break; + case 1: { + resourceDTO.setType("组件服务"); + resourceDTO.setName(date.get(1)); + + AttrEntity attrEntity1 = new AttrEntity(); + attrEntity1.setAttrType("算法类别"); + attrEntity1.setAttrValue(date.get(2)); + infoList.add(attrEntity1); // 算法类别 + + AttrEntity attrEntity2 = new AttrEntity(); + attrEntity2.setAttrType("是否免批"); + attrEntity2.setAttrValue(date.get(3)); + infoList.add(attrEntity2); // 算法类别 + + AttrEntity attrEntity3 = new AttrEntity(); + attrEntity3.setAttrType("使用方式"); + attrEntity3.setAttrValue(date.get(4)); + infoList.add(attrEntity3); // 使用方式 + + AttrEntity attrEntity4 = new AttrEntity(); + attrEntity4.setAttrType("部署位置"); + attrEntity4.setAttrValue(date.get(5)); + infoList.add(attrEntity4); // 部署位置 + + AttrEntity attrEntity5 = new AttrEntity(); + attrEntity5.setAttrType("应用领域"); + attrEntity5.setAttrValue(date.get(6)); + infoList.add(attrEntity5); // 应用领域 + + resourceDTO.setShareCondition(date.get(7)); // 共享条件 + resourceDTO.setShareMode(date.get(8)); // 共享类型 + resourceDTO.setShareType(null); + + resourceDTO.setDescription(date.get(9)); + + AttrEntity attrEntity6 = new AttrEntity(); + attrEntity6.setAttrType("算法介绍视频"); + attrEntity6.setAttrValue(date.get(10)); + infoList.add(attrEntity5); // 应用领域 + + AttrEntity attrEntity7 = new AttrEntity(); + attrEntity7.setAttrType("服务商"); + attrEntity7.setAttrValue(date.get(11)); + infoList.add(attrEntity7); // 服务商 + + AttrEntity attrEntity8 = new AttrEntity(); + attrEntity8.setAttrType("服务商联系人"); + attrEntity8.setAttrValue(date.get(12)); + infoList.add(attrEntity8); // 服务商联系人 + + AttrEntity attrEntity9 = new AttrEntity(); + attrEntity9.setAttrType("服务商联系电话"); + attrEntity9.setAttrValue(date.get(13)); + infoList.add(attrEntity9); // 服务商联系人 + + AttrEntity attrEntity10 = new AttrEntity(); + attrEntity10.setAttrType("关联应用"); + attrEntity10.setAttrValue(date.get(14)); + infoList.add(attrEntity10); // 关联应用 + + AttrEntity attrEntity11 = new AttrEntity(); + attrEntity11.setAttrType("算法优势"); + attrEntity11.setAttrValue(date.get(15)); + infoList.add(attrEntity11); // 算法优势 + + AttrEntity attrEntity12 = new AttrEntity(); + attrEntity12.setAttrType("应用场景"); + attrEntity12.setAttrValue(date.get(16)); + infoList.add(attrEntity12); // 应用场景 + + resourceDTO.setLink(date.get(17)); + resourceDTO.setApiMethodType(date.get(18)); + + AttrEntity attrEntity13 = new AttrEntity(); + attrEntity13.setAttrType("技术文档"); + attrEntity13.setAttrValue(date.get(19)); + infoList.add(attrEntity13); // 技术文档 + + AttrEntity attrEntity14 = new AttrEntity(); + attrEntity14.setAttrType("试用地址"); + attrEntity14.setAttrValue(date.get(20)); + infoList.add(attrEntity14); // 试用地址 + + AttrEntity attrEntity15 = new AttrEntity(); + attrEntity15.setAttrType("是否收费"); + attrEntity15.setAttrValue(date.get(21)); + infoList.add(attrEntity15); // 是否收费 + + AttrEntity attrEntity16 = new AttrEntity(); + attrEntity16.setAttrType("计费标准信息"); + attrEntity16.setAttrValue(date.get(22)); + infoList.add(attrEntity16); // 计费标准信息 + + AttrEntity attrEntity17 = new AttrEntity(); + attrEntity17.setAttrType("常见问题"); + attrEntity17.setAttrValue(date.get(23)); + infoList.add(attrEntity17); // 常见问题 + } + break; + case 2: { + resourceDTO.setType("知识库"); + resourceDTO.setName(date.get(1)); + resourceDTO.setLink(date.get(2)); + resourceDTO.setDescription(date.get(3)); + + Date createDate = new Date(Long.parseLong(date.get(5))); + resourceDTO.setCreateDate(createDate); + + AttrEntity attrEntity = new AttrEntity(); + attrEntity.setAttrType("文件类型"); + attrEntity.setAttrValue(date.get(6)); + + infoList.add(attrEntity); + + this.headMap.keySet().stream().skip(6).forEach(key -> { // 表头后6个 + AttrEntity attrEntity_ = new AttrEntity(); + attrEntity_.setAttrType(this.headMap.get(key)); + attrEntity_.setAttrValue(date.get(key)); + infoList.add(attrEntity_); + }); + + } + case 3: { + resourceDTO.setType("基础设施"); + resourceDTO.setName(date.get(1)); + + this.headMap.keySet().stream().skip(1).forEach(key -> { // 表头后1个 + AttrEntity attrEntity = new AttrEntity(); + attrEntity.setAttrType(this.headMap.get(key)); + attrEntity.setAttrValue(date.get(key)); + infoList.add(attrEntity); + }); + + } + break; + } + resourceDTO.setInfoList(infoList); + resourceDTO.setDelFlag(0); + resourceDTO.setDeptId(deptId); // 所属部门 + return resourceDTO; + } + +} From 4b7bb257baa0629077bffcf70326b0e1acda6b75 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Thu, 16 Jun 2022 15:24:35 +0800 Subject: [PATCH 3/5] =?UTF-8?q?web=E5=AF=BC=E5=85=A5=E8=83=BD=E5=8A=9B?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ResourceController.java | 54 +++++++- .../excel/ResourceExcelImportListener.java | 116 +++++++++--------- 2 files changed, 113 insertions(+), 57 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index 7d0143ac..fa679bd2 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -1,5 +1,6 @@ package io.renren.modules.resource.controller; +import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import io.renren.common.annotation.LogOperation; @@ -10,6 +11,7 @@ import io.renren.common.validator.ValidatorUtils; import io.renren.common.validator.group.AddGroup; import io.renren.common.validator.group.DefaultGroup; import io.renren.modules.resource.dto.ResourceDTO; +import io.renren.modules.resource.excel.ResourceExcelImportListener; import io.renren.modules.resource.service.ResourceService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -22,14 +24,20 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; -import java.util.HashMap; -import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.util.*; /** * 资源表 @@ -72,12 +80,20 @@ public class ResourceController { @Value("${zsk.catalogIds}") private String[] catalogIds; + @Value("${resource.path}") + private String uploadPath; + @Autowired private ResourceService resourceService; @Autowired private RestTemplate restTemplate; + @Autowired + private JdbcTemplate jdbcTemplate; + + private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/"); + private static final Logger logger = LoggerFactory.getLogger(ResourceController.class); @GetMapping("/page") @@ -186,6 +202,40 @@ public class ResourceController { return new Result().ok(dto.getId() == null ? "" : dto.getId()); } + @PostMapping("/importResource") + @ApiOperation("导入") + @LogOperation("导入") + @ApiImplicitParams({ + @ApiImplicitParam(name = "source", value = "请求来源", paramType = "string", dataType = "string") + }) + public Result importResource(@RequestParam("file") MultipartFile uploadFile, HttpServletRequest request) { + List> dept = + jdbcTemplate.queryForList("SELECT id,`name` FROM sys_dept"); + logger.info("上传文件:" + uploadFile.getOriginalFilename()); + String format = sdf.format(new Date()); + File folder = new File(uploadPath + "upload" + File.separator + format); + logger.info(uploadPath + format); + if (!folder.isDirectory()) { + folder.mkdirs(); + } + // 对上传的文件重命名,避免文件重名 + String oldName = uploadFile.getOriginalFilename(); + String newName = UUID.randomUUID().toString() + + oldName.substring(oldName.lastIndexOf("."), oldName.length()); + try { + // 文件保存 + File file = new File(folder, newName); + uploadFile.transferTo(file); + EasyExcel.read(file, new ResourceExcelImportListener(0, dept, resourceService)).sheet(0).headRowNumber(6).doRead(); + EasyExcel.read(file, new ResourceExcelImportListener(1, dept, resourceService)).sheet(1).headRowNumber(5).doRead(); + EasyExcel.read(file, new ResourceExcelImportListener(2, dept, resourceService)).sheet(2).headRowNumber(5).doRead(); + EasyExcel.read(file, new ResourceExcelImportListener(3, dept, resourceService)).sheet(3).headRowNumber(6).doRead(); + } catch (IOException e) { + return new Result().error(e.getMessage()); + } + return new Result().ok(LocalDateTime.now().toString()); + } + @PutMapping("/update") @ApiOperation("修改") @LogOperation("修改") diff --git a/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java b/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java index 1eb6ecd8..9d319b04 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java @@ -30,6 +30,12 @@ public class ResourceExcelImportListener extends AnalysisEventListener headMap = null; + public ResourceExcelImportListener(int sheet, List> deptList, ResourceService resourceService) { + this.sheet = sheet; + this.deptList = deptList; + this.resourceService = resourceService; + } + /** * When analysis one row trigger invoke function. * @@ -110,202 +116,202 @@ public class ResourceExcelImportListener extends AnalysisEventListener { // 表头后1个 - AttrEntity attrEntity = new AttrEntity(); - attrEntity.setAttrType(this.headMap.get(key)); - attrEntity.setAttrValue(date.get(key)); - infoList.add(attrEntity); + AttrEntity attrEntity_ = new AttrEntity(); + attrEntity_.setAttrType(this.headMap.get(key)); + attrEntity_.setAttrValue(date.get(key)); + infoList.add(attrEntity_); }); } From e0341291675e875c8cd53ea9179538b378515e94 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Thu, 16 Jun 2022 15:47:28 +0800 Subject: [PATCH 4/5] ... --- .../renren/modules/resource/controller/ResourceController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index fa679bd2..9e42c45c 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -214,7 +214,7 @@ public class ResourceController { logger.info("上传文件:" + uploadFile.getOriginalFilename()); String format = sdf.format(new Date()); File folder = new File(uploadPath + "upload" + File.separator + format); - logger.info(uploadPath + format); + logger.info(folder.getPath()); if (!folder.isDirectory()) { folder.mkdirs(); } From 64b44da8598821deb6674fb0ad3e00204cf3255b Mon Sep 17 00:00:00 2001 From: wangliwen Date: Thu, 16 Jun 2022 15:53:19 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E8=A1=A8=E5=A4=B4?= =?UTF-8?q?=E5=8D=87=E5=BA=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/resource/excel/ResourceExcelImportListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java b/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java index 9d319b04..15271aaa 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java @@ -320,7 +320,7 @@ public class ResourceExcelImportListener extends AnalysisEventListener { // 表头后6个 + this.headMap.keySet().stream().sorted().skip(6).forEach(key -> { // 表头后6个 AttrEntity attrEntity_ = new AttrEntity(); attrEntity_.setAttrType(this.headMap.get(key)); attrEntity_.setAttrValue(date.get(key)); @@ -332,7 +332,7 @@ public class ResourceExcelImportListener extends AnalysisEventListener { // 表头后1个 + this.headMap.keySet().stream().sorted().skip(1).forEach(key -> { // 表头后1个 AttrEntity attrEntity_ = new AttrEntity(); attrEntity_.setAttrType(this.headMap.get(key)); attrEntity_.setAttrValue(date.get(key));