提交 ae76ad66 authored 作者: Matrix's avatar Matrix

[核查模块] 增加了核查的手动与自动的字段区分

上级 2c924d95
package com.tykj.dev.device.confirmcheck.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* CheckType.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/10/26 at 2:29 下午
*/
@Getter
@AllArgsConstructor
public enum CheckType {
/**
* 自动核查
*/
AUTO_CHECK(1, "自动核查"),
/**
* 手动核查
*/
MANUAL_CHECK(2, "手动核查");
private Integer id;
private String name;
}
package com.tykj.dev.device.confirmcheck.common;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.util.stream.Stream;
/**
* CheckTypeConvert.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/10/26 at 2:36 下午
*/
@Converter(autoApply = true)
public class CheckTypeConvert implements AttributeConverter<CheckType, Integer> {
/**
* Converts the value stored in the entity attribute into the
* data representation to be stored in the database.
*
* @param attribute the entity attribute value to be converted
* @return the converted data to be stored in the database
* column
*/
@Override
public Integer convertToDatabaseColumn(CheckType attribute) {
if (attribute == null) {
return null;
}
return attribute.getId();
}
/**
* Converts the data stored in the database column into the
* value to be stored in the entity attribute.
* Note that it is the responsibility of the converter writer to
* specify the correct <code>dbData</code> type for the corresponding
* column for use by the JDBC driver: i.e., persistence providers are
* not expected to do such type conversion.
*
* @param dbData the data from the database column to be
* converted
* @return the converted value to be stored in the entity
* attribute
*/
@Override
public CheckType convertToEntityAttribute(Integer dbData) {
if (dbData == null) {
return null;
}
return Stream.of(CheckType.values())
.filter(t -> t.getId().equals(dbData))
.findFirst()
.orElseThrow(IllegalArgumentException::new);
}
}
...@@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableMap; ...@@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.tykj.dev.config.GlobalMap; import com.tykj.dev.config.GlobalMap;
import com.tykj.dev.config.swagger.AutoDocument; import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.confirmcheck.service.ConfirmCheckService; import com.tykj.dev.device.confirmcheck.common.CheckType;
import com.tykj.dev.device.confirmcheck.entity.cache.AreaCache; import com.tykj.dev.device.confirmcheck.entity.cache.AreaCache;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBill; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBill;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail;
...@@ -13,6 +13,7 @@ import com.tykj.dev.device.confirmcheck.entity.vo.*; ...@@ -13,6 +13,7 @@ import com.tykj.dev.device.confirmcheck.entity.vo.*;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckBillDao; import com.tykj.dev.device.confirmcheck.repository.DeviceCheckBillDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao; import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckStatRepo; import com.tykj.dev.device.confirmcheck.repository.DeviceCheckStatRepo;
import com.tykj.dev.device.confirmcheck.service.ConfirmCheckService;
import com.tykj.dev.device.confirmcheck.utils.ObjTransUtil; import com.tykj.dev.device.confirmcheck.utils.ObjTransUtil;
import com.tykj.dev.device.library.repository.DeviceLibraryDao; import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary; import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
...@@ -99,12 +100,12 @@ public class DeviceCheckController { ...@@ -99,12 +100,12 @@ public class DeviceCheckController {
@ApiOperation(value = "根据id查询核查统计数据", notes = "可以通过这个接口查询核查统计数据") @ApiOperation(value = "根据id查询核查统计数据", notes = "可以通过这个接口查询核查统计数据")
@GetMapping("/stat/{id}") @GetMapping("/stat/{id}")
public ResponseEntity<ResultObj<CheckStatVo>> findStatById(@PathVariable Integer id) { public CheckStatVo findStatById(@PathVariable Integer id) {
//还要查询出所有的 //还要查询出所有的
CheckStatVo statVoList = statRepo.findById(id) CheckStatVo statVoList = statRepo.findById(id)
.map(transUtil::checkStatDo2Vo) .map(transUtil::checkStatDo2Vo)
.orElse(CheckStatVo.empty()); .orElse(CheckStatVo.empty());
return ResponseEntity.ok(new ResultObj<>(statVoList)); return statVoList;
} }
...@@ -129,7 +130,7 @@ public class DeviceCheckController { ...@@ -129,7 +130,7 @@ public class DeviceCheckController {
@ApiOperation(value = "发起自动核查", notes = "发起自动核查") @ApiOperation(value = "发起自动核查", notes = "发起自动核查")
@PostMapping("/auto") @PostMapping("/auto")
public ResponseEntity<ResultObj<Map<String, List<Integer>>>> startAutoCheck() { public ResultObj<Map<String, List<Integer>>> startAutoCheck() {
// 构建返回数据对象 // 构建返回数据对象
Map<String, List<Integer>> resultIds = new HashMap<>(8); Map<String, List<Integer>> resultIds = new HashMap<>(8);
resultIds.put("statId", new ArrayList<>()); resultIds.put("statId", new ArrayList<>());
...@@ -145,6 +146,7 @@ public class DeviceCheckController { ...@@ -145,6 +146,7 @@ public class DeviceCheckController {
// 构建省的统计账单 // 构建省的统计账单
DeviceCheckStat provStatDo = new DeviceCheckStat( DeviceCheckStat provStatDo = new DeviceCheckStat(
CheckType.AUTO_CHECK,
baseTitle + provUnit.getName() + "核查统计单", baseTitle + provUnit.getName() + "核查统计单",
"核查统计单", "核查统计单",
"系统发起的统计|" + provUnit.getName() + "|" + provUnit.getAreaId()); "系统发起的统计|" + provUnit.getName() + "|" + provUnit.getAreaId());
...@@ -177,6 +179,7 @@ public class DeviceCheckController { ...@@ -177,6 +179,7 @@ public class DeviceCheckController {
// 构建市统账单 // 构建市统账单
DeviceCheckStat cityStatDo = new DeviceCheckStat( DeviceCheckStat cityStatDo = new DeviceCheckStat(
CheckType.AUTO_CHECK,
baseTitle + cityUnit.getName() + "核查统计单", baseTitle + cityUnit.getName() + "核查统计单",
"核查统计单", "核查统计单",
"系统发起的统计|" + cityUnit.getName() + "|" + cityUnit.getAreaId() "系统发起的统计|" + cityUnit.getName() + "|" + cityUnit.getAreaId()
...@@ -300,7 +303,7 @@ public class DeviceCheckController { ...@@ -300,7 +303,7 @@ public class DeviceCheckController {
statRepo.saveAll(cityStatList); statRepo.saveAll(cityStatList);
return ResponseEntity.ok(new ResultObj<>(resultIds, "自动核查任务发起成功")); return new ResultObj<>(resultIds, "自动核查任务发起成功");
} }
/** /**
...@@ -701,7 +704,9 @@ public class DeviceCheckController { ...@@ -701,7 +704,9 @@ public class DeviceCheckController {
.collect(toMap(CheckDeviceStatVo::getDeviceModel, Function.identity(), CheckDeviceStatVo::reduce)) .collect(toMap(CheckDeviceStatVo::getDeviceModel, Function.identity(), CheckDeviceStatVo::reduce))
.values(); .values();
return new DeviceCheckStat(title, return new DeviceCheckStat(
CheckType.MANUAL_CHECK,
title,
startUnitName + "待核查装备统计单", startUnitName + "待核查装备统计单",
JacksonUtil.toJSon(new ArrayList<>(statVos)), JacksonUtil.toJSon(new ArrayList<>(statVos)),
checkAId, checkAId,
......
package com.tykj.dev.device.confirmcheck.entity.domain; package com.tykj.dev.device.confirmcheck.entity.domain;
import com.tykj.dev.device.confirmcheck.common.CheckType;
import com.tykj.dev.misc.base.BaseEntity; import com.tykj.dev.misc.base.BaseEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import lombok.Data; import lombok.Data;
...@@ -53,6 +54,13 @@ public class DeviceCheckStat extends BaseEntity { ...@@ -53,6 +54,13 @@ public class DeviceCheckStat extends BaseEntity {
*/ */
private String statInfo; private String statInfo;
/**
* 检查类型,数据库里的数据结构是int类型,其中1为自动,2为手动
*
* @see com.tykj.dev.device.confirmcheck.common.CheckTypeConvert
*/
private CheckType checkType;
/** /**
* 检查组成员A * 检查组成员A
*/ */
...@@ -89,7 +97,8 @@ public class DeviceCheckStat extends BaseEntity { ...@@ -89,7 +97,8 @@ public class DeviceCheckStat extends BaseEntity {
this.remark = remark; this.remark = remark;
} }
public DeviceCheckStat(String title, String subtitle, String statInfo, Integer checkUserAId, Integer checkUserBId, String remark) { public DeviceCheckStat(CheckType checkType, String title, String subtitle, String statInfo, Integer checkUserAId, Integer checkUserBId, String remark) {
this.checkType = checkType;
this.title = title; this.title = title;
this.subtitle = subtitle; this.subtitle = subtitle;
this.startTime = LocalDateTime.now(); this.startTime = LocalDateTime.now();
...@@ -100,7 +109,8 @@ public class DeviceCheckStat extends BaseEntity { ...@@ -100,7 +109,8 @@ public class DeviceCheckStat extends BaseEntity {
this.remark = remark; this.remark = remark;
} }
public DeviceCheckStat(String title, String subtitle, String remark) { public DeviceCheckStat(CheckType checkType, String title, String subtitle, String remark) {
this.checkType = checkType;
this.title = title; this.title = title;
this.subtitle = subtitle; this.subtitle = subtitle;
this.startTime = LocalDateTime.now(); this.startTime = LocalDateTime.now();
......
...@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; ...@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
import com.tykj.dev.misc.base.BeanHelper; import com.tykj.dev.misc.base.BeanHelper;
import com.tykj.dev.misc.utils.JacksonUtil; import com.tykj.dev.misc.utils.JacksonUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -63,6 +64,9 @@ public class CheckStatVo { ...@@ -63,6 +64,9 @@ public class CheckStatVo {
private LocalDateTime updateTime; private LocalDateTime updateTime;
@ApiModelProperty(name = "检查类型(0异常,1自动,2手动)")
private Integer checkType;
private Integer createUserId; private Integer createUserId;
private Integer updateUserId; private Integer updateUserId;
......
package com.tykj.dev.device.confirmcheck.utils;
import com.tykj.dev.device.confirmcheck.common.CheckType;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckStatVo;
import com.tykj.dev.misc.base.BeanHelper;
import lombok.Getter;
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper;
/**
* MapperHelper.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/10/26 at 2:50 下午
*/
public class MapperHelper {
private static ModelMapper mapper = BeanHelper.getUserMapper();
static {
Converter<CheckType, Integer> checkTypeConverter =
ctx -> ctx.getSource() == null ? 0 : ctx.getSource().getId();
mapper.typeMap(DeviceCheckStat.class, CheckStatVo.class)
.addMappings(mapping -> mapping
.using(checkTypeConverter)
.map(DeviceCheckStat::getCheckType, CheckStatVo::setCheckType));
}
public static ModelMapper getMapper() {
return mapper;
}
}
...@@ -152,7 +152,7 @@ public class ObjTransUtil { ...@@ -152,7 +152,7 @@ public class ObjTransUtil {
* Do类转化为Vo类 * Do类转化为Vo类
*/ */
public CheckStatVo checkStatDo2Vo(DeviceCheckStat statDo) { public CheckStatVo checkStatDo2Vo(DeviceCheckStat statDo) {
ModelMapper mapper = BeanHelper.getUserMapper(); ModelMapper mapper = MapperHelper.getMapper();
//复制基本信息 //复制基本信息
CheckStatVo initialStat = mapper.map(statDo, CheckStatVo.class); CheckStatVo initialStat = mapper.map(statDo, CheckStatVo.class);
// 查询userAName 与 userBName // 查询userAName 与 userBName
......
...@@ -101,7 +101,7 @@ class DeviceCheckControllerTest extends BaseTest { ...@@ -101,7 +101,7 @@ class DeviceCheckControllerTest extends BaseTest {
.map(JsonNode::asInt) .map(JsonNode::asInt)
.forEach(statId -> { .forEach(statId -> {
//测试访问 //测试访问
CheckStatVo statRes = checkController.findStatById(statId).getBody().getData(); CheckStatVo statRes = checkController.findStatById(statId);
try { try {
System.out.println(objectMapper.writeValueAsString(statRes)); System.out.println(objectMapper.writeValueAsString(statRes));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论