feat(task): copy saved scan parameters into independent tasks
This commit is contained in:
parent
d8e1c23fd3
commit
c3ae7c4222
@ -24,6 +24,11 @@ public class DimensionController {
|
||||
public CommonResult<?> get(@RequestParam long taskId,@RequestParam(defaultValue="0") long unitId){return success(service.get(taskId,unitId));}
|
||||
@PostMapping("/create") @PreAuthorize("@ss.hasPermission('lab:task:import')")
|
||||
public CommonResult<?> create(@Valid @RequestBody DimensionService.Create req){return success(service.create(req));}
|
||||
@GetMapping("/copy-source") @PreAuthorize("@ss.hasPermission('lab:task:query') and @ss.hasPermission('lab:task:import')")
|
||||
public CommonResult<?> copySource(@RequestParam long taskId){return success(service.copySource(taskId));}
|
||||
@PostMapping("/copy") @PreAuthorize("@ss.hasPermission('lab:task:query') and @ss.hasPermission('lab:task:import')")
|
||||
@cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog(operateType=cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.CREATE)
|
||||
public CommonResult<?> copy(@Valid @RequestBody DimensionService.Copy req){return success(service.copy(req));}
|
||||
@DeleteMapping("/delete") @PreAuthorize("@ss.hasPermission('lab:task:cancel')")
|
||||
@cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog(operateType=cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.DELETE)
|
||||
public CommonResult<?> delete(@RequestParam long taskId){service.deleteTask(taskId);return success(true);}
|
||||
|
||||
@ -43,6 +43,7 @@ public class DimensionService {
|
||||
@Resource private LabTaskSeqRedisDAO numbers;
|
||||
@Resource private LabTestTaskService taskService;
|
||||
@Resource private ScanOnlyTaskService scans;
|
||||
@Resource private cn.iocoder.yudao.module.lab.dal.mysql.scanonly.ScanTaskConfigMapper scanConfigs;
|
||||
@Resource private SecurityFrameworkService security;
|
||||
@Resource private DimensionFiles files;
|
||||
@Resource private LabArtifactService artifacts;
|
||||
@ -66,6 +67,10 @@ public class DimensionService {
|
||||
private Long modelId,drawingId,cloudId;
|
||||
@NotBlank @Size(max=2000) private String reason;
|
||||
}
|
||||
@Data @lombok.EqualsAndHashCode(callSuper=true) public static class Copy extends Create {
|
||||
@NotNull private Long sourceTaskId;
|
||||
@Min(0) private Integer sourceConfigRevision;
|
||||
}
|
||||
@Data public static class Action {
|
||||
@NotNull private Long taskId,unitId;
|
||||
@NotNull private Integer revision;
|
||||
@ -123,6 +128,29 @@ public class DimensionService {
|
||||
else scans.initializeDraft(task.getId(),req.getQuantity());
|
||||
taskService.recordEvent(task.getId(),"DIMENSION_TASK_CREATED",map("quantity",req.getQuantity(),"scan",true));return task.getId();
|
||||
}
|
||||
public Map<String,Object> copySource(long taskId){
|
||||
LabTestTaskDO source=task(taskId,false);actor();
|
||||
var links=taskSamples.selectListByTaskId(taskId);
|
||||
LabSampleDO sample=links.isEmpty()?null:samples.selectById(links.get(0).getSampleId());
|
||||
var config=scanConfigs.byTask(taskId);
|
||||
int quantity=config!=null&&config.getQuantity()!=null?config.getQuantity():links.isEmpty()||links.get(0).getQuantity()==null?1:links.get(0).getQuantity().intValue();
|
||||
String name=Objects.toString(source.getTaskName(),"");name=name.substring(0,Math.min(name.length(),195))+" - 副本";
|
||||
return map("sourceTaskNo",source.getTaskNo(),"sourceConfigRevision",config==null?null:config.getRevision(),
|
||||
"caseName",config==null?null:config.getCaseName(),"versionNo",config==null?null:config.getVersionNo(),
|
||||
"form",map("taskName",name,"externalTaskNo","","sampleCode",sample==null?"":sample.getSampleCode(),
|
||||
"sampleName",sample==null?"":sample.getSampleName(),"quantity",quantity,"projectName",source.getProjectName(),"requirement",source.getRequirement()));
|
||||
}
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public Long copy(Copy req){
|
||||
tenant();actor();LabTestTaskDO source=tasks.selectByIdForUpdate(req.getSourceTaskId());
|
||||
if(source==null)throw invalidParamException("原任务不存在或已删除");
|
||||
// The selected source workflow is copied by the scan aggregate, never by browser input.
|
||||
req.setTestCaseId(null);Long id=create(req);
|
||||
if("SCAN_ONLY".equals(source.getProcessType()))scans.copyPreparation(source.getId(),id,req.getSourceConfigRevision());
|
||||
taskService.recordEvent(id,"DIMENSION_TASK_COPIED",map("sourceTaskId",source.getId(),"sourceTaskNo",source.getTaskNo()));
|
||||
event(id,0,"TASK_COPIED",map("sourceTaskId",source.getId(),"sourceTaskNo",source.getTaskNo()));
|
||||
return id;
|
||||
}
|
||||
/** Logical deletion preserves files and audit history; never issues device commands. */
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public void deleteTask(long taskId){
|
||||
|
||||
@ -7,6 +7,7 @@ public interface ScanOnlyTaskService {
|
||||
boolean isScanTask(Long taskId);
|
||||
void initializeImported(Long taskId,String caseId,int quantity);
|
||||
void initializeDraft(Long taskId,int quantity);
|
||||
void copyPreparation(Long sourceTaskId,Long targetTaskId,Integer expectedSourceRevision);
|
||||
void onExecutionFinished(Long executionId,boolean success,String outputJson,String error);
|
||||
void onControl(Long executionId,String status);
|
||||
void assertRobotAvailable(String robotId,String nativeTaskId);
|
||||
|
||||
@ -99,6 +99,39 @@ public class ScanOnlyTaskServiceImpl implements ScanOnlyTaskService {
|
||||
public void initializeDraft(Long taskId,int quantity) {
|
||||
initializeTask(taskId,"",quantity);
|
||||
}
|
||||
@Override @Transactional(rollbackFor=Exception.class)
|
||||
public void copyPreparation(Long sourceTaskId,Long targetTaskId,Integer expectedSourceRevision) {
|
||||
required(sourceTaskId,true);
|
||||
LabTestTaskDO target=owned(targetTaskId,true);
|
||||
ScanTaskConfigDO source=configs.byTask(sourceTaskId),copy=config(targetTaskId);
|
||||
if(source==null){if(expectedSourceRevision!=null)throw invalidParamException("原任务配置已变化,请重新复制");return;}
|
||||
if(!Objects.equals(source.getRevision(),expectedSourceRevision))throw invalidParamException("原任务参数已更新,请重新打开复制窗口");
|
||||
if(copy.getStartedAt()!=null||Boolean.TRUE.equals(copy.getStopPending())||copy.getResourcesAcquiredAt()!=null
|
||||
||!"PENDING_CONFIRM".equals(target.getStatus()))throw invalidParamException("只能向新建任务复制参数");
|
||||
// Whitelist preparation choices; execution state, physical confirmations and leases stay new.
|
||||
var snapshot=JSON.parseObject(JSON.toJSONString(source),ScanTaskConfigDO.class);
|
||||
if(!ScanOnlyRules.blank(snapshot.getSelectedTestCaseId())){
|
||||
if(ScanOnlyRules.blank(snapshot.getVersionId()))throw invalidParamException("原任务缺少发布版本,请先核对原任务方案");
|
||||
LabTestMethodRefDO method=methods.ensureMethod(snapshot.getSelectedTestCaseId(),snapshot.getVersionId());
|
||||
copy.setSelectedTestCaseId(snapshot.getSelectedTestCaseId());applyRelease(copy,method,snapshot.getVersionId());
|
||||
target.setMethodId(method.getId());tasks.updateById(target);
|
||||
}
|
||||
copy.setRequireFixture(!Boolean.FALSE.equals(snapshot.getRequireFixture()));copy.setFixtureId(snapshot.getFixtureId());
|
||||
copy.setLengthMm(snapshot.getLengthMm());copy.setWidthMm(snapshot.getWidthMm());copy.setHeightMm(snapshot.getHeightMm());copy.setWeightKg(snapshot.getWeightKg());
|
||||
copy.setRobotId(snapshot.getRobotId());copy.setRuntimeAssignments(snapshot.getRuntimeAssignments()==null?new ArrayList<>():snapshot.getRuntimeAssignments());
|
||||
var params=snapshot.getRunParams()==null?new LinkedHashMap<String,Object>():snapshot.getRunParams();
|
||||
stripCopiedFramework(params);
|
||||
var plan=ScanExecutionPlanService.manifest(params);
|
||||
if(plan!=null){
|
||||
for(String key:List.of("steps","allSteps")){JSONArray steps=plan.getJSONArray(key);if(steps!=null)for(Object step:steps)stripCopiedFramework(((JSONObject)step).getJSONObject("params"));}
|
||||
params.put(ScanExecutionPlanService.KEY,plan);copy.setCaseName(snapshot.getCaseName());
|
||||
}
|
||||
copy.setRunParams(params);copy.setRequireLaboratory(snapshot.getRequireLaboratory());copy.setLaboratoryId(snapshot.getLaboratoryId());
|
||||
copy.setExpectedMinutes(snapshot.getExpectedMinutes());copy.setReservationMode("IMMEDIATE");
|
||||
copy.setSampleReceived(false);copy.setFixtureConfirmed(false);copy.setRevision(copy.getRevision()+1);configs.updateById(copy);
|
||||
audit(target,"SCAN_PARAMETERS_COPIED",map("sourceTaskId",sourceTaskId,"sourceRevision",expectedSourceRevision,"versionId",copy.getVersionId()));
|
||||
}
|
||||
private static void stripCopiedFramework(Map<String,Object> params){if(params!=null){params.remove("fixtureFrameworkUrls");params.remove("fixtureFrameworkVersion");}}
|
||||
private void initializeTask(Long taskId,String caseId,int quantity) {
|
||||
primary();
|
||||
if(quantity<1||quantity>10000) throw invalidParamException("样品数量必须为1至10000的整数");
|
||||
|
||||
@ -6,7 +6,11 @@ export const page = (params: any) => request.get<any>({ url: base + '/page', par
|
||||
export const detail = (taskId: any, unitId: any = 0) =>
|
||||
request.get<any>({ url: base + '/get', params: { taskId, unitId } })
|
||||
export const create = (data: any) => request.post<any>({ url: base + '/create', data })
|
||||
export const deleteTask = (taskId: any) => request.delete({ url: base + '/delete', params: { taskId } })
|
||||
export const copySource = (taskId: string | number) =>
|
||||
request.get<any>({ url: base + '/copy-source', params: { taskId } })
|
||||
export const copyTask = (data: any) => request.post<string | number>({ url: base + '/copy', data })
|
||||
export const deleteTask = (taskId: any) =>
|
||||
request.delete({ url: base + '/delete', params: { taskId } })
|
||||
export const claim = (taskId: any) => request.post({ url: base + '/claim', params: { taskId } })
|
||||
export const syncScan = (taskId: any, unitId: any) =>
|
||||
request.post<any>({ url: base + '/sync-scan', params: { taskId, unitId }, timeout: 180000 })
|
||||
|
||||
141
am-web/src/views/lab/dimension/CopyTaskDialog.vue
Normal file
141
am-web/src/views/lab/dimension/CopyTaskDialog.vue
Normal file
@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<Dialog v-model="visible" title="复制任务" width="640px" @closed="invalidate">
|
||||
<div v-loading="loading">
|
||||
<el-alert
|
||||
v-if="source"
|
||||
type="info"
|
||||
:closable="false"
|
||||
class="mb-16px"
|
||||
:title="`从 ${source.sourceTaskNo} 复制${source.caseName ? ` · ${source.caseName}${source.versionNo ? ` V${source.versionNo}` : ''}` : ''}`"
|
||||
/>
|
||||
<el-form label-position="top" :disabled="loading || saving">
|
||||
<el-form-item label="新任务名称" required
|
||||
><el-input v-model="form.taskName" maxlength="200"
|
||||
/></el-form-item>
|
||||
<el-form-item label="委托/外部任务编号(可选)"
|
||||
><el-input
|
||||
v-model="form.externalTaskNo"
|
||||
maxlength="128"
|
||||
placeholder="留空自动生成,填写时请使用新编号"
|
||||
/></el-form-item>
|
||||
<div class="copy-fields">
|
||||
<el-form-item label="样品编号" required
|
||||
><el-input v-model="form.sampleCode" maxlength="64"
|
||||
/></el-form-item>
|
||||
<el-form-item label="样品名称" required
|
||||
><el-input v-model="form.sampleName" maxlength="128"
|
||||
/></el-form-item>
|
||||
<el-form-item label="样件数量" required
|
||||
><el-input-number v-model="form.quantity" :min="1" :max="10000" :precision="0"
|
||||
/></el-form-item>
|
||||
<el-form-item label="项目"
|
||||
><el-input v-model="form.projectName" maxlength="128"
|
||||
/></el-form-item>
|
||||
</div>
|
||||
<el-form-item label="计划完成时间"
|
||||
><el-date-picker
|
||||
v-model="form.plannedFinishAt"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DDTHH:mm:ss"
|
||||
/></el-form-item>
|
||||
<el-form-item label="检测要求"
|
||||
><el-input v-model="form.requirement" type="textarea" maxlength="1024"
|
||||
/></el-form-item>
|
||||
<el-alert
|
||||
title="带入原扫描方案及版本、扫描参数、夹具、尺寸和设备选择,创建后可在扫描准备中修改。新任务需要重新确认收样与装夹,并重新预约资源。"
|
||||
:closable="false"
|
||||
/>
|
||||
<p class="copy-hint">扫描成果、执行记录、已交付状态和原预约时间保留在原任务中。</p>
|
||||
</el-form>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button :disabled="saving" @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" :disabled="loading || !source" @click="submit"
|
||||
>复制并创建</el-button
|
||||
>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import * as Api from '@/api/lab/dimension'
|
||||
|
||||
const emit = defineEmits<{ created: [id: string | number] }>()
|
||||
const message = useMessage()
|
||||
const visible = ref(false),
|
||||
loading = ref(false),
|
||||
saving = ref(false)
|
||||
const source = ref<any>()
|
||||
const sourceTaskId = ref<string | number>()
|
||||
const blank = () => ({
|
||||
taskName: '',
|
||||
externalTaskNo: '',
|
||||
sampleCode: '',
|
||||
sampleName: '',
|
||||
quantity: 1,
|
||||
projectName: '',
|
||||
requirement: '',
|
||||
plannedFinishAt: undefined as string | undefined
|
||||
})
|
||||
const form = reactive(blank())
|
||||
let generation = 0
|
||||
function invalidate() {
|
||||
generation++
|
||||
source.value = undefined
|
||||
}
|
||||
async function open(id: string | number) {
|
||||
if (saving.value) return
|
||||
const request = ++generation
|
||||
sourceTaskId.value = id
|
||||
source.value = undefined
|
||||
Object.assign(form, blank())
|
||||
visible.value = true
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await Api.copySource(id)
|
||||
if (request !== generation || !visible.value) return
|
||||
source.value = data
|
||||
Object.assign(form, blank(), data.form)
|
||||
} finally {
|
||||
if (request === generation) loading.value = false
|
||||
}
|
||||
}
|
||||
async function submit() {
|
||||
if (saving.value || loading.value || !source.value || !sourceTaskId.value) return
|
||||
if (!form.taskName.trim() || !form.sampleCode.trim() || !form.sampleName.trim())
|
||||
return message.warning('请填写任务名称、样品编号和名称')
|
||||
if (!Number.isInteger(form.quantity) || form.quantity < 1 || form.quantity > 10000)
|
||||
return message.warning('样件数量必须为1至10000的整数')
|
||||
saving.value = true
|
||||
try {
|
||||
const id = await Api.copyTask({
|
||||
...form,
|
||||
sourceTaskId: sourceTaskId.value,
|
||||
sourceConfigRevision: source.value.sourceConfigRevision
|
||||
})
|
||||
visible.value = false
|
||||
message.success('任务已复制,原扫描参数已带入新任务')
|
||||
emit('created', id)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
defineExpose({ open })
|
||||
onBeforeUnmount(invalidate)
|
||||
</script>
|
||||
<style scoped>
|
||||
.copy-fields {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0 16px;
|
||||
}
|
||||
.copy-hint {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
@media (max-width: 700px) {
|
||||
.copy-fields {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -26,7 +26,11 @@
|
||||
@keyup.enter="load" /></el-form-item
|
||||
><el-button @click="load" :loading="loading">查询</el-button
|
||||
><el-button v-if="!resultMode" @click="router.push('/lab/task/import')">批量导入</el-button
|
||||
><el-button v-if="!resultMode" v-hasPermi="['lab:barcode:query']" @click="router.push('/lab/task/barcode')">扫码识别</el-button
|
||||
><el-button
|
||||
v-if="!resultMode"
|
||||
v-hasPermi="['lab:barcode:query']"
|
||||
@click="router.push('/lab/task/barcode')"
|
||||
>扫码识别</el-button
|
||||
><MaintenanceActions v-if="mine && !resultMode"
|
||||
/></el-form>
|
||||
<el-table :data="rows" v-loading="loading">
|
||||
@ -53,12 +57,23 @@
|
||||
><span v-else>历史任务,进入查看原有记录</span></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="任务创建时间" prop="create_time" width="185" :formatter="dateFormatter" />
|
||||
<el-table-column label="操作" :width="resultMode ? 120 : 220"
|
||||
<el-table-column
|
||||
label="任务创建时间"
|
||||
prop="create_time"
|
||||
width="185"
|
||||
:formatter="dateFormatter"
|
||||
/>
|
||||
<el-table-column label="操作" :width="resultMode ? 220 : 310"
|
||||
><template #default="{ row }"
|
||||
><el-button type="primary" link @click="open(row)">{{
|
||||
resultMode ? '查看成果' : '进入任务'
|
||||
}}</el-button
|
||||
><el-button
|
||||
v-hasPermi="['lab:task:import']"
|
||||
type="primary"
|
||||
link
|
||||
@click="copyDialog?.open(row.id)"
|
||||
>复制任务</el-button
|
||||
><el-button
|
||||
v-if="!resultMode"
|
||||
v-hasPermi="['lab:task:cancel']"
|
||||
@ -119,6 +134,10 @@
|
||||
>
|
||||
</Dialog>
|
||||
<ResultFilesDialog v-if="resultMode" ref="resultFiles" />
|
||||
<CopyTaskDialog
|
||||
ref="copyDialog"
|
||||
@created="(id) => router.push('/lab/dimension/workbench/' + id)"
|
||||
/>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
@ -126,7 +145,9 @@ import * as Api from '@/api/lab/dimension'
|
||||
import { deliveryStages, taskStates } from './presentation.mjs'
|
||||
import ResultFilesDialog from './ResultFilesDialog.vue'
|
||||
import MaintenanceActions from './MaintenanceActions.vue'
|
||||
import CopyTaskDialog from './CopyTaskDialog.vue'
|
||||
const resultFiles = ref<any>()
|
||||
const copyDialog = ref<InstanceType<typeof CopyTaskDialog>>()
|
||||
const router = useRouter(),
|
||||
route = useRoute(),
|
||||
message = useMessage()
|
||||
|
||||
@ -54,6 +54,7 @@ export function validateUpload(file, role, limit = 0) {
|
||||
return ''
|
||||
}
|
||||
export const eventLabels = {
|
||||
TASK_COPIED: '复制任务并复用参数',
|
||||
SCAN_CLOUD_LINKED: '自动关联本次扫描PLY',
|
||||
TASK_CLAIMED: '领取任务',
|
||||
DIMENSION_TASK_CREATED: '创建检测任务',
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
}} · {{ ['DELIVERED', 'PENDING_CONFIRM'].includes(data.stage) ? '查看成果' : '查看待办' }}</el-button>
|
||||
<el-button v-hasPermi="['lab:barcode:query']" @click="barcodeVisible = true">扫码关联</el-button>
|
||||
<el-button :loading="loading" @click="refresh">刷新</el-button>
|
||||
<el-button v-hasPermi="['lab:task:import']" @click="copyDialog?.open(taskId)">复制任务</el-button>
|
||||
<el-button
|
||||
v-if="!data.task.ownerId && data.task.processType === 'SCAN_ONLY'"
|
||||
type="primary"
|
||||
@ -424,9 +425,11 @@
|
||||
<pre class="snapshot">{{ snapshotText }}</pre>
|
||||
</Dialog>
|
||||
<el-dialog v-model="barcodeVisible" title="扫码关联当前任务" width="min(1000px,95vw)" destroy-on-close><BarcodeScanPanel v-if="barcodeVisible" :task-id="taskId" embedded @navigated="barcodeVisible=false" /></el-dialog>
|
||||
<CopyTaskDialog ref="copyDialog" @created="id => router.push('/lab/dimension/workbench/' + id)" />
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import * as Api from '@/api/lab/dimension'
|
||||
import CopyTaskDialog from './CopyTaskDialog.vue'
|
||||
import { formatNullableDate, dateFormatter } from '@/utils/formatTime'
|
||||
import { checkPermi } from '@/utils/permission'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
@ -446,6 +449,7 @@ const ModelViewer = defineAsyncComponent(
|
||||
const ComparisonPanel = defineAsyncComponent(() => import('./ComparisonPanel.vue'))
|
||||
const BarcodeScanPanel = defineAsyncComponent(() => import('@/views/lab/barcode/BarcodeScanPanel.vue'))
|
||||
const barcodeVisible = ref(false)
|
||||
const copyDialog = ref<InstanceType<typeof CopyTaskDialog>>()
|
||||
const comparisonPanel = ref<any>()
|
||||
const route = useRoute(),
|
||||
router = useRouter(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user