Browse Source

update fileUpload&&fileDownload

Antiloveg 8 years ago
parent
commit
04183bad61

+ 10 - 0
schema/2017-03-11.sql

@@ -0,0 +1,10 @@
+CREATE TABLE IF NOT EXISTS `aft_dev`.`aft_file` (
+  `id` VARCHAR(36) NOT NULL,
+  `uid` VARCHAR(36) NULL COMMENT '用户id',
+  `file_name` VARCHAR(32) NULL COMMENT '文件名称',
+  `file_path` VARCHAR(255) NOT NULL COMMENT '文件路径',
+  `sign` VARCHAR(45) NULL COMMENT '模版标记',
+  `comment` VARCHAR(45) NULL COMMENT '备注',
+  `deleleted_sign` INT(1) NOT NULL DEFAULT 0 COMMENT '删除标记',
+  PRIMARY KEY (`id`))
+ENGINE = InnoDB

+ 60 - 0
src/main/java/com/goafanti/admin/controller/AdminApiController.java

@@ -1,5 +1,6 @@
 package com.goafanti.admin.controller;
 
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.util.Calendar;
@@ -9,16 +10,20 @@ import java.util.Map;
 import java.util.UUID;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.multipart.MultipartFile;
 
+import com.goafanti.admin.service.AftFileService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.model.AftFile;
 import com.goafanti.common.model.OrgActivity;
 import com.goafanti.common.model.OrgActivityCost;
 import com.goafanti.common.model.OrgAnnualReport;
@@ -37,6 +42,7 @@ import com.goafanti.common.model.OrganizationIdentity;
 import com.goafanti.common.model.UserAbility;
 import com.goafanti.common.model.UserIdentity;
 import com.goafanti.common.utils.DateUtils;
+import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
@@ -109,6 +115,8 @@ public class AdminApiController extends BaseApiController {
 	private UserAbilityService				userAbilityService;
 	@Resource
 	private OrgAnnualReportService			orgAnnualReportService;
+	@Resource
+	private AftFileService                  aftFileService;
 
 	/**
 	 * 个人用户列表
@@ -925,6 +933,7 @@ public class AdminApiController extends BaseApiController {
 			cog.setConsultant(null == log.getOperator() ? "" : log.getOperator());
 			log.setId(UUID.randomUUID().toString());
 			log.setCid(cog.getId());
+			log.setOperator(TokenManager.getAdminId());
 			if (!StringUtils.isBlank(recordTimeFormattedDate)) {
 				log.setRecordTime(DateUtils.parseDate(recordTimeFormattedDate, "yyyy-MM-dd"));
 			}
@@ -1036,6 +1045,40 @@ public class AdminApiController extends BaseApiController {
 		}
 		return res;
 	}
+	
+	/**
+	 * 上传专利代理委托书模版
+	 * @param req
+	 * @return
+	 */
+	@RequestMapping(value = "/uploadPatentTemplate", method = RequestMethod.POST)
+	public Result uploadPatentTemplate(HttpServletRequest req){
+		Result res = new Result();
+		List<MultipartFile> files = getFiles(req);
+		MultipartFile mf = files.get(0);
+		String suffix = mf.getOriginalFilename().substring(mf.getOriginalFilename().lastIndexOf("."));
+		if (suffix.equals("doc") || suffix.equals("doxc")){
+			String fileName = "patent_prory_statement" + suffix;
+			res.setData(handleFile(res, req, fileName, files, mf));
+			if (res.getData() != ""){
+				AftFile f = new AftFile();
+				f.setId(UUID.randomUUID().toString());
+				f.setFileName("专利代理委托书模版");
+				f.setSign("patent_prory_statement");
+				f.setFilePath("/admin/" + fileName);
+				f.setDeleletedSign(0);
+				aftFileService.insert(f);
+			}
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_PATTERN_ERROR, "文件格式错误,请重新上传!"));
+		}
+		return res;
+	}
+	
+	/**
+	 * 
+	 * @return
+	 */
 
 	// 判断用户是否通过认证
 	private Result checkCertify(Result res, String uid) {
@@ -1156,5 +1199,22 @@ public class AdminApiController extends BaseApiController {
 
 		return report;
 	}
+	
+	private String handleFile(Result res, HttpServletRequest req, String fileName,List<MultipartFile> files, MultipartFile mf) {
+		if (!files.isEmpty()) {
+			try {
+				mf.transferTo(toAdminPrivateFile(fileName));
+				LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
+			} catch (IllegalStateException | IOException e) {
+				LoggerUtils.error(getClass(), "文件上传失败", e);
+				res.getError().add(buildError("", "文件上传失败!"));
+				return "";
+			}
+		} else {
+			res.getError().add(buildError("", "文件上传失败!"));
+			return "";
+		}
+		return fileName;
+	}
 
 }

+ 11 - 0
src/main/java/com/goafanti/admin/service/AftFileService.java

@@ -0,0 +1,11 @@
+package com.goafanti.admin.service;
+
+import com.goafanti.common.model.AftFile;
+
+public interface AftFileService {
+
+	AftFile insert(AftFile f);
+
+	AftFile selectAftFileBySign(String sign);
+
+}

+ 24 - 0
src/main/java/com/goafanti/admin/service/impl/AftFileServiceImpl.java

@@ -0,0 +1,24 @@
+package com.goafanti.admin.service.impl;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.goafanti.admin.service.AftFileService;
+import com.goafanti.common.dao.AftFileMapper;
+import com.goafanti.common.model.AftFile;
+@Service
+public class AftFileServiceImpl implements AftFileService {
+	@Autowired
+	private AftFileMapper aftFileMapper;
+
+	@Override
+	public AftFile insert(AftFile f) {
+		aftFileMapper.insert(f);
+		return f;
+	}
+
+	@Override
+	public AftFile selectAftFileBySign(String sign) {
+		return aftFileMapper.selectAftFileBySign(sign);
+	}
+}

+ 11 - 0
src/main/java/com/goafanti/common/controller/BaseApiController.java

@@ -61,4 +61,15 @@ public class BaseApiController extends BaseController {
 		toFile.mkdirs();
 		return toFile;
 	}
+	
+	/**
+	 * 
+	 * @param fileName
+	 * @return
+	 */
+	protected File toAdminPrivateFile(String fileName) {
+		File toFile = new File(uploadPrivatePath + "/admin/"+ fileName);
+		toFile.mkdirs();
+		return toFile;
+	}
 }

+ 81 - 0
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -11,6 +11,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Controller;
@@ -26,6 +27,7 @@ import com.aliyuncs.profile.DefaultProfile;
 import com.aliyuncs.profile.IClientProfile;
 import com.aliyuncs.sms.model.v20160927.SingleSendSmsRequest;
 import com.aliyuncs.sms.model.v20160927.SingleSendSmsResponse;
+import com.goafanti.admin.service.AftFileService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.utils.LoggerUtils;
@@ -56,6 +58,9 @@ public class PublicController extends BaseController {
 	
 	@Resource
 	private UserService						userService;
+	
+	@Resource
+	private AftFileService                  aftFileService;
 
 	/**
 	 * 获取验证码
@@ -244,5 +249,81 @@ public class PublicController extends BaseController {
 		}
 	}
 	
+	
+	/**
+	 * 下载文件
+	 * @param res
+	 * @param fileName
+	 * @param response
+	 * @param path
+	 * @param request
+	 * @return
+	 */
+	@RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
+	public Result downloadFile(String fileName, HttpServletResponse response, String path) {
+		Result res = new Result();
+		return handleDownloadFile(response, fileName, path, res);
+	}
+	
+	/**
+	 * 下载模版文件
+	 * @param response
+	 * @return
+	 */
+	@RequestMapping(value = "/downloadTemplateFile", method = RequestMethod.GET)
+	public Result downloadTemplateFile(HttpServletResponse response,String sign){
+		Result res = new Result();
+		String fileName = "";
+		if (sign.equals("patent_prory_statement")){
+			fileName = "专利代理委托书模版";
+		} else {
+			fileName = System.nanoTime() + " ";
+		}
+		String path = aftFileService.selectAftFileBySign(sign).getFilePath();
+		if (!StringUtils.isBlank(path)){
+			return handleDownloadFile(response, fileName, path, res);
+		} else {
+			res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "下载文件不存在!"));
+			return res;
+		}
+	}
+	
+	private Result handleDownloadFile(HttpServletResponse response, String fileName, String path, Result res){
+		String fileSaveRootPath = uploadPrivatePath + path;
+		InputStream in = null;
+		OutputStream out = null;
+		byte[] buffer = new byte[8 * 1024];
+		try {
+			File file = new File(fileSaveRootPath);
+			in = new FileInputStream(file);
+			out = response.getOutputStream();
+			// 设置文件MIME类型
+			response.setContentType("application/octet-stream");
+			response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
+			for (;;) {
+				int bytes = in.read(buffer);
+				if (bytes == -1) {
+					break;
+				}
+				out.write(buffer, 0, bytes);
+			}
+		} catch (IOException e) {
+			LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
+		} finally {
+			try {
+				in.close();
+			} catch (IOException e) {
+				LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
+			}
+			try {
+				out.close();
+			} catch (IOException e) {
+				LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
+			}
+		}
+		return res;
+	}
+	
+	
 
 }

+ 19 - 0
src/main/java/com/goafanti/common/dao/AftFileMapper.java

@@ -0,0 +1,19 @@
+package com.goafanti.common.dao;
+
+import com.goafanti.common.model.AftFile;
+
+public interface AftFileMapper {
+    int deleteByPrimaryKey(String id);
+
+    int insert(AftFile record);
+
+    int insertSelective(AftFile record);
+
+    AftFile selectByPrimaryKey(String id);
+
+    int updateByPrimaryKeySelective(AftFile record);
+
+    int updateByPrimaryKey(AftFile record);
+
+	AftFile selectAftFileBySign(String sign);
+}

+ 124 - 0
src/main/java/com/goafanti/common/mapper/AftFileMapper.xml

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.goafanti.common.dao.AftFileMapper" >
+  <resultMap id="BaseResultMap" type="com.goafanti.common.model.AftFile" >
+    <id column="id" property="id" jdbcType="VARCHAR" />
+    <result column="uid" property="uid" jdbcType="VARCHAR" />
+    <result column="file_name" property="fileName" jdbcType="VARCHAR" />
+    <result column="file_path" property="filePath" jdbcType="VARCHAR" />
+    <result column="sign" property="sign" jdbcType="VARCHAR" />
+    <result column="comment" property="comment" jdbcType="VARCHAR" />
+    <result column="deleleted_sign" property="deleletedSign" jdbcType="INTEGER" />
+  </resultMap>
+  <sql id="Base_Column_List" >
+    id, uid, file_name, file_path, sign, comment, deleleted_sign
+  </sql>
+  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
+    select 
+    <include refid="Base_Column_List" />
+    from aft_file
+    where id = #{id,jdbcType=VARCHAR}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
+    delete from aft_file
+    where id = #{id,jdbcType=VARCHAR}
+  </delete>
+  <insert id="insert" parameterType="com.goafanti.common.model.AftFile" >
+    insert into aft_file (id, uid, file_name, 
+      file_path, sign, comment, 
+      deleleted_sign)
+    values (#{id,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, #{fileName,jdbcType=VARCHAR}, 
+      #{filePath,jdbcType=VARCHAR}, #{sign,jdbcType=VARCHAR}, #{comment,jdbcType=VARCHAR}, 
+      #{deleletedSign,jdbcType=INTEGER})
+  </insert>
+  <insert id="insertSelective" parameterType="com.goafanti.common.model.AftFile" >
+    insert into aft_file
+    <trim prefix="(" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        id,
+      </if>
+      <if test="uid != null" >
+        uid,
+      </if>
+      <if test="fileName != null" >
+        file_name,
+      </if>
+      <if test="filePath != null" >
+        file_path,
+      </if>
+      <if test="sign != null" >
+        sign,
+      </if>
+      <if test="comment != null" >
+        comment,
+      </if>
+      <if test="deleletedSign != null" >
+        deleleted_sign,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        #{id,jdbcType=VARCHAR},
+      </if>
+      <if test="uid != null" >
+        #{uid,jdbcType=VARCHAR},
+      </if>
+      <if test="fileName != null" >
+        #{fileName,jdbcType=VARCHAR},
+      </if>
+      <if test="filePath != null" >
+        #{filePath,jdbcType=VARCHAR},
+      </if>
+      <if test="sign != null" >
+        #{sign,jdbcType=VARCHAR},
+      </if>
+      <if test="comment != null" >
+        #{comment,jdbcType=VARCHAR},
+      </if>
+      <if test="deleletedSign != null" >
+        #{deleletedSign,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.AftFile" >
+    update aft_file
+    <set >
+      <if test="uid != null" >
+        uid = #{uid,jdbcType=VARCHAR},
+      </if>
+      <if test="fileName != null" >
+        file_name = #{fileName,jdbcType=VARCHAR},
+      </if>
+      <if test="filePath != null" >
+        file_path = #{filePath,jdbcType=VARCHAR},
+      </if>
+      <if test="sign != null" >
+        sign = #{sign,jdbcType=VARCHAR},
+      </if>
+      <if test="comment != null" >
+        comment = #{comment,jdbcType=VARCHAR},
+      </if>
+      <if test="deleletedSign != null" >
+        deleleted_sign = #{deleletedSign,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.AftFile" >
+    update aft_file
+    set uid = #{uid,jdbcType=VARCHAR},
+      file_name = #{fileName,jdbcType=VARCHAR},
+      file_path = #{filePath,jdbcType=VARCHAR},
+      sign = #{sign,jdbcType=VARCHAR},
+      comment = #{comment,jdbcType=VARCHAR},
+      deleleted_sign = #{deleletedSign,jdbcType=INTEGER}
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  
+   <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
+    select 
+    <include refid="Base_Column_List" />
+    from aft_file
+    where sign = #{sign,jdbcType=VARCHAR}
+  </select>
+</mapper>

+ 1 - 1
src/main/java/com/goafanti/common/mapper/OrgCognizanceMapper.xml

@@ -260,7 +260,7 @@
   <select id="findCognizanceBoByPage" parameterType="String"  resultType="com.goafanti.techservice.cognizance.bo.CognizanceBo">
   	select x.uid, x.cid, x.serial_number as serialNumber, x.location_province as locationProvince, 
   	x.unit_name as unitName, x.contacts, x.create_time as createTime, x.comment, x.state, x.certificate_number as certificateNumber,
-	x.issuing_date as issuingDate, a.name as consultant from 
+	x.issuing_date as issuingDate, a.name as consultant, x.year from 
 	(select u.id as uid,
 	c.id as cid, c.serial_number, i.location_province,
 	i.unit_name, c.contacts, c.create_time, 

+ 94 - 0
src/main/java/com/goafanti/common/model/AftFile.java

@@ -0,0 +1,94 @@
+package com.goafanti.common.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class AftFile {
+    private String id;
+
+    /**
+    * 用户id
+    */
+    private String uid;
+
+    /**
+    * 文件名称
+    */
+    private String fileName;
+
+    /**
+    * 文件路径
+    */
+    private String filePath;
+
+    /**
+    * 模版标记
+    */
+    private String sign;
+
+    /**
+    * 备注
+    */
+    private String comment;
+
+    /**
+    * 删除标记
+    */
+    private Integer deleletedSign;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getUid() {
+        return uid;
+    }
+
+    public void setUid(String uid) {
+        this.uid = uid;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public String getFilePath() {
+        return filePath;
+    }
+
+    public void setFilePath(String filePath) {
+        this.filePath = filePath;
+    }
+
+    public String getSign() {
+        return sign;
+    }
+
+    public void setSign(String sign) {
+        this.sign = sign;
+    }
+
+    public String getComment() {
+        return comment;
+    }
+
+    public void setComment(String comment) {
+        this.comment = comment;
+    }
+    
+    @JsonIgnore
+    public Integer getDeleletedSign() {
+        return deleletedSign;
+    }
+
+    public void setDeleletedSign(Integer deleletedSign) {
+        this.deleletedSign = deleletedSign;
+    }
+}

+ 15 - 0
src/main/java/com/goafanti/common/model/OrgActivity.java

@@ -3,9 +3,11 @@ package com.goafanti.common.model;
 import java.math.BigDecimal;
 import java.util.Date;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.goafanti.common.utils.FileUtils;
 
 public class OrgActivity {
     private String id;
@@ -316,4 +318,17 @@ public class OrgActivity {
 	public void setEndDateFormattedDate(String endDateFormattedDate){
 		
 	}
+	
+	//立项证明材料
+	public String getProofDownloadFileName(){
+		if (StringUtils.isBlank(this.proofUrl)){
+			return null;
+		} else {
+			return (null == this.activityName) ? "" : this.activityName +FileUtils.getDownloadFileName(this.proofUrl);
+		}
+	}
+	
+	public void setProofDownloadFileName(String proofDownloadFileName){
+		
+	}
 }

+ 14 - 0
src/main/java/com/goafanti/common/model/OrgActivityCost.java

@@ -3,9 +3,11 @@ package com.goafanti.common.model;
 import java.math.BigDecimal;
 import java.util.Date;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.goafanti.common.utils.FileUtils;
 
 public class OrgActivityCost {
     private String id;
@@ -292,4 +294,16 @@ public class OrgActivityCost {
 	public void setEndDateFormattedDate(String endDateFormattedDate){
 		
 	}
+	
+	public String getAccountDownloadFileName(){
+		if (StringUtils.isBlank(this.accountUrl)){
+			return null;
+		} else {
+			return (null == this.activityNumber) ? "" : this.activityNumber +FileUtils.getDownloadFileName(this.accountUrl);
+		}
+	}
+	
+	public void setAccountDownloadFileName(String accountDownloadFileName){
+		
+	}
 }

+ 1 - 1
src/main/java/com/goafanti/common/model/OrgHonorDatum.java

@@ -112,7 +112,7 @@ public class OrgHonorDatum {
 		if (StringUtils.isBlank(this.enclosureUrl)){
 			return null;
 		} else {
-			return FileUtils.getDownloadFileName(this.enclosureUrl);
+			return (null == this.name ? "" : this.name )+ FileUtils.getDownloadFileName(this.enclosureUrl);
 		}
 	}
 		

+ 15 - 0
src/main/java/com/goafanti/common/model/OrgIntellectualProperty.java

@@ -2,11 +2,13 @@ package com.goafanti.common.model;
 
 import java.util.Date;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonFormat.Shape;
+import com.goafanti.common.utils.FileUtils;
 
 public class OrgIntellectualProperty {
     private String id;
@@ -187,4 +189,17 @@ public class OrgIntellectualProperty {
 	public void setAuthorizationDateFormattedDate(String authorizationDateFormattedDate){
 		
 	}
+	
+	//知识产权证明
+	public String getPropertyRightDownloadFileName(){
+		if (StringUtils.isBlank(this.propertyRightUrl)){
+			return null;
+		} else {
+			return (null == this.intellectualPropertyName) ? "" : this.intellectualPropertyName +FileUtils.getDownloadFileName(this.propertyRightUrl);
+		}
+	}
+	
+	public void setPropertyRightDownloadFileName(String propertyRightDownloadFileName){
+		
+	}
 }

+ 2 - 1
src/main/java/com/goafanti/common/model/OrgTechCenter.java

@@ -134,11 +134,12 @@ public class OrgTechCenter {
 		
 	}
 	
+	//制度目录
 	public String getSystemDownloadFileName(){
 		if (StringUtils.isBlank(this.systemUrl)){
 			return null;
 		} else {
-			return FileUtils.getDownloadFileName(this.systemUrl);
+			return (null == this.centerName) ? "" : this.centerName +FileUtils.getDownloadFileName(this.systemUrl);
 		}
 	}
 	

+ 15 - 1
src/main/java/com/goafanti/common/model/OrgTechProduct.java

@@ -3,8 +3,11 @@ package com.goafanti.common.model;
 import java.math.BigDecimal;
 import java.util.Date;
 
+import org.apache.commons.lang3.StringUtils;
+
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonFormat.Shape;
+import com.goafanti.common.utils.FileUtils;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 /**
  * 上年度高新技术产品(服务)
@@ -247,5 +250,16 @@ public class OrgTechProduct {
 		this.deletedSign = deletedSign;
 	}
     
-    
+	//高新技术产品台帐
+	public String getAccountDownloadFileName(){
+		if (StringUtils.isBlank(this.accountUrl)){
+			return null;
+		} else {
+			return (null == this.productName) ? "" : this.productName +FileUtils.getDownloadFileName(this.accountUrl);
+		}
+	}
+	
+	public void setAccountDownloadFileName(String accountDownloadFileName){
+		
+	}
 }

+ 27 - 61
src/main/java/com/goafanti/common/utils/FileUtils.java

@@ -1,9 +1,6 @@
 package com.goafanti.common.utils;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
@@ -15,13 +12,10 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.multipart.MultipartFile;
 
-import com.goafanti.common.bo.Result;
-
 public class FileUtils {
 	@Value(value = "${upload.private.path}")
-	private String							uploadPrivatePath	= null;
-	
-	
+	private String uploadPrivatePath = null;
+
 	/**
 	 * response 输出JSON
 	 * 
@@ -92,18 +86,20 @@ public class FileUtils {
 	public static String mosaicFileName(MultipartFile mf, boolean isPrivate, String sign, String path, String uid) {
 		String suffix = mf.getOriginalFilename().substring(mf.getOriginalFilename().lastIndexOf("."));
 		boolean uniq = false;
-		if (sign.indexOf("protocol") != -1 || sign.indexOf("achievement") != -1 || sign.indexOf("honor") != -1){
+		if (sign.indexOf("protocol") != -1 || sign.indexOf("achievement") != -1 || sign.indexOf("honor") != -1
+				|| sign.indexOf("proof") != -1 || sign.indexOf("activity_cost_account") != -1
+				|| sign.indexOf("tech_product") != -1 || sign.indexOf("property_ritht") != -1) {
 			uniq = true;
 		}
 		String fileName = "";
 		if (isPrivate || sign != "") {
-			if (uniq){
-				fileName = path + uid + "/" + System.nanoTime()+ "_" + sign + suffix;
+			if (uniq) {
+				fileName = path + uid + "/" + System.nanoTime() + "_" + sign + suffix;
 			} else {
 				fileName = path + uid + "/" + sign + suffix;
 			}
 		} else {
-			fileName = path + System.nanoTime() + suffix;
+			fileName = path + uid + "/" + System.nanoTime() + suffix;
 		}
 		return fileName;
 	}
@@ -137,6 +133,22 @@ public class FileUtils {
 			prefix = "专利证书";
 		}
 
+		if (path.indexOf("proof") != -1) {
+			prefix = "立项证明材料";
+		}
+
+		if (path.indexOf("activity_cost_account") != -1) {
+			prefix = "研发活动费用台帐";
+		}
+		
+		if (path.indexOf("tech_product") != -1) {
+			prefix = "高新技术产品台帐";
+		}
+		
+		if (path.indexOf("property_ritht") != -1) {
+			prefix = "知识产权证书";
+		}
+
 		if (path.indexOf("roster") != -1) {
 			prefix = subStr(path) + "花名册";
 		}
@@ -146,15 +158,15 @@ public class FileUtils {
 		}
 
 		if (path.indexOf("honor") != -1) {
-			prefix = "企业荣誉材料证明";
+			prefix = "荣誉材料证明";
 		}
 
 		if (path.indexOf("achievement") != -1) {
-			prefix = "科技成果";
+			prefix = "科技成果附件";
 		}
 
 		if (path.indexOf("institution") != -1) {
-			prefix = "技术中心制度";
+			prefix = "制度目录";
 		}
 
 		if (path.indexOf("protocol") != -1) {
@@ -172,52 +184,6 @@ public class FileUtils {
 		fileName = prefix + suffix;
 		return fileName;
 	}
-	
-	
-	/**
-	 * 下载文件
-	 * @param res
-	 * @param fileName
-	 * @param response
-	 * @param path
-	 * @param request
-	 * @return
-	 */
-	public Result downloadFile(Result res, String fileName, HttpServletResponse response, String path) {
-		String fileSaveRootPath = uploadPrivatePath + path;
-		InputStream in = null;
-		OutputStream out = null;
-		byte[] buffer = new byte[8 * 1024];
-		try {
-			File file = new File(fileSaveRootPath);
-			in = new FileInputStream(file);
-			out = response.getOutputStream();
-			// 设置文件MIME类型
-			response.setContentType("application/octet-stream");
-			response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
-			for (;;) {
-				int bytes = in.read(buffer);
-				if (bytes == -1) {
-					break;
-				}
-				out.write(buffer, 0, bytes);
-			}
-		} catch (IOException e) {
-			LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
-		} finally {
-			try {
-				in.close();
-			} catch (IOException e) {
-				LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
-			}
-			try {
-				out.close();
-			} catch (IOException e) {
-				LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
-			}
-		}
-		return res;
-	}
 
 	// year
 	private static String subStr(String s) {

+ 4 - 0
src/main/java/com/goafanti/techservice/cognizance/controller/CognizanceApiController.java

@@ -1046,6 +1046,10 @@ public class CognizanceApiController extends BaseApiController {
 		return res;
 	}
 	
+	
+	@RequestMapping(value = "/download", method = RequestMethod.POST)
+	
+	
 	private AnnualReportBo handleAnnualReport(String uid, Integer year) {
 		AnnualReportBo report = new AnnualReportBo();
 		

+ 1 - 77
src/main/java/com/goafanti/techservice/patent/controller/PatentApiController.java

@@ -750,86 +750,10 @@ public class PatentApiController extends BaseApiController {
 	@RequestMapping(value = "/patentFile", method = RequestMethod.POST)
 	public Result patentFile(HttpServletRequest req, String sign, String oid) {
 		Result res = new Result();
-		/*String fileName = "";
-		if (StringUtils.isBlank(oid)) {
-			fileName = "/patent/" + TokenManager.getUserId() + "_" + sign + ".doc";
-		} else {
-			if (sign.equals("patent_prory_statement") || sign.equals("patent_writing")) {
-				fileName = "/patent/" + oid + "_" + sign + ".doc";
-			} else {
-				fileName = "/patent/" + oid + "_" + sign + ".jpg";
-			}
-		}*/
-		//res.setData(handleFile(res, fileName, req));
-		res.setData(handleFile(res, "/patent/", true, req, sign,  oid));
+		res.setData(handleFile(res, "/cognizannce/", true, req, sign,  oid));
 		return res;
 	}
 
-	/**
-	 * 下载专利代理委托书模版(用户端及管理端)
-	 * 
-	 * @return
-	 */
-	@RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
-	public Result downloadPatentProryStatement(HttpServletResponse response, String fileName) {
-		Result res = new Result();
-		FileUtils f = new FileUtils();
-		String path =  "/patent/patent_prory_statement.doc";
-		return f.downloadFile(res, fileName, response, path);
-	}
-
-	/**
-	 * 下载专利相关材料
-	 * 
-	 * @return
-	 */
-	@RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
-	public Result downloadPatentFile(HttpServletResponse response, String path, String fileName) {
-		Result res = new Result();
-		if (StringUtils.isBlank(path)) {
-			res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "下载文件不存在!"));
-			return res;
-		}
-		FileUtils f = new FileUtils();
-		return f.downloadFile(res, fileName, response, path);
-
-	}
-
-	/*private Result patentDownload(Result res, HttpServletResponse response, String filename, String fileSaveRootPath) {
-		InputStream in = null;
-		OutputStream out = null;
-		byte[] buffer = new byte[8 * 1024];
-		try {
-			File file = new File(fileSaveRootPath);
-			in = new FileInputStream(file);
-			out = response.getOutputStream();
-			// 设置文件MIME类型
-			response.setContentType("application/octet-stream");
-			response.setHeader("Content-Disposition", "attachment; filename=" + filename);
-			for (;;) {
-				int bytes = in.read(buffer);
-				if (bytes == -1) {
-					break;
-				}
-				out.write(buffer, 0, bytes);
-			}
-		} catch (IOException e) {
-			LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
-		} finally {
-			try {
-				in.close();
-			} catch (IOException e) {
-				LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
-			}
-			try {
-				out.close();
-			} catch (IOException e) {
-				LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
-			}
-		}
-		return res;
-
-	}*/
 
 	private String handleFile(Result res, String path, boolean isPrivate, HttpServletRequest req, String sign, String oid) {
 		List<MultipartFile> files = getFiles(req);