Browse Source

Merge branch 'branch_other'

deason 5 years ago
parent
commit
e4961f2709

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

@@ -0,0 +1,96 @@
+package cn.com.qmth.examcloud.core.oe.admin.api.bean;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+
+import java.util.Date;
+
+public class IllegallyTypeDomain implements JsonSerializable {
+
+	private static final long serialVersionUID = 239263456816448160L;
+
+	private Long id;
+
+	private String code;
+
+	private String name;
+
+	private Long rootOrgId;
+
+	private Boolean enable;
+
+	/**
+	 * 排序号
+	 */
+	private Integer sortNo;
+
+	/**
+	 * 数据分类
+	 */
+	private String dataCategory;
+
+	private Date updateTime;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		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;
+	}
+
+	public Date getUpdateTime() {
+		return updateTime;
+	}
+
+	public void setUpdateTime(Date updateTime) {
+		this.updateTime = updateTime;
+	}
+}

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

@@ -0,0 +1,360 @@
+package cn.com.qmth.examcloud.core.oe.admin.api.controller;
+
+import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
+import cn.com.qmth.examcloud.api.commons.security.bean.User;
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.helpers.poi.ExcelWriter;
+import cn.com.qmth.examcloud.commons.util.PathUtil;
+import cn.com.qmth.examcloud.core.oe.admin.api.bean.IllegallyTypeDomain;
+import cn.com.qmth.examcloud.core.oe.admin.dao.ExamAuditRepo;
+import cn.com.qmth.examcloud.core.oe.admin.dao.IllegallyTypeRepo;
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamAuditEntity;
+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;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.fileupload.disk.DiskFileItem;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+
+import javax.persistence.criteria.Predicate;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * @Description 违纪类型
+ * @Author lideyin
+ * @Date 2020/2/20 18:56
+ * @Version 1.0
+ */
+@RestController
+@RequestMapping("${$rmp.ctr.oe}/illegallyType")
+public class IllegallyTypeController extends ControllerSupport {
+
+    @Autowired
+    IllegallyTypeService illegallyTypeService;
+
+    @Autowired
+    SystemProperties systemConfig;
+
+    @Autowired
+    IllegallyTypeRepo illegallyTypeRepo;
+
+    @Autowired
+    ExamAuditRepo examAuditRepo;
+
+    private static final String[] EXCEL_HEADER = new String[]{"违纪类型名称", "违纪类型代码", "排序号"};
+
+    /**
+     * 方法注释
+     *
+     * @param curPage
+     * @param pageSize
+     * @param name
+     * @param code
+     * @param enable
+     * @return
+     * @author WANGWEI
+     */
+    @ApiOperation(value = "分页查询违纪类型")
+    @GetMapping("illegallyTypePage/{curPage}/{pageSize}")
+    public PageInfo<IllegallyTypeDomain> illegallyTypePage(@PathVariable Integer curPage,
+                                                           @PathVariable Integer pageSize,
+                                                           @RequestParam(required = false) String name,
+                                                           @RequestParam(required = false) String code,
+                                                           @RequestParam(required = false) Boolean enable) {
+        User accessUser = getAccessUser();
+
+        Specification<IllegallyTypeEntity> specification = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+
+            List<Long> rootOrgIdList = new ArrayList<>();
+            rootOrgIdList.add(accessUser.getRootOrgId());
+            rootOrgIdList.add(-1L);//系统级别的数据默认rootOrgId为-1
+
+            predicates.add(root.get("rootOrgId").in(rootOrgIdList));
+
+            if (StringUtils.isNotBlank(name)) {
+                predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
+            }
+            if (StringUtils.isNotBlank(code)) {
+                predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
+            }
+            if (null != enable) {
+                predicates.add(cb.equal(root.get("enable"), enable));
+            }
+
+
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+
+        PageRequest pageRequest = PageRequest.of(curPage, pageSize,
+                new Sort(Direction.DESC, "id"));
+
+
+        Page<IllegallyTypeEntity> page = illegallyTypeRepo.findAll(specification, pageRequest);
+
+        List<IllegallyTypeEntity> entityList = page.getContent();
+
+        List<IllegallyTypeDomain> domainList = new ArrayList<>();
+
+        for (IllegallyTypeEntity entity : entityList) {
+            IllegallyTypeDomain domain = new IllegallyTypeDomain();
+            domain.setRootOrgId(entity.getRootOrgId());
+            domain.setCode(entity.getCode());
+            domain.setEnable(entity.getEnable());
+            domain.setId(entity.getId());
+            domain.setName(entity.getName());
+            domain.setEnable(entity.getEnable());
+            domain.setSortNo(entity.getSortNo());
+            domain.setDataCategory(entity.getDataCategory() == null ? DataCategory.CUSTOM.name() : entity.getDataCategory().name());
+            domain.setUpdateTime(entity.getUpdateTime());
+            domainList.add(domain);
+        }
+
+        PageInfo<IllegallyTypeDomain> pageInfo = new PageInfo<>();
+        pageInfo.setList(domainList);
+        pageInfo.setTotal(page.getTotalElements());
+
+        return pageInfo;
+    }
+
+    @ApiOperation(value = "查询违纪类型")
+    @GetMapping("queryByNameLike")
+    public List<IllegallyTypeEntity> query(@RequestParam(required = false) String name,
+                                           @RequestParam(required = false) String code,
+                                           @RequestParam(required = false) Boolean enable) {
+
+        User accessUser = getAccessUser();
+        Long rootOrgId = accessUser.getRootOrgId();
+
+        Specification<IllegallyTypeEntity> specification = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+
+            List<Long> rootOrgIdList = new ArrayList<>();
+            rootOrgIdList.add(rootOrgId);
+            rootOrgIdList.add(-1L);//系统级别的数据默认rootOrgId为-1
+
+            predicates.add(root.get("rootOrgId").in(rootOrgIdList));
+
+            if (StringUtils.isNotBlank(name)) {
+                predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
+            }
+            if (StringUtils.isNotBlank(code)) {
+                predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
+            }
+            if (null != enable) {
+                predicates.add(cb.equal(root.get("enable"), enable));
+            }
+
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+
+        // 过载保护
+        long total = illegallyTypeRepo.count(specification);
+        if (total > 1000) {
+            List<IllegallyTypeEntity> list = Lists.newArrayList();
+            return list;
+        }
+
+        List<Sort.Order> orderList=new ArrayList<>();
+        orderList.add(new Sort.Order(Direction.DESC,"dataCategory"));
+        orderList.add(new Sort.Order(Direction.ASC,"id"));
+
+        List<IllegallyTypeEntity> list = illegallyTypeRepo.findAll(specification,
+                new Sort(orderList));
+        return list;
+    }
+
+    /**
+     * 修正
+     *
+     * @param domain
+     * @return
+     * @author WANGWEI
+     */
+    @ApiOperation(value = "新增违纪类型", notes = "新增")
+    @PostMapping
+    @Transactional
+    public Long addIllegallyType(@RequestBody IllegallyTypeDomain domain) {
+        trim(domain, true);
+
+        User accessUser = getAccessUser();
+        Long rootOrgId = accessUser.getRootOrgId();
+
+        String code = domain.getCode();
+        if (StringUtils.isBlank(code)) {
+            throw new StatusException("620001", "code is blank");
+        }
+        IllegallyTypeEntity course = illegallyTypeRepo.findByRootOrgIdAndCode(rootOrgId, code);
+        if (null != course) {
+            throw new StatusException("620002", "违纪类型编码已被占用");
+        }
+
+        IllegallyTypeInfo info = new IllegallyTypeInfo();
+        info.setRootOrgId(rootOrgId);
+        info.setCode(domain.getCode());
+        info.setEnable(true);
+        info.setName(domain.getName());
+        info.setSortNo(domain.getSortNo());
+        info.setDataCategory(info.getDataCategory() == null ? DataCategory.CUSTOM.name() : info.getDataCategory());
+
+        IllegallyTypeEntity saved = illegallyTypeService.saveIllegallyType(info);
+        return saved.getId();
+    }
+
+    /**
+     * 修正
+     *
+     * @param domain
+     * @return
+     * @author WANGWEI
+     */
+    @ApiOperation(value = "修改违纪类型", notes = "修改")
+    @PutMapping
+    @Transactional
+    public Long updateIllegallyType(@RequestBody IllegallyTypeDomain domain) {
+        trim(domain, true);
+
+        User accessUser = getAccessUser();
+        Long rootOrgId = accessUser.getRootOrgId();
+
+        IllegallyTypeInfo info = new IllegallyTypeInfo();
+        info.setId(info.getId());
+        info.setRootOrgId(rootOrgId);
+        info.setCode(domain.getCode());
+        info.setId(domain.getId());
+        info.setName(domain.getName());
+        info.setSortNo(domain.getSortNo());
+        info.setDataCategory(info.getDataCategory() == null ? DataCategory.CUSTOM.name() : info.getDataCategory());
+
+        IllegallyTypeEntity saved = illegallyTypeService.saveIllegallyType(info);
+        return saved.getId();
+    }
+
+    /**
+     * 方法注释
+     *
+     * @param ids
+     * @author WANGWEI
+     */
+    @ApiOperation(value = "删除违纪类型")
+    @DeleteMapping("{ids}")
+    @Transactional
+    public void delete(@PathVariable String ids) {
+        List<Long> typeIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for (Long typeId : typeIds) {
+            IllegallyTypeEntity one = GlobalHelper.getEntity(illegallyTypeRepo, typeId,
+                    IllegallyTypeEntity.class);
+            if (null == one) {
+                continue;
+            }
+
+            //判断审核表中是否存在当前类型的违纪类型
+            ExamAuditEntity examAudit =
+                    examAuditRepo.findFirstByDisciplineTypeAndCreationTimeGreaterThan(one.getCode(), one.getCreationTime());
+            boolean isIllegallyTypeInUse = (null != examAudit);
+            if (isIllegallyTypeInUse) {
+                throw new StatusException("100001","违纪类型已使用不允许删除");
+            }
+
+            validateRootOrgIsolation(one.getRootOrgId());
+            illegallyTypeRepo.delete(one);
+
+        }
+    }
+
+    @ApiOperation(value = "下载导入模板", notes = "下载导入模板")
+    @GetMapping("importTemplate")
+    public void getDownloadTemplate(HttpServletResponse response) {
+        String resoucePath = PathUtil.getResoucePath("templates/illegallyTypeImportTemplate.xlsx");
+        exportFile("违纪类型导入模板.xlsx", new File(resoucePath));
+    }
+
+    @ApiOperation(value = "导入", notes = "导入")
+    @PostMapping("import")
+    @Transactional
+    public Map<String, Object> importIllegallyType(@RequestParam CommonsMultipartFile file) {
+        DiskFileItem item = (DiskFileItem) file.getFileItem();
+        File storeLocation = item.getStoreLocation();
+        List<Map<String, Object>> failRecords = illegallyTypeService.importIllegallyType(getRootOrgId(),
+                storeLocation);
+        Map<String, Object> map = Maps.newHashMap();
+        map.put("hasError", CollectionUtils.isNotEmpty(failRecords));
+        map.put("failRecords", failRecords);
+        return map;
+    }
+
+    @ApiOperation(value = "导出违纪类型")
+    @GetMapping("export")
+    public void export(@RequestParam(required = false) String name,
+                       @RequestParam(required = false) String code,
+                       @RequestParam(required = false) Boolean enable) {
+        User accessUser = getAccessUser();
+
+        Specification<IllegallyTypeEntity> specification = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+
+            predicates.add(cb.equal(root.get("rootOrgId"), accessUser.getRootOrgId()));
+
+            if (StringUtils.isNotBlank(name)) {
+                predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
+            }
+            if (StringUtils.isNotBlank(code)) {
+                predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
+            }
+            if (null != enable) {
+                predicates.add(cb.equal(root.get("enable"), enable));
+            }
+
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+
+        long count = illegallyTypeRepo.count(specification);
+        if (100000 < count) {
+            throw new StatusException("620200", "数据量过大,无法导出");
+        }
+
+        List<IllegallyTypeEntity> list = illegallyTypeRepo.findAll(specification);
+
+        List<Object[]> datas = Lists.newArrayList();
+
+        for (IllegallyTypeEntity cur : list) {
+            datas.add(new Object[]{cur.getName(), cur.getCode(), cur.getSortNo()});
+        }
+
+        String filePath = systemConfig.getTempDataDir() + File.separator
+                + System.currentTimeMillis() + ".xlsx";
+        File file = new File(filePath);
+
+        ExcelWriter.write(EXCEL_HEADER, new Class[]{String.class, String.class}, datas,
+                new File(filePath));
+
+        exportFile("违纪类型列表-" + getRootOrgId() + ".xlsx", file);
+
+        FileUtils.deleteQuietly(file);
+    }
+}

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

@@ -0,0 +1,23 @@
+package cn.com.qmth.examcloud.core.oe.admin.dao;
+
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.IllegallyTypeEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import java.util.List;
+
+public interface IllegallyTypeRepo
+		extends
+			JpaRepository<IllegallyTypeEntity, Long>,
+			QueryByExampleExecutor<IllegallyTypeEntity>,
+			JpaSpecificationExecutor<IllegallyTypeEntity> {
+
+	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);
+}

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

@@ -0,0 +1,92 @@
+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.*;
+
+/**
+ * @Description 违纪类型
+ * @Author lideyin
+ * @Date 2020/2/20 15:06
+ * @Version 1.0
+ */
+@Entity
+@Table(name = "EC_OE_ILLEGALLY_TYPE", indexes = {
+        @Index(name = "IDX_E_O_I_T_001", columnList = "rootOrgId,code", unique = true)})
+public class IllegallyTypeEntity extends WithIdJpaEntity {
+    private static final long serialVersionUID = 2612362994854920896L;
+
+    @Column(nullable = false)
+    private String code;
+
+    @Column(nullable = false)
+    private String name;
+
+    @Column(nullable = false)
+    private Long rootOrgId;
+
+    @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;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Long getRootOrgId() {
+        return rootOrgId;
+    }
+
+    public void setRootOrgId(Long rootOrgId) {
+        this.rootOrgId = rootOrgId;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        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;
+    }
+}

+ 37 - 0
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/IllegallyTypeService.java

@@ -0,0 +1,37 @@
+package cn.com.qmth.examcloud.core.oe.admin.service;
+
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.IllegallyTypeEntity;
+import cn.com.qmth.examcloud.core.oe.admin.service.bean.IllegallyTypeInfo;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description 违纪类型
+ * @Author lideyin
+ * @Date 2020/2/20 15:23
+ * @Version 1.0
+ */
+public interface IllegallyTypeService {
+
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param info
+	 * @return
+	 */
+	IllegallyTypeEntity saveIllegallyType(IllegallyTypeInfo info);
+
+	/**
+	 * 导入专业
+	 *
+	 * @author WANGWEI
+	 * @param rootOrgId
+	 * @param file
+	 * @return
+	 */
+	List<Map<String, Object>> importIllegallyType(Long rootOrgId, File file);
+
+}

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

@@ -0,0 +1,89 @@
+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 {
+
+	private static final long serialVersionUID = 239263456816448160L;
+
+	private Long id;
+
+	private String code;
+
+	private String name;
+
+	private Long rootOrgId;
+
+	private Boolean enable;
+
+	/**
+	 * 排序号
+	 */
+	private Integer sortNo;
+
+	/**
+	 * 数据分类
+	 */
+	private String dataCategory;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		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;
+	}
+}

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

@@ -0,0 +1,235 @@
+package cn.com.qmth.examcloud.core.oe.admin.service.impl;
+
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.helpers.poi.ExcelReader;
+import cn.com.qmth.examcloud.commons.util.PathUtil;
+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;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+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();
+        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.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);
+        }
+
+        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