cheng
2024-01-16 7279b6314b350cc0c865d82dbaa4d0624e4f7b3f
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
package com.product.data.center.controller;
 
import com.product.common.enums.IEnum;
import com.product.core.config.CoreConst;
import com.product.core.controller.support.AbstractBaseController;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.data.center.config.ErrorCode;
import com.product.data.center.service.DataSyncService;
import com.product.data.center.utils.RSAUtil;
import com.product.module.sys.version.ApiVersion;
import com.product.quartz.config.SystemCode;
import com.product.quartz.service.ISysJobService;
import com.product.quartz.service.impl.SysJobService;
import com.product.util.BaseUtil;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
/**
 * @Author cheng
 * @Date 2022/11/14 14:36
 * @Desc
 */
@RestController
@RequestMapping("/api/mes/sync-data/")
public class SyncDataController extends AbstractBaseController {
 
 
    @Resource
    DataSyncService dataSyncService;
    @Resource
    SysJobService jobService;
 
    @RequestMapping(value = "/runTask/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String runTask(HttpServletResponse response,HttpServletRequest request,HttpSession session)
    {
        try {
            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            RequestParameterEntity reqp = (RequestParameterEntity) bean;
            String jobUuid = (String)reqp.getFormData().getValue("uuid");//表uuid
            //数据操作的权限验证
//            if(!permissionService.validDataPermission(CmnConst.PRODUCT_SYS_TIMED_TASK,jobUuid, CoreConst.DATA_PERMISSION_VALID_TYPE_USER)) {
//                SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
//                        SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
//                return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
//            }
//             if(!Global.getPropertyToBoolean("org.quartz.task.isEnable", "true").booleanValue()){
//                 throw new BaseException(SystemCode.SYSTEM_TIME_TASK_CLOSE);
//             }
            Object proxyInstance = getProxyInstance(jobService);
 
            ISysJobService service=(ISysJobService)proxyInstance;
            service.run(jobUuid);
        } catch (BaseException e) {
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e.getCode(), e.getMessageInfo());
        }
//        catch (SchedulerException e) {
//            SpringMVCContextHolder.getSystemLogger().error(e);
//            return error(SystemCode.SYSTEM_QUARTZ_RUN_FAIL.getValue(),SystemCode.SYSTEM_QUARTZ_RUN_FAIL.getText());
//        }
        catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return error(SystemCode.SYSTEM_QUARTZ_RUN_FAIL.getValue(),
                    SystemCode.SYSTEM_QUARTZ_RUN_FAIL.getText());
        }
        return OK();
    }
 
    @PostMapping("/{version}")
    @ApiVersion(1)
    public String syncData(HttpServletRequest request) {
        try {
            FieldSetEntity fieldSetEntity = BaseUtil.getFieldSetEntity(request);
            String syncInfo = fieldSetEntity.getString("syncInfo");
            String encodedData = RSAUtil.publicEncrypt(syncInfo, RSAUtil.getPublicKey(dataSyncService.cryptPublicKey));
//            dataSyncService.dataSync(encodedData);
            return OK();
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.DATA_SYNC_FAIL.getValue(), getErrorMessage(ErrorCode.DATA_SYNC_FAIL, e));
        }
    }
 
 
    public String getErrorMessage(IEnum iEnum, Throwable throwable) {
        String message = iEnum.getText();
        if (throwable.getMessage() != null) {
            message += "," + throwable.getMessage();
        }
        return message;
    }
}