提交 2409a64f authored 作者: Matrix's avatar Matrix

[核查模块]

- 重构了核查统计的逻辑,现在的逻辑更加的清晰简洁,且优化了统计速度 - 优化了核查模块的单元测试部分 - 优化了核查模块一些类的命名以及将时间字段统一为LocalDateTime - 增加了BaseEntity类,用于普通类别的继承 - 将ResultObj对象添加泛型类型 - 增加了AreaUnitService服务,用于频繁的进行单位和地区的查询 - 去除了测试类的事务部分,后面会将单元测试的环境更改为内存数据库
上级 70295f20
package com.tykj.dev.device.confirmcheck.entity.domain; package com.tykj.dev.device.confirmcheck.entity.domain;
import com.tykj.dev.misc.base.BaseEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
...@@ -18,98 +20,53 @@ import java.util.Date; ...@@ -18,98 +20,53 @@ import java.util.Date;
/** /**
* entity class for device_check_bill * entity class for device_check_bill
* 装备核查账单 * 装备核查账单
* @author matrix
*/ */
@Data @Data
@Entity @Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update device_check_bill set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("装备核查账单")
@NoArgsConstructor @NoArgsConstructor
@ApiModel("装备核查账单")
@Table(name = "device_check_bill") @Table(name = "device_check_bill")
public class DeviceCheckBillEntity { @EqualsAndHashCode(callSuper = true)
@SQLDelete(sql = "update device_check_bill set delete_tag = 1 where id = ?")
public class DeviceCheckBill extends BaseEntity {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(name = "主键id")
private Integer id;
/** /**
* 检查组成员1(省A岗)id * 检查组成员1(省A岗)id
*/ */
@ApiModelProperty(value = "检查组成员1(省A岗)id")
@Column(name = "userA_id") @Column(name = "userA_id")
private Integer userAId; private Integer userAId;
/** /**
* 检查组成员2(省A岗)id * 检查组成员2(省A岗)id
*/ */
@ApiModelProperty(value = "检查组成员2(省A岗)id") @ApiModelProperty(value = "检查组成员2(省A岗)id")
@Column(name = "userB_id") @Column(name = "userB_id")
private Integer userBId; private Integer userBId;
/** /**
* 核查状态(0:决算待审核,1:决算审核失败,2:决算中,3:决算完成) * 核查状态(0:决算待审核,1:决算审核失败,2:决算中,3:决算完成)
*/ */
@ApiModelProperty(value = "核查状态(0:决算待审核,1:决算审核失败,2:决算中,3:决算完成)")
private Integer checkStatus; private Integer checkStatus;
/** /**
* 核查单位主键id(x作为分隔符),例如1x2,意为单位id为1和2的装备核查 * 核查单位主键id(x作为分隔符),例如1x2,意为单位id为1和2的装备核查
*/ */
@ApiModelProperty(value = "核查单位主键id(x作为分隔符),例如1x2,意为单位id为1和2的装备核查")
private String checkDetail; private String checkDetail;
/** /**
* 核查标题 * 核查标题
*/ */
@ApiModelProperty(value = "核查标题") @ApiModelProperty(value = "核查标题")
private String checkTitle; private String checkTitle;
/** /**
* 备注 * 备注
*/ */
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private String remark; private String remark;
/**
* 创建用户id
*/
@CreatedBy
@ApiModelProperty(value = "创建用户id")
private Integer createUserId;
/**
* 创建时间
*/
@CreatedDate
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 更新用户id
*/
@LastModifiedBy
@ApiModelProperty(value = "更新用户id")
private Integer updateUserId;
/**
* 更新时间
*/
@LastModifiedDate
@ApiModelProperty(value = "更新时间")
private Date updateTime;
/**
* 删除标记(0:未删除,1:已删除)
*/
@ApiModelProperty(value = "删除标记(0:未删除,1:已删除)")
private Integer deleteTag = 0;
public DeviceCheckBillEntity(Integer userAId, Integer userBId, Integer checkStatus, String checkDetail, String checkTitle, Date completeTime, String remark) { public DeviceCheckBill(Integer userAId, Integer userBId, Integer checkStatus, String checkDetail, String checkTitle, Date completeTime, String remark) {
this.userAId = userAId; this.userAId = userAId;
this.userBId = userBId; this.userBId = userBId;
this.checkStatus = checkStatus; this.checkStatus = checkStatus;
......
package com.tykj.dev.device.confirmcheck.entity.domain; package com.tykj.dev.device.confirmcheck.entity.domain;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary; import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.misc.base.BaseEntity;
import com.tykj.dev.misc.utils.TimestampUtil; import com.tykj.dev.misc.utils.TimestampUtil;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -24,24 +25,15 @@ import java.util.stream.Collectors; ...@@ -24,24 +25,15 @@ import java.util.stream.Collectors;
/** /**
* entity class for device_check_detail * entity class for device_check_detail
* 核查详情 * 核查详情
* @author matrix
*/ */
@Data @Data
@Entity @Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update device_check_detail set delete_tag = 1 where id = ?") @SQLDelete(sql = "update device_check_detail set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("核查详情") @ApiModel("核查详情")
@NoArgsConstructor @NoArgsConstructor
@Table(name = "device_check_detail") @Table(name = "device_check_detail")
public class DeviceCheckDetailEntity { public class DeviceCheckDetail extends BaseEntity {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(name = "主键id")
private Integer id;
/** /**
* 检查详情名称 * 检查详情名称
...@@ -113,7 +105,7 @@ public class DeviceCheckDetailEntity { ...@@ -113,7 +105,7 @@ public class DeviceCheckDetailEntity {
@ApiModelProperty(value = "核查结果") @ApiModelProperty(value = "核查结果")
private String checkResult; private String checkResult;
/** /**
* 核查详情(装备主键id+核对结果(0缺失1无误2新增,字符-作为状态分隔符字符,作为分隔符)) * 核查详情(装备主键id+核对结果(0缺失1无误2新增3不在库9未检查,字符-作为状态分隔符字符,作为分隔符))
*/ */
@ApiModelProperty(value = "核查详情(装备主键id+核对结果(0缺失1无误2新增3不在库9未检查,字符x作为分隔符)),例如1-2,2-2,意为主键id为1的装备缺失,为2的无误,为3的新增") @ApiModelProperty(value = "核查详情(装备主键id+核对结果(0缺失1无误2新增3不在库9未检查,字符x作为分隔符)),例如1-2,2-2,意为主键id为1的装备缺失,为2的无误,为3的新增")
...@@ -124,66 +116,23 @@ public class DeviceCheckDetailEntity { ...@@ -124,66 +116,23 @@ public class DeviceCheckDetailEntity {
@ApiModelProperty(value = "核查状态(0:待核查,1:审核失败,2:核查完成)") @ApiModelProperty(value = "核查状态(0:待核查,1:审核失败,2:核查完成)")
private Integer checkStatus; private Integer checkStatus;
/**
* 创建用户id
*/
@CreatedBy
@ApiModelProperty(value = "创建用户id")
private Integer createUserId;
/**
* 创建时间
*/
@CreatedDate
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 更新用户id
*/
@LastModifiedBy
@ApiModelProperty(value = "更新用户id")
private Integer updateUserId;
/**
* 更新时间
*/
@LastModifiedDate
@ApiModelProperty(value = "更新时间")
private Date updateTime;
/**
* 删除标记(0:未删除,1:已删除)
*/
@ApiModelProperty(value = "删除标记(0:未删除,1:已删除)")
private Integer deleteTag = 0;
/** /**
* 预留字段1 * 预留字段1
*/ */
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private String remark; private String remark;
/** /**
* 预留字段2 * 预留字段2
*/ */
@ApiModelProperty(value = "预留字段2") @ApiModelProperty(value = "预留字段2")
private String var2; private String var2;
@ApiModelProperty(value = "创建人")
@Transient
private String createUser;
@ApiModelProperty(value = "核查人")
@Transient
private String checkUser;
@ApiModelProperty(value = "审核人")
@Transient
private String confirmUser;
/** /**
* 用于生成市级的核查详情账单的构造函数 * 用于生成市级的核查详情账单的构造函数
*/ */
public DeviceCheckDetailEntity(Integer finalCheckId, Date checkTime, String checkUnit, Integer checkingCount, Integer checkedCount, String checkResult, String checkDetail, Integer checkStatus) { public DeviceCheckDetail(Integer finalCheckId, Date checkTime, String checkUnit, Integer checkingCount, Integer checkedCount, String checkResult, String checkDetail, Integer checkStatus) {
this.finalCheckId = finalCheckId; this.finalCheckId = finalCheckId;
this.checkTime = checkTime; this.checkTime = checkTime;
this.checkUnit = checkUnit; this.checkUnit = checkUnit;
...@@ -197,7 +146,7 @@ public class DeviceCheckDetailEntity { ...@@ -197,7 +146,7 @@ public class DeviceCheckDetailEntity {
/** /**
* 用于生成县级的核查详情账单的构造函数 * 用于生成县级的核查详情账单的构造函数
*/ */
public DeviceCheckDetailEntity(String title, public DeviceCheckDetail(String title,
Integer finalCheckId, Integer finalCheckId,
Integer checkUserAId, Integer checkUserAId,
Integer checkUserBId, Integer checkUserBId,
...@@ -233,7 +182,7 @@ public class DeviceCheckDetailEntity { ...@@ -233,7 +182,7 @@ public class DeviceCheckDetailEntity {
* @param devNotInLib 所属在,但所在不在本单位的装备集合 * @param devNotInLib 所属在,但所在不在本单位的装备集合
* @return 初始化的账单(还没有被人修改过的) * @return 初始化的账单(还没有被人修改过的)
*/ */
public static DeviceCheckDetailEntity EmptyWithChecker( public static DeviceCheckDetail EmptyWithChecker(
String remark, String remark,
String title, String title,
Integer checkUserA, Integer checkUserA,
...@@ -262,7 +211,7 @@ public class DeviceCheckDetailEntity { ...@@ -262,7 +211,7 @@ public class DeviceCheckDetailEntity {
//如果不在库的不为空,则拼接,否则没必要 //如果不在库的不为空,则拼接,否则没必要
String checkDetail = StringUtils.isEmpty(badCheckDetail) ? goodCheckDetail : goodCheckDetail + "," + badCheckDetail; String checkDetail = StringUtils.isEmpty(badCheckDetail) ? goodCheckDetail : goodCheckDetail + "," + badCheckDetail;
return new DeviceCheckDetailEntity( return new DeviceCheckDetail(
title + checkUnit + "核查详情单", title + checkUnit + "核查详情单",
0, 0,
checkUserA, checkUserA,
......
package com.tykj.dev.device.confirmcheck.entity.domain; package com.tykj.dev.device.confirmcheck.entity.domain;
import com.tykj.dev.misc.base.BaseEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
...@@ -13,7 +15,7 @@ import org.springframework.data.annotation.LastModifiedDate; ...@@ -13,7 +15,7 @@ import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.time.LocalDateTime;
/** /**
* DeviceCheckStat. * DeviceCheckStat.
...@@ -21,21 +23,15 @@ import java.util.Date; ...@@ -21,21 +23,15 @@ import java.util.Date;
* @author Matrix <xhyrzldf@gmail.com> * @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/15 at 7:09 下午 * @since 2020/8/15 at 7:09 下午
*/ */
@EqualsAndHashCode(callSuper = true)
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
@Data @Data
@Entity @Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update device_check_stat set delete_tag = 1 where id = ?") @SQLDelete(sql = "update device_check_stat set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("装备核查统计") @ApiModel("装备核查统计")
@NoArgsConstructor @NoArgsConstructor
@Table(name = "device_check_stat") @Table(name = "device_check_stat")
public class DeviceCheckStat { public class DeviceCheckStat extends BaseEntity {
/**
* 主键
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/** /**
* 父标题 * 父标题
...@@ -50,66 +46,73 @@ public class DeviceCheckStat { ...@@ -50,66 +46,73 @@ public class DeviceCheckStat {
/** /**
* 开始时间 * 开始时间
*/ */
private Date startTime; private LocalDateTime startTime;
/** /**
* 结束时间 * 结束时间
*/ */
private Date endTime; private LocalDateTime endTime;
/** /**
* 统计信息以JSON形式存储 * 统计信息以JSON形式存储
*/ */
private String statInfo; private String statInfo;
@Column(name = "check_userA_id")
private Integer checkUserAId;
@Column(name = "check_userB_id")
private Integer checkUserBId;
private String remark;
/** /**
* 创建用户id * 检查组成员A
*/ */
@CreatedBy @Column(name = "check_userA_id")
private Integer checkUserAId;
@ApiModelProperty(value = "创建用户id")
private Integer createUserId;
/**
* 创建时间
*/
@CreatedDate
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 更新用户id
*/
@LastModifiedBy
@ApiModelProperty(value = "更新用户id")
private Integer updateUserId;
/** /**
* 更新时间 * 检查组成员B
*/ */
@LastModifiedDate @Column(name = "check_userB_id")
private Integer checkUserBId;
@ApiModelProperty(value = "更新时间")
private Date updateTime;
/** /**
* 删除标记(0:未删除,1:已删除) * 备注信息
*/ */
private String remark;
@ApiModelProperty(value = "删除标记(0:未删除,1:已删除)") public DeviceCheckStat(String title, String subtitle, LocalDateTime startTime, LocalDateTime endTime, String statInfo) {
private Integer deleteTag = 0; this.title = title;
this.subtitle = subtitle;
this.startTime = startTime;
this.endTime = endTime;
this.statInfo = statInfo;
}
public DeviceCheckStat(String title, String subtitle, Date startTime, Date endTime, String statInfo) { public DeviceCheckStat(String title, String subtitle, LocalDateTime startTime, LocalDateTime endTime, String statInfo, Integer checkUserAId, Integer checkUserBId, String remark) {
this.title = title; this.title = title;
this.subtitle = subtitle; this.subtitle = subtitle;
this.startTime = startTime; this.startTime = startTime;
this.endTime = endTime; this.endTime = endTime;
this.statInfo = statInfo; this.statInfo = statInfo;
this.checkUserAId = checkUserAId;
this.checkUserBId = checkUserBId;
this.remark = remark;
} }
public DeviceCheckStat(String title, String subtitle, String statInfo, Integer checkUserAId, Integer checkUserBId, String remark) {
this.title = title;
this.subtitle = subtitle;
this.startTime = LocalDateTime.now();
this.endTime = LocalDateTime.now().plusMonths(1);
this.statInfo = statInfo;
this.checkUserAId = checkUserAId;
this.checkUserBId = checkUserBId;
this.remark = remark;
}
public DeviceCheckStat(String title, String subtitle, String remark) {
this.title = title;
this.subtitle = subtitle;
this.startTime = LocalDateTime.now();
this.endTime = LocalDateTime.now().plusMonths(1);
this.statInfo = "";
this.checkUserAId = 0;
this.checkUserBId = 0;
this.remark = remark;
}
} }
...@@ -3,6 +3,9 @@ package com.tykj.dev.device.confirmcheck.entity.vo; ...@@ -3,6 +3,9 @@ package com.tykj.dev.device.confirmcheck.entity.vo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/** /**
* CheckAreaStatVo. * CheckAreaStatVo.
...@@ -13,7 +16,8 @@ import lombok.NoArgsConstructor; ...@@ -13,7 +16,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Data @Data
public class CheckAreaStatVo { @Accessors(chain = true)
public class CheckAreaStatVo implements Cloneable {
/** /**
* 地区名 * 地区名
...@@ -50,23 +54,92 @@ public class CheckAreaStatVo { ...@@ -50,23 +54,92 @@ public class CheckAreaStatVo {
*/ */
private int areaDetailId; private int areaDetailId;
public CheckAreaStatVo(CheckAreaStatVo vo) {
this.areaName = vo.getAreaName();
this.actualCount = vo.getActualCount();
this.supposeCount = vo.getSupposeCount();
this.comProgress = vo.getComProgress();
this.comSituation = vo.getComSituation();
this.areaStatId = vo.getAreaStatId();
this.areaDetailId = vo.getAreaDetailId();
}
public CheckAreaStatVo addSuppose(int supposeCount) { public CheckAreaStatVo addSuppose(int supposeCount) {
this.supposeCount += supposeCount; this.supposeCount += supposeCount;
return this; return this;
} }
public CheckAreaStatVo add(CheckAreaStatVo other) { public void start() {
comProgress = 1;
}
/**
* 将相同地区的统计数据合并
*
* @param other 要合并的地区
* @return 合并后的新地区数据(深度拷贝出来的新对象)
* @throws IllegalArgumentException 在合并的地区名不同或者统计账单id不同时会抛出(初始账单合并除外,即this.detailId=0)
*/
public CheckAreaStatVo reduce(@NotNull CheckAreaStatVo other) {
// 合并的两个对象地区与账单id必须相同
if (!this.areaName.equals(other.areaName) || this.areaStatId != other.areaStatId) {
//初始化账单的话则不用抛出异常,将other的detailId赋予即可
if (this.areaDetailId == 0) {
this.areaDetailId = other.areaStatId;
} else {
throw new IllegalArgumentException(String.format(
"要合并的两个地区统计数据的areaName与areaDetailId必须保持一致," +
"你提供的分别是areaName = %s 与 %s , areaDetailId = %d 与 %d %n",
this.areaName, other.areaName, this.areaStatId, other.areaStatId));
}
}
CheckAreaStatVo reducedVo = new CheckAreaStatVo(this);
reducedVo.supposeCount += other.supposeCount;
reducedVo.actualCount += other.actualCount;
reducedVo.comProgress = other.comProgress;
reducedVo.comSituation = other.comSituation;
return reducedVo;
}
/**
* 将相同地区的统计数据合并(清洁版)
* 只会将实际核查的结果添加进去,并不会重复添加期望指标数字
*
* @param other 要合并的地区
* @return 合并后的新地区数据(深度拷贝出来的新对象)
* @throws IllegalArgumentException 在合并的地区名不同或者统计账单id不同时会抛出(初始账单合并除外,即this.detailId=0)
*/
@SuppressWarnings("DuplicatedCode")
public CheckAreaStatVo cleanReduce(@NotNull CheckAreaStatVo other) {
// 合并的两个对象地区与账单id必须相同
if (!this.areaName.equals(other.areaName) || this.areaStatId != other.areaStatId) {
//初始化账单的话则不用抛出异常,将other的detailId赋予即可
if (this.areaDetailId == 0) {
this.areaDetailId = other.areaStatId;
} else {
throw new IllegalArgumentException(String.format(
"要合并的两个地区统计数据的areaName与areaDetailId必须保持一致," +
"你提供的分别是areaName = %s 与 %s , areaDetailId = %d 与 %d %n",
this.areaName, other.areaName, this.areaStatId, other.areaStatId));
}
}
CheckAreaStatVo reducedVo = new CheckAreaStatVo(this);
reducedVo.actualCount += other.actualCount;
reducedVo.comProgress = other.comProgress;
reducedVo.comSituation = other.comSituation;
return reducedVo;
}
public CheckAreaStatVo combine(CheckAreaStatVo other, Integer cityStatId) {
this.areaName = other.getAreaName(); this.areaName = other.getAreaName();
this.areaStatId = other.getAreaStatId(); this.areaStatId = cityStatId;
this.areaDetailId = other.getAreaDetailId(); this.areaDetailId = 0;
this.supposeCount += other.getSupposeCount();
this.actualCount += other.getActualCount(); this.actualCount += other.getActualCount();
this.comProgress = other.getComProgress(); this.comProgress = other.getComProgress();
this.comSituation = other.getComSituation(); this.comSituation = other.getComSituation();
return this; return this;
} }
public void start() {
comProgress = 1;
}
} }
package com.tykj.dev.device.confirmcheck.entity.vo; package com.tykj.dev.device.confirmcheck.entity.vo;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
...@@ -25,7 +26,7 @@ import static java.util.stream.Collectors.toMap; ...@@ -25,7 +26,7 @@ import static java.util.stream.Collectors.toMap;
@Data @Data
@Builder @Builder
@Slf4j @Slf4j
public class CheckDeviceStatVo { public class CheckDeviceStatVo implements Cloneable {
/** /**
* 装备型号 * 装备型号
...@@ -48,39 +49,131 @@ public class CheckDeviceStatVo { ...@@ -48,39 +49,131 @@ public class CheckDeviceStatVo {
*/ */
private List<CheckAreaStatVo> areaStatList; private List<CheckAreaStatVo> areaStatList;
public CheckDeviceStatVo(CheckDeviceStatVo vo) {
this.deviceModel = vo.getDeviceModel();
this.deviceName = vo.getDeviceName();
this.deviceCount = vo.getDeviceCount();
this.areaStatList = new ArrayList<>();
for (CheckAreaStatVo areaStatVo : vo.getAreaStatList()) {
this.areaStatList.add(new CheckAreaStatVo(areaStatVo));
}
}
/** /**
* other的model一定要与本deviceModel相同 * 增加指定的装备数量
*
* @param count 装备数量
*/ */
public CheckDeviceStatVo add(CheckDeviceStatVo other) { public CheckDeviceStatVo addDeviceCount(int count) {
if (!deviceModel.equals(other.getDeviceModel())) { this.deviceCount += count;
log.warn("[核查] 合并统计的数据发现装备不统一的情况");
return this; return this;
} }
deviceCount += other.getDeviceCount(); /**
* 累加装备统计数据(相同型号),并将其下面各个地区的统计信息合并(次级地区会强制更改为{cityName})
* 多用于装备统计数据中既附带区又附带市的统计信息,想全部合并为市的操作(为了统一给省级单位查看统计数据)
* <li>将所有地区全部改名为市级地区</li>
* <li>合并所有数据</li>
*
* @param other 要合并的装备统计对象
* @param cityName 统一后的地区名称
* @return 合并后的装备统计对象,基于深拷贝的新对象
*/
public CheckDeviceStatVo reduce(CheckDeviceStatVo other, String cityName, Integer cityStatId) {
if (!deviceModel.equals(other.deviceModel)) {
throw new IllegalArgumentException("累加的统计信息对象必须是相同型号的装备");
}
CheckDeviceStatVo mergeVo = new CheckDeviceStatVo(this);
mergeVo.deviceCount += other.deviceCount;
//添加地区数据 -> 调用combine 合并地区数据
mergeVo.areaStatList.addAll(other.getAreaStatList());
return mergeVo.combine(cityName, cityStatId);
}
/**
* 将相同型号的不同地区数据合并到一起
*
* @param other 要合并的装备统计信息
* @return 合并后的装备统计信息对相关,基于深拷贝
* @throws IllegalArgumentException 累加的统计信息对象必须是相同型号的装备
*/
public CheckDeviceStatVo reduce(CheckDeviceStatVo other) {
if (!deviceModel.equals(other.getDeviceModel())) {
throw new IllegalArgumentException("累加的统计信息对象必须是相同型号的装备");
}
CheckDeviceStatVo mergeVo = new CheckDeviceStatVo(this);
mergeVo.deviceCount += other.deviceCount;
// 如果源地区为空,则直接覆盖掉 // 如果源地区为空,则直接覆盖掉
if (CollectionUtils.isEmpty(areaStatList)) { if (CollectionUtils.isEmpty(areaStatList)) {
areaStatList = other.getAreaStatList(); mergeVo.areaStatList = other.getAreaStatList();
return mergeVo;
} }
Map<String, CheckAreaStatVo> areaMap = areaStatList.stream() Map<String, CheckAreaStatVo> areaMap = mergeVo.areaStatList.stream()
.collect(toMap(CheckAreaStatVo::getAreaName, Function.identity())); .collect(toMap(CheckAreaStatVo::getAreaName, Function.identity()));
for (CheckAreaStatVo otherArea : other.getAreaStatList()) { for (CheckAreaStatVo otherArea : other.getAreaStatList()) {
//如果原来的没有则添加,否则累加 //如果原来的没有则添加,否则累加
areaMap.putIfAbsent(otherArea.getAreaName(), otherArea); areaMap.putIfAbsent(otherArea.getAreaName(), otherArea);
areaMap.computeIfPresent(otherArea.getAreaName(), (k, v) -> v.add(otherArea)); areaMap.computeIfPresent(otherArea.getAreaName(), (k, v) -> v.reduce(otherArea));
} }
areaStatList = new ArrayList<>(areaMap.values()); mergeVo.areaStatList = new ArrayList<>(areaMap.values());
return mergeVo;
}
return this; /**
* 将相同型号的不同地区数据合并到一起(清洁版)
* 与普通reduce的区别是只会将统计结果合并,不会将统计指标合并,适用于预期结果+实际核查结果类型数据相加
*
* @param other 要合并的装备统计信息
* @return 合并后的装备统计信息对相关,基于深拷贝
* @throws IllegalArgumentException 累加的统计信息对象必须是相同型号的装备
*/
public CheckDeviceStatVo cleanReduce(CheckDeviceStatVo other) {
if (!deviceModel.equals(other.getDeviceModel())) {
throw new IllegalArgumentException("累加的统计信息对象必须是相同型号的装备");
} }
public CheckDeviceStatVo addDeviceCount(int count) { CheckDeviceStatVo mergeVo = new CheckDeviceStatVo(this);
this.deviceCount += count;
return this; // 如果源地区为空,则直接覆盖掉
if (CollectionUtils.isEmpty(areaStatList)) {
mergeVo.areaStatList = other.getAreaStatList();
return mergeVo;
} }
Map<String, CheckAreaStatVo> areaMap = mergeVo.areaStatList.stream()
.collect(toMap(CheckAreaStatVo::getAreaName, Function.identity()));
for (CheckAreaStatVo otherArea : other.getAreaStatList()) {
//如果原来的没有则添加,否则累加
areaMap.putIfAbsent(otherArea.getAreaName(), otherArea);
areaMap.computeIfPresent(otherArea.getAreaName(), (k, v) -> v.cleanReduce(otherArea));
}
mergeVo.areaStatList = new ArrayList<>(areaMap.values());
return mergeVo;
}
/**
* 将当前 {@link CheckDeviceStatVo} 对象里的所有地区数据统一改名并合并数据
*
* @param newAreaName 要更新的地区名称
* @param statId 要重新绑定的stat统计账单id,多为市级的账单统计id
* @return 改名&合并地区数据后的统计对象,基于深拷贝的新对象
*/
public CheckDeviceStatVo combine(String newAreaName, Integer statId) {
CheckDeviceStatVo mergeVo = new CheckDeviceStatVo(this);
CheckAreaStatVo mergedAreaStat = mergeVo.getAreaStatList().stream()
.map(v -> v.setAreaName(newAreaName))
.reduce((vo1, vo2) -> vo1.combine(vo2, statId))
.orElse(new CheckAreaStatVo());
mergeVo.setAreaStatList(Lists.newArrayList(mergedAreaStat));
return mergeVo;
}
} }
...@@ -13,6 +13,8 @@ import org.springframework.util.CollectionUtils; ...@@ -13,6 +13,8 @@ import org.springframework.util.CollectionUtils;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -52,17 +54,17 @@ public class CheckStatVo { ...@@ -52,17 +54,17 @@ public class CheckStatVo {
* 开始时间 * 开始时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date startTime; private LocalDateTime startTime;
/** /**
* 结束时间 * 结束时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date endTime; private LocalDateTime endTime;
private Date createTime; private LocalDateTime createTime;
private Date updateTime; private LocalDateTime updateTime;
private Integer createUserId; private Integer createUserId;
...@@ -84,7 +86,7 @@ public class CheckStatVo { ...@@ -84,7 +86,7 @@ public class CheckStatVo {
private List<CheckDeviceStatVo> deviceStatVoList; private List<CheckDeviceStatVo> deviceStatVoList;
public CheckStatVo(String remark, Integer checkUserAId, Integer checkUserBId, Integer id, String title, String subtitle, Date startTime, Date endTime, List<CheckDeviceStatVo> deviceStatVoList) { public CheckStatVo(String remark, Integer checkUserAId, Integer checkUserBId, Integer id, String title, String subtitle, LocalDateTime startTime, LocalDateTime endTime, List<CheckDeviceStatVo> deviceStatVoList) {
this.checkUserAId = checkUserAId; this.checkUserAId = checkUserAId;
this.checkUserBId = checkUserBId; this.checkUserBId = checkUserBId;
this.id = id; this.id = id;
...@@ -101,7 +103,7 @@ public class CheckStatVo { ...@@ -101,7 +103,7 @@ public class CheckStatVo {
return new CheckStatVo("", 0, 0, 0, "无指定数据", "无指定数据", null, null, emptyList); return new CheckStatVo("", 0, 0, 0, "无指定数据", "无指定数据", null, null, emptyList);
} }
public CheckStatVo addStatList(List<CheckDeviceStatVo> otherList) { public CheckStatVo cleanReduce(List<CheckDeviceStatVo> otherList) {
if (CollectionUtils.isEmpty(deviceStatVoList)) { if (CollectionUtils.isEmpty(deviceStatVoList)) {
deviceStatVoList = otherList; deviceStatVoList = otherList;
return this; return this;
...@@ -112,12 +114,11 @@ public class CheckStatVo { ...@@ -112,12 +114,11 @@ public class CheckStatVo {
//遍历要加入的LIST 如果在源数据map中寻找到了则累加,否则添加进去 //遍历要加入的LIST 如果在源数据map中寻找到了则累加,否则添加进去
for (CheckDeviceStatVo vo : otherList) { for (CheckDeviceStatVo vo : otherList) {
oriModelMap.computeIfPresent(vo.getDeviceModel(), (k, v) -> v.cleanReduce(vo));
oriModelMap.putIfAbsent(vo.getDeviceModel(), vo); oriModelMap.putIfAbsent(vo.getDeviceModel(), vo);
oriModelMap.computeIfPresent(vo.getDeviceModel(), (k, v) -> v.add(vo));
} }
deviceStatVoList = new ArrayList<>(oriModelMap.values()); deviceStatVoList = new ArrayList<>(oriModelMap.values());
return this; return this;
} }
......
...@@ -29,5 +29,8 @@ public class DeviceInLibVo { ...@@ -29,5 +29,8 @@ public class DeviceInLibVo {
private String rfidCardId; private String rfidCardId;
/**
* 0缺失1无误2新增3不在库9未检查
*/
private int proofResult; private int proofResult;
} }
package com.tykj.dev.device.confirmcheck.repository; package com.tykj.dev.device.confirmcheck.repository;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBillEntity; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBill;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/** /**
* @author dengdiyi * @author dengdiyi
*/ */
public interface DeviceCheckBillDao extends JpaRepository<DeviceCheckBillEntity, Integer>, JpaSpecificationExecutor<DeviceCheckBillEntity> { public interface DeviceCheckBillDao extends JpaRepository<DeviceCheckBill, Integer>, JpaSpecificationExecutor<DeviceCheckBill> {
} }
package com.tykj.dev.device.confirmcheck.repository; package com.tykj.dev.device.confirmcheck.repository;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetailEntity; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
...@@ -11,7 +11,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -11,7 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author dengdiyi * @author dengdiyi
*/ */
@Transactional @Transactional
public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetailEntity, Integer>, JpaSpecificationExecutor<DeviceCheckDetailEntity> { public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetail, Integer>, JpaSpecificationExecutor<DeviceCheckDetail> {
/** /**
* 根据id更新checkDetail * 根据id更新checkDetail
...@@ -20,11 +20,11 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetailEnt ...@@ -20,11 +20,11 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetailEnt
* @param checkDetail 要更新的检查结果 * @param checkDetail 要更新的检查结果
*/ */
@Modifying @Modifying
@Query("update DeviceCheckDetailEntity o set o.checkDetail=?2,o.checkResult = ?3,o.userAId =?4,o.userBId=?5,o.checkedCount=?6 where o.id=?1") @Query("update DeviceCheckDetail o set o.checkDetail=?2,o.checkResult = ?3,o.userAId =?4,o.userBId=?5,o.checkedCount=?6 where o.id=?1")
void updateCheckDetail(Integer id, String checkDetail, String checkResult, int userAId, int userBId, Integer checkedCount); void updateCheckDetail(Integer id, String checkDetail, String checkResult, int userAId, int userBId, Integer checkedCount);
@Modifying @Modifying
@Query("update DeviceCheckDetailEntity o set o.checkStatus=?2 where o.id=?1") @Query("update DeviceCheckDetail o set o.checkStatus=?2 where o.id=?1")
int updateCheckStatus(int id, int checkStatus); int updateCheckStatus(int id, int checkStatus);
/** /**
...@@ -35,6 +35,6 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetailEnt ...@@ -35,6 +35,6 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetailEnt
* @param checkUserBId 核查组成员B * @param checkUserBId 核查组成员B
*/ */
@Modifying @Modifying
@Query("update DeviceCheckDetailEntity o set o.checkUserAId =?2,o.checkUserBId=?3 where o.id =?1") @Query("update DeviceCheckDetail o set o.checkUserAId =?2,o.checkUserBId=?3 where o.id =?1")
void updateCheckUser(int id, int checkUserAId, int checkUserBId); void updateCheckUser(int id, int checkUserAId, int checkUserBId);
} }
...@@ -3,8 +3,8 @@ package com.tykj.dev.device.confirmcheck.utils; ...@@ -3,8 +3,8 @@ package com.tykj.dev.device.confirmcheck.utils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBillEntity; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBill;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetailEntity; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat; import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
import com.tykj.dev.device.confirmcheck.entity.vo.*; import com.tykj.dev.device.confirmcheck.entity.vo.*;
import com.tykj.dev.device.library.repository.DeviceLibraryDao; import com.tykj.dev.device.library.repository.DeviceLibraryDao;
...@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -102,9 +103,9 @@ public class ObjTransUtil { ...@@ -102,9 +103,9 @@ public class ObjTransUtil {
return initialStat; return initialStat;
} }
public DeviceCheckBillEntity checkBillVo2Do(CheckBillVo vo) { public DeviceCheckBill checkBillVo2Do(CheckBillVo vo) {
ModelMapper modelMapper = BeanHelper.getUserMapper(); ModelMapper modelMapper = BeanHelper.getUserMapper();
DeviceCheckBillEntity billDo = modelMapper.map(vo, DeviceCheckBillEntity.class); DeviceCheckBill billDo = modelMapper.map(vo, DeviceCheckBill.class);
billDo.setCheckStatus(0); billDo.setCheckStatus(0);
//areas -> unitIds -> unitStrings //areas -> unitIds -> unitStrings
String unitString = vo.getAreaRange().stream() String unitString = vo.getAreaRange().stream()
...@@ -116,9 +117,9 @@ public class ObjTransUtil { ...@@ -116,9 +117,9 @@ public class ObjTransUtil {
return billDo; return billDo;
} }
public DeviceCheckDetailEntity checkDetailVo2Do(CheckDetailVo detailVo) { public DeviceCheckDetail checkDetailVo2Do(CheckDetailVo detailVo) {
ModelMapper modelMapper = BeanHelper.getUserMapper(); ModelMapper modelMapper = BeanHelper.getUserMapper();
DeviceCheckDetailEntity detailDo = modelMapper.map(detailVo, DeviceCheckDetailEntity.class); DeviceCheckDetail detailDo = modelMapper.map(detailVo, DeviceCheckDetail.class);
//将inLib与notInLib 的集合 转化为压缩字符串 //将inLib与notInLib 的集合 转化为压缩字符串
String checkDetailString = devLib2String(detailVo.getDevInLibrary(), detailVo.getDevNotInLibrary()); String checkDetailString = devLib2String(detailVo.getDevInLibrary(), detailVo.getDevNotInLibrary());
detailDo.setCheckDetail(checkDetailString); detailDo.setCheckDetail(checkDetailString);
...@@ -145,7 +146,7 @@ public class ObjTransUtil { ...@@ -145,7 +146,7 @@ public class ObjTransUtil {
} }
public CheckDetailVo CheckDetailDo2Vo(DeviceCheckDetailEntity detailDo) { public CheckDetailVo CheckDetailDo2Vo(DeviceCheckDetail detailDo) {
//查询人物id //查询人物id
Integer checkUserAId = detailDo.getCheckUserAId(); Integer checkUserAId = detailDo.getCheckUserAId();
Integer checkUserBId = detailDo.getCheckUserBId(); Integer checkUserBId = detailDo.getCheckUserBId();
...@@ -177,8 +178,11 @@ public class ObjTransUtil { ...@@ -177,8 +178,11 @@ public class ObjTransUtil {
List<DeviceInLibVo> inLibVoList = new ArrayList<>(); List<DeviceInLibVo> inLibVoList = new ArrayList<>();
List<DeviceNotInLibVo> notInLibVoList = new ArrayList<>(); List<DeviceNotInLibVo> notInLibVoList = new ArrayList<>();
String checkDetail = detailDo.getCheckDetail(); String checkDetail = detailDo.getCheckDetail();
String[] detailArray = checkDetail.split(","); List<String> devCheckList = Lists.newArrayList(checkDetail.split(","));
for (String detail : detailArray) { for (String detail : devCheckList) {
if (StringUtils.isEmpty(detail)) {
continue;
}
String[] array = detail.split("-"); String[] array = detail.split("-");
Integer deviceId = Integer.valueOf(array[0]); Integer deviceId = Integer.valueOf(array[0]);
int proofResult = Integer.parseInt(array[1]); int proofResult = Integer.parseInt(array[1]);
......
...@@ -20,11 +20,6 @@ ...@@ -20,11 +20,6 @@
<artifactId>config</artifactId> <artifactId>config</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.1.0.Final</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
package com.tykj.dev.misc.base;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import java.util.Date;
/**
* BaseEntity.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/27 at 1:25 上午
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Where(clause = "delete_tag = 0")
public class BaseEntity {
/**
* 主键id
*/
@Id
@GeneratedValue
private Integer id;
/**
* 创建用户id
*/
@CreatedBy
private Integer createUserId;
/**
* 更新用户id
*/
@LastModifiedBy
private Integer updateUserId;
/**
* 创建时间
*/
@CreatedDate
private LocalDateTime createTime;
/**
* 更新时间
*/
@LastModifiedDate
private LocalDateTime updateTime;
/**
* 删除标记(0:未删除,1:已删除)
*/
private Integer deleteTag = 0;
}
...@@ -13,19 +13,18 @@ import lombok.NoArgsConstructor; ...@@ -13,19 +13,18 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@JsonPropertyOrder(value = {"message","data"}) @JsonPropertyOrder(value = {"message","data"})
public class ResultObj { public class ResultObj<T> {
private Object data; private T data;
private String message; private String message;
public ResultObj(Object o) { public ResultObj(T o) {
this.data = o; this.data = o;
this.message = "no message"; this.message = "no message";
} }
public ResultObj(String m) { public ResultObj(String m) {
this.message = m; this.message = m;
this.data = new Object();
} }
} }
...@@ -5,6 +5,7 @@ import org.modelmapper.convention.MatchingStrategies; ...@@ -5,6 +5,7 @@ import org.modelmapper.convention.MatchingStrategies;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -64,6 +65,18 @@ public class MapperUtils { ...@@ -64,6 +65,18 @@ public class MapperUtils {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* @param entityList list of entities that needs to be mapped
* @param constructor deep copy constructor
* @param <D> type of objects in result list and entityList
* @return the deepCopy List of entityList
*/
public static <D extends Cloneable> List<D> deepClone(final Collection<D> entityList, Function<D, D> constructor) {
return entityList.stream()
.map(constructor)
.collect(Collectors.toList());
}
/** /**
* Maps {@code source} to {@code destination}. * Maps {@code source} to {@code destination}.
* *
......
package com.tykj.dev.union; package com.tykj.dev.union;
import cn.hutool.core.util.ArrayUtil;
import com.tykj.dev.config.GlobalMap;
import com.tykj.dev.config.Log; import com.tykj.dev.config.Log;
import com.tykj.dev.config.Param; import com.tykj.dev.config.Param;
import com.tykj.dev.config.LogType; import com.tykj.dev.config.LogType;
import com.tykj.dev.device.allot.repository.AllotBillDao;
import com.tykj.dev.device.allot.service.AllotBackBillService; import com.tykj.dev.device.allot.service.AllotBackBillService;
import com.tykj.dev.device.allot.service.AllotBillService; import com.tykj.dev.device.allot.service.AllotBillService;
import com.tykj.dev.device.allot.subject.domin.AllotBackBill; import com.tykj.dev.device.allot.subject.domin.AllotBackBill;
import com.tykj.dev.device.allot.subject.domin.AllotBill; import com.tykj.dev.device.allot.subject.domin.AllotBill;
import com.tykj.dev.device.apply.service.DeviceApplyBillService; import com.tykj.dev.device.apply.service.DeviceApplyBillService;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBillEntity;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetailEntity;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
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.destroy.entity.domain.DeviceDestroyBill; import com.tykj.dev.device.destroy.entity.domain.DeviceDestroyBill;
import com.tykj.dev.device.destroy.service.DeviceDestroyBillService; import com.tykj.dev.device.destroy.service.DeviceDestroyBillService;
import com.tykj.dev.device.library.subject.vo.FileVo; import com.tykj.dev.device.library.subject.vo.FileVo;
import com.tykj.dev.device.library.subject.vo.LogVo;
import com.tykj.dev.device.matching.service.MatchingDeviceBillService; import com.tykj.dev.device.matching.service.MatchingDeviceBillService;
import com.tykj.dev.device.matching.service.MatchingDeviceLibraryService;
import com.tykj.dev.device.matching.subject.domin.MatchingDeviceBill; import com.tykj.dev.device.matching.subject.domin.MatchingDeviceBill;
import com.tykj.dev.device.packing.service.PackingLibraryService; import com.tykj.dev.device.packing.service.PackingLibraryService;
import com.tykj.dev.device.packing.subject.domin.PackingLibrary;
import com.tykj.dev.device.repair.repository.RepairBackBillDao; import com.tykj.dev.device.repair.repository.RepairBackBillDao;
import com.tykj.dev.device.repair.repository.RepairSendBillDao; import com.tykj.dev.device.repair.repository.RepairSendBillDao;
import com.tykj.dev.device.repair.service.RepairBillService; import com.tykj.dev.device.repair.service.RepairBillService;
import com.tykj.dev.device.repair.service.RepairSendBillService;
import com.tykj.dev.device.repair.subject.domin.RepairBackBill; import com.tykj.dev.device.repair.subject.domin.RepairBackBill;
import com.tykj.dev.device.repair.subject.domin.RepairBill; import com.tykj.dev.device.repair.subject.domin.RepairBill;
import com.tykj.dev.device.repair.subject.domin.RepairSendBill; import com.tykj.dev.device.repair.subject.domin.RepairSendBill;
import com.tykj.dev.device.retired.entity.domain.DeviceRetiredBill;
import com.tykj.dev.device.retired.service.DeviceRetiredBillService; import com.tykj.dev.device.retired.service.DeviceRetiredBillService;
import com.tykj.dev.device.selfcheck.service.SelfCheckBillService; import com.tykj.dev.device.selfcheck.service.SelfCheckBillService;
import com.tykj.dev.device.selfcheck.subject.domin.SelfCheckBill;
import com.tykj.dev.device.sendback.entity.domain.SendBackBill;
import com.tykj.dev.device.sendback.repository.SendBackBillDao; import com.tykj.dev.device.sendback.repository.SendBackBillDao;
import com.tykj.dev.device.storage.service.StorageBillService; import com.tykj.dev.device.storage.service.StorageBillService;
import com.tykj.dev.device.storage.subject.domin.StorageBill; import com.tykj.dev.device.storage.subject.domin.StorageBill;
...@@ -46,14 +33,10 @@ import com.tykj.dev.device.task.subject.bto.TaskBto; ...@@ -46,14 +33,10 @@ import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.task.subject.bto.TaskLogBto; import com.tykj.dev.device.task.subject.bto.TaskLogBto;
import com.tykj.dev.device.train.dao.TrainThemeDao; import com.tykj.dev.device.train.dao.TrainThemeDao;
import com.tykj.dev.device.train.dao.WorkHandoverDao; import com.tykj.dev.device.train.dao.WorkHandoverDao;
import com.tykj.dev.device.train.entity.TrainTheme;
import com.tykj.dev.device.train.entity.WorkHandover;
import com.tykj.dev.device.train.service.TrainThemeService;
import com.tykj.dev.device.user.util.UserUtils; import com.tykj.dev.device.user.util.UserUtils;
import com.tykj.dev.misc.base.BeanHelper; import com.tykj.dev.misc.base.BeanHelper;
import com.tykj.dev.misc.base.StatusEnum; import com.tykj.dev.misc.base.StatusEnum;
import com.tykj.dev.misc.utils.SpringUtils; import com.tykj.dev.misc.utils.SpringUtils;
import com.tykj.dev.rfid.entity.domin.RfidChangeBill;
import com.tykj.dev.rfid.service.RfidChangeBillService; import com.tykj.dev.rfid.service.RfidChangeBillService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
...@@ -65,7 +48,6 @@ import org.modelmapper.ModelMapper; ...@@ -65,7 +48,6 @@ import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
......
...@@ -15,6 +15,5 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -15,6 +15,5 @@ import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = UnionApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = UnionApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc @AutoConfigureMockMvc
//@Transactional
public class BaseTest { public class BaseTest {
} }
package com.tykj.dev.device.user.base.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* AuExample.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/26 at 8:22 下午
*/
@AllArgsConstructor
@Getter
public enum AuExample {
/**
* 查询条件是area表的name字段
*/
AreaId("id", 1),
/**
* 查询条件是area表的name字段
*/
AreaName("name", 1),
/**
* 查询条件是area表的fatherId字段
*/
AreaFatherId("fatherId", 1),
/**
* 查询条件是unit表的unitId字段
*/
UnitId("unitId", 2),
/**
* 查询条件是unit表的name字段
*/
UnitName("name", 2);
private final String fieldName;
/**
* 1 = 地区 2 = 单位 ,根据type来决定查哪张表
*/
private final int type;
}
...@@ -32,6 +32,8 @@ public interface UnitsDao extends JpaRepository<Units, Integer>, JpaSpecificatio ...@@ -32,6 +32,8 @@ public interface UnitsDao extends JpaRepository<Units, Integer>, JpaSpecificatio
@Query("select o.areaId from Units o where o.unitId=?1") @Query("select o.areaId from Units o where o.unitId=?1")
int findAreaId(int id); int findAreaId(int id);
Units findByAreaIdAndLevel(Integer areaId , Integer level); Units findByAreaIdAndLevel(Integer areaId, Integer level);
Units findByAreaIdEquals(Integer areaId);
} }
...@@ -56,4 +56,8 @@ public class Area { ...@@ -56,4 +56,8 @@ public class Area {
return mapper.map(this, AreaVo.class); return mapper.map(this, AreaVo.class);
} }
public static Area empty(){
return new Area(0, "不存在的地区", 0, "0", 0);
}
} }
package com.tykj.dev.device.user.subject.entity.bto;
import com.google.common.collect.Lists;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Units;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* AreaUnit.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/26 at 8:11 下午
*/
@Data
@NoArgsConstructor
public class AreaUnit {
private Integer id;
private String name;
private Integer type;
private String orders;
private Integer fatherId;
/**
* 默认等于{@link #unitList}里的第一个元素
*/
private Unit unit;
/**
* 为以后的扩展准备,防止一个地区有多个单位出现
*/
private List<Unit> unitList;
public AreaUnit(Area area, Units units) {
this.id = area.getId();
this.name = area.getName();
this.type = area.getType();
this.orders = area.getOrders();
this.fatherId = area.getFatherId();
this.unit = new Unit(units.getUnitId(), units.getName(), units.getUnitDesc(), units.getCode());
this.unitList = Lists.newArrayList(this.unit);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
class Unit {
private Integer unitId;
private String name;
private String unitDesc;
private String code;
}
}
package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.base.enums.AuExample;
import com.tykj.dev.device.user.subject.entity.bto.AreaUnit;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* AuService.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/26 at 8:28 下午
*/
public interface AuService {
List<AreaUnit> findAll(AuExample example, Object value);
AreaUnit findOne(AuExample example, Object value);
}
package com.tykj.dev.device.user.subject.service.impl;
import com.github.wenhao.jpa.Specifications;
import com.tykj.dev.device.user.base.enums.AuExample;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.entity.bto.AreaUnit;
import com.tykj.dev.device.user.subject.service.AuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* AuServiceImpl.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/26 at 8:29 下午
*/
@Service
public class AuServiceImpl implements AuService {
@Autowired
private AreaDao areaRepo;
@Autowired
private UnitsDao unitsRepo;
@Override
public List<AreaUnit> findAll(AuExample example, Object value) {
//解析条件
if (example.getType() == 1) {
Specification<Area> pred = Specifications.<Area>and()
.eq(Objects.nonNull(value), example.getFieldName(), value)
.build();
List<Area> areaList = areaRepo.findAll(pred);
List<AreaUnit> areaUnits = new ArrayList<>();
for (Area area : areaList) {
Units units = unitsRepo.findByAreaId(area.getId()).get(0);
areaUnits.add(new AreaUnit(area, units));
}
return areaUnits;
} else {
Specification<Units> pred = Specifications.<Units>and()
.eq(Objects.nonNull(value), example.getFieldName(), value)
.build();
List<Units> unitList = unitsRepo.findAll(pred);
List<AreaUnit> areaUnits = new ArrayList<>();
for (Units units : unitList) {
Area area = areaRepo.findById(units.getAreaId()).get();
areaUnits.add(new AreaUnit(area, units));
}
return areaUnits;
}
}
@Override
public AreaUnit findOne(AuExample example, Object value) {
if (example.getType() == 1) {
Specification<Area> pred = Specifications.<Area>and()
.eq(Objects.nonNull(value), example.getFieldName(), value)
.build();
Area area = areaRepo.findOne(pred).orElse(Area.empty());
Units units = unitsRepo.findByAreaIdEquals(area.getId());
return new AreaUnit(area, units);
} else {
Specification<Units> pred = Specifications.<Units>and()
.eq(Objects.nonNull(value), example.getFieldName(), value)
.build();
Units units = unitsRepo.findOne(pred).get();
Area area = areaRepo.findById(units.getAreaId()).get();
return new AreaUnit(area, units);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论