Przeglądaj źródła

RD研发活动库导入开发

anderx 3 lat temu
rodzic
commit
60203e9628

+ 1 - 2
src/main/java/com/goafanti/RD/controller/RDContorller.java

@@ -87,8 +87,7 @@ public class RDContorller extends BaseApiController {
             res.getError().add(buildError("格式不正确","格式不正确"));
             return res;
         }
-        rdService.batchList(file);
-        res.data(1);
+        res.data(rdService.batchList(file));
         return res;
     }
 }

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

@@ -14,5 +14,5 @@ public interface RDService {
 
     Object list(InputRdList in);
 
-    void batchList(MultipartFile file);
+    Object batchList(MultipartFile file);
 }

+ 138 - 84
src/main/java/com/goafanti/RD/service/impl/RDServiceImpl.java

@@ -13,8 +13,10 @@ import com.goafanti.common.model.Admin;
 import com.goafanti.common.model.RdDetails;
 import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.ExcelUtils;
+import com.goafanti.common.utils.StringUtils;
 import com.goafanti.common.utils.excel.NewExcelUtil;
 import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.order.bo.TemporaryReceivablesBo;
 import org.apache.poi.ss.usermodel.*;
@@ -64,100 +66,152 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
     }
 
     @Override
-    public void batchList(MultipartFile file) {
+    public Object batchList(MultipartFile file) {
+
+        List<InputRdDetails> list=  pushRdDetails(file);
+
+        //新增
+        return insertBatch(list);
+    }
+
+    private List<InputRdDetails> pushRdDetails(MultipartFile file) {
         List<InputRdDetails> list=new ArrayList<>();
-            //获得Workbook工作薄对象
-            Workbook workbook = ExcelUtils.getWorkBook(file);
-            //创建一个对象,用来存储数据
-            if(workbook != null){
-                //获得当前sheet工作表
-                Sheet sheet = workbook.getSheetAt(0);
-                if(sheet == null){
-                    return;
+        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;
                 }
-                //获得当前sheet的开始行
-                int firstRowNum = sheet.getFirstRowNum();
-                //获得当前sheet的结束行
-                int lastRowNum = sheet.getLastRowNum();
-                //处理空白行
-                for (int i = firstRowNum; 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){
-                        i++;
-                        continue;
-                    } else{//如果是空白行(即可能没有数据,但是有一定格式)
-                        if(i == sheet.getLastRowNum())//如果到了最后一行,直接将那一行remove掉
-                            sheet.removeRow(r);
-                        else//如果还没到最后一行,则数据往上移一行
-                            sheet.shiftRows(i+1, sheet.getLastRowNum(),-1);
+                boolean flag = false;
+                for (Cell c : r) {
+                    if (c.getCellTypeEnum() != CellType.BLANK) {
+                        flag = true;
+                        break;
                     }
                 }
-                lastRowNum=sheet.getLastRowNum();
-                if (lastRowNum<2) {
-                    throw new BusinessException(new Error("未找到正确的参数。"));
+                if (flag) {
+                    getLast++;
+                    continue;
                 }
-                //循环除了第2行的所有行
-                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();
-                    //循环当前行 cellNum = (firstCellNum+1) 则是除开第一例
-                    InputRdDetails in=new InputRdDetails();
-                    for(int cellNum = (firstCellNum); cellNum < lastCellNum;cellNum++){
-                        Cell cell = row.getCell(cellNum);
-                        try {
-                            switch (cellNum) {
-                                case 0:
-                                    trb.setFinancialPayNo(ExcelUtils.getCellValue(cell));
-                                    break;
-                                case 1:
-                                    trb.setOrderNo(ExcelUtils.getCellValue(cell).trim());
-                                    break;
-                                case 2:
-                                    trb.setCorporateName(ExcelUtils.getCellValue(cell));
-                                    break;
-                                case 3:
-                                    trb.setAmount(new BigDecimal((ExcelUtils.getCellValue(cell).equals("")?"0":ExcelUtils.getCellValue(cell))));
-                                    break;
-                                case 4:
-                                    trb.setReceivablesTime(DateUtils.StringToDate(ExcelUtils.getCellValue(cell), AFTConstants.YYYYMMDD));
-                                    break;
-                                case 5:
-                                    trb.setRemarks(ExcelUtils.getCellValue(cell));
-                                    break;
-                            }
-                        } catch (Exception e) {
-                            throw new BusinessException(new Error("表格第"+(rowNum+1)+"行输入内容不正确。"));
+            }
+            //行数从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();
+                InputRdDetails in = new InputRdDetails();
+                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) + "行输入内容不正确。"));
                     }
-                    trb.setAid(TokenManager.getAdminId());
-                    trb.setCreateTime(new Date());
-                    trb.setStatus(0);
-                    list.add(trb);
                 }
+                in.setAid(TokenManager.getAdminId());
+                in.setCreateTime(date);
+                in.setStatus(0);
+                list.add(in);
             }
-            temporaryReceivablesMapper.insertBatch(list);
-            //计算重复的单
-            temporaryReceivablesMapper.updateRepeatOrderNo(TokenManager.getAdminId());
+        }
+        return list;
+
+    }
 
 
+
+    private Map<String,Object> insertBatch(List<InputRdDetails> list) {
+        Map<String,Object> map=new HashMap<>();
+        List<InputRdDetails> relust= new ArrayList<>();
+        List<String>errors=new ArrayList<>();
+        for (InputRdDetails in : list) {
+            boolean falg = checkRdNo(in.getRdNo());
+            if (falg){
+                errors.add(in.getRdNo());
+            }else {
+                relust.add(in);
+            }
+        }
+        if (relust.size()>0)rdDetailsMapper.insertBatch(list);
+        map.put("OK",relust.size());
+        map.put("ERROR",errors);
+        return map;
     }
 }

+ 1 - 0
src/main/java/com/goafanti/common/constant/AFTConstants.java

@@ -4,6 +4,7 @@ public class AFTConstants {
 	public static final String	YYYYMMDDHHMMSS						= "yyyy-MM-dd HH:mm:ss";
 	public static final String	YMDHMS_CHINESE						= "yyyy年MM月dd日 HH:mm:ss";
 	public static final String	YYYYMMDD							= "yyyy-MM-dd";
+	public static final String	YYYYMMDD_2							= "yyyy/MM/dd";
 	public static final String	YYYYMM								= "yyyy-MM";
 	public static final String	YYYY								= "yyyy";
 

+ 11 - 1
src/main/java/com/goafanti/common/dao/RdDetailsMapper.java

@@ -1,7 +1,11 @@
 package com.goafanti.common.dao;
 
+import com.goafanti.RD.bo.InputRdDetails;
+import com.goafanti.RD.bo.OutRdDetails;
 import com.goafanti.common.model.RdDetails;
 
+import java.util.List;
+
 public interface RdDetailsMapper {
     int deleteByPrimaryKey(Long id);
 
@@ -14,4 +18,10 @@ public interface RdDetailsMapper {
     int updateByPrimaryKeySelective(RdDetails record);
 
     int updateByPrimaryKey(RdDetails record);
-}
+
+    OutRdDetails details(Long id);
+
+    int checkRdNo(String rdNo);
+
+    void insertBatch(List<InputRdDetails> list);
+}

+ 38 - 6
src/main/java/com/goafanti/common/mapper/RdDetailsMapper.xml

@@ -20,11 +20,12 @@
     <result column="status" jdbcType="INTEGER" property="status" />
     <result column="open_time" jdbcType="TIMESTAMP" property="openTime" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
+    <result column="aid" jdbcType="VARCHAR" property="aid" />
   </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
+    consultant_name, `status`, open_time, create_time, aid
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
     select
@@ -32,8 +33,7 @@
     from rd_details
     where id = #{id,jdbcType=BIGINT}
   </select>
-
-    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
     delete from rd_details
     where id = #{id,jdbcType=BIGINT}
   </delete>
@@ -43,13 +43,15 @@
       technical_field, technology_source, total_amount,
       recent_three_amount, rd_objective, core_technology,
       achieve_results, consultant_name, `status`,
-      open_time, create_time)
+      open_time, create_time, aid
+      )
     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})
+      #{openTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{aid,jdbcType=VARCHAR}
+      )
   </insert>
   <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.RdDetails" useGeneratedKeys="true">
     insert into rd_details
@@ -105,6 +107,9 @@
       <if test="createTime != null">
         create_time,
       </if>
+      <if test="aid != null">
+        aid,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="userName != null">
@@ -158,8 +163,12 @@
       <if test="createTime != null">
         #{createTime,jdbcType=TIMESTAMP},
       </if>
+      <if test="aid != null">
+        #{aid,jdbcType=VARCHAR},
+      </if>
     </trim>
   </insert>
+
   <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.RdDetails">
     update rd_details
     <set>
@@ -214,6 +223,9 @@
       <if test="createTime != null">
         create_time = #{createTime,jdbcType=TIMESTAMP},
       </if>
+      <if test="aid != null">
+        aid = #{aid,jdbcType=VARCHAR},
+      </if>
     </set>
     where id = #{id,jdbcType=BIGINT}
   </update>
@@ -235,7 +247,8 @@
       consultant_name = #{consultantName,jdbcType=VARCHAR},
       `status` = #{status,jdbcType=INTEGER},
       open_time = #{openTime,jdbcType=TIMESTAMP},
-      create_time = #{createTime,jdbcType=TIMESTAMP}
+      create_time = #{createTime,jdbcType=TIMESTAMP},
+      aid = #{aid,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}
   </update>
 
@@ -286,6 +299,25 @@
       and a.rd_name =#{RdName}
     </if>
   </select>
+  <insert id="insertBatch">
+    insert into rd_details (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
+    ) values
+    <foreach item="item" index="index" collection="list" separator=",">
+      (#{item.userName,jdbcType=VARCHAR}, #{item.rdNo,jdbcType=VARCHAR}, #{item.ipNo,jdbcType=VARCHAR},
+      #{item.rdName,jdbcType=VARCHAR}, #{item.rdStart,jdbcType=TIMESTAMP}, #{item.rdEnd,jdbcType=TIMESTAMP},
+      #{item.technicalField,jdbcType=VARCHAR}, #{item.technologySource,jdbcType=VARCHAR}, #{item.totalAmount,jdbcType=DECIMAL},
+      #{item.recentThreeAmount,jdbcType=DECIMAL}, #{item.rdObjective,jdbcType=VARCHAR}, #{item.coreTechnology,jdbcType=VARCHAR},
+      #{item.achieveResults,jdbcType=VARCHAR}, #{item.consultantName,jdbcType=VARCHAR}, #{item.status,jdbcType=INTEGER},
+      #{item.openTime,jdbcType=TIMESTAMP}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.aid,jdbcType=VARCHAR}
+      )
+    </foreach>
 
 
+  </insert>
+
 </mapper>

+ 8 - 2
src/main/java/com/goafanti/common/utils/ExcelUtils.java

@@ -14,6 +14,8 @@ import java.util.List;
 import java.util.Set;
 import java.util.regex.Pattern;
 
+import com.goafanti.common.bo.Error;
+import com.goafanti.common.error.BusinessException;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -774,8 +776,11 @@ public class ExcelUtils {
         }
         return value.trim();
     }
-
 	public static Date getCellDate(Cell cell) {
+		return getCellDate( cell,AFTConstants.YYYYMMDD );
+	}
+	public static Date getCellDate(Cell cell,String format) {
+    	if(format==null)format=AFTConstants.YYYYMMDD;
 		Date date=new Date();
 		  if (cell != null) {
 	            switch (cell.getCellTypeEnum()) {
@@ -783,7 +788,7 @@ public class ExcelUtils {
 	            		 date = cell.getDateCellValue();
 	                     break;
 	                case STRING://字符串
-	                	date = DateUtils.StringToDate(cell.getStringCellValue(), AFTConstants.YYYYMMDD);
+	                	date = DateUtils.StringToDate(cell.getStringCellValue(), format);
 	                default:
 	                    date = new Date();
 	            }
@@ -809,4 +814,5 @@ public class ExcelUtils {
         }
 
 
+
 }