许鹏程
2024-11-05 2264630f3bc0483fd432cdd8e85e55abd3c4b10f
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
package com.product.patch.controller;
 
import com.product.core.config.CoreConst;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.module.sys.version.ApiVersion;
import com.product.patch.config.ErrorCode;
import com.product.patch.service.idel.IPatchImportService;
import com.product.util.BaseUtil;
import com.product.util.support.AbstractBaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Map;
 
/**
 * @Author cheng
 * @Date 2024/10/24 18:22
 * @Desc 补丁导入
 */
@RestController
@RequestMapping("/api/patch/import")
public class PatchImportController extends AbstractBaseController {
 
 
    @Resource
    public IPatchImportService patchImportService;
 
    @PostMapping("/upload/{version}")
    @ApiVersion(1)
    public String upload(HttpServletRequest request) {
        try {
 
            RequestParameterEntity rpe = null;
            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            if (bean != null) {
                rpe = (RequestParameterEntity) bean;
            }
 
            FieldSetEntity fse = rpe.getFormData();
            String fileName = fse.getString("patchFile");
            if (rpe == null || rpe.getFormData() == null || rpe.getFiles() == null || rpe.getFiles().isEmpty() || rpe.getFiles().get(fileName) == null) {
                throw new BaseException(ErrorCode.SYSTEM_FORM_COUNT);
            }
            File patchFile = rpe.getFiles().get(fileName);
 
            IPatchImportService service = (IPatchImportService) getProxyInstance(patchImportService);
 
            Map<String, Object> result = service.uploadPatchFile(patchFile);
 
            return BaseUtil.success(result);
        } catch (BaseException e) {
            e.printStackTrace();
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.EXTRACT_FAIL, e);
        }
    }
}