提交 64c506e5 authored 作者: Matrix's avatar Matrix

[核查模块] 重构1.0

上级 d60337ae
......@@ -11,5 +11,19 @@
<artifactId>device-confitmcheck</artifactId>
<dependencies>
<dependency>
<groupId>com.tykj.dev</groupId>
<artifactId>device-task</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.tykj.dev</groupId>
<artifactId>device-library</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.tykj.dev.device.confirmcheck.common;
import lombok.AllArgsConstructor;
/**
* AreaLevel.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/16 at 7:03 下午
*/
@AllArgsConstructor
public enum AreaLevel {
PROVINCE(1, "省级"),
CITY(2, "市级"),
COUNTY(3, "县级");
public int id;
public String name;
}
package com.tykj.dev.device.confirmcheck.controller;
import com.tykj.dev.config.swagger.AutoDocument;
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.entity.vo.*;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckBillDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckStatRepo;
import com.tykj.dev.device.confirmcheck.utils.ObjTransUtil;
import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.task.repository.TaskDao;
import com.tykj.dev.device.task.service.TaskService;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.task.subject.common.GlobalMap;
import com.tykj.dev.device.task.subject.common.StatusEnum;
import com.tykj.dev.device.task.subject.domin.Task;
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.Units;
import com.tykj.dev.device.user.subject.entity.User;
import com.tykj.dev.device.user.util.AuthenticationUtils;
import com.tykj.dev.misc.base.ResultObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static com.tykj.dev.device.task.subject.common.BusinessEnum.CONFIRM_CHECK_DETAIL;
import static com.tykj.dev.device.task.subject.common.BusinessEnum.CONFIRM_CHECK_STAT;
import static com.tykj.dev.device.task.subject.common.StatusEnum.CHECK_DETAIL_0;
import static com.tykj.dev.misc.utils.TimestampUtil.localDateToDate;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
/**
* @author dengdiyi
*/
@RestController
@RequestMapping(value = "/check/confirm")
@AutoDocument
@Api(tags = "核查模块")
@Transactional(rollbackFor = Exception.class)
public class DeviceCheckController {
@Autowired
private DeviceCheckStatRepo statRepo;
@Autowired
private DeviceCheckBillDao billRepo;
@Autowired
private AreaDao areaRepo;
@Autowired
private UnitsDao unitsRepo;
@Autowired
private DeviceLibraryDao deviceRepo;
@Autowired
private DeviceCheckDetailDao detailRepo;
@Autowired
private ObjTransUtil transUtil;
@Autowired
private TaskDao taskRepo;
@Autowired
private TaskService taskService;
@GetMapping("/area/{fatherId}")
@ApiOperation(value = "查询指定区域下的所有区域信息")
public ResultObj findAreaUnderId(@PathVariable Integer fatherId) {
return new ResultObj(areaRepo.findByFatherId(fatherId));
}
@ApiOperation(value = "根据id查询核查统计数据", notes = "可以通过这个接口查询核查统计数据")
@GetMapping("/stat/{id}")
public ResultObj findStatById(@PathVariable Integer id) {
//还要查询出所有的
CheckStatVo statVoList = statRepo.findById(id)
.map(DeviceCheckStat::toVo)
.orElse(CheckStatVo.empty());
return new ResultObj(statVoList);
}
@ApiOperation(value = "根据id查询核查详情数据", notes = "可以通过这个接口查询核查详情数据")
@GetMapping("/detail/{id}")
public ResultObj findDetail(@PathVariable Integer id) {
CheckDetailVo detailVoList = detailRepo.findById(id)
.map(transUtil::CheckDetailDo2Vo)
.orElse(null);
return new ResultObj(detailVoList);
}
/**
* 手动发起核查
* <li>1. 添加发起核查bill记录</>
* <li>2. 构建发起单位的统计账单与Task</>
* <li>3. 构建被核查单位的详情账单与Task</li>
*
* @param billVo 核查发起对象
*/
@ApiOperation(value = "发起核查", notes = "发起核查流程")
@PostMapping("/check/bill")
public ResultObj startManualCheck(@RequestBody CheckBillVo billVo) {
// 1. 添加发起核查bill记录
DeviceCheckBillEntity billDo = transUtil.checkBillVo2Do(billVo);
billRepo.save(billDo);
// 2 构建发起单位的 统计账单 与 统计任务
Integer startUnitId = billVo.getUnitId();
Units startUnit = unitsRepo.findById(startUnitId).get();
List<Units> checkedUnits = unitsRepo.findByAreaIdIn(billVo.getAreaRange());
List<String> checkedUnitNames = checkedUnits.stream().map(Units::getName).collect(toList());
// 2-1 构建发起单位的 统计账单
DeviceCheckStat provinceCheckStat = initStatData(startUnit.getName(), checkedUnits);
Integer billId = statRepo.save(provinceCheckStat).getId();
// 2-2 构建发起单位的 统计任务
TaskBto provStatTask = new Task(CONFIRM_CHECK_STAT.name, 0, ".0.", CONFIRM_CHECK_STAT.id, billId, startUnitId)
.parse2Bto();
taskService.start(provStatTask);
// 3 构建被查单位的 自查账单 与 自查任务
// 获取所有在库装备与不在库装备
Map<String, List<DeviceLibrary>> devInLib = deviceRepo.findAll().stream()
.filter(device -> device.getOwnUnit().equals(device.getLocationUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit));
Map<String, List<DeviceLibrary>> devNotInLib = deviceRepo.findAll().stream()
.filter(device -> !device.getOwnUnit().equals(device.getLocationUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit));
// 3. 构建被核查单位的详情账单与Task
// 对每个需要核查的单位构建其detail账单与task
for (Units unit : checkedUnits) {
// 3-1 构建被查单位的 自查账单
DeviceCheckDetailEntity unitDetailDoc = DeviceCheckDetailEntity.EmptyWithChecker(billVo.getUserAId(), billVo.getUserBId(), 0, 0, unit.getName(), devInLib.get(unit.getName()), devNotInLib.get(unit.getName()));
DeviceCheckDetailEntity detail = detailRepo.save(unitDetailDoc);
// 3-1 构建被查单位的 自查任务 (根据被查单位的级别来区分是县级状态是市级状态)
TaskBto checkedTask = new TaskBto(CHECK_DETAIL_0.id, "自核查任务", provStatTask.getId(), addNode(provStatTask.getNodeIdDetail(), provStatTask.getId()), CONFIRM_CHECK_DETAIL.id, detail.getId(), unit.getUnitId(), 0);
taskService.start(checkedTask);
}
return new ResultObj(String.format("[%s]单位成功发起对 %s 单位的核查任务分发", startUnit.getName(), checkedUnitNames));
}
/**
* 对于专员A来说的逻辑
* 1. 修改detailString
* 2. 更新task状态
* 3. 更新job状态(完成A的job,同时发起b的job)
*
* @param assignUserId 指定专管员B来接受这件事
*/
@ApiOperation(value = "专管员A核查详情单")
@PutMapping("/detail/A/{id}")
public ResponseEntity checkUserA(@PathVariable Integer id,
@RequestParam int assignUserId,
@RequestParam String checkResult,
@RequestBody DevLibVo devLibVo) {
//1. 更新checkDetail
String detailString = transUtil.devLib2String(devLibVo.getDevInLibrary(), devLibVo.getDevNotInLibrary());
User currentUser = Objects.requireNonNull(AuthenticationUtils.getAuthentication()).getCurrentUserInfo();
detailRepo.updateCheckDetail(id, detailString, checkResult, currentUser.getUserId(), assignUserId);
//2. 推进TASK 状态
TaskBto currentTask = taskService.get(id, CONFIRM_CHECK_DETAIL.id);
taskService.moveToNext(currentTask);
return ResponseEntity.ok(new ResultObj("专管员A操作成功"));
}
/**
* 对于专管员B来说的逻辑
*/
@ApiOperation(value = "专管员B核查详情单")
@PutMapping("/detail/B/{id}")
public ResponseEntity checkUserA(@PathVariable Integer id,
@RequestParam int checkStatus,
@RequestParam(required = false, defaultValue = "0") int checkUserAId,
@RequestParam(required = false, defaultValue = "0") int checkUserBId) {
if (checkStatus == 0) {
return ResponseEntity.status(400).body("checkStatus不应该为0!");
}
//先更新checkUser
if (checkUserAId > 0 && checkUserBId > 0) {
detailRepo.updateCheckUser(id, checkUserAId, checkUserBId);
}
// 审核通过与不通过的逻辑不同
TaskBto currentTask = taskService.get(id, CONFIRM_CHECK_DETAIL.id);
if (checkStatus == 1) {
//依据detail账单对应的checkUserId来判断是2流程还是多流程的
DeviceCheckDetailEntity detailDo = detailRepo.findById(id).get();
Integer userAId = detailDo.getCheckUserAId();
Integer userBId = detailDo.getCheckUserBId();
// 如果是4流程的,则需要指定核查组成员A接任务
if (userAId > 0 && userBId > 0) {
detailRepo.updateCheckStatus(id, checkStatus);
taskService.moveToNext(currentTask, checkUserAId);
} else {
// 如果是2流程的,则直接结束该任务
detailRepo.updateCheckStatus(id, checkStatus);
taskService.moveToEnd(currentTask);
}
} else {
//不通过则回到第一阶段
StatusEnum firstStatus = getFirstStatus(currentTask.getBillStatus());
taskService.moveToSpecial(currentTask, firstStatus, currentTask.getFirstUserId());
}
return ResponseEntity.ok(new ResultObj("专管B操作成功"));
}
@ApiOperation(value = "核查组A/B确认核查详情单")
@PutMapping("/detail/C/{id}")
public ResponseEntity checkUserC(@PathVariable Integer id,
@RequestParam boolean pass) {
TaskBto currentTask = taskService.get(id, CONFIRM_CHECK_DETAIL.id);
DeviceCheckDetailEntity currentDetail = detailRepo.findById(id).get();
if (pass) {
// 如果当前是第3步(利用余数来判断),则需要指定核查组B的人来接受任务
if (currentTask.getBillStatus() % 10 == 2) {
currentTask = taskService.moveToNext(currentTask, currentDetail.getCheckUserBId());
}
// 如果当前是第4步,则直接结束任务,并且进行结果汇总
if (currentTask.getBillStatus() % 10 == 3) {
currentTask = taskService.moveToEnd(currentTask);
// 任务结束后需要将当前城市的统计信息汇总上去
Units units = unitsRepo.findById(currentTask.getOwnUnit()).get();
int level = units.getLevel();
// 先找到汇总地区的账单id 查询当前detail task 的 父级TASK
Integer fatherTaskId = currentTask.getParentTaskId();
int statId = taskRepo.findBillId(fatherTaskId, CONFIRM_CHECK_STAT.id);
// 获得当前城市的统计信息 以及 要汇总的地区信息 并累加保存
List<CheckDeviceStatVo> addVos = parseStatString2Vo(currentTask, level, currentDetail.getCheckDetail());
CheckStatVo resultVo = statRepo.findById(statId).get().toVo();
resultVo.setDeviceStatVoList(accumulateStat(addVos, resultVo.getDeviceStatVoList()));
statRepo.save(resultVo.toDo());
// 判断地区数据是否均汇总完毕
boolean over = taskService.TaskTreeIsOver(fatherTaskId);
// 如果汇总完毕则将父级的统计任务推进
if (over) {
TaskBto fatherTask = taskService.get(fatherTaskId);
taskService.moveToNext(fatherTask, fatherTask.getLastUserId());
}
}
} else {
// 如果没通过则返回第1步
StatusEnum firstStatus = getFirstStatus(currentTask.getBillStatus());
taskService.moveToSpecial(currentTask, firstStatus, currentTask.getFirstUserId());
}
return ResponseEntity.ok(new ResultObj("操作成功"));
}
@ApiOperation(value = "统计数据确认")
@PostMapping("/stat/verify")
public ResponseEntity statConfirm(@RequestParam int statId,
@RequestParam int areaId) {
//将当前的统计task完结
TaskBto currentTask = taskService.get(CONFIRM_CHECK_STAT.id, statId);
taskService.moveToEnd(currentTask);
//如果有上级统计任务 则累加当前地区数据
Integer parentTaskId = currentTask.getParentTaskId();
boolean hasParent = parentTaskId != 0;
if (hasParent) {
// 累加当前地区数据
TaskBto parentTask = taskService.get(parentTaskId);
CheckStatVo cityStat = statRepo.findById(statId).get().toVo();
CheckStatVo provinceStat = statRepo.findById(parentTask.getBillId()).get().toVo();
List<CheckDeviceStatVo> accStat = accumulateStat(cityStat.getDeviceStatVoList(), provinceStat.getDeviceStatVoList());
provinceStat.setDeviceStatVoList(accStat);
statRepo.save(provinceStat.toDo());
// 如果所有子地区统计任务都已经完结,则推进父地区统计任务进度
boolean allOver = taskService.TaskTreeIsOver(parentTaskId);
if (allOver) {
taskService.moveToEnd(parentTask);
}
}
return ResponseEntity.ok(new ResultObj("统计数据确认完毕"));
}
/**
* 获取指定任务的第一步的任务状态
*
* @param currentStatusId 任务状态id
*/
private StatusEnum getFirstStatus(Integer currentStatusId) {
int remainder = currentStatusId % 10;
return GlobalMap.getStatusEnumMap().get(currentStatusId - remainder);
}
private List<CheckDeviceStatVo> accumulateStat(List<CheckDeviceStatVo> originalVos, List<CheckDeviceStatVo> addVos) {
for (CheckDeviceStatVo originalVo : originalVos) {
for (CheckDeviceStatVo addVo : addVos) {
if (originalVo.getDeviceModel().equals(addVo.getDeviceModel())) {
addVo.add(originalVo);
}
}
}
return addVos;
}
public List<CheckDeviceStatVo> parseStatString2Vo(TaskBto task, int cityLevel, String statString) {
List<CheckDeviceStatVo> statVoList = new ArrayList<>();
//分为 id - status 的数组 其中status 0缺失 1无误 2新增 3不在库
String[] statArray = statString.split(",");
//将 id - status 转化为 model - count - status(只统计新增和无误的作为数量)
for (String s : statArray) {
String[] device = s.split("-");
int deviceId = Integer.parseInt(device[0]);
int deviceStatus = Integer.parseInt(device[1]);
DeviceLibrary checkDevice = deviceRepo.findById(deviceId).get();
//查询出地区对应的统计账单与详情账单
// 如果是level为3的城市,那么可以通过taskId获得详情id
int statId = 0;
int detailId = 0;
if (cityLevel == 3) {
Integer resultDetailId = taskRepo.findBillIdByTaskId(task.getId());
detailId = resultDetailId == null ? 0 : resultDetailId;
}
// 如果是level为2的城市,可以通过unitId以及fatherId获得统计
if (cityLevel == 2) {
Integer resultDetailId = taskRepo.findBillIdByTaskId(task.getId());
detailId = resultDetailId == null ? 0 : resultDetailId;
Integer resultStatId = taskRepo.findBillId(task.getParentTaskId(), CONFIRM_CHECK_STAT.id);
statId = resultStatId == null ? 0 : resultStatId;
}
// 根据unitId 查到 areaId 根据 areaId 查询到 areaName
int areaId = unitsRepo.findAreaId(task.getOwnUnit());
String areaName = areaRepo.findNameById(areaId);
CheckAreaStatVo checkAreaStatVo;
if (deviceStatus == 1) {
checkAreaStatVo = new CheckAreaStatVo(areaName, 1, 1, 2, 0, statId, detailId);
} else {
checkAreaStatVo = new CheckAreaStatVo(areaName, 1, 1, 2, 1, statId, detailId);
}
List<CheckAreaStatVo> areaStatVoList = new ArrayList<>();
areaStatVoList.add(checkAreaStatVo);
statVoList.add(new CheckDeviceStatVo(checkDevice.getModel(), checkDevice.getName(), 1, areaStatVoList));
}
return statVoList;
}
/**
* 构建初始化核查统计数据
* 依据不同地区装备的在库情况构造出舒适化的统计数据出来
*
* @param startUnitName 发起核查的单位名
* @param unitsList 被核查单位列表
*/
private DeviceCheckStat initStatData(String startUnitName, List<Units> unitsList) {
//获得要被统计的单位名列表
List<String> unitNameList = unitsList.stream().map(Units::getName).collect(toList());
Map<String, List<DeviceLibrary>> modelMap = deviceRepo.findAll()
.stream()
.collect(groupingBy(DeviceLibrary::getModel));
//查询所有装备-按照型号分组-遍历每一组型号的装备,过滤出所属在指定单位的装备,并按照单位名称分组
List<CheckDeviceStatVo> checkDeviceStatVos = new ArrayList<>();
modelMap.forEach((model, deviceModelList) -> {
//按照市级区域分组
Map<String, List<DeviceLibrary>> unitMap = deviceModelList.stream()
.filter(device -> unitNameList.contains(device.getOwnUnit()))
.collect(groupingBy(DeviceLibrary::getOwnUnit));
List<CheckAreaStatVo> areaStatVoList = new ArrayList<>();
// 遍历每个地区的该型号的装备 -> 构造出该地区的该型号的初始数据
unitMap.forEach((unitName, devices) -> {
//unitName map to area
int areaId = unitsRepo.findAreaIdByName(unitName);
String areaName = areaRepo.findNameById(areaId);
areaStatVoList.add(new CheckAreaStatVo(areaName, 0, devices.size(), 0, 0, 0, 0));
});
//构造出各型号装备的list - 如果该型号的装备在所有地区都没有,那么就不添加这条数据
if (!CollectionUtils.isEmpty(areaStatVoList)) {
checkDeviceStatVos.add(new CheckDeviceStatVo(model, deviceModelList.get(0).getName(), deviceModelList.size(), areaStatVoList));
}
});
//构造最终数据
LocalDate startTime = LocalDate.now();
LocalDate endTime = startTime.plusMonths(1);
return new CheckStatVo(null,
"2020年下半年核查--" + startUnitName,
startUnitName + "待核查装备统计",
localDateToDate(startTime),
localDateToDate(endTime),
checkDeviceStatVos).toDo();
}
private String addNode(String originalNode, Integer fatherId) {
return originalNode + fatherId + ".";
}
}
package com.tykj.dev.device.confirmcheck.entity.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
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.*;
import java.util.Date;
/**
* entity class for device_check_bill
* 装备核查账单
*/
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update device_check_bill set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("装备核查账单")
@Table(name = "device_check_bill", schema = "device_check_bill")
@NoArgsConstructor
public class DeviceCheckBillEntity {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", columnDefinition = "not null int(11) 主键id")
@ApiModelProperty(name = "主键id")
private Integer id;
/**
* 检查组成员1(省A岗)id
*/
@Column(name = "userA_id", columnDefinition = "not null int(11) 检查组成员1(省A岗)id")
@ApiModelProperty(value = "检查组成员1(省A岗)id")
private Integer userAId;
/**
* 检查组成员2(省A岗)id
*/
@Column(name = "userB_id", columnDefinition = "not null int(11) 检查组成员2(省A岗)id")
@ApiModelProperty(value = "检查组成员2(省A岗)id")
private Integer userBId;
/**
* 核查状态(0:决算待审核,1:决算审核失败,2:决算中,3:决算完成)
*/
@Column(name = "check_status", columnDefinition = "not null int(11) 核查状态(0:决算待审核,1:决算审核失败,2:决算中,3:决算完成)")
@ApiModelProperty(value = "核查状态(0:决算待审核,1:决算审核失败,2:决算中,3:决算完成)")
private Integer checkStatus;
/**
* 核查单位主键id(x作为分隔符),例如1x2,意为单位id为1和2的装备核查
*/
@Column(name = "check_detail", columnDefinition = "not null text 核查单位主键id(x作为分隔符),例如1x2,意为单位id为1和2的装备核查")
@ApiModelProperty(value = "核查单位主键id(x作为分隔符),例如1x2,意为单位id为1和2的装备核查")
private String checkDetail;
/**
* 核查标题
*/
@Column(name = "check_title", columnDefinition = "not null varchar(32) 核查标题")
@ApiModelProperty(value = "核查标题")
private String checkTitle;
/**
* 备注
*/
@Column(name = "remark", columnDefinition = "not null varchar(255) 备注")
@ApiModelProperty(value = "备注")
private String remark;
/**
* 创建用户id
*/
@CreatedBy
@Column(name = "create_user_id", columnDefinition = "not null int(11) 创建用户id")
@ApiModelProperty(value = "创建用户id")
private Integer createUserId;
/**
* 创建时间
*/
@CreatedDate
@Column(name = "create_time", columnDefinition = "not null datetime 创建时间")
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 更新用户id
*/
@LastModifiedBy
@Column(name = "update_user_id", columnDefinition = "not null int(11) 更新用户id")
@ApiModelProperty(value = "更新用户id")
private Integer updateUserId;
/**
* 更新时间
*/
@LastModifiedDate
@Column(name = "update_time", columnDefinition = "not null datetime 更新时间")
@ApiModelProperty(value = "更新时间")
private Date updateTime;
/**
* 删除标记(0:未删除,1:已删除)
*/
@Column(name = "delete_tag", columnDefinition = "not null int(11) 删除标记(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) {
this.userAId = userAId;
this.userBId = userBId;
this.checkStatus = checkStatus;
this.checkDetail = checkDetail;
this.checkTitle = checkTitle;
this.remark = remark;
}
}
package com.tykj.dev.device.confirmcheck.entity.domain;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.misc.utils.TimestampUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
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 org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* entity class for device_check_detail
* 核查详情
*/
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update device_check_detail set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("核查详情")
@Table(name = "device_check_detail", schema = "device_check_detail")
@NoArgsConstructor
public class DeviceCheckDetailEntity {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", columnDefinition = "not null int(11) 主键id")
@ApiModelProperty(name = "主键id")
private Integer id;
/**
* 核查账单id
*/
@Column(name = "final_check_id", columnDefinition = "not null int(11) 核查账单id")
@ApiModelProperty(value = "核查账单id")
private Integer finalCheckId;
/**
* 检查组成员1(省A岗)id
*/
@Column(name = "check_userA_id", columnDefinition = "not null int(11) 检查组成员1(省A岗)id")
@ApiModelProperty(value = "检查组成员1(省A岗)id")
private Integer checkUserAId = 0;
/**
* 检查组成员2(省A岗)id
*/
@Column(name = "check_userB_id", columnDefinition = "not null int(11) 检查组成员2(省A岗)id")
@ApiModelProperty(value = "检查组成员2(省A岗)id")
private Integer checkUserBId = 0;
/**
* 本级经办人id(A岗)
*/
@Column(name = "userA_id", columnDefinition = "not null int(11) 本级经办人id(A岗)")
@ApiModelProperty(value = "本级经办人id(A岗)")
private Integer userAId;
/**
* 本级审核人id(B岗)
*/
@Column(name = "userB_id", columnDefinition = " null int(11) 本级审核人id(B岗)")
@ApiModelProperty(value = "本级审核人id(B岗)")
private Integer userBId;
/**
* 核查时间
*/
@Column(name = "check_time", columnDefinition = " null date 核查时间")
@ApiModelProperty(value = "核查时间")
private Date checkTime;
/**
* 核查单位
*/
@Column(name = "check_unit", columnDefinition = "not null varchar(32) 核查单位")
@ApiModelProperty(value = "核查单位")
private String checkUnit;
/**
* 应查数量
*/
@Column(name = "checking_count", columnDefinition = "not null int(11) 应查数量")
@ApiModelProperty(value = "应查数量")
private Integer checkingCount;
/**
* 实查数量
*/
@Column(name = "checked_count", columnDefinition = "null int(11) 实查数量")
@ApiModelProperty(value = "实查数量")
private Integer checkedCount;
/**
* 核查结果
*/
@Column(name = "check_result", columnDefinition = "null varchar(32) 核查结果")
@ApiModelProperty(value = "核查结果")
private String checkResult;
/**
* 核查详情(装备主键id+核对结果(0缺失1无误2新增,字符-作为状态分隔符字符,作为分隔符))
*/
@Column(name = "check_detail", columnDefinition = "null text 核查详情")
@ApiModelProperty(value = "核查详情(装备主键id+核对结果(0缺失1无误2新增3不在库9未检查,字符x作为分隔符)),例如1-2,2-2,意为主键id为1的装备缺失,为2的无误,为3的新增")
private String checkDetail;
/**
* 核查状态(0:待核查,1:审核失败,2:核查完成)
*/
@Column(name = "check_status", columnDefinition = "not null int(11) 核查状态(0:待核查,1:审核失败,2:核查完成)")
@ApiModelProperty(value = "核查状态(0:待核查,1:审核失败,2:核查完成)")
private Integer checkStatus;
/**
* 创建用户id
*/
@CreatedBy
@Column(name = "create_user_id", columnDefinition = "not null int(11) 创建用户id")
@ApiModelProperty(value = "创建用户id")
private Integer createUserId;
/**
* 创建时间
*/
@CreatedDate
@Column(name = "create_time", columnDefinition = "not null datetime 创建时间")
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 更新用户id
*/
@LastModifiedBy
@Column(name = "update_user_id", columnDefinition = "not null int(11) 更新用户id")
@ApiModelProperty(value = "更新用户id")
private Integer updateUserId;
/**
* 更新时间
*/
@LastModifiedDate
@Column(name = "update_time", columnDefinition = "not null datetime 更新时间")
@ApiModelProperty(value = "更新时间")
private Date updateTime;
/**
* 删除标记(0:未删除,1:已删除)
*/
@Column(name = "delete_tag", columnDefinition = "not null int(11) 删除标记(0:未删除,1:已删除)")
@ApiModelProperty(value = "删除标记(0:未删除,1:已删除)")
private Integer deleteTag = 0;
/**
* 预留字段1
*/
@Column(name = "remark", columnDefinition = "null varchar(255) 备注")
@ApiModelProperty(value = "备注")
private String remark;
/**
* 预留字段2
*/
@Column(name = "var2", columnDefinition = "null varchar(255) 预留字段2")
@ApiModelProperty(value = "预留字段2")
private String var2;
@ApiModelProperty(value = "核查标题")
@Transient
private String title;
@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) {
this.finalCheckId = finalCheckId;
this.checkTime = checkTime;
this.checkUnit = checkUnit;
this.checkingCount = checkingCount;
this.checkedCount = checkedCount;
this.checkResult = checkResult;
this.checkDetail = checkDetail;
this.checkStatus = checkStatus;
}
/**
* 用于生成县级的核查详情账单的构造函数
*/
public DeviceCheckDetailEntity(Integer finalCheckId,
Integer checkUserAId,
Integer checkUserBId,
Integer userAId,
Integer userBId,
Date checkTime,
String checkUnit,
Integer checkingCount,
Integer checkedCount,
String checkResult,
String checkDetail,
Integer checkStatus) {
this.finalCheckId = finalCheckId;
this.checkUserAId = checkUserAId;
this.checkUserBId = checkUserBId;
this.userAId = userAId;
this.userBId = userBId;
this.checkTime = checkTime;
this.checkUnit = checkUnit;
this.checkingCount = checkingCount;
this.checkedCount = checkedCount;
this.checkResult = checkResult;
this.checkDetail = checkDetail;
this.checkStatus = checkStatus;
}
/**
* @param checkUnit 要核查的单位
* @param goodDevices 所属与所在均在本单位的装备集合
* @param badDevices 所属在,但所在不在本单位的装备集合
* @return 初始化的账单(还没有被人修改过的)
*/
public static DeviceCheckDetailEntity Empty(String checkUnit, List<DeviceLibrary> goodDevices, List<DeviceLibrary> badDevices) {
//构造checkDetail 分当前在库与不在库的 赋予不同状态
String goodCheckDetail = goodDevices.stream()
.map(DeviceLibrary::getId)
.map(Objects::toString)
.collect(Collectors.joining("-2,"));
String badCheckDetail = badDevices.stream()
.map(DeviceLibrary::getId)
.map(Objects::toString)
.collect(Collectors.joining("-3,"));
//如果不在库的不为空,则拼接,否则没必要
String checkDetail = StringUtils.isEmpty(badCheckDetail) ? goodCheckDetail : goodCheckDetail + "," + badCheckDetail;
return new DeviceCheckDetailEntity(
0,
0,
0,
0,
0,
TimestampUtil.getNowDate(),
checkUnit,
goodDevices.size(),
0,
"",
checkDetail,
0
);
}
public static DeviceCheckDetailEntity EmptyWithChecker(
Integer checkUserA,
Integer checkUserB,
Integer userAId,
Integer userBId,
String checkUnit,
List<DeviceLibrary> goodDevices,
List<DeviceLibrary> badDevices) {
//构造checkDetail 分当前在库与不在库的 赋予不同状态
String goodCheckDetail = "";
if (!CollectionUtils.isEmpty(goodDevices)) {
goodCheckDetail = goodDevices.stream()
.map(device -> device.getId() + "-9")
.collect(Collectors.joining(","));
}
String badCheckDetail = "";
if (!CollectionUtils.isEmpty(badDevices)) {
badCheckDetail = badDevices.stream()
.map(device -> device.getId() + "-3")
.collect(Collectors.joining(","));
}
//如果不在库的不为空,则拼接,否则没必要
String checkDetail = StringUtils.isEmpty(badCheckDetail) ? goodCheckDetail : goodCheckDetail + "," + badCheckDetail;
return new DeviceCheckDetailEntity(
0,
checkUserA,
checkUserB,
userAId,
userBId,
TimestampUtil.getNowDate(),
checkUnit,
goodDevices.size(),
0,
"",
checkDetail,
0
);
}
}
package com.tykj.dev.device.confirmcheck.entity.domain;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckDeviceStatVo;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckStatVo;
import com.tykj.dev.misc.base.BeanHelper;
import com.tykj.dev.misc.utils.JacksonUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.modelmapper.ModelMapper;
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.*;
import java.util.Arrays;
import java.util.Date;
/**
* DeviceCheckStat.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/15 at 7:09 下午
*/
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update device_check_stat set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("装备核查统计")
@Table(name = "device_check_stat", schema = "device_check_stat")
@NoArgsConstructor
public class DeviceCheckStat {
/**
* 主键
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/**
* 父标题
*/
private String title;
/**
* 子标题
*/
private String subtitle;
/**
* 开始时间
*/
private Date startTime;
/**
* 结束时间
*/
private Date endTime;
/**
* 统计信息以JSON形式存储
*/
private String statInfo;
/**
* 创建用户id
*/
@CreatedBy
@Column(name = "create_user_id", columnDefinition = "not null int(11) 创建用户id")
@ApiModelProperty(value = "创建用户id")
private Integer createUserId;
/**
* 创建时间
*/
@CreatedDate
@Column(name = "create_time", columnDefinition = "not null datetime 创建时间")
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 更新用户id
*/
@LastModifiedBy
@Column(name = "update_user_id", columnDefinition = "not null int(11) 更新用户id")
@ApiModelProperty(value = "更新用户id")
private Integer updateUserId;
/**
* 更新时间
*/
@LastModifiedDate
@Column(name = "update_time", columnDefinition = "not null datetime 更新时间")
@ApiModelProperty(value = "更新时间")
private Date updateTime;
/**
* 删除标记(0:未删除,1:已删除)
*/
@Column(name = "delete_tag", columnDefinition = "not null int(11) 删除标记(0:未删除,1:已删除)")
@ApiModelProperty(value = "删除标记(0:未删除,1:已删除)")
private Integer deleteTag = 0;
public DeviceCheckStat(String title, String subtitle, Date startTime, Date endTime, String statInfo) {
this.title = title;
this.subtitle = subtitle;
this.startTime = startTime;
this.endTime = endTime;
this.statInfo = statInfo;
}
/**
* Do类转化为Vo类
*/
public CheckStatVo toVo() {
ModelMapper mapper = BeanHelper.getUserMapper();
//复制基本信息
CheckStatVo initialStat = mapper.map(this, CheckStatVo.class);
//解析JSON并赋值
CheckDeviceStatVo[] checkDeviceStatVos = JacksonUtil.readValue(this.statInfo, CheckDeviceStatVo[].class);
initialStat.setDeviceStatVoList(Arrays.asList(checkDeviceStatVos));
return initialStat;
}
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* CheckAreaStatVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/15 at 7:20 下午
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class CheckAreaStatVo {
/**
* 地区名
*/
private String areaName;
/**
* 实查数量
*/
private int actualCount;
/**
* 应查数量
*/
private int supposeCount;
/**
* 完成进度 0-待办 , 1-进行中, 2-已完成
*/
private int comProgress;
/**
* 完成情况 0-无误 1-有异常
*/
private int comSituation;
/**
* 该地区对应的统计账单id
*/
private int areaStatId;
/**
* 该地区对应的详情账单id
*/
private int areaDetailId;
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* CheckBillVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/17 at 6:20 下午
*/
@Data
@ApiModel("核查发起对象")
public class CheckBillVo {
@ApiModelProperty(name = "业务标题", example = "浙江省手动核查测试")
@JSONField(name = "title")
private String checkTitle;
@ApiModelProperty(name = "核查组成员A id", example = "1")
private Integer userAId;
@ApiModelProperty(name = "核查组成员B id", example = "2")
private Integer userBId;
@ApiModelProperty(name = "发起单位id", example = "1")
private Integer unitId;
@ApiModelProperty(name = "要核查的区域id数组", example = "[\"2\"]")
private List<Integer> areaRange;
@ApiModelProperty(name = "备注", example = "这是一段测试数据")
private String remark;
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
* CheckDetailVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/17 at 8:46 下午
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CheckDetailVo {
/**
* 主键id
*/
@ApiModelProperty(name = "主键id")
private Integer id;
/**
* 核查账单id
*/
@ApiModelProperty(value = "核查账单id")
private Integer finalCheckId;
/**
* 检查组成员1(省A岗) 名称
*/
@ApiModelProperty(value = "检查组成员1(省A岗)名称")
private String checkUserAName;
/**
* 检查组成员2(省A岗) 名称
*/
@ApiModelProperty(value = "检查组成员2(省A岗)名称")
private String checkUserBName;
/**
* 本级经办人名称(A岗)
*/
@ApiModelProperty(value = "本级经办人名称(A岗)")
private String userAName;
/**
* 本级审核人名称(B岗)
*/
@ApiModelProperty(value = "本级审核人名称(B岗)")
private String userBName;
/**
* 检查组成员1(省A岗)id
*/
@ApiModelProperty(value = "检查组成员1(省A岗)id")
private Integer checkUserAId;
/**
* 检查组成员2(省A岗)id
*/
@ApiModelProperty(value = "检查组成员2(省A岗)id")
private Integer checkUserBId;
/**
* 本级经办人id(A岗)
*/
@ApiModelProperty(value = "本级经办人id(A岗)")
private Integer userAId;
/**
* 本级审核人id(B岗)
*/
@ApiModelProperty(value = "本级审核人id(B岗)")
private Integer userBId;
/**
* 核查时间
*/
@ApiModelProperty(value = "核查时间")
private Date checkTime;
/**
* 核查单位
*/
@ApiModelProperty(value = "核查单位")
private String checkUnit;
/**
* 应查数量
*/
@ApiModelProperty(value = "应查数量")
private Integer checkingCount;
/**
* 实查数量
*/
@ApiModelProperty(value = "实查数量")
private Integer checkedCount;
/**
* 核查结果
*/
@ApiModelProperty(value = "核查结果")
private String checkResult;
@ApiModelProperty(value = "在库装备列表")
private List<DeviceInLibVo> devInLibrary;
@ApiModelProperty(value = "非在库装备列表")
private List<DeviceNotInLibVo> devNotInLibrary;
/**
* 核查状态(0:待核查,1:审核失败,2:核查完成)
*/
@ApiModelProperty(value = "核查状态(0:待核查,1:审核失败,2:核查完成)")
private Integer checkStatus;
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* CheckDeviceStatVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/15 at 7:18 下午
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
@Slf4j
public class CheckDeviceStatVo {
/**
* 装备型号
*/
private String deviceModel;
/**
* 装备名称
*/
private String deviceName;
/**
* 装备总数
*/
private int deviceCount;
/**
* 核查该型号装备的各地区统计情况
*/
private List<CheckAreaStatVo> areaStatList;
/**
* other的model一定要与本deviceModel相同
*/
public void add(CheckDeviceStatVo other) {
if (!deviceModel.equals(other.getDeviceModel())) {
log.warn("[核查] 合并统计的数据发现装备不统一的情况");
return;
}
deviceCount += other.getDeviceCount();
for (CheckAreaStatVo otherArea : other.getAreaStatList()) {
if (deviceModel.equals(other.getDeviceModel())) {
for (CheckAreaStatVo statVo : areaStatList) {
if (statVo.getAreaName().equals(otherArea.getAreaName())) {
statVo.setAreaName(otherArea.getAreaName());
statVo.setAreaStatId(otherArea.getAreaStatId());
statVo.setAreaDetailId(otherArea.getAreaDetailId());
statVo.setActualCount(statVo.getActualCount() + otherArea.getActualCount());
statVo.setSupposeCount(statVo.getSupposeCount() + otherArea.getSupposeCount());
statVo.setComProgress(otherArea.getComProgress());
statVo.setComSituation(otherArea.getComSituation());
}
}
}
}
}
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
import com.tykj.dev.misc.base.BeanHelper;
import com.tykj.dev.misc.utils.JacksonUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* DeviceCheckStatVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/15 at 7:13 下午
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CheckStatVo {
/**
* 主键
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/**
* 父标题
*/
private String title;
/**
* 子标题
*/
private String subtitle;
/**
* 开始时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date startTime;
/**
* 结束时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date endTime;
private Date createTime;
private Date updateTime;
private Integer createUserId;
private Integer updateUserId;
/**
* 核查装备详情
*/
private List<CheckDeviceStatVo> deviceStatVoList;
public CheckStatVo(Integer id, String title, String subtitle, Date startTime, Date endTime, List<CheckDeviceStatVo> deviceStatVoList) {
this.id = id;
this.title = title;
this.subtitle = subtitle;
this.startTime = startTime;
this.endTime = endTime;
this.deviceStatVoList = deviceStatVoList;
}
public static CheckStatVo empty() {
List<CheckDeviceStatVo> emptyList = new ArrayList<>();
return new CheckStatVo(0, "无指定数据", "无指定数据", null, null, emptyList);
}
/**
* Vo转Do
*/
public DeviceCheckStat toDo() {
ModelMapper mapper = BeanHelper.getUserMapper();
//复制基本信息
DeviceCheckStat initialStat = mapper.map(this, DeviceCheckStat.class);
//数据转JSON并赋值
String jsonString = JacksonUtil.toJSon(this.deviceStatVoList);
initialStat.setStatInfo(jsonString);
return initialStat;
}
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* DevLibVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/19 at 4:56 下午
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DevLibVo {
private List<DeviceInLibVo> devInLibrary;
private List<DeviceNotInLibVo> devNotInLibrary;
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* DeviceInLibVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/18 at 4:41 下午
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class DeviceInLibVo {
private int id;
private String model;
private String name;
private String seqNumber;
private String prodNumber;
private String rfidSurfaceId;
private String rfidCardId;
private int proofResult;
}
package com.tykj.dev.device.confirmcheck.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* DeviceNotInLibVo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/18 at 4:41 下午
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class DeviceNotInLibVo {
private int id;
private String model;
private String name;
private String seqNumber;
private String prodNumber;
private String rfidSurfaceId;
private String rfidCardId;
private String locationUnit;
private String ownUnit;
private int status;
}
package com.tykj.dev.device.confirmcheck.repository;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBillEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author dengdiyi
*/
public interface DeviceCheckBillDao extends JpaRepository<DeviceCheckBillEntity, Integer>, JpaSpecificationExecutor<DeviceCheckBillEntity> {
}
package com.tykj.dev.device.confirmcheck.repository;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetailEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
/**
* @author dengdiyi
*/
@Transactional
public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetailEntity, Integer>, JpaSpecificationExecutor<DeviceCheckDetailEntity> {
/**
* 根据id更新checkDetail
*
* @param id detail id
* @param checkDetail 要更新的检查结果
*/
@Modifying
@Query("update DeviceCheckDetailEntity o set o.checkDetail=?2,o.checkResult = ?3,o.userAId =?4,o.userBId=?5 where o.id=?1")
void updateCheckDetail(Integer id, String checkDetail, String checkResult, int userAId, int userBId);
@Modifying
@Query("update DeviceCheckDetailEntity o set o.checkStatus=?2 where o.id=?1")
int updateCheckStatus(int id, int checkStatus);
/**
* 更新 checkUserAId 与 checkUserBId
*
* @param id detailId
* @param checkUserAId 核查组成员A
* @param checkUserBId 核查组成员B
*/
@Modifying
@Query("update DeviceCheckDetailEntity o set o.checkUserAId =?2,o.checkUserBId=?3 where o.id =?1")
void updateCheckUser(int id, int checkUserAId, int checkUserBId);
}
package com.tykj.dev.device.confirmcheck.repository;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckStat;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* DeviceCheckStatRepo.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/16 at 5:26 下午
*/
@Repository
public interface DeviceCheckStatRepo extends JpaRepository<DeviceCheckStat, Integer> {
}
package com.tykj.dev.device.confirmcheck.utils;
import com.tykj.dev.device.task.subject.bto.TaskBto;
/**
* ObjConsUtil.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/2 at 2:02 下午
*/
public class ObjConsUtil {
public static TaskBto newTaskBto(Integer status,
String title,
Integer parentTaskId,
String nodeIdDetail,
Integer billId,
Integer ownUnit
) {
TaskBto taskBto = new TaskBto();
taskBto.setBillStatus(status);
taskBto.setTitle(title);
taskBto.setParentTaskId(parentTaskId);
taskBto.setNodeIdDetail(nodeIdDetail);
taskBto.setBillId(billId);
taskBto.setOwnUnit(ownUnit);
return taskBto;
}
}
package com.tykj.dev.device.confirmcheck.utils;
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.vo.CheckBillVo;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckDetailVo;
import com.tykj.dev.device.confirmcheck.entity.vo.DeviceInLibVo;
import com.tykj.dev.device.confirmcheck.entity.vo.DeviceNotInLibVo;
import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
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.dao.UserDao;
import com.tykj.dev.misc.base.BeanHelper;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* ObjTransUtil.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/17 at 8:45 下午
*/
@Component
public class ObjTransUtil {
@Autowired
private UserDao userRepo;
@Autowired
private DeviceLibraryDao deviceRepo;
@Autowired
private AreaDao areaRepo;
@Autowired
private UnitsDao unitRepo;
public DeviceCheckBillEntity checkBillVo2Do(CheckBillVo vo) {
ModelMapper modelMapper = BeanHelper.getUserMapper();
DeviceCheckBillEntity billDo = modelMapper.map(vo, DeviceCheckBillEntity.class);
billDo.setCheckStatus(0);
//areas -> unitIds -> unitStrings
String unitString = vo.getAreaRange().stream()
.flatMap(id -> unitRepo.findAllByAreaId(id).stream())
.map(units -> units.getUnitId().toString())
.collect(Collectors.joining("x"));
billDo.setCheckDetail(unitString);
return billDo;
}
public DeviceCheckDetailEntity checkDetailVo2Do(CheckDetailVo detailVo) {
ModelMapper modelMapper = BeanHelper.getUserMapper();
DeviceCheckDetailEntity detailDo = modelMapper.map(detailVo, DeviceCheckDetailEntity.class);
//将inLib与notInLib 的集合 转化为压缩字符串
String checkDetailString = devLib2String(detailVo.getDevInLibrary(), detailVo.getDevNotInLibrary());
detailDo.setCheckDetail(checkDetailString);
return detailDo;
}
public String devLib2String(List<DeviceInLibVo> inLibrary, List<DeviceNotInLibVo> notInLibrary) {
String inLibString = inLibrary.stream()
.map(lib -> String.format("%d-%d", lib.getId(), lib.getProofResult()))
.collect(Collectors.joining(","));
String notInLibString = notInLibrary.stream()
.map(lib -> String.format("%d-%d", lib.getId(), 3))
.collect(Collectors.joining(","));
//不为空则拼接
String checkDetailString = inLibString;
if (!CollectionUtils.isEmpty(notInLibrary)) {
checkDetailString = checkDetailString + notInLibString;
}
return checkDetailString;
}
public CheckDetailVo CheckDetailDo2Vo(DeviceCheckDetailEntity detailDo) {
//查询人物id
Integer checkUserAId = detailDo.getCheckUserAId();
Integer checkUserBId = detailDo.getCheckUserBId();
Integer userAId = detailDo.getUserAId();
Integer userBId = detailDo.getUserBId();
String checkUserAName = userRepo.findById(checkUserAId).orElse(null).getName();
String checkUserBName = userRepo.findById(checkUserBId).orElse(null).getName();
String userAName = "";
String userBName = "";
if (userAId != null && userAId != 0) {
userAName = userRepo.findById(userAId).orElse(null).getName();
}
if (userBId != null && userBId != 0) {
userBName = userRepo.findById(userBId).orElse(null).getName();
}
//解析核查详情 -> 获取id与核查结果
List<DeviceInLibVo> inLibVoList = new ArrayList<>();
List<DeviceNotInLibVo> notInLibVoList = new ArrayList<>();
String checkDetail = detailDo.getCheckDetail();
String[] detailArray = checkDetail.split(",");
for (String detail : detailArray) {
String[] array = detail.split("-");
Integer deviceId = Integer.valueOf(array[0]);
int proofResult = Integer.parseInt(array[1]);
DeviceLibrary device = deviceRepo.findById(deviceId).orElse(null);
//依据proofResult 判断是否是在库装备
if (proofResult == 3) {
// 非在库装备
notInLibVoList.add(toCheckNotInLibVo(device));
} else {
// 在库装备
inLibVoList.add(toCheckInLibVo(device, proofResult));
}
}
// detailDo -> detailVo
ModelMapper modelMapper = BeanHelper.getUserMapper();
CheckDetailVo detailVo = modelMapper.map(detailDo, CheckDetailVo.class);
detailVo.setCheckUserAName(checkUserAName);
detailVo.setCheckUserBName(checkUserBName);
detailVo.setUserAName(userAName);
detailVo.setUserBName(userBName);
detailVo.setDevInLibrary(inLibVoList);
detailVo.setDevNotInLibrary(notInLibVoList);
return detailVo;
}
public DeviceInLibVo toCheckInLibVo(DeviceLibrary device, int proofResult) {
return new DeviceInLibVo(
device.getId(),
device.getModel(),
device.getName(),
device.getSeqNumber(),
device.getProdNumber(),
device.getRfidSurfaceId(),
device.getRfidCardId(),
proofResult
);
}
public DeviceNotInLibVo toCheckNotInLibVo(DeviceLibrary device) {
return new DeviceNotInLibVo(
device.getId(),
device.getModel(),
device.getName(),
device.getSeqNumber(),
device.getProdNumber(),
device.getRfidSurfaceId(),
device.getRfidCardId(),
device.getLocationUnit(),
device.getOwnUnit(),
device.getLifeStatus()
);
}
}
......@@ -199,4 +199,5 @@ public class DeviceLibrary {
public void addChildNode(DeviceLibrary deviceLibraryEntity) {
childs.add(deviceLibraryEntity);
}
}
......@@ -3,6 +3,7 @@ package com.tykj.dev.device.task.repository;
import com.tykj.dev.device.task.subject.domin.Task;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
......@@ -12,27 +13,38 @@ import java.util.List;
public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationExecutor<Task> {
/**
* @param billId 账单id
* @param billId 账单id
* @param businessType 业务类型
* 根据账单Id和业务类型查询task
* 根据账单Id和业务类型查询task
*/
Task findByBillIdAndBusinessType(Integer billId, Integer businessType);
/**
* 根据账单id、业务类型、任务状态查询task
* @param billId 账单id
*
* @param billId 账单id
* @param businessType 业务类型
* @param billStatus 任务状态
* @param billStatus 任务状态
*/
List<Task> findAllByBillIdAndBusinessTypeAndBillStatus(Integer billId,Integer businessType,Integer billStatus);
List<Task> findAllByBillIdAndBusinessTypeAndBillStatus(Integer billId, Integer businessType, Integer billStatus);
/**
* 根据账单id、业务类型、以及父id为null
* @param billId 账单ID
*
* @param billId 账单ID
* @param businessType 业务类型
*/
Task findAllByParentTaskIdIsNullAndBillIdAndBusinessType(Integer billId,Integer businessType);
Task findAllByParentTaskIdIsNullAndBillIdAndBusinessType(Integer billId, Integer businessType);
List<Task> findAllByParentTaskId(Integer parentTaskId);
@Query("select o.billId from Task o where o.id=?1")
Integer findBillIdByTaskId(int taskId);
@Query("select o.billId from Task o where o.id=?1 and o.businessType=?2")
Integer findBillId(int id, int businessType);
@Query("select o.billId from Task o where o.parentTaskId = ?1 and o. businessType = ?2")
Integer findBillIdByParentId(int parentTaskId, int businessType);
}
......@@ -106,8 +106,18 @@ public interface TaskService {
/**
* @param taskBto 任务bto
* @param userId 新增涉及用户id
* 不指定用户的任务被用户接取之后新增涉及用户
* @param userId 新增涉及用户id
* 不指定用户的任务被用户接取之后新增涉及用户
*/
TaskBto addInvolveUser(TaskBto taskBto,Integer userId);
TaskBto addInvolveUser(TaskBto taskBto, Integer userId);
/**
* 判断该根任务节点下的所有task是否都处于完结状态
*
* @param rootId task的根节点id
* @return Task Tree 是否已经结束
*/
boolean TaskTreeIsOver(int rootId);
}
......@@ -6,8 +6,8 @@ import com.tykj.dev.device.task.repository.TaskDao;
import com.tykj.dev.device.task.repository.TaskLogDao;
import com.tykj.dev.device.task.service.TaskService;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.task.subject.common.StatusEnum;
import com.tykj.dev.device.task.subject.common.GlobalMap;
import com.tykj.dev.device.task.subject.common.StatusEnum;
import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.task.subject.domin.TaskLog;
import com.tykj.dev.device.task.subject.vo.TaskSelectVo;
......@@ -20,6 +20,7 @@ import com.tykj.dev.misc.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import javax.persistence.Transient;
......@@ -68,6 +69,7 @@ public class TaskServiceImpl implements TaskService {
* <p>业务进行到下一个状态</p>
* <li>不指定待办用户</li>
* <li>添加自定义信息</li>
*
* @param customInfo 自定义信息
*/
@Override
......@@ -87,6 +89,7 @@ public class TaskServiceImpl implements TaskService {
/**
* <p>业务进行到下一个状态(指定待办用户)</p>
* <li>指定待办用户</li>
*
* @param userId 待办用户Id
*/
@Override
......@@ -105,6 +108,7 @@ public class TaskServiceImpl implements TaskService {
* <p>业务进行到下一个状态(指定待办用户)</p>
* <li>指定待办用户</li>
* <li>添加自定义信息</li>
*
* @param userId 待办用户Id
* @param customInfo 自定义信息
*/
......@@ -125,6 +129,7 @@ public class TaskServiceImpl implements TaskService {
/**
* <p>业务进行到特殊状态</p>
* <li>不指定待办用户</li>
*
* @param statusEnum 状态枚举
*/
@Override
......@@ -143,6 +148,7 @@ public class TaskServiceImpl implements TaskService {
* <p>业务进行到特殊状态</p>
* <li>不指定待办用户</li>
* <li>添加自定义信息</li>
*
* @param statusEnum 状态枚举
* @param customInfo 自定义信息
*/
......@@ -163,6 +169,7 @@ public class TaskServiceImpl implements TaskService {
/**
* <p>业务进行到特殊状态</p>
* <li>指定待办用户</li>
*
* @param statusEnum 状态枚举
* @param userId 待办用户Id
*/
......@@ -182,6 +189,7 @@ public class TaskServiceImpl implements TaskService {
* <p>业务进行到特殊状态</p>
* <li>指定待办用户</li>
* <li>添加自定义信息</li>
*
* @param statusEnum 状态枚举
* @param userId 待办用户Id
* @param customInfo 自定义信息
......@@ -255,8 +263,7 @@ public class TaskServiceImpl implements TaskService {
}
/**
* @param taskSelectVo
* 获取跟踪和待办业务列表
* @param taskSelectVo 获取跟踪和待办业务列表
*/
@Override
public List<TaskUserVo> getList(TaskSelectVo taskSelectVo) {
......@@ -291,7 +298,7 @@ public class TaskServiceImpl implements TaskService {
Integer num = taskSelectVo.getSelectNum();
Integer userId = userUtils.getCurrentUserId();
//业务管理中的待办和跟踪
if (num==2||num==3){
if (num == 2 || num == 3) {
//查询出符合筛选条件的所有task
List<TaskUserVo> list = taskDao.findAll(getSelectSpecification(taskSelectVo)).stream()
.map(Task::parse2Bto)
......@@ -299,10 +306,10 @@ public class TaskServiceImpl implements TaskService {
.collect(Collectors.toList());
//查询当前用户的跟踪和待办并和list按id取交集
List<TaskUserVo> taskUserVos = getList(taskSelectVo).stream()
.filter(taskUserVo -> find(taskUserVo.getId(),list)>-1)
.filter(taskUserVo -> find(taskUserVo.getId(), list) > -1)
.collect(Collectors.toList());
//判断是否需要按发起时间排序
if (taskSelectVo.getOrders()!=null) {
if (taskSelectVo.getOrders() != null) {
if ("createTime".equals(taskSelectVo.getOrders().get(0).getCoulmn())) {
if ("ASC".equals(taskSelectVo.getOrders().get(0).getDirection().toString())) {
return taskUtils.orderByCreateTimeAsc2(taskUserVos);
......@@ -314,21 +321,21 @@ public class TaskServiceImpl implements TaskService {
}
return taskUserVos;
}
if (num==4||num==5||num==1||num==0) {
if (num == 4 || num == 5 || num == 1 || num == 0) {
//获取单位等级
Integer level = userUtils.getCurrentUnitLevel();
//获取该单位以及下属单位所有用户Id
List<Integer> idLists = userPublicService.findAllUserIdByUnitsName(userUtils.getCurrentUserUnitName());
List<TaskUserVo> taskUserVos = new ArrayList<>();
//省能看到所有业务
if (level==1) {
if (level == 1) {
taskUserVos = taskDao.findAll(getSelectSpecification(taskSelectVo)).stream()
.map(Task::parse2Bto)
.map(TaskBto::toVo)
.collect(Collectors.toList());
}
//市或县只能看到涉及人员和idLists有交集的
if (level==2||level==3){
if (level == 2 || level == 3) {
taskUserVos = taskDao.findAll(getSelectSpecification(taskSelectVo)).stream()
.map(Task::parse2Bto)
.map(TaskBto::toVo)
......@@ -336,7 +343,7 @@ public class TaskServiceImpl implements TaskService {
.collect(Collectors.toList());
}
//set经办人,置顶以及阅读情况
for (TaskUserVo taskUserVo:taskUserVos) {
for (TaskUserVo taskUserVo : taskUserVos) {
List<Integer> idList = taskUserVo.getUserReadDetailList();
List<Integer> idList2 = taskUserVo.getTopFlagDetailList();
if (taskUserVo.getInvolveUserIdList() != null && taskUserVo.getInvolveUserIdList().size() > 0) {
......@@ -357,7 +364,7 @@ public class TaskServiceImpl implements TaskService {
}
}
//判断是否需要按发起时间排序
if (taskSelectVo.getOrders()!=null) {
if (taskSelectVo.getOrders() != null) {
if ("createTime".equals(taskSelectVo.getOrders().get(0).getCoulmn())) {
if ("ASC".equals(taskSelectVo.getOrders().get(0).getDirection().toString())) {
return taskUtils.orderByCreateTimeAsc2(taskUserVos);
......@@ -368,8 +375,7 @@ public class TaskServiceImpl implements TaskService {
}
}
return taskUserVos;
}
else {
} else {
throw new ApiException(ResultUtil.failed("selectNum只能为0,1,2,3,4,5"));
}
}
......@@ -380,18 +386,36 @@ public class TaskServiceImpl implements TaskService {
*/
@Override
public TaskBto addInvolveUser(TaskBto taskBto, Integer userId) {
List<Integer> list = taskBto.getInvolveUserIdList();
List<Integer> list = taskBto.getInvolveUserIdList();
//添加涉及用户Id
list.add(userId);
taskBto.setInvolveUserIdList(list);
//指针后移
taskBto.setCurrentPoint(taskBto.getCurrentPoint()+1);
taskBto.setCurrentPoint(taskBto.getCurrentPoint() + 1);
return taskBto;
}
/**
* 判断该根任务节点下的所有task是否都处于完结状态
*
* @param rootId task的根节点id
* @return Task Tree 是否已经结束
*/
@Override
public boolean TaskTreeIsOver(int rootId) {
List<Task> taskList = taskDao.findAllByParentTaskId(rootId);
if (CollectionUtils.isEmpty(taskList)) {
return true;
} else {
return taskList.stream()
.allMatch(task -> task.getBillStatus().equals(StatusEnum.END.id));
}
}
/**
* @param taskSelectVo 查询vo
* 查询跟踪和待办列表
* 查询跟踪和待办列表
* @return taskUserVo列表
*/
private List<TaskUserVo> getTaskUserVoList(TaskSelectVo taskSelectVo) {
......@@ -399,7 +423,7 @@ public class TaskServiceImpl implements TaskService {
Integer bussinessType = taskSelectVo.getBusinessType();
//筛选出未完结和封存业务,映射成bto
List<TaskBto> taskBtos = taskDao.findAll().stream()
.filter(task -> (!task.getBillStatus().equals(StatusEnum.END.id))&&(!task.getBillStatus().equals(StatusEnum.ARCHIVE.id)))
.filter(task -> (!task.getBillStatus().equals(StatusEnum.END.id)) && (!task.getBillStatus().equals(StatusEnum.ARCHIVE.id)))
.map(Task::parse2Bto)
.collect(Collectors.toList());
//查询待办
......@@ -411,15 +435,15 @@ public class TaskServiceImpl implements TaskService {
//查询所有的业务
if (bussinessType == null) {
List<TaskUserVo> taskUserVos = taskBtoList.stream().map(TaskBto::toVo).collect(Collectors.toList());
return setTaskUserVo(taskUserVos,0);
return setTaskUserVo(taskUserVos, 0);
} else {
//查询工作台其它业务
if (bussinessType == 0) {
List<TaskUserVo> taskUserVos = taskBtoList.stream()
.filter(taskBto -> !new ArrayList<>(Arrays.asList(3,4,5,6)).contains(taskBto.getBusinessType()))
.filter(taskBto -> !new ArrayList<>(Arrays.asList(3, 4, 5, 6)).contains(taskBto.getBusinessType()))
.map(TaskBto::toVo)
.collect(Collectors.toList());
return setTaskUserVo(taskUserVos,0);
return setTaskUserVo(taskUserVos, 0);
}
//查询某一业务
else {
......@@ -427,7 +451,7 @@ public class TaskServiceImpl implements TaskService {
.filter(taskBto -> taskBto.getBusinessType().equals(bussinessType))
.map(TaskBto::toVo)
.collect(Collectors.toList());
return setTaskUserVo(taskUserVos,0);
return setTaskUserVo(taskUserVos, 0);
}
}
}
......@@ -435,20 +459,20 @@ public class TaskServiceImpl implements TaskService {
if (taskSelectVo.getSelectNum() == 3) {
//涉及人员包括当前用户且指针对应UserId不是当前用户
List<TaskBto> taskBtoList = taskBtos.stream()
.filter(taskBto -> taskBto.getInvolveUserIdList().contains(userId)&&!userId.equals(taskBto.getInvolveUserIdList().get(taskBto.getCurrentPoint())))
.filter(taskBto -> taskBto.getInvolveUserIdList().contains(userId) && !userId.equals(taskBto.getInvolveUserIdList().get(taskBto.getCurrentPoint())))
.collect(Collectors.toList());
//查询所有业务
if (bussinessType == null) {
List<TaskUserVo> taskUserVos = taskBtoList.stream().map(TaskBto::toVo).collect(Collectors.toList());
return setTaskUserVo(taskUserVos,1);
return setTaskUserVo(taskUserVos, 1);
} else {
//查询工作台其它业务
if (bussinessType == 0) {
List<TaskUserVo> taskUserVos = taskBtoList.stream()
.filter(taskBto -> !new ArrayList<>(Arrays.asList(3,4,5,6)).contains(taskBto.getBusinessType()))
.filter(taskBto -> !new ArrayList<>(Arrays.asList(3, 4, 5, 6)).contains(taskBto.getBusinessType()))
.map(TaskBto::toVo)
.collect(Collectors.toList());
return setTaskUserVo(taskUserVos,1);
return setTaskUserVo(taskUserVos, 1);
}
//查询某一业务
else {
......@@ -456,7 +480,7 @@ public class TaskServiceImpl implements TaskService {
.filter(taskBto -> taskBto.getBusinessType().equals(bussinessType))
.map(TaskBto::toVo)
.collect(Collectors.toList());
return setTaskUserVo(taskUserVos,1);
return setTaskUserVo(taskUserVos, 1);
}
}
} else {
......@@ -467,7 +491,7 @@ public class TaskServiceImpl implements TaskService {
/**
* @param list taskUserVos
* @param type 0:set待办 1:set跟踪
* set一些输出给前端的值
* set一些输出给前端的值
*/
private List<TaskUserVo> setTaskUserVo(List<TaskUserVo> list, int type) {
Integer userId = userUtils.getCurrentUserId();
......@@ -504,8 +528,7 @@ public class TaskServiceImpl implements TaskService {
if (userTime == null) {
taskUserVo.setUserTime("0天0小时");
taskUserVo.setUserTimeDate(new Date(0));
}
else {
} else {
long time = System.currentTimeMillis() - userTime.getTime();
int day = new Long(time / 86_400_000).intValue();
int hour = new Long((time % 86_400_000) / 3_600_000).intValue();
......@@ -519,54 +542,52 @@ public class TaskServiceImpl implements TaskService {
/**
* @param taskId 业务id
* 获取当前用户上次处理业务时间
* 获取当前用户上次处理业务时间
*/
private Date getUserTime(Integer taskId) {
List<TaskLog> list = taskLogDao.getAllByTaskId(taskId);
if (list.size()>0) {
if (list.size() > 0) {
//筛选出当前用户操作该业务的所有日志,根据业务日志的创建时间降序排列,得到最新的上一次操作时间
List<TaskLog> taskLogs = taskUtils.orderByCreateTimeDesc(list.stream().filter(taskLog -> taskLog.getCreateUserId().equals(userUtils.getCurrentUserId())).collect(Collectors.toList()));
return taskLogs.get(0).getCreateTime();
}
else {
} else {
return null;
}
}
/**
* @param taskSelectVo
* task查询器
* @param taskSelectVo task查询器
*/
private Specification<Task> getSelectSpecification(TaskSelectVo taskSelectVo){
private Specification<Task> getSelectSpecification(TaskSelectVo taskSelectVo) {
PredicateBuilder<Task> predicateBuilder = Specifications.and();
if (taskSelectVo.getBusinessType()!=null){
if (taskSelectVo.getBusinessType() != null) {
predicateBuilder.eq("businessType", taskSelectVo.getBusinessType());
}
if (taskSelectVo.getContent()!=null){
if (taskSelectVo.getContent() != null) {
Class<Task> taskEntityClass = Task.class;
Field[] declaredFields = taskEntityClass.getDeclaredFields();
PredicateBuilder<Task> p = Specifications.or();
for (Field field : declaredFields) {
if (field.getType().equals(String.class)&&field.getAnnotation(Transient.class)==null) {
if (field.getType().equals(String.class) && field.getAnnotation(Transient.class) == null) {
p.like(field.getName(), "%" + taskSelectVo.getContent() + "%");
}
}
predicateBuilder.predicate(p.build());
}
if (taskSelectVo.getStartTime()!=null){
if (taskSelectVo.getStartTime() != null) {
predicateBuilder.gt("createTime", taskSelectVo.getStartTime());
}
if (taskSelectVo.getEndTime()!=null){
if (taskSelectVo.getEndTime() != null) {
predicateBuilder.lt("createTime", taskSelectVo.getEndTime());
}
if (taskSelectVo.getSelectNum()==4){
predicateBuilder.eq("billStatus",StatusEnum.END.id);
if (taskSelectVo.getSelectNum() == 4) {
predicateBuilder.eq("billStatus", StatusEnum.END.id);
}
if (taskSelectVo.getSelectNum()==5){
predicateBuilder.eq("billStatus",StatusEnum.ARCHIVE.id);
if (taskSelectVo.getSelectNum() == 5) {
predicateBuilder.eq("billStatus", StatusEnum.ARCHIVE.id);
}
if (taskSelectVo.getSelectNum()==1){
predicateBuilder.eq("createUserId",userUtils.getCurrentUnitId());
if (taskSelectVo.getSelectNum() == 1) {
predicateBuilder.eq("createUserId", userUtils.getCurrentUnitId());
}
return predicateBuilder.build();
}
......@@ -574,11 +595,11 @@ public class TaskServiceImpl implements TaskService {
/**
* 判断list中是否包含某个id的taskUserVo,若不存在返回-1,存在则返回第一次出现的索引值
*/
int find(Integer id,List<TaskUserVo> list){
int find(Integer id, List<TaskUserVo> list) {
int index = -1;
if (list!=null&&list.size()>0){
for (int i=0;i<list.size();i++){
if (list.get(i).getId().equals(id)){
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getId().equals(id)) {
index = i;
break;
}
......
......@@ -12,10 +12,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -75,13 +73,40 @@ public class TaskBto {
@ApiModelProperty(value = "工作涉及人员id")
private List<Integer> involveUserIdList;
public TaskBto(Integer billStatus, String title, Integer parentTaskId, String nodeIdDetail, Integer billId, Integer businessType, Integer ownUnit, Integer currentPoint, String customInfo, List<Integer> involveUserIdList) {
this.billStatus = billStatus;
this.title = title;
this.parentTaskId = parentTaskId;
this.nodeIdDetail = nodeIdDetail;
this.billId = billId;
this.businessType = businessType;
this.ownUnit = ownUnit;
this.currentPoint = currentPoint;
this.customInfo = customInfo;
this.involveUserIdList = involveUserIdList;
}
public TaskBto(Integer status, String title, Integer parentTaskId, String nodeIdDetail, Integer businessType, Integer billId, Integer ownUnit, int startUserId) {
this.billStatus = status;
this.title = title;
this.parentTaskId = parentTaskId;
this.nodeIdDetail = nodeIdDetail;
this.businessType = businessType;
this.billId = billId;
this.ownUnit = ownUnit;
List<Integer> involveUserIdList = new ArrayList<>();
involveUserIdList.add(startUserId);
this.involveUserIdList = involveUserIdList;
}
/**
* bto类转化为do类
*/
public Task toDo(){
public Task toDo() {
//复制相同属性
ModelMapper modelMapper = BeanHelper.getUserMapper();
Task task = modelMapper.map(this,Task.class);
Task task = modelMapper.map(this, Task.class);
//set组合字段
task.setInvolveUsers(StringSplitUtil.idListToString(this.involveUserIdList));
task.setUserReadDetail(StringSplitUtil.idListToString(this.userReadDetailList));
......@@ -89,16 +114,14 @@ public class TaskBto {
return task;
}
/**
* bto类转化为vo类
*/
public TaskUserVo toVo(){
public TaskUserVo toVo() {
UserPublicService userPublicService = SpringUtils.getBean("userPublicServiceImpl");
//复制相同属性
ModelMapper modelMapper = BeanHelper.getUserMapper();
TaskUserVo taskUserVo = modelMapper.map(this,TaskUserVo.class);
TaskUserVo taskUserVo = modelMapper.map(this, TaskUserVo.class);
//set vo字段
if (userPublicService != null) {
taskUserVo.setStartUnit(userPublicService.findUnitsNameByUserId(this.createUserId));
......@@ -107,16 +130,17 @@ public class TaskBto {
return taskUserVo;
}
public TaskBto(Integer billStatus, String title, Integer parentTaskId, String nodeIdDetail, Integer billId, Integer businessType, Integer ownUnit, Integer currentPoint, String customInfo, List<Integer> involveUserIdList) {
this.billStatus = billStatus;
this.title = title;
this.parentTaskId = parentTaskId;
this.nodeIdDetail = nodeIdDetail;
this.billId = billId;
this.businessType = businessType;
this.ownUnit = ownUnit;
this.currentPoint = currentPoint;
this.customInfo = customInfo;
this.involveUserIdList = involveUserIdList;
/**
* @return 最后一个参与该任务的人员id, 用于任务状态变化时人员不变的情况
*/
public Integer getLastUserId() {
return involveUserIdList.get(involveUserIdList.size() - 1);
}
/**
* @return 第一个参与该任务的人员id, 用于任务状态变化时需要返回初始状态的情况
*/
public Integer getFirstUserId() {
return involveUserIdList.get(0);
}
}
......@@ -26,25 +26,38 @@ public enum StatusEnum {
CREATE_DESTROY_BUSINESS(8110,"标签制作业务开始"),
DESTROY_BUSINESS_NEED_CONFIRM(8111,"等待审核"),
DESTROY_BUSINESS_CONFIRM_FINISH_SUCCESS(8112,"审核成功"),
DESTROY_BUSINESS_CONFIRM_FINISH_FAILED(8113,"审核失败"),
DESTROY_BUSINESS_CONFIRM_FINISH_FAILED(8113, "审核失败"),
/**
* 退装业务
*/
CREATE_RETIRED_BUSINESS(8120,"标签制作业务开始"),
RETIRED_BUSINESS_NEED_CONFIRM(8121,"等待审核"),
RETIRED_BUSINESS_CONFIRM_FINISH_SUCCESS(8122,"审核成功"),
RETIRED_BUSINESS_CONFIRM_FINISH_FAILED(8123,"审核失败"),
CREATE_RETIRED_BUSINESS(8120, "标签制作业务开始"),
RETIRED_BUSINESS_NEED_CONFIRM(8121, "等待审核"),
RETIRED_BUSINESS_CONFIRM_FINISH_SUCCESS(8122, "审核成功"),
RETIRED_BUSINESS_CONFIRM_FINISH_FAILED(8123, "审核失败"),
/**
* 核查任务
*/
//以下为stat状态
CHECK_STAT_0(100, "省级统计数据收集中"),
CHECK_STAT_1(101, "省级统计数据等待确认"),
//以下为detail状态
CHECK_DETAIL_0(120, "等待专管员A处理"),
CHECK_DETAIL_1(121, "等待专管员B处理"),
CHECK_DETAIL_2(122, "等待核查员A处理"),
CHECK_DETAIL_3(123, "等待核查员B处理"),
/**
* 业务完结
*/
END(9999,"业务完结"),
END(9999, "业务完结"),
TRAIN1000(1000,"报名中"),
TRAIN1000(1000, "报名中"),
TRAIN1001(1001,"报名确认"),
TRAIN1001(1001, "报名确认"),
TRAIN1002(1002,"待报名"),
......
......@@ -95,13 +95,33 @@ public class Task {
@ApiModelProperty(value = "工作涉及人员id(x作为分隔符),例如x1x2x,意为id为1,2的用户参与了该任务")
private String involveUsers;
public Task(String title, Integer parentTaskId, String nodeIdDetail, Integer businessType, Integer billId, Integer ownUnit) {
this.title = title;
this.parentTaskId = parentTaskId;
this.nodeIdDetail = nodeIdDetail;
this.businessType = businessType;
this.billId = billId;
this.ownUnit = ownUnit;
}
public Task(Integer status, String title, Integer parentTaskId, String nodeIdDetail, Integer businessType, Integer billId, Integer ownUnit) {
this.billStatus = status;
this.title = title;
this.parentTaskId = parentTaskId;
this.nodeIdDetail = nodeIdDetail;
this.businessType = businessType;
this.billId = billId;
this.ownUnit = ownUnit;
this.currentPoint = 0;
}
/**
* do类转化为bto类
*/
public TaskBto parse2Bto(){
public TaskBto parse2Bto() {
//modelMap复制
ModelMapper mapper = BeanHelper.getUserMapper();
TaskBto taskBto = mapper.map(this,TaskBto.class);
TaskBto taskBto = mapper.map(this, TaskBto.class);
//解析组合字段并添加
taskBto.setInvolveUserIdList(StringSplitUtil.userIdSplit(this.involveUsers));
taskBto.setTopFlagDetailList(StringSplitUtil.userIdSplit(this.topFlagDetail));
......
......@@ -3,6 +3,7 @@ package com.tykj.dev.device.user.subject.dao;
import com.tykj.dev.device.user.subject.entity.Area;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -22,4 +23,7 @@ public interface AreaDao extends JpaRepository<Area, Integer>, JpaSpecificationE
List<Area> findAreasByType(Integer type);
@Query("select o.name from Area o where o.id=?1")
String findNameById(int id);
}
......@@ -3,6 +3,7 @@ package com.tykj.dev.device.user.subject.dao;
import com.tykj.dev.device.user.subject.entity.Units;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -19,11 +20,17 @@ public interface UnitsDao extends JpaRepository<Units, Integer>, JpaSpecificatio
List<Units> findByAreaIdIn(List<Integer> areaIds);
List<Units> findAllByAreaIdIn(List<Integer> ids);
List<Units> findAllByAreaIdIn(List<Integer> ids);
List<Units> findByAreaId(Integer area);
List<Units> findByAreaId(Integer area);
List<Units> findByIdDel(Integer idDel);
List<Units> findByIdDel(Integer idDel);
@Query("select o.areaId from Units o where o.name = ?1")
int findAreaIdByName(String unitName);
@Query("select o.areaId from Units o where o.unitId=?1")
int findAreaId(int id);
}
......@@ -3,6 +3,8 @@ package com.tykj.dev.misc.utils;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
......@@ -15,18 +17,19 @@ import java.util.Date;
public class TimestampUtil {
/**
*
* 获取当前系统时间,并返回时间戳
*
* @return 时间戳
*/
public static Timestamp getCurrentTimestamp(){
public static Timestamp getCurrentTimestamp() {
return new Timestamp(System.currentTimeMillis());
}
/**
* 获取今天
*
* @return String
* */
*/
public static Date getToday() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String format = simpleDateFormat.format(new Date());
......@@ -35,77 +38,107 @@ public class TimestampUtil {
/**
* 获取本月开始日期
*
* @return String
* **/
**/
public static Date getMonthStart() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal=Calendar.getInstance();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 1);
Date time=cal.getTime();
Date time = cal.getTime();
String format = simpleDateFormat.format(time);
return simpleDateFormat.parse(format);
}
/**
* 获取本月最后一天
*
* @return String
* **/
**/
public static Date getMonthEnd() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal=Calendar.getInstance();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
Date time=cal.getTime();
String format = simpleDateFormat.format(time)+" 23:59:59";
Date time = cal.getTime();
String format = simpleDateFormat.format(time) + " 23:59:59";
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(format);
}
/**
* 获取本周的第一天
*
* @return String
* **/
**/
public static Date getWeekStart() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal=Calendar.getInstance();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.WEEK_OF_MONTH, 0);
cal.set(Calendar.DAY_OF_WEEK, 2);
Date time=cal.getTime();
Date time = cal.getTime();
String format = simpleDateFormat.format(time);
return simpleDateFormat.parse(format);
}
/**
* 获取本周的最后一天
*
* @return String
* **/
**/
public static Date getWeekEnd() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal=Calendar.getInstance();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
cal.add(Calendar.DAY_OF_WEEK, 1);
Date time=cal.getTime();
String format = simpleDateFormat.format(time)+" 23:59:59";
Date time = cal.getTime();
String format = simpleDateFormat.format(time) + " 23:59:59";
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(format);
}
/**
* 获取本年的第一天
*
* @return String
* **/
**/
public static Date getYearStart() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
String format = simpleDateFormat.format(new Date())+"-01-01 00:00:00";
String format = simpleDateFormat.format(new Date()) + "-01-01 00:00:00";
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(format);
}
/**
* 获取本年的最后一天
*
* @return String
* **/
**/
public static Date getYearEnd() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH,calendar.getActualMaximum(Calendar.MONTH));
calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH));
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Date currYearLast = calendar.getTime();
String format = simpleDateFormat.format(currYearLast)+" 23:59:59";
String format = simpleDateFormat.format(currYearLast) + " 23:59:59";
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(format);
}
/**
* 默认将时分秒设置为00:00:00
*/
public static Date localDateToDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
public static LocalDate dateToLocalDate(Date date) {
return date.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}
/**
* @return 当前时间的Date类型
*/
public static Date getNowDate() {
return Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论