Browse Source

Merge branch 'develop' of gitadmin/tuoheng_freeway into release

tags/v1.1.0^2
wanjing 1 year ago
parent
commit
ee1882a736
6 changed files with 147 additions and 65 deletions
  1. +54
    -17
      tuoheng-common/tuoheng-common-core/src/main/java/com/tuoheng/common/core/utils/DateUtils.java
  2. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Structure.java
  3. +12
    -10
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/EditInspectionCodeEnum.java
  4. +0
    -10
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/inspection/EditInspectionRequest.java
  5. +79
    -27
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/UpdateInspectionService.java
  6. +1
    -0
      tuoheng-service/tuoheng-admin/src/main/resources/mapper/InspectionMapper.xml

+ 54
- 17
tuoheng-common/tuoheng-common-core/src/main/java/com/tuoheng/common/core/utils/DateUtils.java View File

@@ -76,9 +76,10 @@ public final class DateUtils extends org.apache.commons.lang3.time.DateUtils {
}

/**
* 检查字符串是否使时间格式
* 检查字符串是否使时间格式
*
* @param format 格式
* @param ts 时间字符串
* @param ts 时间字符串
* @return 布尔值
*/
public static boolean checkStrIsDate(final String format, final String ts) {
@@ -152,7 +153,7 @@ public final class DateUtils extends org.apache.commons.lang3.time.DateUtils {
/**
* 根据时间生成code
*/
public static String generateCode(String prefix){
public static String generateCode(String prefix) {
// 根据当前时间,生成任务编码
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
@@ -161,11 +162,12 @@ public final class DateUtils extends org.apache.commons.lang3.time.DateUtils {

/**
* 生成图片编号,P+年月日时分秒+随机三位数
*
* @return
*/
public static String generateFileCode(){
public static String generateFileCode() {
String Date = DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS);
int randomNum = (int)(Math.random() * 900) + 100;
int randomNum = (int) (Math.random() * 900) + 100;
String fileCode = "P" + Date + randomNum;

return fileCode;
@@ -173,16 +175,17 @@ public final class DateUtils extends org.apache.commons.lang3.time.DateUtils {

/**
* 返回字符串
*
* <p>
* 给原本的时间originDate加上自定义的时间
*
* @param originDate 原本的时间
* @param day 要加的天数
* @param hour 要加的小时数
* @param minute 要加的分钟数
* @param second 要加的秒数
* @param day 要加的天数
* @param hour 要加的小时数
* @param minute 要加的分钟数
* @param second 要加的秒数
* @return 返回加完时间后的时间str_goalDate
*/
public static String addDateTimeToStr(Date originDate, int day, int hour, int minute,int second) {
public static String addDateTimeToStr(Date originDate, int day, int hour, int minute, int second) {
SimpleDateFormat dateFormate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(originDate);
@@ -197,16 +200,17 @@ public final class DateUtils extends org.apache.commons.lang3.time.DateUtils {

/**
* 返回java.util.Date
*
* <p>
* 给原本的时间originDate加上自定义的时间
*
* @param originDate 原本的时间
* @param day 要加的天数
* @param hour 要加的小时数
* @param minute 要加的分钟数
* @param second 要加的秒数
* @param day 要加的天数
* @param hour 要加的小时数
* @param minute 要加的分钟数
* @param second 要加的秒数
* @return 返回加完时间后的时间goalDate
*/
public static Date addDateTimeToDate(Date originDate, int day, int hour, int minute,int second) {
public static Date addDateTimeToDate(Date originDate, int day, int hour, int minute, int second) {
Calendar cal = Calendar.getInstance();
cal.setTime(originDate);
cal.add(Calendar.DATE, day);// 24小时制,加天
@@ -218,6 +222,39 @@ public final class DateUtils extends org.apache.commons.lang3.time.DateUtils {
return goalDate;
}

/**
* 比较2个时间
*
* @param date1
* @param date2
* @return -1:时间格式不对
* 0:date1 == date2
* 1:date1 < date2
* 2:date1 > date2
*/
public static int compareToDate(Date date1, Date date2) {
String dateStr1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date1);
String dateStr2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date2);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
try {
c1.setTime(df.parse(dateStr1));
c2.setTime(df.parse(dateStr2));
} catch (java.text.ParseException e) {
System.err.println("格式不正确");
return -1;
}
int result = c1.compareTo(c2);
if (result == 0) {
return 0;
} else if (result < 0) {
return 1;
} else {
return 2;
}
}

public static void main(String[] args) {
// 当前时间
Date date = new Date(System.currentTimeMillis());

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Structure.java View File

@@ -23,7 +23,7 @@ public class Structure extends BaseEntity {
private String tenantId;

/**
* 构造物种类 1桥梁 2涵洞 3通道 4互通 5服务区 6收费站 7匝道 8机场
* 构造物种类 1桥梁 2涵洞 3通道 4互通 5服务区 6收费站 7匝道 8机场 9其他
*/
private Integer structureType;


+ 12
- 10
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/EditInspectionCodeEnum.java View File

@@ -13,16 +13,18 @@ public enum EditInspectionCodeEnum {

EDIT_IS_FAILED(1230300, "修改任务失败"),
ID_IS_NULL(1230301, "任务ID为空"),
NAME_IS_NULL(1230302, "任务名为空"),
TYPE_IS_NULL(1230303, "任务类型为空"),
ROAD_IS_NULL(1230304, "任务地点为空"),
SECTION_IS_NULL(1230305, "路段信息为空"),
INSPECTION_TYPE_IS_NULL(1230306, "巡检方式为空"),
AIRPORT_IS_NULL(1230307, "巡检机场为空"),
INSPECTION_LINE_IS_NULL(1230308, "巡检路线为空"),
INSPECTION_TIME_IS_NULL(1230309, "巡检时间为空"),
ROAD_IS_NOT_EXIST(1230310, "公路不存在"),
SECTION_IS_NOT_EXIST(1230311, "路段不存在");
ROAD_IS_NULL(1230302, "任务公路为空"),
SECTION_IS_NULL(1230303, "路段信息为空"),
AIRPORT_IS_NULL(1230304, "巡检机场为空"),
INSPECTION_LINE_IS_NULL(1230305, "巡检路线为空"),
INSPECTION_TIME_IS_NULL(1230306, "巡检时间为空"),
INSPECTION_TIME_NOT_AFTER_THAN_CURRENT_TIME(1230307, "巡检时间不能晚于当前时间"),
INSPECTION_IS_NOT_EXIST(1230308, "任务不存在"),
INSPECTION_IS_NOT_WAIT_FLIGHT(1230309, "非待飞行任务,不可修改"),
INSPECTION_IS_EXECUTED(1230310, "任务已执行,不可修改"),
ROAD_IS_NOT_EXIST(1230311, "公路不存在"),
SECTION_IS_NOT_EXIST(1230312, "路段不存在"),
NON_DEPT_ADMIN_NOT_EDIT(1230313, "非本部门管理员不能修改");

/**
* 错误码

+ 0
- 10
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/inspection/EditInspectionRequest.java View File

@@ -22,11 +22,6 @@ public class EditInspectionRequest {
*/
private String id;

/**
* 用户ID
*/
private String userId;

/**
* 任务编码
*/
@@ -67,11 +62,6 @@ public class EditInspectionRequest {
*/
private Integer inspectionType;

/**
* 部门Id
*/
private String deptId;

/**
* 公路Id
*/

+ 79
- 27
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/UpdateInspectionService.java View File

@@ -1,13 +1,22 @@
package com.tuoheng.admin.service.inspection.update;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.conver.InspectionConverMapper;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.entity.RoadInformation;
import com.tuoheng.admin.entity.Section;
import com.tuoheng.admin.enums.code.dept.AddDeptCodeEnum;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.InspectionExecutionStatusEnum;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.RoleEnum;
import com.tuoheng.admin.enums.code.inspection.EditInspectionCodeEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.mapper.RoadInformationMapper;
import com.tuoheng.admin.mapper.SectionMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.request.inspection.EditInspectionRequest;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.utils.DateUtils;
@@ -29,39 +38,51 @@ import org.springframework.stereotype.Service;
public class UpdateInspectionService {

@Autowired
private DeptMapper deptMapper;
private UserMapper userMapper;

@Autowired
private RoadInformationMapper roadInformationMapper;
private InspectionMapper inspectionMapper;

@Autowired
private SectionMapper sectionMapper;
private RoadInformationMapper roadInformationMapper;

@Autowired
private InspectionMapper inspectionMapper;
private SectionMapper sectionMapper;

/**
* 添加任务
* 修改任务
* 1、机场任务:
* 1)、只有本部门管理员(上上级部门管理员不可编辑)和创建用户才能编辑;
* 2)、待执行任务,执行后不可编辑;
* 3)、编辑信息包括,任务地点,路段,巡检机场,巡检路线,巡检时间,执行时间
* 2、飞手任务不能编辑。
*
* @return
*/
public JsonResult update(EditInspectionRequest editInspectionRequest) {
log.info("进入修改任务业务接口");
String tenantId = CurrentUserUtil.getTenantId();
User user = CurrentUserUtil.getUserInfo();
String tenantId = user.getTenantId();
JsonResult result = this.check(tenantId, editInspectionRequest);
if (0 != result.getCode()) {
log.info("修改任务业务接口:校验失败:{}", result.getMsg());
return result;
}
Inspection inspectionOld = (Inspection) result.getData();
result = checkPermissions(user, inspectionOld.getCreateUser());
if (0 != result.getCode()) {
log.info("修改任务业务接口:校验权限失败:{}", result.getMsg());
return result;
}

Inspection inspection = InspectionConverMapper.INSTANCE.fromEditInspectionRequestToInspection(editInspectionRequest);
inspection.setUpdateUser("");
inspection.setUpdateUser(user.getId());
inspection.setUpdateTime(DateUtils.now());

Integer rowId = inspectionMapper.update(inspection);
if (rowId <= 0) {
log.info("修改任务业务接口:修改任务失败:{}", result.getMsg());
return JsonResult.error(AddDeptCodeEnum.ADD_DEPT_IS_FAILED.getCode(), AddDeptCodeEnum.ADD_DEPT_IS_FAILED.getMsg());
return JsonResult.error(EditInspectionCodeEnum.EDIT_IS_FAILED.getCode(), EditInspectionCodeEnum.EDIT_IS_FAILED.getMsg());
}

log.info("修改任务业务接口:修改任务成功:{}", inspection);
@@ -79,14 +100,6 @@ public class UpdateInspectionService {
return JsonResult.error(EditInspectionCodeEnum.ID_IS_NULL.getCode(), EditInspectionCodeEnum.ID_IS_NULL.getMsg());
}

if (StringUtils.isEmpty(editInspectionRequest.getName())) {
return JsonResult.error(EditInspectionCodeEnum.NAME_IS_NULL.getCode(), EditInspectionCodeEnum.NAME_IS_NULL.getMsg());
}

if (null == editInspectionRequest.getType()) {
return JsonResult.error(EditInspectionCodeEnum.TYPE_IS_NULL.getCode(), EditInspectionCodeEnum.TYPE_IS_NULL.getMsg());
}

if (null == editInspectionRequest.getRoadId() || StringUtils.isEmpty(editInspectionRequest.getRoadName())) {
return JsonResult.error(EditInspectionCodeEnum.ROAD_IS_NULL.getCode(), EditInspectionCodeEnum.ROAD_IS_NULL.getMsg());
}
@@ -95,10 +108,6 @@ public class UpdateInspectionService {
return JsonResult.error(EditInspectionCodeEnum.SECTION_IS_NULL.getCode(), EditInspectionCodeEnum.SECTION_IS_NULL.getMsg());
}

if (null == editInspectionRequest.getInspectionType()) {
return JsonResult.error(EditInspectionCodeEnum.INSPECTION_TYPE_IS_NULL.getCode(), EditInspectionCodeEnum.INSPECTION_TYPE_IS_NULL.getMsg());
}

if (null == editInspectionRequest.getAirportId() || StringUtils.isEmpty(editInspectionRequest.getAirportName())) {
return JsonResult.error(EditInspectionCodeEnum.AIRPORT_IS_NULL.getCode(), EditInspectionCodeEnum.AIRPORT_IS_NULL.getMsg());
}
@@ -106,15 +115,33 @@ public class UpdateInspectionService {
if (null == editInspectionRequest.getInspectionLine() || StringUtils.isEmpty(editInspectionRequest.getInspectionLineName())) {
return JsonResult.error(EditInspectionCodeEnum.INSPECTION_LINE_IS_NULL.getCode(), EditInspectionCodeEnum.INSPECTION_LINE_IS_NULL.getMsg());
}

if (null == editInspectionRequest.getInspectionTime()) {
return JsonResult.error(EditInspectionCodeEnum.INSPECTION_TIME_IS_NULL.getCode(), EditInspectionCodeEnum.INSPECTION_TIME_IS_NULL.getMsg());
}
int timaDiff = DateUtils.compareToDate(editInspectionRequest.getInspectionTime(), DateUtils.now());
if (2 != timaDiff) {
return JsonResult.error(EditInspectionCodeEnum.INSPECTION_TIME_NOT_AFTER_THAN_CURRENT_TIME.getCode(), EditInspectionCodeEnum.INSPECTION_TIME_NOT_AFTER_THAN_CURRENT_TIME.getMsg());
}

//查询当前对应的任务
Inspection inspection = inspectionMapper.selectOne(Wrappers.<Inspection>lambdaQuery()
.eq(Inspection::getId, editInspectionRequest.getId())
.eq(Inspection::getTenantId,tenantId)
.eq(Inspection::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isNull(inspection)) {
return JsonResult.error(EditInspectionCodeEnum.INSPECTION_IS_NOT_EXIST.getCode(), EditInspectionCodeEnum.INSPECTION_IS_NOT_EXIST.getMsg());
}
if (InspectionStatusEnum.WAIT_FLIGHT.getCode() != inspection.getStatus()) {
return JsonResult.error(EditInspectionCodeEnum.INSPECTION_IS_NOT_WAIT_FLIGHT.getCode(), EditInspectionCodeEnum.INSPECTION_IS_NOT_WAIT_FLIGHT.getMsg());
}
if (InspectionExecutionStatusEnum.EXECUTED.getCode() == inspection.getExecutionStatus()) {
return JsonResult.error(EditInspectionCodeEnum.INSPECTION_IS_EXECUTED.getCode(), EditInspectionCodeEnum.INSPECTION_IS_EXECUTED.getMsg());
}

Integer roadCount = roadInformationMapper.selectCount(Wrappers.<RoadInformation>lambdaQuery()
.eq(RoadInformation::getTenantId, tenantId)
.eq(RoadInformation::getId, editInspectionRequest.getRoadId())
.eq(RoadInformation::getMark, 1));
.eq(RoadInformation::getMark, MarkEnum.VALID.getCode()));

if (roadCount <= 0) {
return JsonResult.error(EditInspectionCodeEnum.ROAD_IS_NOT_EXIST.getCode(), EditInspectionCodeEnum.ROAD_IS_NOT_EXIST.getMsg());
@@ -123,12 +150,37 @@ public class UpdateInspectionService {
Integer sectionCount = sectionMapper.selectCount(Wrappers.<Section>lambdaQuery()
.eq(Section::getTenantId, tenantId)
.eq(Section::getId, editInspectionRequest.getSectionId())
.eq(Section::getMark, 1));
.eq(Section::getMark, MarkEnum.VALID.getCode()));
if (sectionCount <= 0) {
return JsonResult.error(EditInspectionCodeEnum.SECTION_IS_NOT_EXIST.getCode(), EditInspectionCodeEnum.SECTION_IS_NOT_EXIST.getMsg());
}
return JsonResult.success();
return JsonResult.success(inspection);
}


/**
* 检查权限
* 只有本部门管理员(上上级部门管理员不可编辑)和创建用户才能修改
*
* @param user
* @param createUser
* @return
*/
private JsonResult checkPermissions(User user, String createUser) {
if (user.getId().equals(createUser)) {
// 是自己创建的,可修改
return JsonResult.success();
}
// 查询部门管理员,若是部门管理员可修改,非部门管理员不能修改
User userTmp = userMapper.selectOne(new LambdaQueryWrapper<User>()
.eq(User::getDeptId, user.getDeptId())
.eq(User::getRoleId, RoleEnum.ADMIN.getCode())
.eq(User::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isNull(userTmp)) {
return JsonResult.error(EditInspectionCodeEnum.NON_DEPT_ADMIN_NOT_EDIT.getCode(), EditInspectionCodeEnum.NON_DEPT_ADMIN_NOT_EDIT.getMsg());
}
if (!user.getId().equals(userTmp.getId())) {
return JsonResult.error(EditInspectionCodeEnum.NON_DEPT_ADMIN_NOT_EDIT.getCode(), EditInspectionCodeEnum.NON_DEPT_ADMIN_NOT_EDIT.getMsg());
}
return JsonResult.success();
}
}

+ 1
- 0
tuoheng-service/tuoheng-admin/src/main/resources/mapper/InspectionMapper.xml View File

@@ -60,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateTime" column="update_time" />
<result property="mark" column="mark" />
</resultMap>

<sql id="Base_Column_list">
id, tenant_id, dept_id, code, name, type, road_id, road_name, section_id, section_name, inspection_type,
airport_id, airport_name, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id,

Loading…
Cancel
Save