任务类型
导入,新建,编辑 去重
删除 校验是否可删除
master
周文涛 2 years ago
parent 7498bdcf5b
commit f5d0781aa8

@ -202,4 +202,26 @@ public class JeecgController<T, S extends IService<T>> {
}
return Result.error("文件导入失败!");
}
protected List<T> readExcel(HttpServletRequest request,HttpServletResponse response,Class<T> clazz) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
List<T> list = null;
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return list;
}
}

@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.ocr.entity.OcrTaskType;
import org.jeecg.modules.ocr.service.IOcrTaskTypeService;
@ -86,6 +87,7 @@ public class OcrTaskTypeController extends JeecgController<OcrTaskType, IOcrTask
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_task_type:add")
@PostMapping(value = "/add")
public Result<String> add(@RequestBody OcrTaskType ocrTaskType) {
ocrTaskTypeService.existsByTypeNameList(Arrays.asList(ocrTaskType));
ocrTaskTypeService.save(ocrTaskType);
return Result.OK("添加成功!");
}
@ -101,6 +103,7 @@ public class OcrTaskTypeController extends JeecgController<OcrTaskType, IOcrTask
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_task_type:edit")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
public Result<String> edit(@RequestBody OcrTaskType ocrTaskType) {
ocrTaskTypeService.existsByTypeNameList(Arrays.asList(ocrTaskType));
ocrTaskTypeService.updateById(ocrTaskType);
return Result.OK("编辑成功!");
}
@ -116,6 +119,8 @@ public class OcrTaskTypeController extends JeecgController<OcrTaskType, IOcrTask
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_task_type:delete")
@DeleteMapping(value = "/delete")
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
boolean flag=ocrTaskTypeService.checkMetadataConfigUse(Arrays.asList(id));
AssertUtils.notTrue(flag,"任务类型不可删除,原因:被元数据配置使用中");
ocrTaskTypeService.removeById(id);
return Result.OK("删除成功!");
}
@ -131,6 +136,8 @@ public class OcrTaskTypeController extends JeecgController<OcrTaskType, IOcrTask
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_task_type:deleteBatch")
@DeleteMapping(value = "/deleteBatch")
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
boolean flag=ocrTaskTypeService.checkMetadataConfigUse(Arrays.asList(ids.split(",")));
AssertUtils.notTrue(flag,"任务类型不可删除,原因:被元数据配置使用中");
this.ocrTaskTypeService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!");
}
@ -182,6 +189,8 @@ public class OcrTaskTypeController extends JeecgController<OcrTaskType, IOcrTask
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_task_type:importExcel")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
List<OcrTaskType> ocrTaskTypes = super.readExcel(request, response, OcrTaskType.class);
ocrTaskTypeService.existsByTypeNameList(ocrTaskTypes);
return super.importExcel(request, response, OcrTaskType.class);
}

@ -3,6 +3,8 @@ package org.jeecg.modules.ocr.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.ocr.entity.OcrTaskType;
import java.util.List;
/**
* @Description:
* @Author: jeecg-boot
@ -10,5 +12,17 @@ import org.jeecg.modules.ocr.entity.OcrTaskType;
* @Version: V1.0
*/
public interface IOcrTaskTypeService extends IService<OcrTaskType> {
/**
* ,id
* @param ocrTaskTypes
* @return
*/
boolean existsByTypeNameList(List<OcrTaskType> ocrTaskTypes);
/**
* 使
* @param taskTypeIdList
* @return true:使,false:使
*/
boolean checkMetadataConfigUse(List<String> taskTypeIdList);
}

@ -1,11 +1,22 @@
package org.jeecg.modules.ocr.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.modules.ocr.entity.OcrMetadataConfig;
import org.jeecg.modules.ocr.entity.OcrTaskType;
import org.jeecg.modules.ocr.mapper.OcrMetadataConfigMapper;
import org.jeecg.modules.ocr.mapper.OcrTaskTypeMapper;
import org.jeecg.modules.ocr.service.IOcrTaskTypeService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Description:
* @Author: jeecg-boot
@ -14,5 +25,39 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
*/
@Service
public class OcrTaskTypeServiceImpl extends ServiceImpl<OcrTaskTypeMapper, OcrTaskType> implements IOcrTaskTypeService {
@Resource
private OcrMetadataConfigMapper metadataConfigMapper;
@Override
public boolean existsByTypeNameList(List<OcrTaskType> ocrTaskTypes) {
LambdaQueryWrapper<OcrTaskType> countQueryWrapper = new LambdaQueryWrapper<>();
for (OcrTaskType ocrTaskType : ocrTaskTypes) {
if (StringUtils.isBlank(ocrTaskType.getTypeName())) {
continue;
}
countQueryWrapper.clear();
countQueryWrapper.eq(OcrTaskType::getTypeName,ocrTaskType.getTypeName());
countQueryWrapper.ne(StringUtils.isNotBlank(ocrTaskType.getId()),OcrTaskType::getId,ocrTaskType.getId());
AssertUtils.notTrue(super.count(countQueryWrapper)>0,String.format("[%s]-已存在",ocrTaskType.getTypeName()));
}
//判断重复类型名
Map<String, Long> countMap = ocrTaskTypes.stream().map(o->o.getTypeName()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
if (countMap.keySet().size()>0) {
//有重复的类型名
String typeName = countMap.keySet().stream().filter(key -> countMap.get(key) > 1).distinct().collect(Collectors.joining(","));
AssertUtils.isEmpty(typeName,String.format("[%s]-重复了",typeName));
}
return true;
}
@Override
public boolean checkMetadataConfigUse(List<String> taskTypeIdList) {
if (taskTypeIdList==null||taskTypeIdList.size()==0) {
return false;
}
long count= metadataConfigMapper.selectCount(new LambdaQueryWrapper<OcrMetadataConfig>().in(OcrMetadataConfig::getTaskType, taskTypeIdList));
if (count>0) {
return true;
}
return false;
}
}

Loading…
Cancel
Save