Parcourir la source

Merge branch 'dev'

xiongzhu il y a 4 ans
Parent
commit
1b5dfc63ad

+ 17 - 8
src/main/data-center/src/components/mapChart.vue

@@ -137,16 +137,16 @@ export default {
                 console.log(this.chooseMenu);
                 if (this.chooseMenu === 0) {
                     this.initBaidu();
-                } else if (this.chooseMenu === 2 || this.chooseMenu === 5 || this.chooseMenu === 3) {
+                } else if (this.chooseMenu === 2 || this.chooseMenu === 4 || this.chooseMenu === 3) {
                     this.initScatter();
-                } else if (this.chooseMenu === 4 || this.chooseMenu === 6) {
+                } else if (this.chooseMenu === 5 || this.chooseMenu === 6) {
                     this.showLables =
                         this.chooseMenu === 6
                             ? ['初级示范区', '高级示范区', '重点示范区']
                             : ['高新基地', '高级高新基地', '重点高新基地'];
                     this.initScatter('more');
                 } else if (this.chooseMenu === 1) {
-                    this.initHeatmap();
+                    this.initScatter();
                 }
             });
         },
@@ -341,7 +341,7 @@ export default {
                 zAxis3D: {
                     type: 'value',
                     min: 0,
-                    max: 40,
+                    max: 9000000,
                 },
                 series: [
                     {
@@ -462,11 +462,20 @@ export default {
                             }),
                             symbolSize: function (val) {
                                 let size = val[2];
-                                if (size > 100) {
-                                    size = Math.floor(size / 5);
+                                if (size > 1000000) {
+                                    size = Math.floor(size / 100000);
+                                }
+                                if (size > 100000) {
+                                    size = Math.floor(size / 10000);
+                                }
+                                if (size > 10000) {
+                                    size = Math.floor(size / 1000);
+                                }
+                                if (size > 1000) {
+                                    size = Math.floor(size / 100);
                                 }
                                 if (size > 100) {
-                                    size = Math.floor(size / 20);
+                                    size = Math.floor(size / 10);
                                 }
                                 return size;
                             },
@@ -480,7 +489,7 @@ export default {
                             hoverAnimation: true,
                             label: {
                                 formatter: (params) => {
-                                    return params.name + '\r\n' + params.value[2];
+                                    return params.name + '\r\n' + params.value[2] + '万元';
                                 },
                                 show: true,
                                 color: '#fff',

+ 21 - 0
src/main/java/com/izouma/jmrh/domain/OrgInfo.java

@@ -1,5 +1,7 @@
 package com.izouma.jmrh.domain;
 
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
 import com.izouma.jmrh.converter.EncryptConverter;
 import com.izouma.jmrh.enums.AuditStatus;
 import io.swagger.annotations.ApiModel;
@@ -18,61 +20,79 @@ import java.time.LocalDateTime;
 @AllArgsConstructor
 @Builder
 @ApiModel("企业认证")
+@ExcelIgnoreUnannotated
 public class OrgInfo extends BaseEntity {
     @ApiModelProperty("单位名称")
+    @ExcelProperty("单位名称")
     @Convert(converter = EncryptConverter.class)
     private String orgName;
 
     @ApiModelProperty("单位性质")
+    @ExcelProperty("单位性质")
     private String orgType;
 
     @ApiModelProperty("所属行业")
+    @ExcelProperty("所属行业")
     private String industry;
 
     @ApiModelProperty("上市公司")
+    @ExcelProperty("上市公司")
     private boolean publicCompany;
 
     @ApiModelProperty("隶属单位")
+    @ExcelProperty("隶属单位")
     private String parentOrg;
 
     @ApiModelProperty("所在地")
+    @ExcelProperty("所在地")
     private String address;
 
     @ApiModelProperty("地理位置")
+    @ExcelProperty("地理位置")
     private String location;
 
     @ApiModelProperty("详细地址")
+    @ExcelProperty("详细地址")
     @Convert(converter = EncryptConverter.class)
     private String addressDetail;
 
     @ApiModelProperty("企业介绍")
+    @ExcelProperty("企业介绍")
     private String intro;
 
     @ApiModelProperty("企业logo")
+    @ExcelProperty("企业logo")
     private String logo;
 
     @ApiModelProperty("营业执照")
+    @ExcelProperty("营业执照")
     private String license;
 
     @ApiModelProperty("营业执照")
+    @ExcelProperty("营业执照")
     private String uscc;
 
     @ApiModelProperty("联系人")
+    @ExcelProperty("联系人")
     @Convert(converter = EncryptConverter.class)
     private String contactName;
 
     @ApiModelProperty("身份证号")
+    @ExcelProperty("身份证号")
     @Convert(converter = EncryptConverter.class)
     private String contactIdNo;
 
     @ApiModelProperty("手机号")
+    @ExcelProperty("手机号")
     @Convert(converter = EncryptConverter.class)
     private String contactPhone;
 
     @ApiModelProperty("电子邮箱")
+    @ExcelProperty("电子邮箱")
     private String contactEmail;
 
     @ApiModelProperty("信息报送承诺书扫描件")
+    @ExcelProperty("信息报送承诺书扫描件")
     @Convert(converter = EncryptConverter.class)
     private String attach;
 
@@ -84,6 +104,7 @@ public class OrgInfo extends BaseEntity {
     private AuditStatus status;
 
     @ApiModelProperty("备注")
+    @ExcelProperty("备注")
     private String remark;
 
     @Transient

+ 48 - 3
src/main/java/com/izouma/jmrh/service/OrgInfoService.java

@@ -1,11 +1,27 @@
 package com.izouma.jmrh.service;
 
+import com.alibaba.excel.EasyExcel;
 import com.izouma.jmrh.domain.OrgInfo;
+import com.izouma.jmrh.enums.AuditStatus;
+import com.izouma.jmrh.enums.OrgStatus;
 import com.izouma.jmrh.exception.BusinessException;
 import com.izouma.jmrh.repo.*;
+import com.izouma.jmrh.service.storage.StorageService;
+import com.izouma.jmrh.utils.FileUtils;
+import com.izouma.jmrh.utils.excel.UploadDataListener;
 import lombok.AllArgsConstructor;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.util.TempFile;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -13,13 +29,42 @@ import java.util.Map;
 @AllArgsConstructor
 public class OrgInfoService {
 
-    private OrgInfoRepo orgInfoRepo;
+    private OrgInfoRepo    orgInfoRepo;
+    private StorageService storageService;
 
-    public Map<String, Object> getAllCount(Long id){
+    public Map<String, Object> getAllCount(Long id) {
         HashMap<String, Object> map = new HashMap<>();
         OrgInfo orgInfo = orgInfoRepo.findById(id).orElseThrow(new BusinessException("无记录"));
-        map.put("orgInfo",orgInfo);
+        map.put("orgInfo", orgInfo);
         return map;
     }
 
+    public void upload(MultipartFile file) throws IOException {
+        File destDir = TempFile.createTempDirectory("import");
+        FileUtils.unzip(file.getInputStream(), destDir);
+        File xlsxFile = FileUtils.findExcel(destDir);
+        if (xlsxFile == null) return;
+        UploadDataListener<OrgInfo> listener = new UploadDataListener<>();
+        EasyExcel.read(new FileInputStream(xlsxFile), OrgInfo.class, listener).sheet().doReadSync();
+        for (OrgInfo data : listener.getData()) {
+            data.setStatus(AuditStatus.PASS);
+            if (StringUtils.isBlank(data.getOrgName())) {
+                throw new BusinessException("企业名称不能为空");
+            }
+            if (data.getLogo() != null) {
+                File uploadFile = new File(destDir, data.getLogo());
+                if (uploadFile.exists()) {
+                    try {
+                        String path = "image/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
+                                + RandomStringUtils.randomAlphabetic(8)
+                                + "." + FilenameUtils.getExtension(uploadFile.getName());
+                        String url = storageService.uploadFromInputStream(new FileInputStream(uploadFile), path);
+                        data.setLogo(url);
+                    } catch (Exception ignored) {
+                    }
+                }
+            }
+        }
+        orgInfoRepo.saveAll(listener.getData());
+    }
 }

+ 55 - 0
src/main/java/com/izouma/jmrh/utils/FileUtils.java

@@ -10,6 +10,8 @@ import java.nio.file.attribute.PosixFileAttributes;
 import java.nio.file.attribute.PosixFilePermission;
 import java.nio.file.attribute.PosixFilePermissions;
 import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
 
 public class FileUtils {
 
@@ -200,5 +202,58 @@ public class FileUtils {
 
     }
 
+    public static void unzip(InputStream in, File destDir) throws IOException {
+        byte[] buffer = new byte[1024];
+        ZipInputStream zis = new ZipInputStream(in);
+        ZipEntry zipEntry = zis.getNextEntry();
+        while (zipEntry != null) {
+            File newFile = newFile(destDir, zipEntry);
+            if (zipEntry.isDirectory()) {
+                if (!newFile.isDirectory() && !newFile.mkdirs()) {
+                    throw new IOException("Failed to create directory " + newFile);
+                }
+            } else {
+                // fix for Windows-created archives
+                File parent = newFile.getParentFile();
+                if (!parent.isDirectory() && !parent.mkdirs()) {
+                    throw new IOException("Failed to create directory " + parent);
+                }
+
+                // write file content
+                FileOutputStream fos = new FileOutputStream(newFile);
+                int len;
+                while ((len = zis.read(buffer)) > 0) {
+                    fos.write(buffer, 0, len);
+                }
+                fos.close();
+            }
+            zipEntry = zis.getNextEntry();
+        }
+        zis.closeEntry();
+        zis.close();
+    }
+
+    public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
+        File destFile = new File(destinationDir, zipEntry.getName());
 
+        String destDirPath = destinationDir.getCanonicalPath();
+        String destFilePath = destFile.getCanonicalPath();
+
+        if (!destFilePath.startsWith(destDirPath + File.separator)) {
+            throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
+        }
+
+        return destFile;
+    }
+
+    public static File findExcel(File dir) {
+        if (!(dir.exists() && dir.isDirectory())) return null;
+        for (File file : dir.listFiles()) {
+            String name = file.getName().toLowerCase();
+            if ((name.endsWith(".xlsx") || name.endsWith(".xls")) && !name.startsWith(".") && !file.isHidden()) {
+                return file;
+            }
+        }
+        return null;
+    }
 }

+ 24 - 0
src/main/java/com/izouma/jmrh/utils/excel/ExcelUtils.java

@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModel;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 public class ExcelUtils<T> {
@@ -30,4 +31,27 @@ public class ExcelUtils<T> {
                 .registerConverter(new PrimitiveBooleanConverter())
                 .doWrite(data);
     }
+
+    public static <T> void export(HttpServletResponse response, List<T> data, Class<T> clazz) throws IOException {
+        export(response, data, null);
+    }
+
+    public static <T> void export(HttpServletResponse response, List<T> data, String name, Class<T> clazz) throws IOException {
+        String fileName = "data.xlsx";
+        if (data != null && !data.isEmpty()) {
+            fileName = data.get(0).getClass().getSimpleName() + ".xlsx";
+        }
+        if (name != null) {
+            fileName = name + ".xlsx";
+        }
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        response.setHeader("Content-Disposition", "attachment;filename=" + org.apache.catalina.util.URLEncoder.DEFAULT.encode(fileName, StandardCharsets.UTF_8));
+        EasyExcel.write(response.getOutputStream(), clazz).sheet("sheet")
+                .registerConverter(new LocalDateConverter())
+                .registerConverter(new LocalDateTimeConverter())
+                .registerConverter(new BooleanConverter())
+                .registerConverter(new PrimitiveBooleanConverter())
+                .doWrite(data);
+    }
 }

+ 29 - 0
src/main/java/com/izouma/jmrh/utils/excel/UploadDataListener.java

@@ -0,0 +1,29 @@
+package com.izouma.jmrh.utils.excel;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UploadDataListener<T> extends AnalysisEventListener<T> {
+    private final List<T> data;
+
+    public UploadDataListener() {
+        this.data = new ArrayList<>();
+    }
+
+    public List<T> getData() {
+        return data;
+    }
+
+    @Override
+    public void invoke(T t, AnalysisContext analysisContext) {
+        data.add(t);
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+
+    }
+}

+ 8 - 6
src/main/java/com/izouma/jmrh/web/OrgInfoController.java

@@ -21,6 +21,7 @@ import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
@@ -100,12 +101,8 @@ public class OrgInfoController extends BaseController {
     @GetMapping("/excel")
     @ResponseBody
     public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
-        List<OrgInfoDTO> data = all(pageQuery).getContent().stream().map(orgInfo -> {
-            OrgInfoDTO dto = new OrgInfoDTO();
-            BeanUtils.copyProperties(orgInfo, dto);
-            return dto;
-        }).collect(Collectors.toList());
-        ExcelUtils.export(response, data);
+        List<OrgInfo> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data, "企业", OrgInfo.class);
     }
 
     @PostMapping("/audit")
@@ -121,5 +118,10 @@ public class OrgInfoController extends BaseController {
     public void saveAll() {
         userRepo.saveAll(userRepo.findAll());
     }
+
+    @PostMapping("/upload")
+    public void upload(MultipartFile file) throws IOException {
+        orgInfoService.upload(file);
+    }
 }
 

+ 54 - 0
src/main/vue/src/mixins/pageableTable.js

@@ -190,6 +190,60 @@ export default {
             });
             console.log(rowWidth);
             console.log(headWidth);
+        },
+        template() {
+            this.downloading = true;
+            this.$axios
+                .get(this.url.replace('/all', '/excel'), {
+                    responseType: 'blob',
+                    params: { size: 10000, query: { id: -1 } }
+                })
+                .then(res => {
+                    console.log(res);
+                    this.downloading = false;
+                    const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
+                    const link = document.createElement('a');
+                    link.href = downloadUrl;
+                    link.setAttribute(
+                        'download',
+                        decodeURIComponent(res.headers['content-disposition'].split('filename=')[1]).replace(
+                            '.xlsx',
+                            '导入模版.xlsx'
+                        )
+                    );
+                    document.body.appendChild(link);
+                    link.click();
+                    link.remove();
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.downloading = false;
+                    this.$message.error(e.error);
+                });
+        },
+        importData() {
+            let input = document.createElement('input');
+            input.type = 'file';
+            // input.accept =
+            //     'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
+            input.accept = 'application/zip, application/octet-stream';
+            input.onchange = e => {
+                let form = new FormData();
+                form.append('file', input.files[0]);
+                this.downloading = true;
+                this.$axios
+                    .post(this.url.replace('/all', '/upload'), form)
+                    .then(res => {
+                        this.downloading = false;
+                        this.$message.success('导入成功');
+                        this.getData();
+                    })
+                    .catch(e => {
+                        this.downloading = false;
+                        this.$message.error(e.error || '导入失败');
+                    });
+            };
+            input.click();
         }
     },
     watch: {

+ 18 - 0
src/main/vue/src/views/OrgInfoList.vue

@@ -11,6 +11,24 @@
                 class="filter-item"
                 >导出EXCEL
             </el-button>
+            <el-button
+                @click="importData"
+                icon="el-icon-upload2"
+                :loading="downloading"
+                :disabled="fetchingData"
+                class="filter-item"
+            >
+                导入
+            </el-button>
+            <el-button
+                @click="template"
+                icon="el-icon-notebook-2"
+                :loading="downloading"
+                :disabled="fetchingData"
+                class="filter-item"
+            >
+                模版
+            </el-button>
         </div>
         <el-table
             :data="tableData"