Browse Source

导出、导入开发

anderx 3 years ago
parent
commit
5d81978dae

+ 17 - 0
src/main/java/com/goafanti/RD/bo/InputExcelRdDetails.java

@@ -93,6 +93,23 @@ public class InputExcelRdDetails  extends InputRdDetails{
     private String achieveResults;
 
 
+    /**
+     * 咨询师名称
+     */
+    @Excel(name="咨询师名称")
+    private String consultantName;
+
+
+    @Override
+    public String getConsultantName() {
+        return consultantName;
+    }
+
+    @Override
+    public void setConsultantName(String consultantName) {
+        this.consultantName = consultantName;
+    }
+
     @Override
     public String getTechnicalField() {
         return technicalField;

+ 10 - 10
src/main/java/com/goafanti/RD/bo/InputRdList.java

@@ -4,23 +4,23 @@ public class InputRdList {
     private String rdStart;
     private String rdEnd;
     private String rdName;
-    private Integer paseSize;
-    private Integer paseNo;
+    private Integer pageSize;
+    private Integer pageNo;
 
-    public Integer getPaseNo() {
-        return paseNo;
+    public Integer getPageSize() {
+        return pageSize;
     }
 
-    public void setPaseNo(Integer paseNo) {
-        this.paseNo = paseNo;
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
     }
 
-    public Integer getPaseSize() {
-        return paseSize;
+    public Integer getPageNo() {
+        return pageNo;
     }
 
-    public void setPaseSize(Integer paseSize) {
-        this.paseSize = paseSize;
+    public void setPageNo(Integer pageNo) {
+        this.pageNo = pageNo;
     }
 
     public String getRdStart() {

+ 36 - 0
src/main/java/com/goafanti/RD/controller/RDContorller.java

@@ -7,12 +7,18 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.controller.PublicController;
+import com.goafanti.common.enums.AttachmentType;
+import com.goafanti.common.model.Attachment;
 import com.goafanti.common.model.RdDetails;
 import com.goafanti.common.utils.DateUtils;
+import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.ParamUtils;
 import com.goafanti.common.utils.StringUtils;
+import com.goafanti.common.utils.excel.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.MediaType;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -22,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
 
 @RestController
@@ -31,6 +38,9 @@ public class RDContorller extends BaseApiController {
     @Autowired
     private RDService rdService;
 
+    @Value(value = "${upload.path}")
+    private final String	uploadPath			= null;
+
 
     @RequestMapping(value="/add",method = RequestMethod.POST)
     public Result add(@Validated InputRdDetails in ,BindingResult bindingResult) {
@@ -69,6 +79,12 @@ public class RDContorller extends BaseApiController {
         return res;
     }
 
+    @RequestMapping(value = "/exportList",method = RequestMethod.GET)
+    public Result exportList(InputRdList in){
+        return rdService.exportList(in,uploadPath);
+    }
+
+
     /**
      * 	Excel批量导入回款
      *
@@ -90,4 +106,24 @@ public class RDContorller extends BaseApiController {
         res.data(rdService.batchList(file));
         return res;
     }
+
+    /**
+     * 	批量导入回款模版
+     *
+     * @return
+     */
+    @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
+    public void downloadTemplate(HttpServletResponse response) {
+        Result res = new Result();
+        StringBuffer url= new StringBuffer(uploadPath);
+        url=url.append("/tmp").append("/RD_details_template.xlsx");
+        try {
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+            FileUtils.setAttachmentResponseHeader(response, url.toString(),"研发活动导入模版.xlsx");
+            FileUtils.writeBytes(url.toString(), response.getOutputStream());
+        }
+        catch (Exception e) {
+            LoggerUtils.error(PublicController.class,"下载文件失败", e);
+        }
+    }
 }

+ 3 - 0
src/main/java/com/goafanti/RD/service/RDService.java

@@ -2,6 +2,7 @@ package com.goafanti.RD.service;
 
 import com.goafanti.RD.bo.InputRdList;
 import com.goafanti.RD.bo.OutRdDetails;
+import com.goafanti.common.bo.Result;
 import com.goafanti.common.model.RdDetails;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -15,4 +16,6 @@ public interface RDService {
     Object list(InputRdList in);
 
     Object batchList(MultipartFile file);
+
+    Result exportList(InputRdList in, String uploadPath);
 }

+ 44 - 131
src/main/java/com/goafanti/RD/service/impl/RDServiceImpl.java

@@ -6,9 +6,11 @@ import com.goafanti.RD.bo.InputRdList;
 import com.goafanti.RD.bo.OutRdDetails;
 import com.goafanti.RD.service.RDService;
 import com.goafanti.common.bo.Error;
+import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.dao.AdminMapper;
 import com.goafanti.common.dao.RdDetailsMapper;
+import com.goafanti.common.enums.NoticeTypes;
 import com.goafanti.common.error.BusinessException;
 import com.goafanti.common.model.Admin;
 import com.goafanti.common.model.RdDetails;
@@ -22,6 +24,7 @@ import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.order.bo.TemporaryReceivablesBo;
 import org.apache.poi.ss.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -36,6 +39,8 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
     private AdminMapper adminMapper;
 
 
+
+
     @Override
     public int add(RdDetails in) {
         Admin admin = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
@@ -58,17 +63,30 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
 
     @Override
     public Object list(InputRdList in) {
+        Map<String, Object> param = getParam(in);
+
+        return findPage("RdDetailsList","RdDetailsCount",param,in.getPageNo(), in.getPageSize());
+    }
+
+    private Map<String, Object> getParam(InputRdList in) {
         Map<String,Object> param=new HashMap<>();
-        param.put("RdStart",in.getRdStart());
-        param.put("RdEnd",in.getRdStart());
-        param.put("RdName",in.getRdName());
+        param.put("RdStart", in.getRdStart());
+        param.put("RdEnd", in.getRdStart());
+        param.put("RdName", in.getRdName());
+        return param;
+    }
 
-        return findPage("RdDetailsList","RdDetailsCount",param,in.getPaseNo(), in.getPaseSize());
+    @Override
+    public Result exportList(InputRdList in, String uploadPath) {
+        Map<String, Object> param = getParam(in);
+        List<InputExcelRdDetails> list = (List<InputExcelRdDetails>) findList("RdDetailsList", param, 1, 9999);
+        NewExcelUtil<InputExcelRdDetails> newExcelUtil=new NewExcelUtil<>(InputExcelRdDetails.class);
+        return newExcelUtil.exportExcel(list,"研发活动信息",uploadPath);
     }
 
     @Override
     public Object batchList(MultipartFile file) {
-        NewExcelUtil<InputExcelRdDetails> newExcelUtil=new NewExcelUtil<InputExcelRdDetails>(InputExcelRdDetails.class);
+        NewExcelUtil<InputExcelRdDetails> newExcelUtil=new NewExcelUtil<>(InputExcelRdDetails.class);
         List<InputExcelRdDetails> list = null;
         try {
             list = newExcelUtil.importExcel(file.getInputStream());
@@ -78,133 +96,12 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
 
 //        List<InputRdDetails> list=  pushRdDetails(file);
         //新增
-        return insertBatch(list);
-    }
-
-    private List<InputExcelRdDetails> pushRdDetails(MultipartFile file) {
-        List<InputExcelRdDetails> list=new ArrayList<>();
-        Workbook workbook = ExcelUtils.getWorkBook(file);
-        Sheet sheet=null;
-        //创建一个对象,用来存储数据
-        if (workbook != null) {
-            //获得当前sheet工作表
-            sheet = workbook.getSheetAt(0);
-            if (sheet == null) {
-                throw new BusinessException(new Error("未找到正确的参数。"));
-            }
-            //获得当前sheet的开始行
-            int firstRowNum = sheet.getFirstRowNum();
-            //获得当前sheet的结束行
-            int lastRowNum = sheet.getLastRowNum();
-            //处理空白行
-            Integer getLast = 0;
-            for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
-                Row r = sheet.getRow(i);
-                if (r == null) {
-                    // 如果是空行(即没有任何数据、格式),直接把它以下的数据往上移动
-                    sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1);
-                    continue;
-                }
-                boolean flag = false;
-                for (Cell c : r) {
-                    if (c.getCellTypeEnum() != CellType.BLANK) {
-                        flag = true;
-                        break;
-                    }
-                }
-                if (flag) {
-                    getLast++;
-                    continue;
-                }
-            }
-            //行数从0开始所以减一
-            getLast--;
-            if (getLast < 1) {
-                throw new BusinessException(new Error("未找到正确的参数。"));
-            }
-            lastRowNum=getLast;
-
-            Date date=new Date();
-            //循环除了第1行的所有行 行数从0开始,最大行数所以
-            for(int rowNum = firstRowNum+2;rowNum <= lastRowNum;rowNum++) {
-                //获得当前行
-                Row row = sheet.getRow(rowNum);
-                if (row == null) {
-                    continue;
-                }
-                //获得当前行的开始列
-                int firstCellNum = row.getFirstCellNum();
-                //获得当前行的列数
-                int lastCellNum = row.getLastCellNum();
-                InputExcelRdDetails in = new InputExcelRdDetails();
-                for (int cellNum = (firstCellNum); cellNum < lastCellNum; cellNum++) {
-                    Cell cell = row.getCell(cellNum);
-                    try {
-                        switch (cellNum) {
-                            case 0:
-                                in.setUserName(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 1:
-                                in.setRdNo(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 2:
-                                in.setIpNo(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 3:
-                                in.setRdName(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 4:
-                                in.setRdStart(ExcelUtils.getCellDate(cell, AFTConstants.YYYYMMDD_2));
-                                break;
-                            case 5:
-                                in.setRdEnd(ExcelUtils.getCellDate(cell, AFTConstants.YYYYMMDD_2));
-                                break;
-                            case 6:
-                                in.setTechnicalField(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 7:
-                                in.setTechnologySource(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 8:
-                                String str = ExcelUtils.getCellValue(cell);
-                                if (StringUtils.isBlank(str)) str = "0";
-                                in.setTotalAmount(new BigDecimal(str));
-                                break;
-                            case 9:
-                                String str2 = ExcelUtils.getCellValue(cell);
-                                if (StringUtils.isBlank(str2)) str2 = "0";
-                                in.setRecentThreeAmount(new BigDecimal(str2));
-                                break;
-                            case 10:
-                                in.setRdObjective(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 11:
-                                in.setCoreTechnology(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 12:
-                                in.setAchieveResults(ExcelUtils.getCellValue(cell));
-                                break;
-                            case 13:
-                                in.setConsultantName(ExcelUtils.getCellValue(cell));
-                                break;
-                        }
-                    } catch (Exception e) {
-                        throw new BusinessException(new Error("表格第" + (rowNum + 1) + "行输入内容不正确。"));
-                    }
-                }
-                in.setAid(TokenManager.getAdminId());
-                in.setCreateTime(date);
-                in.setStatus(0);
-                list.add(in);
-            }
-        }
-        return list;
-
+        return insertBatchList(list);
     }
 
-
-
-    private Map<String,Object> insertBatch(List<InputExcelRdDetails> list) {
+    private Map<String,Object> insertBatchList(List<InputExcelRdDetails> list) {
+        String aid=TokenManager.getAdminId();
+        Date date =new Date();
         Map<String,Object> map=new HashMap<>();
         List<InputExcelRdDetails> relust= new ArrayList<>();
         List<String>errors=new ArrayList<>();
@@ -216,9 +113,25 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
                 relust.add(in);
             }
         }
-        if (relust.size()>0)rdDetailsMapper.insertBatch(list);
+        for (InputExcelRdDetails in : relust) {
+            in.setStatus(1);
+            in.setAid(aid);
+            in.setCreateTime(date);
+        }
+        if (relust.size()>0)insertBatch(relust);
         map.put("OK",relust.size());
         map.put("ERROR",errors);
         return map;
     }
+
+    private void insertBatch(List<InputExcelRdDetails> relust) {
+        List<InputExcelRdDetails> list=new ArrayList<>();
+        for (int i = 0; i < relust.size(); i++) {
+            list.add(relust.get(i));
+            if (50 == list.size() || i == relust.size() - 1) {
+                if (list.size() > 0) rdDetailsMapper.insertBatch(list);
+                list.clear();
+            }
+        }
+    }
 }

+ 32 - 11
src/main/java/com/goafanti/common/mapper/RdDetailsMapper.xml

@@ -21,11 +21,13 @@
     <result column="open_time" jdbcType="TIMESTAMP" property="openTime" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="aid" jdbcType="VARCHAR" property="aid" />
+    <result column="browse_count" jdbcType="INTEGER" property="browseCount" />
+    <result column="download_count" jdbcType="INTEGER" property="downloadCount" />
   </resultMap>
   <sql id="Base_Column_List">
     id, user_name, rd_no, ip_no, rd_name, rd_start, rd_end, technical_field, technology_source,
     total_amount, recent_three_amount, rd_objective, core_technology, achieve_results,
-    consultant_name, `status`, open_time, create_time, aid
+    consultant_name, `status`, open_time, create_time, aid, browse_count, download_count
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
     select
@@ -43,15 +45,15 @@
       technical_field, technology_source, total_amount,
       recent_three_amount, rd_objective, core_technology,
       achieve_results, consultant_name, `status`,
-      open_time, create_time, aid
-      )
+      open_time, create_time, aid,
+      browse_count, download_count)
     values (#{userName,jdbcType=VARCHAR}, #{rdNo,jdbcType=VARCHAR}, #{ipNo,jdbcType=VARCHAR},
       #{rdName,jdbcType=VARCHAR}, #{rdStart,jdbcType=TIMESTAMP}, #{rdEnd,jdbcType=TIMESTAMP},
       #{technicalField,jdbcType=VARCHAR}, #{technologySource,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL},
       #{recentThreeAmount,jdbcType=DECIMAL}, #{rdObjective,jdbcType=VARCHAR}, #{coreTechnology,jdbcType=VARCHAR},
       #{achieveResults,jdbcType=VARCHAR}, #{consultantName,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
-      #{openTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{aid,jdbcType=VARCHAR}
-      )
+      #{openTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{aid,jdbcType=VARCHAR},
+      #{browseCount,jdbcType=INTEGER}, #{downloadCount,jdbcType=INTEGER})
   </insert>
   <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.RdDetails" useGeneratedKeys="true">
     insert into rd_details
@@ -110,6 +112,12 @@
       <if test="aid != null">
         aid,
       </if>
+      <if test="browseCount != null">
+        browse_count,
+      </if>
+      <if test="downloadCount != null">
+        download_count,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="userName != null">
@@ -166,9 +174,14 @@
       <if test="aid != null">
         #{aid,jdbcType=VARCHAR},
       </if>
+      <if test="browseCount != null">
+        #{browseCount,jdbcType=INTEGER},
+      </if>
+      <if test="downloadCount != null">
+        #{downloadCount,jdbcType=INTEGER},
+      </if>
     </trim>
   </insert>
-
   <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.RdDetails">
     update rd_details
     <set>
@@ -226,6 +239,12 @@
       <if test="aid != null">
         aid = #{aid,jdbcType=VARCHAR},
       </if>
+      <if test="browseCount != null">
+        browse_count = #{browseCount,jdbcType=INTEGER},
+      </if>
+      <if test="downloadCount != null">
+        download_count = #{downloadCount,jdbcType=INTEGER},
+      </if>
     </set>
     where id = #{id,jdbcType=BIGINT}
   </update>
@@ -248,7 +267,9 @@
       `status` = #{status,jdbcType=INTEGER},
       open_time = #{openTime,jdbcType=TIMESTAMP},
       create_time = #{createTime,jdbcType=TIMESTAMP},
-      aid = #{aid,jdbcType=VARCHAR}
+      aid = #{aid,jdbcType=VARCHAR},
+      browse_count = #{browseCount,jdbcType=INTEGER},
+      download_count = #{downloadCount,jdbcType=INTEGER}
     where id = #{id,jdbcType=BIGINT}
   </update>
 
@@ -259,9 +280,9 @@
   </select>
   <sql id="details_List">
      a.id, a.user_name userName, a.rd_no rdNo, a.ip_no ipNo, a.rd_name rdName,a.technical_field technicalField,
-     a.technology_source technologySource, a.total_amount totalAmount, a.recent_three_amount recentThreeAmount,
-     a.rd_objective rdObjective, a.core_technology coreTechnology, a.achieve_results achieveResults,
-     a.consultant_name consultantName, a.status, date_format(a.rd_start, '%Y-%m-%d %H:%i:%s') rdStartS,
+    a.technology_source technologySource, a.total_amount totalAmount, a.recent_three_amount recentThreeAmount,a.aid,
+     a.rd_objective rdObjective, a.core_technology coreTechnology, a.achieve_results achieveResults,a.consultant_name consultantName,
+    a.status,a.browse_count browseCount ,a.download_count downloadCount, date_format(a.rd_start, '%Y-%m-%d %H:%i:%s') rdStartS,
      date_format(a.rd_end , '%Y-%m-%d %H:%i:%s') rdEndS,date_format(a.open_time, '%Y-%m-%d %H:%i:%s')openTimeS,
      date_format(a.create_time, '%Y-%m-%d %H:%i:%s') createTimeS
   </sql>
@@ -272,7 +293,7 @@
     where a.id =#{id}
   </select>
 
-  <select id="RdDetailsList" resultType="com.goafanti.RD.bo.OutRdDetails">
+  <select id="RdDetailsList" resultType="com.goafanti.RD.bo.InputExcelRdDetails">
     select
     <include refid="details_List" />
     from rd_details a

+ 26 - 0
src/main/java/com/goafanti/common/model/RdDetails.java

@@ -101,6 +101,16 @@ public class RdDetails implements Serializable {
      */
     private String aid;
 
+    /**
+     * 浏览次数
+     */
+    private Integer browseCount;
+
+    /**
+     * 下载次数
+     */
+    private Integer downloadCount;
+
     private static final long serialVersionUID = 1L;
 
     public Long getId() {
@@ -254,4 +264,20 @@ public class RdDetails implements Serializable {
     public void setAid(String aid) {
         this.aid = aid;
     }
+
+    public Integer getBrowseCount() {
+        return browseCount;
+    }
+
+    public void setBrowseCount(Integer browseCount) {
+        this.browseCount = browseCount;
+    }
+
+    public Integer getDownloadCount() {
+        return downloadCount;
+    }
+
+    public void setDownloadCount(Integer downloadCount) {
+        this.downloadCount = downloadCount;
+    }
 }

+ 1 - 1
src/main/java/com/goafanti/common/utils/excel/NewExcelUtil.java

@@ -132,7 +132,7 @@ public class NewExcelUtil<T> {
 		createExcelField();
 		createWorkbook();
 	}
-	public void init(List<T> list, String sheetName, String title, Excel.Type type)
+	public void init(List<T> list, String sheetName, String title, Type type)
 	{
 		if (list == null)
 		{