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