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
package com.ruoyi.process.aspect;
 
import com.ruoyi.inspect.pojo.InsOrder;
import com.ruoyi.process.service.InspectionOrderService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * 成品下单和报告流程完成后,同步检验委托单中的衍生信息。
 *
 * cnas-process 依赖 inspect-server,因此通过切面监听,避免 inspect-server
 * 反向依赖过程要求模块。
 */
@Aspect
@Component
@Slf4j
public class InspectionOrderSyncAspect {
 
    @Resource
    private InspectionOrderService inspectionOrderService;
 
    @AfterReturning(value = "execution(* com.ruoyi.inspect.service.impl.InsOrderServiceImpl.upInsOrderOfState(..)) && args(insOrder)")
    public void syncEntrustCode(InsOrder insOrder) {
        if (insOrder == null || !Integer.valueOf(1).equals(insOrder.getState())) {
            return;
        }
        try {
            inspectionOrderService.syncEntrustCode(insOrder.getId());
        } catch (Exception e) {
            log.error("同步检验委托单委托编号失败,成品下单ID:{}", insOrder.getId(), e);
        }
    }
 
    @AfterReturning(value = "execution(* com.ruoyi.inspect.service.impl.InsReportServiceImpl.ratifyReport(..)) && args(reportId, isRatify, ratifyTell)")
    public void syncReportFile(Integer reportId, Integer isRatify, String ratifyTell) {
        if (!Integer.valueOf(1).equals(isRatify)) {
            return;
        }
        try {
            inspectionOrderService.syncReportFile(reportId);
        } catch (Exception e) {
            // 报告批准不能因委托单附件同步失败而回滚,保留日志供后续重试。
            log.error("同步检验委托单报告失败,报告ID:{}", reportId, e);
        }
    }
}