修复2次关源指令bug
完善数据校验结果接口调用 pqdif功补充
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
package com.njcn.gather.pqdif.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.pqdif.pojo.enums.PqdifResponseEnum;
|
||||
import com.njcn.gather.pqdif.pojo.param.PqPqdifPathParam;
|
||||
import com.njcn.gather.pqdif.pojo.po.PqPqdifPath;
|
||||
import com.njcn.gather.pqdif.service.IPqPqdifPathService;
|
||||
import com.njcn.gather.pqdif.service.support.PqdifImportParser;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "PQDIF管理")
|
||||
@RestController
|
||||
@RequestMapping("/pqdif")
|
||||
@RequiredArgsConstructor
|
||||
public class PqPqdifPathController extends BaseController {
|
||||
private final IPqPqdifPathService pqPqdifPathService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/listAll")
|
||||
@ApiOperation("获取全部PQDIF")
|
||||
public HttpResult<List<PqPqdifPath>> listAll() {
|
||||
String methodDescribe = getMethodDescribe("listAll");
|
||||
List<PqPqdifPath> result = pqPqdifPathService.listAll();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询PQDIF")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<Page<PqPqdifPath>> list(@RequestBody @Validated PqPqdifPathParam.QueryParam param) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
Page<PqPqdifPath> result = pqPqdifPathService.listPqdif(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
|
||||
@PostMapping("/import/json")
|
||||
@ApiOperation("导入PQDIF json")
|
||||
@ApiImplicitParam(name = "file", value = "json文件", required = true)
|
||||
public HttpResult<Boolean> importJson(@RequestParam("file") MultipartFile file) {
|
||||
String methodDescribe = getMethodDescribe("importJson");
|
||||
LogUtil.njcnDebug(log, "{},导入文件为:{}", methodDescribe, file == null ? null : file.getOriginalFilename());
|
||||
List<PqPqdifPathParam.ImportItem> items = parseImportItems(file);
|
||||
boolean result = pqPqdifPathService.importPqdif(items);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
|
||||
private List<PqPqdifPathParam.ImportItem> parseImportItems(MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BusinessException(PqdifResponseEnum.JSON_FILE_NOT_NULL);
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
if (fileName == null || !fileName.toLowerCase().endsWith(".json")) {
|
||||
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||
}
|
||||
try {
|
||||
return PqdifImportParser.parse(new String(file.getBytes(), StandardCharsets.UTF_8));
|
||||
} catch (BusinessException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.njcn.gather.pqdif.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.pqdif.pojo.po.PqPqdifPath;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PqPqdifPathMapper extends MPJBaseMapper<PqPqdifPath> {
|
||||
List<PqPqdifPath> selectPageList(Page<PqPqdifPath> page, @Param("name") String name, @Param("result") Integer result);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.pqdif.mapper.PqPqdifPathMapper">
|
||||
<select id="selectPageList" resultType="com.njcn.gather.pqdif.pojo.po.PqPqdifPath">
|
||||
select id,
|
||||
Name as name,
|
||||
File_Path as filePath,
|
||||
Record_Count as recordCount,
|
||||
Observation_Count as observationCount,
|
||||
Sample_Value_Count as sampleValueCount,
|
||||
Result as result,
|
||||
Msg as msg,
|
||||
State as state,
|
||||
Create_By as createBy,
|
||||
Create_Time as createTime,
|
||||
Update_By as updateBy,
|
||||
Update_Time as updateTime
|
||||
from pq_pqdif_path
|
||||
where State = 1
|
||||
<if test="name != null and name != ''">
|
||||
and Name like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="result != null">
|
||||
and Result = #{result}
|
||||
</if>
|
||||
order by Update_Time desc, Create_Time desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.gather.pqdif.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PqdifResponseEnum {
|
||||
JSON_FILE_NOT_NULL("A019001", "JSON文件不能为空"),
|
||||
JSON_FORMAT_ERROR("A019002", "JSON格式错误"),
|
||||
IMPORT_ITEM_NOT_NULL("A019003", "导入数据项不能为空"),
|
||||
IMPORT_ID_REPEAT("A019004", "导入数据中存在重复id"),
|
||||
IMPORT_FAILED("A019005", "PQDIF导入失败");
|
||||
|
||||
private final String code;
|
||||
private final String message;
|
||||
|
||||
PqdifResponseEnum(String code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.gather.pqdif.pojo.param;
|
||||
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
public class PqPqdifPathParam {
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty(value = "name")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "result")
|
||||
private Integer result;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ImportItem {
|
||||
private String id;
|
||||
private String name;
|
||||
private String filePath;
|
||||
private Long recordCount;
|
||||
private Long observationCount;
|
||||
private Integer sampleValueCount;
|
||||
private Integer result;
|
||||
private String msg;
|
||||
private Integer state;
|
||||
private Object parseResult;
|
||||
private String createBy;
|
||||
private String createTime;
|
||||
private String updateBy;
|
||||
private String updateTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.gather.pqdif.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("pq_pqdif_path")
|
||||
public class PqPqdifPath extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = 2536904714178389110L;
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
@TableField("File_Path")
|
||||
private String filePath;
|
||||
|
||||
@TableField("Record_Count")
|
||||
private Long recordCount;
|
||||
|
||||
@TableField("Observation_Count")
|
||||
private Long observationCount;
|
||||
|
||||
@TableField("Sample_Value_Count")
|
||||
private Integer sampleValueCount;
|
||||
|
||||
@TableField("Result")
|
||||
private Integer result;
|
||||
|
||||
@TableField("Msg")
|
||||
private String msg;
|
||||
|
||||
@TableField("State")
|
||||
private Integer state;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.gather.pqdif.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.pqdif.pojo.param.PqPqdifPathParam;
|
||||
import com.njcn.gather.pqdif.pojo.po.PqPqdifPath;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IPqPqdifPathService extends IService<PqPqdifPath> {
|
||||
List<PqPqdifPath> listAll();
|
||||
|
||||
Page<PqPqdifPath> listPqdif(PqPqdifPathParam.QueryParam param);
|
||||
|
||||
boolean importPqdif(List<PqPqdifPathParam.ImportItem> items);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.njcn.gather.pqdif.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.pojo.constant.DetectionValidMessage;
|
||||
import com.njcn.gather.pqdif.mapper.PqPqdifPathMapper;
|
||||
import com.njcn.gather.pqdif.pojo.enums.PqdifResponseEnum;
|
||||
import com.njcn.gather.pqdif.pojo.param.PqPqdifPathParam;
|
||||
import com.njcn.gather.pqdif.pojo.po.PqPqdifPath;
|
||||
import com.njcn.gather.pqdif.service.IPqPqdifPathService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PqPqdifPathServiceImpl extends ServiceImpl<PqPqdifPathMapper, PqPqdifPath> implements IPqPqdifPathService {
|
||||
|
||||
@Override
|
||||
public List<PqPqdifPath> listAll() {
|
||||
return this.lambdaQuery()
|
||||
.select(PqPqdifPath::getId, PqPqdifPath::getName)
|
||||
.eq(PqPqdifPath::getState, DataStateEnum.ENABLE.getCode())
|
||||
.orderByDesc(PqPqdifPath::getCreateTime)
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<PqPqdifPath> listPqdif(PqPqdifPathParam.QueryParam param) {
|
||||
Page<PqPqdifPath> page = new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param));
|
||||
page.setRecords(this.baseMapper.selectPageList(page, StrUtil.trim(param.getName()), param.getResult()));
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean importPqdif(List<PqPqdifPathParam.ImportItem> items) {
|
||||
if (CollUtil.isEmpty(items)) {
|
||||
return true;
|
||||
}
|
||||
validateItems(items);
|
||||
for (PqPqdifPathParam.ImportItem item : items) {
|
||||
PqPqdifPath entity = toEntity(item);
|
||||
boolean saved = this.saveOrUpdate(entity);
|
||||
if (!saved) {
|
||||
throw new BusinessException(PqdifResponseEnum.IMPORT_FAILED);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void validateItems(List<PqPqdifPathParam.ImportItem> items) {
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (PqPqdifPathParam.ImportItem item : items) {
|
||||
if (item == null) {
|
||||
throw new BusinessException(PqdifResponseEnum.IMPORT_ITEM_NOT_NULL);
|
||||
}
|
||||
String id = StrUtil.trim(item.getId());
|
||||
if (StrUtil.isBlank(id)) {
|
||||
throw new BusinessException(DetectionValidMessage.ID_NOT_BLANK);
|
||||
}
|
||||
if (!ReUtil.isMatch(PatternRegex.SYSTEM_ID, id)) {
|
||||
throw new BusinessException(DetectionValidMessage.ID_FORMAT_ERROR);
|
||||
}
|
||||
if (!ids.add(id)) {
|
||||
throw new BusinessException(PqdifResponseEnum.IMPORT_ID_REPEAT);
|
||||
}
|
||||
if (StrUtil.isBlank(item.getName())) {
|
||||
throw new BusinessException(DetectionValidMessage.NAME_NOT_BLANK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PqPqdifPath toEntity(PqPqdifPathParam.ImportItem item) {
|
||||
PqPqdifPath entity = new PqPqdifPath();
|
||||
entity.setId(StrUtil.trim(item.getId()));
|
||||
entity.setName(StrUtil.trim(item.getName()));
|
||||
entity.setFilePath(StrUtil.trim(item.getFilePath()));
|
||||
entity.setRecordCount(item.getRecordCount());
|
||||
entity.setObservationCount(item.getObservationCount());
|
||||
entity.setSampleValueCount(item.getSampleValueCount());
|
||||
entity.setResult(item.getResult());
|
||||
entity.setMsg(item.getMsg());
|
||||
entity.setState(item.getState() == null ? DataStateEnum.ENABLE.getCode() : item.getState());
|
||||
entity.setCreateBy(StrUtil.trim(item.getCreateBy()));
|
||||
entity.setUpdateBy(StrUtil.trim(item.getUpdateBy()));
|
||||
entity.setCreateTime(parseDateTime(item.getCreateTime()));
|
||||
entity.setUpdateTime(parseDateTime(item.getUpdateTime()));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private LocalDateTime parseDateTime(String value) {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(StrUtil.trim(value));
|
||||
} catch (Exception ex) {
|
||||
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.njcn.gather.pqdif.service.support;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.pqdif.pojo.enums.PqdifResponseEnum;
|
||||
import com.njcn.gather.pqdif.pojo.param.PqPqdifPathParam;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class PqdifImportParser {
|
||||
|
||||
private PqdifImportParser() {
|
||||
}
|
||||
|
||||
public static List<PqPqdifPathParam.ImportItem> parse(String content) {
|
||||
try {
|
||||
JSONArray jsonArray = JSON.parseArray(content);
|
||||
if (jsonArray == null) {
|
||||
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||
}
|
||||
List<PqPqdifPathParam.ImportItem> items = new ArrayList<>();
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
if (jsonObject == null) {
|
||||
throw new BusinessException(PqdifResponseEnum.IMPORT_ITEM_NOT_NULL);
|
||||
}
|
||||
PqPqdifPathParam.ImportItem item = jsonObject.toJavaObject(PqPqdifPathParam.ImportItem.class);
|
||||
Object msg = jsonObject.get("msg");
|
||||
item.setMsg(normalizeMsg(msg));
|
||||
items.add(item);
|
||||
}
|
||||
return items;
|
||||
} catch (BusinessException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
throw new BusinessException(PqdifResponseEnum.JSON_FORMAT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalizeMsg(Object msg) {
|
||||
if (msg == null) {
|
||||
return null;
|
||||
}
|
||||
if (msg instanceof String) {
|
||||
return (String) msg;
|
||||
}
|
||||
return JSON.toJSONString(msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user