|
@ -1,26 +1,43 @@ |
|
|
package org.nl.b_lms.sch.task.service.impl; |
|
|
package org.nl.b_lms.sch.task.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
import cn.hutool.core.date.DateUtil; |
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
|
import cn.hutool.core.map.MapUtil; |
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
|
import lombok.SneakyThrows; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.nl.b_lms.bst.ivt.cutpointivt.service.dao.BstIvtCutpointivt; |
|
|
import org.nl.b_lms.bst.ivt.cutpointivt.service.dao.BstIvtCutpointivt; |
|
|
import org.nl.b_lms.sch.task.dao.SchBaseTask; |
|
|
import org.nl.b_lms.sch.task.dao.SchBaseTask; |
|
|
import org.nl.b_lms.sch.task.dao.mapper.SchBaseTaskMapper; |
|
|
import org.nl.b_lms.sch.task.dao.mapper.SchBaseTaskMapper; |
|
|
|
|
|
import org.nl.b_lms.sch.task.dto.SchBaseTaskQuery; |
|
|
import org.nl.b_lms.sch.task.service.IschBaseTaskService; |
|
|
import org.nl.b_lms.sch.task.service.IschBaseTaskService; |
|
|
import org.nl.b_lms.storage_manage.ios.enums.IOSEnum; |
|
|
import org.nl.b_lms.storage_manage.ios.enums.IOSEnum; |
|
|
import org.nl.common.domain.query.PageQuery; |
|
|
import org.nl.common.domain.query.PageQuery; |
|
|
import org.nl.common.utils.SecurityUtils; |
|
|
import org.nl.common.utils.SecurityUtils; |
|
|
|
|
|
import org.nl.modules.common.exception.BadRequestException; |
|
|
|
|
|
import org.nl.modules.wql.util.SpringContextHolder; |
|
|
|
|
|
import org.nl.wms.basedata.master.classstandard.service.IClassStandardService; |
|
|
|
|
|
import org.nl.wms.basedata.master.classstandard.service.dao.ClassStandard; |
|
|
|
|
|
import org.nl.wms.basedata.st.areapermissions.service.IUserAreaPermissionService; |
|
|
import org.nl.wms.sch.manage.TaskStatusEnum; |
|
|
import org.nl.wms.sch.manage.TaskStatusEnum; |
|
|
|
|
|
import org.redisson.api.RLock; |
|
|
|
|
|
import org.redisson.api.RedissonClient; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.function.Consumer; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -35,6 +52,13 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private SchBaseTaskMapper schBaseTaskMapper; |
|
|
private SchBaseTaskMapper schBaseTaskMapper; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private IUserAreaPermissionService userAreaPermissionService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private IClassStandardService classStandardService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private RedissonClient redissonClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -44,17 +68,32 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa |
|
|
* @param page 分页参数 |
|
|
* @param page 分页参数 |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public IPage<SchBaseTask> queryAll(Map whereJson, PageQuery page) { |
|
|
public IPage<SchBaseTask> queryAll(SchBaseTaskQuery whereJson, PageQuery page) { |
|
|
return schBaseTaskMapper.selectPage(new Page<>(page.getPage() + 1, page.getSize()), new QueryWrapper<SchBaseTask>() |
|
|
List<String> collect = ObjectUtil.isNotEmpty(whereJson.getMore_task_status()) |
|
|
.lambda() |
|
|
? Arrays.stream(whereJson.getMore_task_status().split(",")).collect(Collectors.toList()) : null; |
|
|
// .like(StringUtils.isNotBlank(form.name()), User::getName, form.name())
|
|
|
if (collect != null) { |
|
|
// .between(form.beginTime != null && form.endTime != null, User::getCreateTime, beginTime, endTime)
|
|
|
if (collect.contains("-1")) { |
|
|
// .in(form.Status != null, User::getStatus
|
|
|
collect = null; |
|
|
// , UserStatusEnum.NOT_SUBMITTED
|
|
|
whereJson.setUnFinished("07"); |
|
|
// , UserStatusEnum.TO_REVIEWED)
|
|
|
} |
|
|
// .orderByDesc(User::getId)
|
|
|
} |
|
|
.eq(SchBaseTask::getIs_delete, 0) |
|
|
if (ObjectUtil.isNotEmpty(whereJson.getTask_type())) { |
|
|
); |
|
|
// 获取任务类型
|
|
|
|
|
|
ClassStandard dto = classStandardService.getById(whereJson.getTask_type()); |
|
|
|
|
|
ArrayList<String> allChildrenIds = classStandardService.getAllChildrenIds(dto.getClass_id()); |
|
|
|
|
|
if (CollectionUtil.isEmpty(allChildrenIds)) { |
|
|
|
|
|
allChildrenIds.add(dto.getClass_code()); |
|
|
|
|
|
} |
|
|
|
|
|
whereJson.setTask_types(allChildrenIds); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<String> in_area_id = userAreaPermissionService.getCurrentUserAreas(SecurityUtils.getCurrentUserId()); |
|
|
|
|
|
if (CollectionUtil.isNotEmpty(in_area_id)) { |
|
|
|
|
|
whereJson.setIn_area_id(in_area_id); |
|
|
|
|
|
} |
|
|
|
|
|
IPage<SchBaseTask> pages = new Page<>(page.getPage() + 1, page.getSize()); |
|
|
|
|
|
pages = schBaseTaskMapper.selectPageLeftJoin(pages, whereJson, collect); |
|
|
|
|
|
return pages; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -128,8 +167,8 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa |
|
|
entity.setCreate_name(SecurityUtils.getCurrentNickName()); |
|
|
entity.setCreate_name(SecurityUtils.getCurrentNickName()); |
|
|
entity.setCreate_time(DateUtil.now()); |
|
|
entity.setCreate_time(DateUtil.now()); |
|
|
} |
|
|
} |
|
|
entity.setUpdate_optid(SecurityUtils.getCurrentUserId()); |
|
|
entity.setUpdate_id(SecurityUtils.getCurrentUserId()); |
|
|
entity.setUpdate_optname(SecurityUtils.getCurrentNickName()); |
|
|
entity.setUpdate_name(SecurityUtils.getCurrentNickName()); |
|
|
entity.setUpdate_time(DateUtil.now()); |
|
|
entity.setUpdate_time(DateUtil.now()); |
|
|
return entity; |
|
|
return entity; |
|
|
} |
|
|
} |
|
@ -160,6 +199,81 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa |
|
|
return list(lam).size() > 0; |
|
|
return list(lam).size() > 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
|
|
@Override |
|
|
|
|
|
public void operation(Map<String, Object> map) { |
|
|
|
|
|
String task_id = MapUtil.getStr(map, "task_id"); |
|
|
|
|
|
RLock lock = redissonClient.getLock(task_id); |
|
|
|
|
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); |
|
|
|
|
|
try { |
|
|
|
|
|
if (tryLock) { |
|
|
|
|
|
String method_name = MapUtil.getStr(map, "method_name"); |
|
|
|
|
|
SchBaseTask taskObj = this.getById(task_id); |
|
|
|
|
|
if ("finish".equals(method_name)) { |
|
|
|
|
|
//强制执行,只把任务变更成完成状态
|
|
|
|
|
|
// 更改任务状态为完成
|
|
|
|
|
|
taskObj.setTask_status(TaskStatusEnum.FINISHED.getCode()); |
|
|
|
|
|
taskObj.setUpdate_id(SecurityUtils.getCurrentUserId()); |
|
|
|
|
|
taskObj.setUpdate_name(SecurityUtils.getCurrentNickName()); |
|
|
|
|
|
taskObj.setUpdate_time(DateUtil.now()); |
|
|
|
|
|
taskObj.setRemark("任务被用户:" + SecurityUtils.getCurrentNickName() + "在:" + DateUtil.now() + "强制完成。"); |
|
|
|
|
|
this.updateById(taskObj); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 任务处理类
|
|
|
|
|
|
String processing_class = taskObj.getHandle_class(); |
|
|
|
|
|
String message = ""; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
Object obj = new Object(); |
|
|
|
|
|
try { |
|
|
|
|
|
obj = SpringContextHolder.getBean(Class.forName(processing_class)); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
Class<?> clz = Class.forName(processing_class); |
|
|
|
|
|
obj = clz.newInstance(); |
|
|
|
|
|
} |
|
|
|
|
|
// 调用每个任务类的method_name()强制结束方法
|
|
|
|
|
|
Method m = obj.getClass().getMethod(method_name, String.class); |
|
|
|
|
|
JSONObject result = (JSONObject) m.invoke(obj, task_id); |
|
|
|
|
|
if (ObjectUtil.isEmpty(result)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray arr = result.getJSONArray("errArr"); |
|
|
|
|
|
LambdaUpdateWrapper<SchBaseTask> lam = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
if (ObjectUtil.isNotEmpty(arr)) { |
|
|
|
|
|
for (int i = 0; i < arr.size(); i++) { |
|
|
|
|
|
JSONObject json = arr.getJSONObject(i); |
|
|
|
|
|
lam.set(SchBaseTask::getRemark, json.getString("message")) |
|
|
|
|
|
.eq(SchBaseTask::getTask_id, json.getString("task_id")); |
|
|
|
|
|
this.update(lam); |
|
|
|
|
|
} |
|
|
|
|
|
throw new BadRequestException("任务操作失败!"); |
|
|
|
|
|
} else { |
|
|
|
|
|
lam.set(SchBaseTask::getRemark, "操作成功") |
|
|
|
|
|
.eq(SchBaseTask::getTask_id, task_id); |
|
|
|
|
|
this.update(lam); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (InvocationTargetException e) { |
|
|
|
|
|
if (ObjectUtil.isNull(e.getTargetException().getMessage())) { |
|
|
|
|
|
message = e.getTargetException().toString(); |
|
|
|
|
|
} else { |
|
|
|
|
|
message = e.getTargetException().getMessage(); |
|
|
|
|
|
} |
|
|
|
|
|
throw new BadRequestException(message); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
throw new BadRequestException(e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new BadRequestException("任务标识为:" + task_id + "的任务正在操作中!"); |
|
|
|
|
|
} |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (tryLock) { |
|
|
|
|
|
lock.unlock(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|