新火炬后端单体项目初始化代码
Houjie
2 天以前 67ac603f410319a0d999e5f493c8ef2d74163fe1
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package org.jeecg.modules.mes.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.mes.entity.MesProductionOrder;
import org.jeecg.modules.mes.mapper.MesProductionOrderMapper;
import org.jeecg.modules.mes.service.IMesProductionOrderService;
import org.jeecg.modules.sap.dto.ProductionOrderDTO;
import org.jeecg.modules.sap.request.ProductionOrderSyncRequest;
import org.jeecg.modules.sap.service.ProductionOrderSync;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @Description: SAP生产订单
 * @Author: jeecg-boot
 * @Date: 2025-07-04
 * @Version: V1.0
 */
@Service
public class MesProductionOrderServiceImpl extends ServiceImpl<MesProductionOrderMapper, MesProductionOrder> implements IMesProductionOrderService {
    //工厂编码(新火炬 2301)
    @Value("${xhj.factoryCode:2301}")
    private String FACTORY_CODE;
 
    @Autowired
    private ProductionOrderSync productionOrderSync;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, MesProductionOrder> saveOrUpdateProductionOrder(List<ProductionOrderDTO> productionOrderDTOList) {
        Map<String, MesProductionOrder> resultMap = new HashMap<>();
        for (ProductionOrderDTO productionOrderDTO : productionOrderDTOList) {
            MesProductionOrder updated = getByOrderCode(productionOrderDTO.getAUFNR());
            if (updated == null) {
                updated = new MesProductionOrder(productionOrderDTO);
                resultMap.put(updated.getOrderCode(), updated);
                this.getBaseMapper().insert(updated);
            } else {
                updated.updateEntity(productionOrderDTO);
                resultMap.put(updated.getOrderCode(), updated);
                this.getBaseMapper().updateById(updated);
            }
        }
        return resultMap;
    }
 
    @Override
    public MesProductionOrder getByOrderCode(String orderCode) {
        LambdaQueryWrapper<MesProductionOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MesProductionOrder::getOrderCode, orderCode);
        queryWrapper.eq(MesProductionOrder::getDelFlag, CommonConstant.DEL_FLAG_0);
        List<MesProductionOrder> list = super.list(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
 
    @Override
    public String getLastSyncCreateDate() {
        String lastSyncDate = this.getBaseMapper().getLastSyncCreateDate();
        if (lastSyncDate == null) {
            return null;
        }
        return lastSyncDate.replaceAll("-", "");
    }
 
    @Override
    public String getLastSyncUpdateDate() {
        String lastSyncDate = this.getBaseMapper().getLastSyncUpdateDate();
        if (lastSyncDate == null) {
            return null;
        }
        return lastSyncDate.replaceAll("-", "");
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean syncSapProductionOrder(String id) {
        MesProductionOrder entity = super.getById(id);
        if (entity == null) {
            throw new JeecgBootException("生产订单不存在,请刷新重置!");
        }
        ProductionOrderSyncRequest request = new ProductionOrderSyncRequest();
        request.setOrderCode(entity.getOrderCode());
        request.setFactoryCode(FACTORY_CODE);
        try {
            Map<String, Object> resultMap = productionOrderSync.syncProductionOrder(request);
            if (resultMap == null) {
                throw new JeecgBootException("响应结果为空!");
            }
            if (!CommonConstant.SAP_SUCCESS_CODE.equals(resultMap.get("ztype"))) {
                throw new JeecgBootException(resultMap.get("zmess").toString());
            }
            //调用成功,获取返回数据
            Object result = resultMap.get("result");
            boolean b = result instanceof List;
            if (!b) {
                throw new JeecgBootException("返回结果格式错误!");
            }
            List<ProductionOrderDTO> productionOrderDTOList = (List<ProductionOrderDTO>) result;
            if (CollectionUtil.isEmpty(productionOrderDTOList)) {
                throw new JeecgBootException("SAP未查询到生成订单!");
            }
            ProductionOrderDTO dto = productionOrderDTOList.get(0);
            entity.updateEntity(dto);
            super.updateById(entity);
        } catch (Exception e) {
            throw new JeecgBootException("请求SAP失败:" + e.getMessage());
        }
        return true;
    }
}