Explorar o código

coganizanceRecord import

Antiloveg %!s(int64=8) %!d(string=hai) anos
pai
achega
b1f871acf2

+ 64 - 8
src/main/java/com/goafanti/admin/controller/AdminCognizanceRecordApiController.java

@@ -14,18 +14,23 @@ import com.goafanti.common.controller.CertifyApiController;
 
 @Controller
 @RequestMapping(value = "/api/admin/cognizanceRecord")
-public class AdminCognizanceRecordApiController extends CertifyApiController{
+public class AdminCognizanceRecordApiController extends CertifyApiController {
 	@Resource
-	private CoganizanceRecordService coganizanceRecordService;
-	
-	
+	private CoganizanceRecordService	coganizanceRecordService;
+
+	private static final int			DISTRICT_MAX_LENGTH		= 4;
+
+	private static final int			YEAR_MAX_LENGTH			= 4;
+
+	private static final int			UNIT_NAME_MAX_LENGTH	= 45;
+
 	/**
 	 * 查询
 	 */
 	@RequestMapping(value = "/search", method = RequestMethod.GET)
-	public Result search(Integer district, String unitName, Integer year, String pageSize, String pageNo){
+	public Result search(Integer district, String unitName, Integer year, String pageSize, String pageNo) {
 		Result res = new Result();
-		if (null == district && StringUtils.isBlank(unitName) && null == year){
+		if (null == district && StringUtils.isBlank(unitName) && null == year) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "查询条件"));
 			return res;
 		}
@@ -41,6 +46,57 @@ public class AdminCognizanceRecordApiController extends CertifyApiController{
 		res.setData(coganizanceRecordService.listSearch(district, unitName, year, pNo, pSize));
 		return res;
 	}
-	
-	
+
+	/**
+	 * 批量导入
+	 */
+	@RequestMapping(value = "/import", method = RequestMethod.POST)
+	public Result importCoganizanceRecord(Integer district, String unitName, Integer year) {
+		Result res = new Result();
+		if (null == district) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "地区"));
+			return res;
+		}
+
+		if (StringUtils.isBlank(unitName)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "公司名称"));
+			return res;
+		}
+
+		if (null == year) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "年份"));
+			return res;
+		}
+
+		res = disposeImport(district, unitName, year, res);
+		if (!res.getError().isEmpty()) {
+			return res;
+		}
+		String[] unitNames = (String[])res.getData();
+		coganizanceRecordService.insertImport(district, unitNames, year);
+		return res;
+	}
+
+	private Result disposeImport(Integer district, String unitName, Integer year, Result res) {
+		if (district.toString().length() > DISTRICT_MAX_LENGTH) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "地区"));
+			return res;
+		}
+		if (year.toString().length() > YEAR_MAX_LENGTH) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "年份"));
+			return res;
+		}
+		String[] unitNames = unitName.split(",|,");
+		if (null != unitNames && unitName.length() > 0) {
+			for (String s : unitNames) {
+				if (StringUtils.isNotBlank(s) && s.length() > UNIT_NAME_MAX_LENGTH) {
+					res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "公司名称"));
+					return res;
+				}
+			}
+		}
+		res.setData(unitNames);
+		return res;
+	}
+
 }

+ 2 - 0
src/main/java/com/goafanti/cognizanceRecord/service/CoganizanceRecordService.java

@@ -8,4 +8,6 @@ public interface CoganizanceRecordService {
 	Pagination<CoganizanceRecord> listSearch(Integer district, String unitName, Integer year, Integer pNo,
 			Integer pSize);
 
+	void insertImport(Integer district, String[] unitNames, Integer year);
+
 }

+ 23 - 7
src/main/java/com/goafanti/cognizanceRecord/service/impl/CognizanceRecordServiceImpl.java

@@ -1,6 +1,8 @@
 package com.goafanti.cognizanceRecord.service.impl;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.lang3.StringUtils;
@@ -14,7 +16,7 @@ import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
 
 @Service
-public class CognizanceRecordServiceImpl extends BaseMybatisDao<CoganizanceRecordMapper>
+public class CoganizanceRecordServiceImpl extends BaseMybatisDao<CoganizanceRecordMapper>
 		implements CoganizanceRecordService {
 	@Autowired
 	private CoganizanceRecordMapper coganizanceRecordMapper;
@@ -24,19 +26,19 @@ public class CognizanceRecordServiceImpl extends BaseMybatisDao<CoganizanceRecor
 	public Pagination<CoganizanceRecord> listSearch(Integer district, String unitName, Integer year, Integer pNo,
 			Integer pSize) {
 		Map<String, Object> params = new HashMap<>();
-		
+
 		if (null != district) {
 			params.put("district", district);
 		}
-		
+
 		if (StringUtils.isNotBlank(unitName)) {
 			params.put("unitName", unitName);
 		}
-		
-		if (null != year){
+
+		if (null != year) {
 			params.put("year", year);
 		}
-		
+
 		if (pNo == null || pNo < 0) {
 			pNo = 1;
 		}
@@ -44,9 +46,23 @@ public class CognizanceRecordServiceImpl extends BaseMybatisDao<CoganizanceRecor
 		if (pSize == null || pSize < 0 || pSize > 20) {
 			pSize = 20;
 		}
-		
+
 		return (Pagination<CoganizanceRecord>) findPage("findCoganizanceRecordListByPage", "findCoganizanceRecordCount",
 				params, pNo, pSize);
 	}
 
+	@Override
+	public void insertImport(Integer district, String[] unitNames, Integer year) {
+		CoganizanceRecord cr = null;
+		List<CoganizanceRecord> list = new ArrayList<>();
+		for (String s : unitNames) {
+			if (StringUtils.isNotBlank(s)) {
+				cr = new CoganizanceRecord(district, s, year);
+				list.add(cr);
+			}
+		}
+		coganizanceRecordMapper.insertBatch(list);
+
+	}
+
 }

+ 4 - 0
src/main/java/com/goafanti/common/dao/CoganizanceRecordMapper.java

@@ -1,5 +1,7 @@
 package com.goafanti.common.dao;
 
+import java.util.List;
+
 import com.goafanti.common.model.CoganizanceRecord;
 
 public interface CoganizanceRecordMapper {
@@ -14,4 +16,6 @@ public interface CoganizanceRecordMapper {
     int updateByPrimaryKeySelective(CoganizanceRecord record);
 
     int updateByPrimaryKey(CoganizanceRecord record);
+
+	void insertBatch(List<CoganizanceRecord> list);
 }

+ 14 - 0
src/main/java/com/goafanti/common/mapper/CoganizanceRecordMapper.xml

@@ -115,4 +115,18 @@
      	and year = #{year,jdbcType=INTEGER}
     </if>
   </select>
+  
+   <insert id="insertBatch" parameterType="com.goafanti.common.model.CoganizanceRecord"">
+    insert into coganizance_record 
+    	(id, district, unit_name, year)
+    values 
+    <foreach item="item" index="index" collection="list" separator=",">
+      (
+      	#{item.id,jdbcType=BIGINT}, 
+      	#{item.district,jdbcType=INTEGER}, 
+      	#{item.unitName,jdbcType=VARCHAR},
+      	#{item.year,jdbcType=INTEGER}
+      )
+    </foreach>
+  </insert>
 </mapper>

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

@@ -17,8 +17,17 @@ public class CoganizanceRecord {
     * 高企认定年份
     */
     private Integer year;
+    
+    public CoganizanceRecord(Integer district, String unitName, Integer year){
+    	this.district = district;
+    	this.unitName = unitName;
+    	this.year = year;
+    }
+
+    public CoganizanceRecord() {
+	}
 
-    public Long getId() {
+	public Long getId() {
         return id;
     }