|
|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|