lyh
2026-03-23 533ae8a2dc71edeff73f1e0c62d23718d3ff059b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.lxzn.activiti.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxzn.activiti.dao.ToEquipmentTaskMapper;
import com.lxzn.activiti.service.IToEquipmentTaskService;
import com.lxzn.framework.domain.activiti.ToEquipmentTask;
import com.lxzn.framework.domain.activiti.response.ActivitiCode;
import com.lxzn.framework.domain.nc.DeviceInfo;
import com.lxzn.framework.exception.ExceptionCast;
import com.lxzn.framework.utils.ValidateUtil;
import com.lxzn.framework.utils.file.FileUtil;
import com.lxzn.nc.service.IDeviceGroupService;
import com.lxzn.nc.service.IDeviceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
@Service
public class ToEquipmentTaskServiceImpl extends ServiceImpl<ToEquipmentTaskMapper, ToEquipmentTask> implements IToEquipmentTaskService {
 
    @Autowired
    private IDeviceInfoService deviceInfoService;
    @Autowired
    private IDeviceGroupService deviceGroupService;
    @Value("${fileNcGateway}")
    private  String fileNcGateway;
 
    @Override
    @Transactional(rollbackFor = {Exception.class})
    @Scheduled(cron = "${taskSync}")
    public void updateNcFileFromTask() {
        List<ToEquipmentTask> list = selectTaskSyncFlag(1);
        if(list == null || list.isEmpty()) {
            return;
        }
        for (ToEquipmentTask task : list) {
            //获取文件夹位置
            DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(task.getDeviceNo());
            if(deviceInfo == null) {
                continue;
            }
            List<String> strings =  deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId());
            if (strings == null  || strings.isEmpty()) {
                continue;
            }
            String path = StringUtils.join(strings.toArray(), "/");
            Boolean b =  FileUtil.copyFileUpName(task.getFilePath() + "/" + task.getFileEncodeName(),
                    fileNcGateway +"/" +  path +"/" + task.getDeviceNo() + "/send/" + task.getFileName(),task.getFileSuffix());
            if (b) {
                task.setSyncFlag(2);
            }
        }
        super.saveOrUpdateBatch(list);
    }
 
    @Override
    public List<ToEquipmentTask> selectTaskSyncFlag(Integer syncFlag) {
        if(!ValidateUtil.validateInteger(syncFlag)) {
            return null;
        }
        List<ToEquipmentTask> list = super.lambdaQuery().eq(ToEquipmentTask::getSyncFlag, syncFlag).list();
       /* List<ToEquipmentTask> list = new ArrayList<>();
        ToEquipmentTask t = getById("1800797949617278977");
        list.add(t);*/
        if(list == null || list.isEmpty()) {
            return null;
        }
        return list;
    }
}