Pārlūkot izejas kodu

fix 新增下载相关接口

DYH2020 2 gadi atpakaļ
vecāks
revīzija
e50fe2910c

+ 1 - 0
src/main/java/com/ywt/mg/configs/Constants.java

@@ -12,5 +12,6 @@ public class Constants {
     public static final String ERROR_INFO = "系统开小差,请稍后重试";
 
 
+    public static final String CHARSET_NAME = "iso-8859-1";
 }
 

+ 394 - 334
src/main/java/com/ywt/mg/domain/entities/DownloadRecord.java

@@ -12,338 +12,398 @@ import javax.persistence.Table;
 @Table(name = "download_record")
 @Entity
 public class DownloadRecord implements Serializable {
-  private static final long serialVersionUID = 1L;
-
-  @Id
-  @GeneratedValue(strategy = GenerationType.IDENTITY)
-  @Column(name = "id", insertable = false, nullable = false)
-  private Integer id;
-
-  /**
-   * 下载的文件名称
-   */
-  @Column(name = "name")
-  private String name;
-
-  /**
-   * 药房id
-   */
-  @Column(name = "pharmacy_id")
-  private Integer pharmacyId = 0;
-
-  /**
-   * 药房名称
-   */
-  @Column(name = "pharmacy_name")
-  private String pharmacyName;
-
-  /**
-   * 医药id
-   */
-  @Column(name = "hospital_id")
-  private Integer hospitalId = 0;
-
-  /**
-   * 医药名称
-   */
-  @Column(name = "hospital_name")
-  private String hospitalName;
-
-  /**
-   * 对应ywt_center库的mg_admin表ID
-   */
-  @Column(name = "admin_id")
-  private Integer adminId = 0;
-
-  /**
-   * 对应ywt_center库的mg_admin表account
-   */
-  @Column(name = "admin_name")
-  private String adminName = "";
-
-  /**
-   * 对应oss地址,加密
-   */
-  @Column(name = "url")
-  private String url;
-
-  /**
-   * 创建时间
-   */
-  @Column(name = "create_time")
-  private Date createTime;
-
-  /**
-   * 文件生成时间
-   */
-  @Column(name = "finish_time")
-  private Date finishTime;
-
-  /**
-   * 接口响应时间
-   */
-  @Column(name = "difftime")
-  private Integer difftime;
-
-  /**
-   * 所有参数的md5,防止短时间内的重复点击
-   */
-  @Column(name = "param_md5")
-  private String paramMd5;
-
-  /**
-   * 接口地址(带域名)
-   */
-  @Column(name = "param_url")
-  private String paramUrl;
-
-  /**
-   * 0-下载中,1-下载成功,2-下载失败
-   */
-  @Column(name = "status")
-  private Integer status = 0;
-
-  /**
-   * 更新时间
-   */
-  @Column(name = "update_time")
-  private Date updateTime;
-
-  public Integer getId() {
-    return id;
-  }
-
-  public void setId(Integer id) {
-    this.id = id;
-  }
-
-  /**
-   * 下载的文件名称
-   */
-  public String getName() {
-    return name;
-  }
-
-  /**
-   * 下载的文件名称
-   */
-  public void setName(String name) {
-    this.name = name;
-  }
-
-  /**
-   * 药房id
-   */
-  public Integer getPharmacyId() {
-    return pharmacyId;
-  }
-
-  /**
-   * 药房id
-   */
-  public void setPharmacyId(Integer pharmacyId) {
-    this.pharmacyId = pharmacyId;
-  }
-
-  /**
-   * 药房名称
-   */
-  public String getPharmacyName() {
-    return pharmacyName;
-  }
-
-  /**
-   * 药房名称
-   */
-  public void setPharmacyName(String pharmacyName) {
-    this.pharmacyName = pharmacyName;
-  }
-
-  /**
-   * 医药id
-   */
-  public Integer getHospitalId() {
-    return hospitalId;
-  }
-
-  /**
-   * 医药id
-   */
-  public void setHospitalId(Integer hospitalId) {
-    this.hospitalId = hospitalId;
-  }
-
-  /**
-   * 医药名称
-   */
-  public String getHospitalName() {
-    return hospitalName;
-  }
-
-  /**
-   * 医药名称
-   */
-  public void setHospitalName(String hospitalName) {
-    this.hospitalName = hospitalName;
-  }
-
-  /**
-   * 对应ywt_center库的mg_admin表ID
-   */
-  public Integer getAdminId() {
-    return adminId;
-  }
-
-  /**
-   * 对应ywt_center库的mg_admin表ID
-   */
-  public void setAdminId(Integer adminId) {
-    this.adminId = adminId;
-  }
-
-  /**
-   * 对应ywt_center库的mg_admin表account
-   */
-  public String getAdminName() {
-    return adminName;
-  }
-
-  /**
-   * 对应ywt_center库的mg_admin表account
-   */
-  public void setAdminName(String adminName) {
-    this.adminName = adminName;
-  }
-
-  /**
-   * 对应oss地址,加密
-   */
-  public String getUrl() {
-    return url;
-  }
-
-  /**
-   * 对应oss地址,加密
-   */
-  public void setUrl(String url) {
-    this.url = url;
-  }
-
-  /**
-   * 创建时间
-   */
-  public Date getCreateTime() {
-    return createTime;
-  }
-
-  /**
-   * 创建时间
-   */
-  public void setCreateTime(Date createTime) {
-    this.createTime = createTime;
-  }
-
-  /**
-   * 文件生成时间
-   */
-  public Date getFinishTime() {
-    return finishTime;
-  }
-
-  /**
-   * 文件生成时间
-   */
-  public void setFinishTime(Date finishTime) {
-    this.finishTime = finishTime;
-  }
-
-  /**
-   * 接口响应时间
-   */
-  public Integer getDifftime() {
-    return difftime;
-  }
-
-  /**
-   * 接口响应时间
-   */
-  public void setDifftime(Integer difftime) {
-    this.difftime = difftime;
-  }
-
-  /**
-   * 所有参数的md5,防止短时间内的重复点击
-   */
-  public String getParamMd5() {
-    return paramMd5;
-  }
-
-  /**
-   * 所有参数的md5,防止短时间内的重复点击
-   */
-  public void setParamMd5(String paramMd5) {
-    this.paramMd5 = paramMd5;
-  }
-
-  /**
-   * 接口地址(带域名)
-   */
-  public String getParamUrl() {
-    return paramUrl;
-  }
-
-  /**
-   * 接口地址(带域名)
-   */
-  public void setParamUrl(String paramUrl) {
-    this.paramUrl = paramUrl;
-  }
-
-  /**
-   * 0-下载中,1-下载成功,2-下载失败
-   */
-  public Integer getStatus() {
-    return status;
-  }
-
-  /**
-   * 0-下载中,1-下载成功,2-下载失败
-   */
-  public void setStatus(Integer status) {
-    this.status = status;
-  }
-
-  /**
-   * 更新时间
-   */
-  public Date getUpdateTime() {
-    return updateTime;
-  }
-
-  /**
-   * 更新时间
-   */
-  public void setUpdateTime(Date updateTime) {
-    this.updateTime = updateTime;
-  }
-
-  public String toString() {
-    return "DownloadRecord{id=" + id + 
-      ", name=" + name + 
-      ", pharmacyId=" + pharmacyId + 
-      ", pharmacyName=" + pharmacyName + 
-      ", hospitalId=" + hospitalId + 
-      ", hospitalName=" + hospitalName + 
-      ", adminId=" + adminId + 
-      ", adminName=" + adminName + 
-      ", url=" + url + 
-      ", createTime=" + createTime + 
-      ", finishTime=" + finishTime + 
-      ", difftime=" + difftime + 
-      ", paramMd5=" + paramMd5 + 
-      ", paramUrl=" + paramUrl + 
-      ", status=" + status + 
-      ", updateTime=" + updateTime + 
-      "}";
-  }
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @Column(name = "id", insertable = false, nullable = false)
+    private Integer id;
+
+    /**
+     * 名称(前端路径)
+     */
+    @Column(name = "name")
+    private String name;
+
+    /**
+     * 下载的文件名称
+     */
+    @Column(name = "file_name")
+    private String fileName;
+
+    /**
+     * 药房id
+     */
+    @Column(name = "pharmacy_id")
+    private Integer pharmacyId = 0;
+
+    /**
+     * 药房名称
+     */
+    @Column(name = "pharmacy_name")
+    private String pharmacyName;
+
+    /**
+     * 医药id
+     */
+    @Column(name = "hospital_id")
+    private Integer hospitalId = 0;
+
+    /**
+     * 医药名称
+     */
+    @Column(name = "hospital_name")
+    private String hospitalName;
+
+    /**
+     * 对应ywt_center库的mg_admin表ID
+     */
+    @Column(name = "admin_id")
+    private Integer adminId = 0;
+
+    /**
+     * 对应ywt_center库的mg_admin表account
+     */
+    @Column(name = "admin_name")
+    private String adminName = "";
+
+    /**
+     * 对应oss地址,加密
+     */
+    @Column(name = "url")
+    private String url;
+
+    /**
+     * 是否删除
+     */
+    @Column(name = "deleted", nullable = false)
+    private Boolean deleted;
+
+    /**
+     * 创建时间
+     */
+    @Column(name = "create_time")
+    private Date createTime;
+
+    /**
+     * 文件生成时间
+     */
+    @Column(name = "finish_time")
+    private Date finishTime;
+
+    /**
+     * 接口响应时间
+     */
+    @Column(name = "difftime")
+    private Integer difftime;
+
+    /**
+     * 所有参数的md5,防止短时间内的重复点击
+     */
+    @Column(name = "param_md5")
+    private String paramMd5;
+
+    /**
+     * 接口地址(带域名)
+     */
+    @Column(name = "param_url")
+    private String paramUrl;
+
+    /**
+     * 0-下载中,1-下载成功,2-下载失败
+     */
+    @Column(name = "status")
+    private Integer status = 0;
+
+    /**
+     * 更新时间
+     */
+    @Column(name = "update_time")
+    private Date updateTime;
+
+    /**
+     * 所有参数的json
+     */
+    @Column(name = "param_json")
+    private String paramJson;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    /**
+     * 名称(前端路径)
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 名称(前端路径)
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 下载的文件名称
+     */
+    public String getFileName() {
+        return fileName;
+    }
+
+    /**
+     * 下载的文件名称
+     */
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    /**
+     * 药房id
+     */
+    public Integer getPharmacyId() {
+        return pharmacyId;
+    }
+
+    /**
+     * 药房id
+     */
+    public void setPharmacyId(Integer pharmacyId) {
+        this.pharmacyId = pharmacyId;
+    }
+
+    /**
+     * 药房名称
+     */
+    public String getPharmacyName() {
+        return pharmacyName;
+    }
+
+    /**
+     * 药房名称
+     */
+    public void setPharmacyName(String pharmacyName) {
+        this.pharmacyName = pharmacyName;
+    }
+
+    /**
+     * 医药id
+     */
+    public Integer getHospitalId() {
+        return hospitalId;
+    }
+
+    /**
+     * 医药id
+     */
+    public void setHospitalId(Integer hospitalId) {
+        this.hospitalId = hospitalId;
+    }
+
+    /**
+     * 医药名称
+     */
+    public String getHospitalName() {
+        return hospitalName;
+    }
+
+    /**
+     * 医药名称
+     */
+    public void setHospitalName(String hospitalName) {
+        this.hospitalName = hospitalName;
+    }
+
+    /**
+     * 对应ywt_center库的mg_admin表ID
+     */
+    public Integer getAdminId() {
+        return adminId;
+    }
+
+    /**
+     * 对应ywt_center库的mg_admin表ID
+     */
+    public void setAdminId(Integer adminId) {
+        this.adminId = adminId;
+    }
+
+    /**
+     * 对应ywt_center库的mg_admin表account
+     */
+    public String getAdminName() {
+        return adminName;
+    }
+
+    /**
+     * 对应ywt_center库的mg_admin表account
+     */
+    public void setAdminName(String adminName) {
+        this.adminName = adminName;
+    }
+
+    /**
+     * 对应oss地址,加密
+     */
+    public String getUrl() {
+        return url;
+    }
+
+    /**
+     * 对应oss地址,加密
+     */
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    /**
+     * 是否删除
+     */
+    public Boolean getDeleted() {
+        return deleted;
+    }
+
+    /**
+     * 是否删除
+     */
+    public void setDeleted(Boolean deleted) {
+        this.deleted = deleted;
+    }
+
+    /**
+     * 创建时间
+     */
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    /**
+     * 创建时间
+     */
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    /**
+     * 文件生成时间
+     */
+    public Date getFinishTime() {
+        return finishTime;
+    }
+
+    /**
+     * 文件生成时间
+     */
+    public void setFinishTime(Date finishTime) {
+        this.finishTime = finishTime;
+    }
+
+    /**
+     * 接口响应时间
+     */
+    public Integer getDifftime() {
+        return difftime;
+    }
+
+    /**
+     * 接口响应时间
+     */
+    public void setDifftime(Integer difftime) {
+        this.difftime = difftime;
+    }
+
+    /**
+     * 所有参数的md5,防止短时间内的重复点击
+     */
+    public String getParamMd5() {
+        return paramMd5;
+    }
+
+    /**
+     * 所有参数的md5,防止短时间内的重复点击
+     */
+    public void setParamMd5(String paramMd5) {
+        this.paramMd5 = paramMd5;
+    }
+
+    /**
+     * 接口地址(带域名)
+     */
+    public String getParamUrl() {
+        return paramUrl;
+    }
+
+    /**
+     * 接口地址(带域名)
+     */
+    public void setParamUrl(String paramUrl) {
+        this.paramUrl = paramUrl;
+    }
+
+    /**
+     * 0-下载中,1-下载成功,2-下载失败
+     */
+    public Integer getStatus() {
+        return status;
+    }
+
+    /**
+     * 0-下载中,1-下载成功,2-下载失败
+     */
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
+    /**
+     * 更新时间
+     */
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    /**
+     * 更新时间
+     */
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    /**
+     * 所有参数的json
+     */
+    public String getParamJson() {
+        return paramJson;
+    }
+
+    /**
+     * 所有参数的json
+     */
+    public void setParamJson(String paramJson) {
+        this.paramJson = paramJson;
+    }
+
+    public String toString() {
+        return "DownloadRecord{id=" + id +
+                ", name=" + name +
+                ", pharmacyId=" + pharmacyId +
+                ", pharmacyName=" + pharmacyName +
+                ", hospitalId=" + hospitalId +
+                ", hospitalName=" + hospitalName +
+                ", adminId=" + adminId +
+                ", adminName=" + adminName +
+                ", url=" + url +
+                ", createTime=" + createTime +
+                ", finishTime=" + finishTime +
+                ", difftime=" + difftime +
+                ", paramMd5=" + paramMd5 +
+                ", paramUrl=" + paramUrl +
+                ", status=" + status +
+                ", updateTime=" + updateTime +
+                ", paramJson=" + paramJson +
+                "}";
+    }
 }

+ 4 - 1
src/main/java/com/ywt/mg/domain/entities/DownloadRecordRepository.java

@@ -7,6 +7,9 @@ import org.springframework.data.jpa.repository.Query;
 
 public interface DownloadRecordRepository extends JpaRepository<DownloadRecord, Integer>, JpaSpecificationExecutor<DownloadRecord> {
 
-    @Query(value = "select * from download_record where admin_id = ? and param_md5 = ? and param_url = ? and status = 0 order by id desc limit 1;",nativeQuery = true)
+    @Query(value = "select * from download_record where admin_id = ? and param_md5 = ? and param_url = ? and status = 0 and deleted = 0 order by id desc limit 1;",nativeQuery = true)
     DownloadRecord findCreatingLeastOne(int currentAdminId, String paramMd5, String paramUrl);
+
+    @Query(value = "select * from download_record where id = ? and deleted = 0 limit 1;",nativeQuery = true)
+    DownloadRecord findOne(int id);
 }

+ 33 - 0
src/main/java/com/ywt/mg/domain/entities/SequenceRepository.java

@@ -0,0 +1,33 @@
+package com.ywt.mg.domain.entities;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.persistence.EntityManager;
+import javax.persistence.ParameterMode;
+import javax.persistence.StoredProcedureQuery;
+
+@Service
+public class SequenceRepository {
+
+    @Autowired
+    EntityManager entityManager;
+
+    public Integer gen(String tabName) {
+        StoredProcedureQuery storedProcedureQuery = entityManager.createStoredProcedureQuery("get_sequence")
+                .registerStoredProcedureParameter("flag_name", String.class, ParameterMode.IN)
+                .registerStoredProcedureParameter("seq_id", Integer.class, ParameterMode.OUT)
+                .setParameter("flag_name", tabName);
+        storedProcedureQuery.execute();
+        return (Integer) storedProcedureQuery.getOutputParameterValue("seq_id");
+    }
+
+    public Integer generateSn(String tag) {
+        StoredProcedureQuery storedProcedureQuery = entityManager.createStoredProcedureQuery("generate_sn")
+                .registerStoredProcedureParameter("flag_name", String.class, ParameterMode.IN)
+                .registerStoredProcedureParameter("seq_id", Integer.class, ParameterMode.OUT)
+                .setParameter("flag_name", tag);
+        storedProcedureQuery.execute();
+        return (Integer) storedProcedureQuery.getOutputParameterValue("seq_id");
+    }
+}

+ 96 - 0
src/main/java/com/ywt/mg/domain/entities/SysSequence.java

@@ -0,0 +1,96 @@
+package com.ywt.mg.domain.entities;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Table(name = "sys_sequence")
+@Entity
+public class SysSequence implements Serializable {
+  private static final long serialVersionUID = 1L;
+
+  @Id
+  @GeneratedValue(strategy = GenerationType.IDENTITY)
+  @Column(name = "id", insertable = false, nullable = false)
+  private Integer id;
+
+  /**
+   * 标识
+   */
+  @Column(name = "flag_name")
+  private String flagName;
+
+  /**
+   * 值
+   */
+  @Column(name = "value")
+  private Integer value;
+
+  /**
+   * 步长
+   */
+  @Column(name = "step")
+  private Integer step = 1;
+
+  public Integer getId() {
+    return id;
+  }
+
+  public void setId(Integer id) {
+    this.id = id;
+  }
+
+  /**
+   * 标识
+   */
+  public String getFlagName() {
+    return flagName;
+  }
+
+  /**
+   * 标识
+   */
+  public void setFlagName(String flagName) {
+    this.flagName = flagName;
+  }
+
+  /**
+   * 值
+   */
+  public Integer getValue() {
+    return value;
+  }
+
+  /**
+   * 值
+   */
+  public void setValue(Integer value) {
+    this.value = value;
+  }
+
+  /**
+   * 步长
+   */
+  public Integer getStep() {
+    return step;
+  }
+
+  /**
+   * 步长
+   */
+  public void setStep(Integer step) {
+    this.step = step;
+  }
+
+  public String toString() {
+    return "SysSequence{id=" + id + 
+      ", flagName=" + flagName + 
+      ", value=" + value + 
+      ", step=" + step + 
+      "}";
+  }
+}

+ 9 - 0
src/main/java/com/ywt/mg/domain/entities/SysSequenceRepository.java

@@ -0,0 +1,9 @@
+package com.ywt.mg.domain.entities;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import com.ywt.mg.domain.entities.SysSequence;
+
+public interface SysSequenceRepository extends JpaRepository<SysSequence, Integer>, JpaSpecificationExecutor<SysSequence> {
+
+}

+ 5 - 3
src/main/java/com/ywt/mg/domain/models/ConstantDef.java

@@ -84,8 +84,10 @@ public class ConstantDef {
     /**
      * excel下载存放地址
      */
-    public static final String BIG_DATA_EXCEL_FILE_PATH = "big_data_file/excel";
-
-
+    public static final String BIG_DATA_EXCEL_FILE_PATH = "big_data_file/excel/%s";
 
+    /**
+     * 本地的下载文件路径
+     */
+    public static final String LOCAL_DOWNLOAD_FILE_PATH = "./download_file/";
 }

+ 40 - 0
src/main/java/com/ywt/mg/domain/models/enums/DownloadRecordStatusEnum.java

@@ -0,0 +1,40 @@
+package com.ywt.mg.domain.models.enums;
+
+/**
+ * 对应 download_record 表的 status 字段
+ */
+public enum DownloadRecordStatusEnum {
+    /**
+     * 上传状态:0-下载中,1-下载成功,2-下载失败
+     */
+    Default("下载中", 0),
+    SUCCESS("下载成功", 1),
+    FAILURE("下载失败", 2);
+
+    private final String displayName;
+
+    private final int value;
+
+    DownloadRecordStatusEnum(String displayName, int value){
+        this.displayName = displayName;
+        this.value = value;
+    }
+
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+
+    public static String getDisplayName (int value){
+        for (DownloadRecordStatusEnum typeEnum: DownloadRecordStatusEnum.values()) {
+            if (typeEnum.value == value){
+                return typeEnum.displayName;
+            }
+        }
+        return "";
+    }
+}

+ 28 - 0
src/main/java/com/ywt/mg/params/downloadRecord/DownloadFileRequest.java

@@ -0,0 +1,28 @@
+package com.ywt.mg.params.downloadRecord;
+
+import com.ywt.mg.params.PageRequest;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @author daiyihua
+ * @create 2022-08-24 14:23
+ * @program download_service
+ * @description 下载文件Request
+ **/
+@ApiModel(value = "下载文件Request")
+public class DownloadFileRequest extends PageRequest implements Serializable {
+
+    @ApiModelProperty(value = "下载记录表ID")
+    private int downloadRecordId;
+
+    public int getDownloadRecordId() {
+        return downloadRecordId;
+    }
+
+    public void setDownloadRecordId(int downloadRecordId) {
+        this.downloadRecordId = downloadRecordId;
+    }
+}

+ 45 - 0
src/main/java/com/ywt/mg/params/downloadRecord/QueryDownloadRecordListRequest.java

@@ -0,0 +1,45 @@
+package com.ywt.mg.params.downloadRecord;
+
+import com.ywt.mg.params.PageRequest;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @author daiyihua
+ * @create 2022-08-24 14:23
+ * @program download_service
+ * @description 按条件查询下载记录列表Request
+ **/
+@ApiModel(value = "按条件查询下载记录列表Request")
+public class QueryDownloadRecordListRequest extends PageRequest implements Serializable {
+
+    int hospitalId = 0;
+    int pharmacyId = 0;
+    int adminId = 0;
+
+    public int getHospitalId() {
+        return hospitalId;
+    }
+
+    public void setHospitalId(int hospitalId) {
+        this.hospitalId = hospitalId;
+    }
+
+    public int getPharmacyId() {
+        return pharmacyId;
+    }
+
+    public void setPharmacyId(int pharmacyId) {
+        this.pharmacyId = pharmacyId;
+    }
+
+    public int getAdminId() {
+        return adminId;
+    }
+
+    public void setAdminId(int adminId) {
+        this.adminId = adminId;
+    }
+}

+ 186 - 17
src/main/java/com/ywt/mg/services/DownloadRecordService.java

@@ -1,20 +1,46 @@
 package com.ywt.mg.services;
 
+import com.ywt.gapi.ResultCode;
+import com.ywt.gapi.base.file.ReadFileRequest;
+import com.ywt.gapi.base.file.ReadFileResponse;
+import com.ywt.mg.configs.Constants;
+import com.ywt.mg.core.PagedList;
+import com.ywt.mg.core.SqlHelper;
 import com.ywt.mg.core.utils.Checker;
+import com.ywt.mg.core.utils.CollectionUtil;
+import com.ywt.mg.core.utils.FormatUtil;
+import com.ywt.mg.core.utils.StringHelper;
+import com.ywt.mg.core.utils.serializers.JsonSerializer;
 import com.ywt.mg.domain.entities.*;
 import com.ywt.mg.domain.models.ConstantDef;
+import com.ywt.mg.domain.models.ExcelDataMap;
+import com.ywt.mg.domain.models.ExcelStyleMap;
+import com.ywt.mg.domain.models.enums.DownloadRecordStatusEnum;
+import com.ywt.mg.domain.models.enums.TosEnum;
+import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
 import com.ywt.mg.domain.ywtDrugEntities.Pharmacy;
 import com.ywt.mg.domain.ywtDrugEntities.PharmacyRepository;
+import com.ywt.mg.params.downloadRecord.DownloadFileRequest;
+import com.ywt.mg.params.downloadRecord.QueryDownloadRecordListRequest;
 import com.ywt.mg.params.offline.DownloadOfflineListNewRequest;
+import com.ywt.mg.web.BaseResponse;
+import com.ywt.mg.web.DataResponse;
+import com.ywt.mg.web.PageDataResponse;
+import com.ywt.mg.web.common.ExcelDownloadSrv;
+import com.ywt.mg.web.common.FileSrv;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.stereotype.Service;
+import sun.rmi.runtime.Log;
+import sun.security.provider.MD5;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * 下载记录相关方法
@@ -32,17 +58,26 @@ public class DownloadRecordService {
     @Autowired
     private AuthService authService;
 
+    @Autowired
+    private SqlHelper sqlHelper;
+
+    @Autowired
+    private FileSrv fileSrv;
+
+    @Autowired
+    private ExcelDownloadSrv excelDownloadSrv;
+
     /**
      * 得到(重复点击情况下的下载记录)或插入一条新的下载记录
      *
      * @param id        表ID,需要生成
-     * @param name      名称(格式: 公司后台-一级菜单-二级菜单)
-     * @param paramMd5  下载参数的md5
+     * @param name      名称(前端路径)(格式: 公司后台-一级菜单-二级菜单)
+     * @param fileName  文件名称
      * @param paramJson 下载参数的json
      * @param paramUrl  下载参数url
      * @return 下载记录
      */
-    public DownloadRecord getOrInsertDownloadRecord(int id, String name, String paramMd5, String paramUrl) {
+    public DownloadRecord getOrInsertDownloadRecord(int id, String name, String fileName, String paramUrl, String paramJson) {
         int pharmacyId = 0, hospitalId = 0, currentAdminId = 0;
         String pharmacyName = "", hospitalName = "", currentAdminName = "";
         MGAdmins currentAdmin = authService.getCurrentAdmin();
@@ -50,16 +85,6 @@ public class DownloadRecordService {
             currentAdminId = currentAdmin.getId();
             currentAdminName = currentAdmin.getAccount();
         }
-        DownloadRecord record = downloadRecordRepository.findCreatingLeastOne(currentAdminId, paramMd5, paramUrl);
-        if (!Checker.isNone(record)) {
-            return record;
-        }
-        record = new DownloadRecord();
-        // todo: 需要判断是否有同样的下载
-        record.setId(id);
-        record.setName(name);
-
-
         Pharmacy pharmacy = authService.getCurrentPharmacy();
         if (!Checker.isNone(pharmacy)) {
             pharmacyId = pharmacy.getId();
@@ -70,6 +95,21 @@ public class DownloadRecordService {
             hospitalId = hospital.getId();
             hospitalName = hospital.getName();
         }
+        Map map = new HashMap();
+        map.put("param", paramJson);
+        map.put("adminId", currentAdminId);
+        map.put("hospitalId", hospitalId);
+        map.put("pharmacyId", pharmacyId);
+        String paramMd5 = StringHelper.md5(JsonSerializer.toJson(map));
+        // todo: 判断是否有同样的下载
+        DownloadRecord record = downloadRecordRepository.findCreatingLeastOne(currentAdminId, paramMd5, paramUrl);
+        if (!Checker.isNone(record)) {
+            return record;
+        }
+        record = new DownloadRecord();
+        record.setId(id);
+        record.setName(name);
+        record.setFileName(fileName);
         record.setPharmacyId(pharmacyId);
         record.setPharmacyName(pharmacyName);
         record.setHospitalId(hospitalId);
@@ -78,11 +118,140 @@ public class DownloadRecordService {
         record.setAdminName(currentAdminName);
         record.setCreateTime(new Date());
         record.setParamMd5(paramMd5);
+        record.setParamJson(paramJson);
         record.setParamUrl(paramUrl);
-        record.setStatus(0);
+        record.setStatus(DownloadRecordStatusEnum.Default.getValue());
         record.setUpdateTime(new Date());
         downloadRecordRepository.saveAndFlush(record);
         return record;
     }
 
+    public void saveUrlAndStatus(int id, String url, int status) {
+        DownloadRecord record = downloadRecordRepository.findOne(id);
+        if (!Checker.isNone(record)) {
+            record.setUrl(url);
+            record.setStatus(status);
+            if (status == DownloadRecordStatusEnum.SUCCESS.getValue()) {
+                Date finishTime = new Date();
+                record.setFinishTime(finishTime);
+                try {
+                    int diff = (int) (finishTime.getTime() - record.getCreateTime().getTime());
+                    record.setDifftime(diff);
+                } catch (Exception e) {
+                    logger.error("DownloadRecordService # saveUrlAndStatus 时间戳处理失败", e.getMessage(), e);
+                }
+            }
+            downloadRecordRepository.saveAndFlush(record);
+        }
+    }
+
+    public BaseResponse queryDownloadRecordList(QueryDownloadRecordListRequest request) throws Exception {
+        PageDataResponse<Object> pageDataResponse = new PageDataResponse<>();
+        PagedList<DownloadRecord> downloadRecordPagedList = queryDownloadRecordListCommon(request);
+        //做转换处理
+        if (!Checker.isNone(downloadRecordPagedList.getItems())) {
+            List<Map<String, Object>> datas = CollectionUtil.toList(downloadRecordPagedList.getItems(), p -> {
+                Map<String, Object> item = new HashMap<>(16);
+
+                item.put("id", p.getId());
+                item.put("name", p.getName());
+                item.put("createTime", FormatUtil.createTimeFormatDetail(p.getCreateTime()));
+                item.put("updateTime", FormatUtil.createTimeFormatDetail(p.getUpdateTime()));
+                item.put("status", p.getStatus());
+                item.put("statusStr", DownloadRecordStatusEnum.getDisplayName(p.getStatus()));
+                return item;
+            });
+            pageDataResponse.setData(datas);
+        } else {
+            pageDataResponse.setData(downloadRecordPagedList.getItems());
+        }
+        int count = downloadRecordPagedList.getTotal();
+        pageDataResponse.setPageIndex(request.getPageIndex());
+        pageDataResponse.setPageSize(request.getPageSize());
+        pageDataResponse.setTotalCount(count);
+        return pageDataResponse.succeed("处理成功");
+    }
+
+    private PagedList<DownloadRecord> queryDownloadRecordListCommon(QueryDownloadRecordListRequest request) throws ParseException {
+        List<Object> paramList = new ArrayList<>();
+        String whereSql = " ( 1=1 ) ";
+
+        int hospitalId = request.getHospitalId();
+        if (hospitalId > 0) {
+            whereSql += " and ( hospital_id = ?)";
+            paramList.add(hospitalId);
+        }
+        int adminId = request.getAdminId();
+        if (adminId > 0) {
+            whereSql += " and ( admin_id = ?)";
+            paramList.add(hospitalId);
+        }
+        int pageIndex = request.getPageIndex();
+        int pageSize = request.getPageSize();
+        return sqlHelper.getPagedList(pageIndex, pageSize, "*", whereSql, "create_time desc", DownloadRecord.class, paramList.toArray());
+    }
+
+    public void downloadFile(DownloadFileRequest request, HttpServletResponse httpServletResponse) {
+        int downloadRecordId = request.getDownloadRecordId();
+        try {
+            if (downloadRecordId <= 0) {
+                return;
+            }
+            DownloadRecord record = downloadRecordRepository.findOne(downloadRecordId);
+            if (!Checker.isNone(record)) {
+                String fileName = record.getFileName() + ".xlsx";
+                httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(), Constants.CHARSET_NAME));
+                httpServletResponse.setContentType("application/vnd.ms-excel;charset=UTF-8");
+                httpServletResponse.setHeader("Pragma", "no-cache");
+                httpServletResponse.setHeader("Cache-Control", "no-cache");
+                httpServletResponse.setDateHeader("Expires", 0);
+
+                OutputStream out = httpServletResponse.getOutputStream();
+                String url = Checker.getStringValue(record.getUrl());
+                if (!Checker.isNone(url)) {
+                    byte[] b = fileSrv.readFile(url);
+                    if (!Checker.isNone(b)) {
+                        if (!Checker.isNone(b)) {
+                            out.write(b);
+                        }
+                    }
+                    out.flush();
+                    out.close();
+                }
+            }
+        } catch (Exception e) {
+            logger.error("DownloadRecordService#downloadFile(), downloadRecordId={}", downloadRecordId, e.getMessage(), e);
+        }
+    }
+
+    /**
+     * 创建文件 并且上传到 OSS,最后保存到本地数据库
+     *
+     * @param fileName         文件名称
+     * @param downloadRecordId 对应 downloadRecord 表ID
+     * @param map              数据map
+     * @param itemList         统计map
+     * @throws Exception
+     */
+    public void createFileAndUploadOssAndSaveToDataBase(String fileName, int downloadRecordId, ExcelDataMap map, List<ExcelCollectPojo> itemList) throws Exception {
+        fileName = fileName + FormatUtil.formatDate(new Date(), FormatUtil.FORMAT_DATE_SECOND_NUMBER);
+        String preLocalPath = ConstantDef.LOCAL_DOWNLOAD_FILE_PATH;
+        // 写到服务器上
+        String localPath = preLocalPath + fileName + ".xlsx";
+        ExcelStyleMap excelStyleMap = new ExcelStyleMap(new String[]{});
+        // 生成本地文件
+        excelDownloadSrv.generateAndReturnExcelFileWithNoStyleAndCollectLocal(fileName, localPath, map, excelStyleMap, itemList);
+        String ossPath = String.format(ConstantDef.BIG_DATA_EXCEL_FILE_PATH, FormatUtil.formatDate(new Date(), "yyyy-MM"));
+        // 本地文件上传到oss
+        DataResponse dataResponse = fileSrv.localFileUploadToOss(localPath, fileName, ossPath);
+        if (dataResponse.getCode() == BaseResponse.SUCCEED) {
+            // 上传成功,将上传状态和地址保存到数据库
+            saveUrlAndStatus(downloadRecordId, dataResponse.getData().toString(), DownloadRecordStatusEnum.SUCCESS.getValue());
+        } else {
+            // 上传失败,将上传状态保存到数据库
+            saveUrlAndStatus(downloadRecordId, "", DownloadRecordStatusEnum.FAILURE.getValue());
+        }
+        // 删除文件
+        fileSrv.deleteFile(localPath);
+    }
 }

+ 59 - 0
src/main/java/com/ywt/mg/services/IdGenerator.java

@@ -0,0 +1,59 @@
+package com.ywt.mg.services;
+
+import com.ywt.mg.core.utils.StringHelper;
+import com.ywt.mg.domain.entities.SequenceRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+@Service
+public class IdGenerator {
+
+    /**
+     * 订单号标志
+     */
+    private final String ORDER_NO_TAG_NAME = "orderno";
+
+    public static final String REFUND_LOG_TABLE_NAME = "refund_log";
+
+    @Autowired
+    private SequenceRepository sequenceRepository;
+
+    public Integer getWxPaymentLogsId() {
+        return sequenceRepository.gen("wx_payment_logs");
+    }
+
+    public String generateOrderNo(String prefix) {
+        if (StringHelper.isNullOrEmpty(prefix)) {
+            prefix = "";
+        }
+
+        Date currentDate = new Date();
+        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+
+        int sn = sequenceRepository.generateSn(ORDER_NO_TAG_NAME);
+        return prefix + format.format(currentDate) + String.format("%04d", sn);
+    }
+
+    public String generateRefundOrderNo() {
+        return generateOrderNo("R");
+    }
+
+    public Integer getWechartCorppayLogsId() {
+        return sequenceRepository.gen("wechart_corppay_logs");
+    }
+
+    public Integer genRefundLogId() {
+        return sequenceRepository.gen(REFUND_LOG_TABLE_NAME);
+    }
+
+    /**
+     * 下载记录表id
+     * @return
+     */
+    public int genDownloadRecordId() {
+        return sequenceRepository.gen("download_record");
+    }
+}

+ 121 - 1
src/main/java/com/ywt/mg/services/OfflineNewService.java

@@ -3,13 +3,20 @@ package com.ywt.mg.services;
 import com.ywt.mg.configs.ParameterConfigurer;
 import com.ywt.mg.core.SqlHelper;
 import com.ywt.mg.core.utils.Checker;
+import com.ywt.mg.core.utils.FormatUtil;
 import com.ywt.mg.core.utils.StringHelper;
-import com.ywt.mg.domain.entities.*;
+import com.ywt.mg.core.utils.serializers.JsonSerializer;
+import com.ywt.mg.domain.entities.DownloadRecord;
+import com.ywt.mg.domain.entities.OfflineConsultation;
 import com.ywt.mg.domain.models.ConstantDef;
+import com.ywt.mg.domain.models.ExcelDataMap;
+import com.ywt.mg.domain.models.enums.OfflineConsultationSourceEnum;
 import com.ywt.mg.domain.models.enums.PaymentStatusEnum;
 import com.ywt.mg.domain.models.enums.RefundStatusEnum;
 import com.ywt.mg.domain.models.enums.SettlementStatusEnum;
+import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
 import com.ywt.mg.params.offline.DownloadOfflineListNewRequest;
+import com.ywt.mg.web.common.FileSrv;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -42,6 +49,15 @@ public class OfflineNewService {
     @Autowired
     private AuthService authService;
 
+    @Autowired
+    private HospitalCacheService hospitalCacheService;
+
+    @Autowired
+    private FileSrv fileSrv;
+
+    @Autowired
+    private DownloadRecordService downloadRecordService;
+
 
     public List<OfflineConsultation> queryDownloadOfflineList(DownloadOfflineListNewRequest request) {
         Map map = queryOfflineListCommon(request);
@@ -224,4 +240,108 @@ public class OfflineNewService {
         }
         return "";
     }
+
+    public void downloadOfflineListCommon(int downloadRecordId, String name, String fileName, String paramUrl, DownloadOfflineListNewRequest request) {
+        String paramJson = JsonSerializer.toJson(request);
+        try {
+            downloadRecordService.getOrInsertDownloadRecord(downloadRecordId, name, fileName, paramUrl, paramJson);
+            // 单元格
+            String col0 = "订单号";
+            String col1 = "支付流水号";
+            String col2 = "患者姓名";
+            String col3 = "患者手机号";
+            String col4 = "身份证号";
+            String col5 = "医院流水号";
+            String col6 = "医生姓名";
+            String col7 = "科室";
+            String col8 = "医院";
+            String col9 = "诊查费";
+            String col10 = "状态";
+            String col11 = "支付状态";
+            String col12 = "支付时间";
+            String col13 = "退款时间";
+            String col14 = "备注";
+            String col15 = "来源";
+            String[] columns = new String[]{col0, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10,
+                    col11, col12, col13, col14, col15};
+            // 按条件查找记录
+            int hospitalId = -1;
+            request.setHospitalId(hospitalId);
+            List<OfflineConsultation> offlineList = queryDownloadOfflineList(request);
+            int payTotal = 0, refundTotal = 0;
+            ExcelDataMap map = new ExcelDataMap(columns);
+            if (!Checker.isNone(offlineList)) {
+                // 遍历
+                for (OfflineConsultation v : offlineList) {
+                    String orderNoStr = Checker.getStringValue(v.getOrderNo());
+                    String paymentNoStr = Checker.getStringValue(v.getPaymentNo());
+                    String patientNameNoStr = Checker.getStringValue(v.getRealName());
+                    String patientMobileStr = Checker.getStringValue(v.getMobile());
+                    String idNoStr = Checker.getStringValue(v.getIdNo());
+                    String hisClinicCodeStr = Checker.getStringValue(v.getHisClinicCode() + "");
+                    String doctorNameStr = Checker.getStringValue(v.getDoctorName());
+                    String deptNameStr = Checker.getStringValue(v.getDeptName());
+                    String hospitalNameStr = hospitalCacheService.getCacheHospitalNameByHospitalId(Checker.getIntegerValue(v.getHospitalId()));
+                    String totalStr = FormatUtil.intShrink100ToStr(v.getTotal());
+                    String orderStatusStr = getOfflineStatusStr(v);
+                    String paymentStatusStr = PaymentStatusEnum.getPaymentStatus(Checker.getIntegerValue(v.getPaymentStatus())).getDisplayName();
+                    String payTimeStr = FormatUtil.createTimeFormatList(v.getPayTime());
+                    String refundTimeStr = FormatUtil.createTimeFormatList(v.getRefundTime());
+                    String remarkStr = Checker.getStringValue(v.getRefundRemark());
+                    String sourceStr = OfflineConsultationSourceEnum.getDisplayName(Checker.getIntegerValue(v.getSource()));
+                    if (Checker.getIntegerValue(v.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                        payTotal += Checker.getIntegerValue(v.getTotal());
+                    }
+                    if (Checker.getIntegerValue(v.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                        refundTotal += Checker.getIntegerValue(v.getTotal());
+                    }
+                    map.getStringListSafely(col0).add(orderNoStr);
+                    map.getStringListSafely(col1).add(paymentNoStr);
+                    map.getStringListSafely(col2).add(patientNameNoStr);
+                    map.getStringListSafely(col3).add(patientMobileStr);
+                    map.getStringListSafely(col4).add(idNoStr);
+                    map.getStringListSafely(col5).add(hisClinicCodeStr);
+                    map.getStringListSafely(col6).add(doctorNameStr);
+                    map.getStringListSafely(col7).add(deptNameStr);
+                    map.getStringListSafely(col8).add(hospitalNameStr);
+                    map.getStringListSafely(col9).add(totalStr);
+                    map.getStringListSafely(col10).add(orderStatusStr);
+                    map.getStringListSafely(col11).add(paymentStatusStr);
+                    map.getStringListSafely(col12).add(payTimeStr);
+                    map.getStringListSafely(col13).add(refundTimeStr);
+                    map.getStringListSafely(col14).add(remarkStr);
+                    map.getStringListSafely(col15).add(sourceStr);
+                }
+            }
+            // 得到统计
+            int size = offlineList.size();
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal);
+            // 创建文件 并且上传到 OSS,最后保存到本地数据库
+            downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList);
+        } catch (Exception e) {
+            logger.error("/offline/downloadOfflineList(): {}", e.getMessage(), e);
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取统计数据
+     *
+     * @param size        隔行
+     * @param payTotal    总金额
+     * @param refundTotal 退款金额
+     * @return {@link List<ExcelCollectPojo> }
+     */
+    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal) {
+        int startRows = size + 3;
+        int startColumn = 3;
+
+        List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 2, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 3, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+        return customExcelItemList;
+    }
+
+
 }

+ 12 - 13
src/main/java/com/ywt/mg/web/common/ExcelDownloadSrv.java

@@ -157,7 +157,7 @@ public class ExcelDownloadSrv {
      * @author Walker, added on 06/27/2019.
      */
     public void generateAndReturnExcelFileWithNoStyle(String fileName, ExcelDataMap data, ExcelStyleMap excelStyleMap,
-                                           HttpServletResponse httpServletResponse) throws AppMessageException {
+                                                      HttpServletResponse httpServletResponse) throws AppMessageException {
         if (data == null || data.isEmpty()) {
             throw new AppMessageException("数据为空");
         }
@@ -257,11 +257,11 @@ public class ExcelDownloadSrv {
                 headerColumn++;
             }
             // 添加汇总
-            if (!Checker.isNone(collectList)){
+            if (!Checker.isNone(collectList)) {
                 for (ExcelCollectPojo pojo : collectList) {
                     String[] dataArr = pojo.getDataArr();
-                    for (int i = 0, j = dataArr.length;i < j; i++) {
-                        Label lb = new Label(pojo.getCol()+i, pojo.getRow(), dataArr[i], cellFormat);
+                    for (int i = 0, j = dataArr.length; i < j; i++) {
+                        Label lb = new Label(pojo.getCol() + i, pojo.getRow(), dataArr[i], cellFormat);
                         sheet.addCell(lb);
                     }
                 }
@@ -282,16 +282,15 @@ public class ExcelDownloadSrv {
      *
      * @param fileName            excel 文件名
      * @param data                需要填充的数据,key 是列名,value 是每一列的数据组成的 list, 类型必须是 {@link String}
-     * @param httpServletResponse resp
      * @throws AppMessageException 业务层异常抛出,如传入数据为空
      * @author Walker, added on 06/27/2019.
      */
-    public String generateAndReturnExcelFileWithNoStyleAndCollectLocal(String fileName, String path,ExcelDataMap data, ExcelStyleMap excelStyleMap,
-                                                                   List<ExcelCollectPojo> collectList, HttpServletResponse httpServletResponse) throws AppMessageException {
+    public String generateAndReturnExcelFileWithNoStyleAndCollectLocal(String fileName, String path, ExcelDataMap data, ExcelStyleMap excelStyleMap,
+                                                                       List<ExcelCollectPojo> collectList) throws AppMessageException {
         if (data == null || data.isEmpty()) {
             throw new AppMessageException("数据为空");
         }
-        try  {
+        try {
             File file = new File(path);
             // 创建写工作簿对象
             WritableWorkbook workbook = Workbook.createWorkbook(file);
@@ -327,11 +326,11 @@ public class ExcelDownloadSrv {
                 headerColumn++;
             }
             // 添加汇总
-            if (!Checker.isNone(collectList)){
+            if (!Checker.isNone(collectList)) {
                 for (ExcelCollectPojo pojo : collectList) {
                     String[] dataArr = pojo.getDataArr();
-                    for (int i = 0, j = dataArr.length;i < j; i++) {
-                        Label lb = new Label(pojo.getCol()+i, pojo.getRow(), dataArr[i], cellFormat);
+                    for (int i = 0, j = dataArr.length; i < j; i++) {
+                        Label lb = new Label(pojo.getCol() + i, pojo.getRow(), dataArr[i], cellFormat);
                         sheet.addCell(lb);
                     }
                 }
@@ -342,8 +341,8 @@ public class ExcelDownloadSrv {
             workbook.close();
 
         } catch (Exception e) {
-            logger.error("ExcelDownloadSrv#generateAndReturnExcelFileWithNoStyleAndCollectLocal(fileName={} ):\n {}",
-                    fileName, e.getMessage(), e);
+            logger.error("ExcelDownloadSrv#generateAndReturnExcelFileWithNoStyleAndCollectLocal(fileName={}, path={} ):\n {}",
+                    fileName, path, e.getMessage(), e);
         }
         return path;
     }

+ 16 - 0
src/main/java/com/ywt/mg/web/common/FileSrv.java

@@ -100,5 +100,21 @@ public class FileSrv {
         }
     }
 
+    /**
+     * 读取文件
+     *
+     * @param key
+     * @return
+     */
+    public byte[] readFile(String key) {
+        ReadFileRequest req = ReadFileRequest.newBuilder().setFileUrl(key).build();
+        ReadFileResponse res = fileServiceBlockingStub.readFile(req);
+
+        if (res.getCode() == 0) {
+            return res.getDatas().toByteArray();
+        }
+
+        return null;
+    }
 
 }

+ 53 - 0
src/main/java/com/ywt/mg/web/controllers/DownloadRecordController.java

@@ -0,0 +1,53 @@
+package com.ywt.mg.web.controllers;
+
+
+import com.ywt.mg.core.MGRight;
+import com.ywt.mg.core.MGRightTypeDef;
+import com.ywt.mg.params.downloadRecord.DownloadFileRequest;
+import com.ywt.mg.params.downloadRecord.QueryDownloadRecordListRequest;
+import com.ywt.mg.services.AuthService;
+import com.ywt.mg.services.DownloadRecordService;
+import com.ywt.mg.web.BaseResponse;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+
+@RestController("/downloadRecord")
+@RequestMapping({"/downloadRecord"})
+@MGRight
+@Api(description = "公司后台-下载记录相关接口,前缀:downloadRecord")
+public class DownloadRecordController {
+
+    private static Logger logger = LoggerFactory.getLogger(DownloadRecordController.class);
+
+    @Autowired
+    private AuthService authService;
+
+    @Autowired
+    private DownloadRecordService downloadRecordService;
+
+    @ApiOperation(value = "按条件查询下载记录列表")
+    @RequestMapping(value = {"/downloadRecordList"}, method = RequestMethod.POST)
+    @MGRight(menuCode = {"/downloadRecord/queryDownloadRecordList"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
+    BaseResponse queryDownloadRecordList(@Validated @RequestBody QueryDownloadRecordListRequest request) throws Exception {
+        request.setHospitalId(-1);
+        return downloadRecordService.queryDownloadRecordList(request);
+    }
+
+    @ApiOperation(value = "下载文件")
+    @RequestMapping(value = {"/downloadFile"}, method = RequestMethod.GET)
+    @MGRight(menuCode = {"/downloadRecord/downloadFile"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
+    public void downloadFile(@Validated DownloadFileRequest request, HttpServletResponse httpServletResponse) {
+        downloadRecordService.downloadFile(request, httpServletResponse);
+    }
+
+}

+ 19 - 120
src/main/java/com/ywt/mg/web/controllers/OfflineController.java

@@ -4,25 +4,22 @@ package com.ywt.mg.web.controllers;
 import com.ywt.mg.core.MGRight;
 import com.ywt.mg.core.MGRightTypeDef;
 import com.ywt.mg.core.PagedList;
+import com.ywt.mg.core.utils.AsyncUtil;
 import com.ywt.mg.core.utils.Checker;
 import com.ywt.mg.core.utils.CollectionUtil;
 import com.ywt.mg.core.utils.FormatUtil;
-import com.ywt.mg.domain.entities.DoctorRepository;
-import com.ywt.mg.domain.entities.OfflineConsultation;
-import com.ywt.mg.domain.entities.TreatmentOrderViewMgRepository;
-import com.ywt.mg.domain.entities.TreatmentRepository;
+import com.ywt.mg.core.utils.serializers.JsonSerializer;
+import com.ywt.mg.domain.entities.*;
 import com.ywt.mg.domain.models.ConstantDef;
 import com.ywt.mg.domain.models.ExcelDataMap;
 import com.ywt.mg.domain.models.ExcelStyleMap;
+import com.ywt.mg.domain.models.enums.DownloadRecordStatusEnum;
 import com.ywt.mg.domain.models.enums.OfflineConsultationSourceEnum;
 import com.ywt.mg.domain.models.enums.PaymentStatusEnum;
 import com.ywt.mg.domain.models.enums.RefundStatusEnum;
 import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
 import com.ywt.mg.params.offline.DownloadOfflineListNewRequest;
-import com.ywt.mg.services.AuthService;
-import com.ywt.mg.services.HospitalCacheService;
-import com.ywt.mg.services.OfflineNewService;
-import com.ywt.mg.services.OfflineService;
+import com.ywt.mg.services.*;
 import com.ywt.mg.web.BaseResponse;
 import com.ywt.mg.web.DataResponse;
 import com.ywt.mg.web.PageDataResponse;
@@ -67,13 +64,7 @@ public class OfflineController {
     private OfflineNewService offlineNewService;
 
     @Autowired
-    private HospitalCacheService hospitalCacheService;
-
-    @Autowired
-    private ExcelDownloadSrv excelDownloadSrv;
-
-    @Autowired
-    private FileSrv fileSrv;
+    private IdGenerator idGenerator;
 
     /**
      * 查询线下就诊列表
@@ -313,113 +304,21 @@ public class OfflineController {
         }
     }
 */
-    @RequestMapping({"/downloadOfflineListNew"})
-    public void downloadOfflineListNew(DownloadOfflineListNewRequest request) {
-
-        try {
-            ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-            HttpServletResponse httpServletResponse = requestAttributes.getResponse();
-            HttpServletRequest httpServletRequest = requestAttributes.getRequest();
-
-            // 单元格
-            String col0 = "订单号";
-            String col1 = "支付流水号";
-            String col2 = "患者姓名";
-            String col3 = "患者手机号";
-            String col4 = "身份证号";
-            String col5 = "医院流水号";
-            String col6 = "医生姓名";
-            String col7 = "科室";
-            String col8 = "医院";
-            String col9 = "诊查费";
-            String col10 = "状态";
-            String col11 = "支付状态";
-            String col12 = "支付时间";
-            String col13 = "退款时间";
-            String col14 = "备注";
-            String col15 = "来源";
-            String[] columns = new String[]{col0, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10,
-                    col11, col12, col13, col14, col15};
-            // 按条件查找记录
-            int hospitalId = -1;
-            request.setHospitalId(hospitalId);
-            List<OfflineConsultation> offlineList = offlineNewService.queryDownloadOfflineList(request);
-            int payTotal = 0, refundTotal = 0;
-            ExcelDataMap map = new ExcelDataMap(columns);
-            if (!Checker.isNone(offlineList)) {
-                // 遍历
-                for (OfflineConsultation v : offlineList) {
-                    String orderNoStr = Checker.getStringValue(v.getOrderNo());
-                    String paymentNoStr = Checker.getStringValue(v.getPaymentNo());
-                    String patientNameNoStr = Checker.getStringValue(v.getRealName());
-                    String patientMobileStr = Checker.getStringValue(v.getMobile());
-                    String idNoStr = Checker.getStringValue(v.getIdNo());
-                    String hisClinicCodeStr = Checker.getStringValue(v.getHisClinicCode() + "");
-                    String doctorNameStr = Checker.getStringValue(v.getDoctorName());
-                    String deptNameStr = Checker.getStringValue(v.getDeptName());
-                    String hospitalNameStr = hospitalCacheService.getCacheHospitalNameByHospitalId(Checker.getIntegerValue(v.getHospitalId()));
-                    String totalStr = FormatUtil.intShrink100ToStr(v.getTotal());
-                    String orderStatusStr = offlineNewService.getOfflineStatusStr(v);
-                    String paymentStatusStr = PaymentStatusEnum.getPaymentStatus(Checker.getIntegerValue(v.getPaymentStatus())).getDisplayName();
-                    String payTimeStr = FormatUtil.createTimeFormatList(v.getPayTime());
-                    String refundTimeStr = FormatUtil.createTimeFormatList(v.getRefundTime());
-                    String remarkStr = Checker.getStringValue(v.getRefundRemark());
-                    String sourceStr = OfflineConsultationSourceEnum.getDisplayName(Checker.getIntegerValue(v.getSource()));
-                    if (Checker.getIntegerValue(v.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
-                        payTotal += Checker.getIntegerValue(v.getTotal());
-                    }
-                    if (Checker.getIntegerValue(v.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()){
-                        refundTotal += Checker.getIntegerValue(v.getTotal());
-                    }
-                    map.getStringListSafely(col0).add(orderNoStr);
-                    map.getStringListSafely(col1).add(paymentNoStr);
-                    map.getStringListSafely(col2).add(patientNameNoStr);
-                    map.getStringListSafely(col3).add(patientMobileStr);
-                    map.getStringListSafely(col4).add(idNoStr);
-                    map.getStringListSafely(col5).add(hisClinicCodeStr);
-                    map.getStringListSafely(col6).add(doctorNameStr);
-                    map.getStringListSafely(col7).add(deptNameStr);
-                    map.getStringListSafely(col8).add(hospitalNameStr);
-                    map.getStringListSafely(col9).add(totalStr);
-                    map.getStringListSafely(col10).add(orderStatusStr);
-                    map.getStringListSafely(col11).add(paymentStatusStr);
-                    map.getStringListSafely(col12).add(payTimeStr);
-                    map.getStringListSafely(col13).add(refundTimeStr);
-                    map.getStringListSafely(col14).add(remarkStr);
-                    map.getStringListSafely(col15).add(sourceStr);
-                }
-            }
-            // 得到统计
-            int size = offlineList.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal);
-            ExcelStyleMap excelStyleMap = new ExcelStyleMap(new String[]{});
-            String fileName = "线下就诊记录"+ FormatUtil.formatDate(new Date(), FormatUtil.FORMAT_DATE_SECOND_NUMBER);
-            String preLocalPath = httpServletRequest.getSession().getServletContext().getRealPath("./download_file/");
-            // 写到服务器上
-            String localPath = preLocalPath + "/" + fileName+".xls";
-            excelDownloadSrv.generateAndReturnExcelFileWithNoStyleAndCollectLocal(fileName, localPath, map, excelStyleMap, itemList, httpServletResponse);
-            DataResponse dataResponse = fileSrv.localFileUploadToOss(fileName, localPath, ConstantDef.BIG_DATA_EXCEL_FILE_PATH);
-            if (dataResponse.getCode() == BaseResponse.SUCCEED){
-                // 上传成功
-            }else{
-                // 上传失败
-
+    @RequestMapping({"/downloadOfflineList"})
+    public BaseResponse downloadOfflineList(DownloadOfflineListNewRequest request) {
+        // 插入记录
+        int downloadRecordId = idGenerator.genDownloadRecordId();
+        String name = "线下就诊记录";
+        String fileName = "公司后台-订单管理-线下就诊";
+        String paramUrl = "/offline/downloadOfflineList";
+        Thread t = new Thread(){
+            @Override
+            public void run() {
+                offlineNewService.downloadOfflineListCommon(downloadRecordId, name, fileName, paramUrl, request);
             }
-
-        } catch (Exception e) {
-            logger.error("/offline/downloadOfflineList(): {}", e.getMessage(), e);
-            e.printStackTrace();
-        }
+        };
+        return new BaseResponse().succeed("后台下载中...");
     }
 
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal) {
-        int startRows = size + 3;
-        int startColumn = 3;
 
-        List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 2, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
-        customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 3, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal-refundTotal)}));
-        return customExcelItemList;
-    }
 }

+ 3 - 0
src/main/java/com/ywt/mg/web/interceptors/AuthInterceptor.java

@@ -131,6 +131,9 @@ public class AuthInterceptor implements HandlerInterceptor {
      */
     private void settingWebAppContextParam(HttpServletRequest httpServletRequest){
         String authData = httpServletRequest.getHeader("auth-data");
+        if (Checker.isNone(authData)){
+            authData = httpServletRequest.getHeader("authdata");
+        }
         if (!Checker.isNone(authData)) {
             JsonNode jsonNode = JsonSerializer.readToNode(authData);
             if (!Checker.isNone(jsonNode)) {