Quellcode durchsuchen

违纪类型相关代码改进及优化

lideyin vor 5 Jahren
Ursprung
Commit
b0d45f606b

+ 25 - 0
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/bean/IllegallyTypeDomain.java

@@ -16,6 +16,16 @@ public class IllegallyTypeDomain implements JsonSerializable {
 
 	private Boolean enable;
 
+	/**
+	 * 排序号
+	 */
+	private Integer sortNo;
+
+	/**
+	 * 数据分类
+	 */
+	private String dataCategory;
+
 	public Long getId() {
 		return id;
 	}
@@ -56,4 +66,19 @@ public class IllegallyTypeDomain implements JsonSerializable {
 		this.enable = enable;
 	}
 
+	public Integer getSortNo() {
+		return sortNo;
+	}
+
+	public void setSortNo(Integer sortNo) {
+		this.sortNo = sortNo;
+	}
+
+	public String getDataCategory() {
+		return dataCategory;
+	}
+
+	public void setDataCategory(String dataCategory) {
+		this.dataCategory = dataCategory;
+	}
 }

+ 10 - 8
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/controller/IllegallyTypeController.java

@@ -9,6 +9,7 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.IllegallyTypeRepo;
 import cn.com.qmth.examcloud.core.oe.admin.dao.entity.IllegallyTypeEntity;
 import cn.com.qmth.examcloud.core.oe.admin.service.IllegallyTypeService;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.IllegallyTypeInfo;
+import cn.com.qmth.examcloud.support.enums.DataCategory;
 import cn.com.qmth.examcloud.web.config.SystemProperties;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
@@ -57,7 +58,7 @@ public class IllegallyTypeController extends ControllerSupport {
     @Autowired
     IllegallyTypeRepo illegallyTypeRepo;
 
-    private static final String[] EXCEL_HEADER = new String[]{"违纪类型名称", "违纪类型代码"};
+    private static final String[] EXCEL_HEADER = new String[]{"违纪类型名称", "违纪类型代码","排序号"};
 
     /**
      * 方法注释
@@ -67,7 +68,6 @@ public class IllegallyTypeController extends ControllerSupport {
      * @param name
      * @param code
      * @param enable
-     * @param courseId
      * @return
      * @author WANGWEI
      */
@@ -196,6 +196,8 @@ public class IllegallyTypeController extends ControllerSupport {
         info.setId(domain.getId());
         info.setName(domain.getName());
         info.setEnable(domain.getEnable());
+        info.setSortNo(domain.getSortNo());
+        info.setDataCategory(info.getDataCategory()==null? DataCategory.CUSTOM.name() :info.getDataCategory());
 
         IllegallyTypeEntity saved = illegallyTypeService.saveIllegallyType(info);
         return saved.getId();
@@ -208,10 +210,10 @@ public class IllegallyTypeController extends ControllerSupport {
      * @return
      * @author WANGWEI
      */
-    @ApiOperation(value = "修改违纪类型", notes = "新增")
+    @ApiOperation(value = "修改违纪类型", notes = "修改")
     @PutMapping
     @Transactional
-    public Long updateSpecialty(@RequestBody IllegallyTypeDomain domain) {
+    public Long updateIllegallyType(@RequestBody IllegallyTypeDomain domain) {
         trim(domain, true);
 
         User accessUser = getAccessUser();
@@ -221,10 +223,11 @@ public class IllegallyTypeController extends ControllerSupport {
         info.setId(info.getId());
         info.setRootOrgId(rootOrgId);
         info.setCode(domain.getCode());
-        info.setEnable(domain.getEnable());
         info.setId(domain.getId());
         info.setName(domain.getName());
         info.setEnable(domain.getEnable());
+        info.setSortNo(domain.getSortNo());
+        info.setDataCategory(info.getDataCategory()==null? DataCategory.CUSTOM.name() :info.getDataCategory());
 
         IllegallyTypeEntity saved = illegallyTypeService.saveIllegallyType(info);
         return saved.getId();
@@ -279,8 +282,7 @@ public class IllegallyTypeController extends ControllerSupport {
     @GetMapping("export")
     public void export(@RequestParam(required = false) String name,
                        @RequestParam(required = false) String code,
-                       @RequestParam(required = false) Boolean enable,
-                       @RequestParam(required = false) Long courseId) {
+                       @RequestParam(required = false) Boolean enable) {
         User accessUser = getAccessUser();
 
         Specification<IllegallyTypeEntity> specification = (root, query, cb) -> {
@@ -311,7 +313,7 @@ public class IllegallyTypeController extends ControllerSupport {
         List<Object[]> datas = Lists.newArrayList();
 
         for (IllegallyTypeEntity cur : list) {
-            datas.add(new Object[]{cur.getName(), cur.getCode()});
+            datas.add(new Object[]{cur.getName(), cur.getCode(),cur.getSortNo()});
         }
 
         String filePath = systemConfig.getTempDataDir() + File.separator

+ 2 - 0
examcloud-core-oe-admin-dao/src/main/java/cn/com/qmth/examcloud/core/oe/admin/dao/IllegallyTypeRepo.java

@@ -15,6 +15,8 @@ public interface IllegallyTypeRepo
 
 	IllegallyTypeEntity findByRootOrgIdAndCode(Long rootOrgId, String code);
 
+	IllegallyTypeEntity findByRootOrgIdAndCodeAndDataCategory(Long rootOrgId, String code,String dataCategory);
+
 	List<IllegallyTypeEntity> findByRootOrgId(Long rootOrgId);
 
 	int countByRootOrgIdAndNameLike(Long rootOrgId, String name);

+ 30 - 4
examcloud-core-oe-admin-dao/src/main/java/cn/com/qmth/examcloud/core/oe/admin/dao/entity/IllegallyTypeEntity.java

@@ -1,11 +1,9 @@
 package cn.com.qmth.examcloud.core.oe.admin.dao.entity;
 
+import cn.com.qmth.examcloud.support.enums.DataCategory;
 import cn.com.qmth.examcloud.web.jpa.WithIdJpaEntity;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Index;
-import javax.persistence.Table;
+import javax.persistence.*;
 
 /**
  * @Description 违纪类型
@@ -31,6 +29,19 @@ public class IllegallyTypeEntity extends WithIdJpaEntity {
     @Column(nullable = false)
     private Boolean enable;
 
+    /**
+     * 排序号
+     */
+    @Column(nullable = false)
+    private Integer sortNo;
+
+    /**
+     * 数据分类
+     */
+    @Column(nullable = false)
+    @Enumerated(EnumType.STRING)
+    private DataCategory dataCategory;
+
     public String getCode() {
         return code;
     }
@@ -63,4 +74,19 @@ public class IllegallyTypeEntity extends WithIdJpaEntity {
         this.enable = enable;
     }
 
+    public DataCategory getDataCategory() {
+        return dataCategory;
+    }
+
+    public void setDataCategory(DataCategory dataCategory) {
+        this.dataCategory = dataCategory;
+    }
+
+    public Integer getSortNo() {
+        return sortNo;
+    }
+
+    public void setSortNo(Integer sortNo) {
+        this.sortNo = sortNo;
+    }
 }

+ 30 - 0
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/bean/IllegallyTypeInfo.java

@@ -1,6 +1,11 @@
 package cn.com.qmth.examcloud.core.oe.admin.service.bean;
 
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+import cn.com.qmth.examcloud.support.enums.DataCategory;
+
+import javax.persistence.Column;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 
 public class IllegallyTypeInfo implements JsonSerializable {
 
@@ -16,6 +21,16 @@ public class IllegallyTypeInfo implements JsonSerializable {
 
 	private Boolean enable;
 
+	/**
+	 * 排序号
+	 */
+	private Integer sortNo;
+
+	/**
+	 * 数据分类
+	 */
+	private String dataCategory;
+
 	public Long getId() {
 		return id;
 	}
@@ -56,4 +71,19 @@ public class IllegallyTypeInfo implements JsonSerializable {
 		this.enable = enable;
 	}
 
+	public Integer getSortNo() {
+		return sortNo;
+	}
+
+	public void setSortNo(Integer sortNo) {
+		this.sortNo = sortNo;
+	}
+
+	public String getDataCategory() {
+		return dataCategory;
+	}
+
+	public void setDataCategory(String dataCategory) {
+		this.dataCategory = dataCategory;
+	}
 }

+ 206 - 171
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/impl/IllegallyTypeServiceImpl.java

@@ -7,6 +7,7 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.IllegallyTypeRepo;
 import cn.com.qmth.examcloud.core.oe.admin.dao.entity.IllegallyTypeEntity;
 import cn.com.qmth.examcloud.core.oe.admin.service.IllegallyTypeService;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.IllegallyTypeInfo;
+import cn.com.qmth.examcloud.support.enums.DataCategory;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -24,176 +25,210 @@ import java.util.Map;
 @Service
 public class IllegallyTypeServiceImpl implements IllegallyTypeService {
 
-	@Autowired
-	IllegallyTypeRepo illegallyTypeRepo;
-
-	private static final String[] EXCEL_HEADER = new String[]{"违纪类型名称", "违纪类型代码"};
-
-	@Override
-	public IllegallyTypeEntity saveIllegallyType(IllegallyTypeInfo info) {
-		Long id = info.getId();
-		String code = info.getCode();
-		Boolean enable = info.getEnable();
-		Long rootOrgId = info.getRootOrgId();
-		String name = info.getName();
-
-		if (null == rootOrgId) {
-			throw new StatusException("620001", "rootOrgId is null");
-		}
-		IllegallyTypeEntity entity = null;
-
-		if (null != id) {
-			entity = GlobalHelper.getEntity(illegallyTypeRepo, id, IllegallyTypeEntity.class);
-			if (null == entity) {
-				throw new StatusException("620001", "id is wrong");
-			}
-			if (!entity.getRootOrgId().equals(rootOrgId)) {
-				throw new StatusException("620001", "rootOrgId or id is worng");
-			}
-		} else if (StringUtils.isNotBlank(code)) {
-			entity = illegallyTypeRepo.findByRootOrgIdAndCode(rootOrgId, code);
-			if (null == entity) {
-				if (StringUtils.isBlank(name)) {
-					throw new StatusException("620001", "name is blank");
-				}
-				entity = new IllegallyTypeEntity();
-				entity.setCode(code);
-				entity.setName(name);
-				entity.setRootOrgId(rootOrgId);
-				entity.setEnable(true);
-			}
-		} else {
-			throw new StatusException("620001", "id and code can not be all null");
-		}
-
-		if (null != enable) {
-			entity.setEnable(enable);
-		}
-		if (StringUtils.isNotBlank(name)) {
-			entity.setName(name);
-		}
-
-		IllegallyTypeEntity saved = illegallyTypeRepo.save(entity);
-
-		return saved;
-	}
-
-	@Override
-	public List<Map<String, Object>> importIllegallyType(Long rootOrgId, File file) {
-		List<String[]> lineList = null;
-		try {
-			lineList = ExcelReader.readSheetBySax(PathUtil.getCanonicalPath(file), 1, 2);
-		} catch (Exception e) {
-			throw new StatusException("100110", "Excel 解析失败");
-		}
-
-		if (CollectionUtils.isEmpty(lineList)) {
-			throw new StatusException("100111", "Excel无内容");
-		}
-
-		if (10001 < lineList.size()) {
-			throw new StatusException("100112", "数据行数不能超过10000");
-		}
-
-		List<Map<String, Object>> failRecords = Collections
-				.synchronizedList(new ArrayList<Map<String, Object>>());
-
-		List<IllegallyTypeEntity> illegallyTypeList = Lists.newArrayList();
-
-		for (int i = 0; i < lineList.size(); i++) {
-			String[] line = lineList.get(i);
-			if (0 == i) {
-				if (headerError(line)) {
-					throw new StatusException("100111", "Excel表头错误");
-				}
-				continue;
-			}
-
-			boolean hasError = false;
-			StringBuilder msg = new StringBuilder();
-
-			IllegallyTypeEntity illegallyType = new IllegallyTypeEntity();
-			illegallyType.setRootOrgId(rootOrgId);
-			illegallyType.setEnable(true);
-
-			String name = trimAndNullIfBlank(line[0]);
-			if (StringUtils.isBlank(name)) {
-				msg.append("  违纪类型名称不能为空");
-				hasError = true;
-			} else if (name.length() > 30) {
-				msg.append("  违纪类型名称不能超过30个字符");
-				hasError = true;
-			}
-			illegallyType.setName(name);
-
-			String code = trimAndNullIfBlank(line[1]);
-			if (StringUtils.isBlank(code)) {
-				msg.append("  违纪类型代码不能为空");
-				hasError = true;
-			} else if (code.length() > 30) {
-				msg.append("  违纪类型代码不能超过30个字符");
-				hasError = true;
-			}
-
-			illegallyType.setCode(code);
-
-			if (hasError) {
-				failRecords.add(newError(i + 1, msg.toString()));
-			} else {
-				illegallyTypeList.add(illegallyType);
-			}
-
-		}
-
-		if (CollectionUtils.isNotEmpty(failRecords)) {
-			return failRecords;
-		}
-
-		for (IllegallyTypeEntity cur : illegallyTypeList) {
-			IllegallyTypeEntity query = illegallyTypeRepo.findByRootOrgIdAndCode(cur.getRootOrgId(),
-					cur.getCode());
-
-			if (null != query) {
-				query.setName(cur.getName());
-				illegallyTypeRepo.save(query);
-			} else {
-				illegallyTypeRepo.save(cur);
-			}
-		}
-
-		return failRecords;
-	}
-
-	private Map<String, Object> newError(int lineNum, String msg) {
-		Map<String, Object> map = Maps.newHashMap();
-		map.put("lineNum", lineNum);
-		map.put("msg", msg);
-		return map;
-	}
-
-	private String trimAndNullIfBlank(String s) {
-		if (StringUtils.isBlank(s)) {
-			return null;
-		}
-		return s.trim();
-	}
-
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param header
-	 */
-	private boolean headerError(String[] header) {
-		for (int i = 0; i < EXCEL_HEADER.length; i++) {
-			if (null == header[i]) {
-				return true;
-			}
-			if (!EXCEL_HEADER[i].equals(header[i].trim())) {
-				return true;
-			}
-		}
-		return false;
-	}
+    @Autowired
+    IllegallyTypeRepo illegallyTypeRepo;
+
+    private static final String[] EXCEL_HEADER = new String[]{"违纪类型名称", "违纪类型代码"};
+
+    @Override
+    public IllegallyTypeEntity saveIllegallyType(IllegallyTypeInfo info) {
+        Long id = info.getId();
+        String code = info.getCode();
+        Boolean enable = info.getEnable();
+        Long rootOrgId = info.getRootOrgId();
+        String name = info.getName();
+        Integer sortNo = info.getSortNo();
+        String dataCategory = info.getDataCategory();
+
+        if (null == rootOrgId) {
+            throw new StatusException("620001", "rootOrgId is null");
+        }
+        IllegallyTypeEntity entity = null;
+
+        if (null != id) {
+            entity = GlobalHelper.getEntity(illegallyTypeRepo, id, IllegallyTypeEntity.class);
+            if (null == entity) {
+                throw new StatusException("620001", "id is wrong");
+            }
+            if (!entity.getRootOrgId().equals(rootOrgId)) {
+                throw new StatusException("620001", "rootOrgId or id is worng");
+            }
+
+        } else if (StringUtils.isNotBlank(code)) {
+            entity = illegallyTypeRepo.findByRootOrgIdAndCode(rootOrgId, code);
+            if (null == entity) {
+                if (StringUtils.isBlank(name)) {
+                    throw new StatusException("620001", "name is blank");
+                }
+                entity = new IllegallyTypeEntity();
+
+                entity.setName(name);
+                entity.setRootOrgId(rootOrgId);
+                entity.setEnable(true);
+            }
+        } else {
+            throw new StatusException("620001", "id and code can not be all null");
+        }
+
+        if (null != enable) {
+            entity.setEnable(enable);
+        }
+        if (StringUtils.isNotBlank(name)) {
+            entity.setName(name);
+        }
+
+        if (null != sortNo) {
+            entity.setSortNo(sortNo);
+        }
+
+        if (StringUtils.isNotEmpty(dataCategory)) {
+            entity.setDataCategory(DataCategory.valueOf(dataCategory));
+        }
+
+        IllegallyTypeEntity saved = illegallyTypeRepo.save(entity);
+
+        return saved;
+    }
+
+    @Override
+    public List<Map<String, Object>> importIllegallyType(Long rootOrgId, File file) {
+        List<String[]> lineList = null;
+        try {
+            lineList = ExcelReader.readSheetBySax(PathUtil.getCanonicalPath(file), 1, 2);
+        } catch (Exception e) {
+            throw new StatusException("100110", "Excel 解析失败");
+        }
+
+        if (CollectionUtils.isEmpty(lineList)) {
+            throw new StatusException("100111", "Excel无内容");
+        }
+
+        if (10001 < lineList.size()) {
+            throw new StatusException("100112", "数据行数不能超过10000");
+        }
+
+        List<Map<String, Object>> failRecords = Collections
+                .synchronizedList(new ArrayList<Map<String, Object>>());
+
+        List<IllegallyTypeEntity> illegallyTypeList = Lists.newArrayList();
+
+        for (int i = 0; i < lineList.size(); i++) {
+            String[] line = lineList.get(i);
+            if (0 == i) {
+                if (headerError(line)) {
+                    throw new StatusException("100111", "Excel表头错误");
+                }
+                continue;
+            }
+
+            boolean hasError = false;
+            StringBuilder msg = new StringBuilder();
+
+            IllegallyTypeEntity illegallyType = new IllegallyTypeEntity();
+            illegallyType.setRootOrgId(rootOrgId);
+            illegallyType.setEnable(true);
+
+            String name = trimAndNullIfBlank(line[0]);
+            if (StringUtils.isBlank(name)) {
+                msg.append("  违纪类型名称不能为空");
+                hasError = true;
+            } else if (name.length() > 30) {
+                msg.append("  违纪类型名称不能超过30个字符");
+                hasError = true;
+            }
+            illegallyType.setName(name);
+
+            String code = trimAndNullIfBlank(line[1]);
+            if (StringUtils.isBlank(code)) {
+                msg.append("  违纪类型代码不能为空");
+                hasError = true;
+            } else if (code.length() > 30) {
+                msg.append("  违纪类型代码不能超过30个字符");
+                hasError = true;
+            }
+
+            illegallyType.setCode(code);
+
+            //校验当前编码是否为系统编码
+            IllegallyTypeEntity existSysData = illegallyTypeRepo.findByRootOrgIdAndCodeAndDataCategory(
+                    rootOrgId, code, DataCategory.SYSTEM.name());
+            if (null != existSysData) {
+                msg.append("  违纪类型编码不允许存在数据类型为系统的数据");
+                hasError = true;
+            }
+
+
+            //排序号
+            String sortNo = trimAndNullIfBlank(line[2]);
+            if (StringUtils.isBlank(code)) {
+                msg.append("  排序号不能为空");
+                hasError = true;
+            } else if (StringUtils.isNumeric(sortNo)) {
+                msg.append("  排序号必须为正整数的数字");
+                hasError = true;
+            }
+
+            illegallyType.setSortNo(Integer.valueOf(sortNo));
+
+            if (hasError) {
+                failRecords.add(newError(i + 1, msg.toString()));
+            } else {
+                illegallyTypeList.add(illegallyType);
+            }
+
+
+        }
+
+        if (CollectionUtils.isNotEmpty(failRecords)) {
+            return failRecords;
+        }
+
+        for (IllegallyTypeEntity cur : illegallyTypeList) {
+            IllegallyTypeEntity existData = illegallyTypeRepo.findByRootOrgIdAndCode(cur.getRootOrgId(),
+                    cur.getCode());
+
+            if (null != existData) {
+                existData.setName(cur.getName());
+                existData.setSortNo(cur.getSortNo());
+                illegallyTypeRepo.save(existData);
+            } else {
+                illegallyTypeRepo.save(cur);
+            }
+        }
+
+        return failRecords;
+    }
+
+    private Map<String, Object> newError(int lineNum, String msg) {
+        Map<String, Object> map = Maps.newHashMap();
+        map.put("lineNum", lineNum);
+        map.put("msg", msg);
+        return map;
+    }
+
+    private String trimAndNullIfBlank(String s) {
+        if (StringUtils.isBlank(s)) {
+            return null;
+        }
+        return s.trim();
+    }
+
+    /**
+     * 方法注释
+     *
+     * @param header
+     * @author WANGWEI
+     */
+    private boolean headerError(String[] header) {
+        for (int i = 0; i < EXCEL_HEADER.length; i++) {
+            if (null == header[i]) {
+                return true;
+            }
+            if (!EXCEL_HEADER[i].equals(header[i].trim())) {
+                return true;
+            }
+        }
+        return false;
+    }
 
 }

BIN
examcloud-core-oe-admin-starter/src/main/resources/templates/illegallyTypeImportTemplate.xlsx