许鹏程
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.product.patch.controller;
 
import com.product.common.utils.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.module.sys.version.ApiVersion;
import com.product.patch.config.ErrorCode;
import com.product.patch.service.PatchExportService;
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 javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Author cheng
 * @Date 2024/10/23 10:05
 * @Desc 补丁导出
 */
@RestController
@RequestMapping("/api/patch/export")
public class PatchExportController extends AbstractBaseController {
 
    @Resource
    private PatchExportService patchExportService;
 
    @PostMapping("/get-table-field-reference/{version}")
    @ApiVersion(1)
    public String getTableFieldReference(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
            String tableUuid = fse.getString("table_uuid");
            String[] uuids = tableUuid.split(",");
            DataTableEntity fields = new DataTableEntity();
            for (String uuid : uuids) {
                DataTableEntity f = DataPoolCacheImpl.getInstance().getCacheData("所有字段信息并按表分组", new String[]{uuid});
                BaseUtil.dataTableMerge(fields, f);
            }
            List<String> result = new ArrayList<>();
            for (int i = 0; i < fields.getRows(); i++) {
                if (StringUtils.isEmpty(fields.getString(i, "field_reference"))) {
                    result.add(fields.getString(i, "field_reference"));
                }
            }
            return BaseUtil.success(result);
        } catch (BaseException e) {
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.GET_TABLE_FIELD_REFERENCE_FAIL, e);
        }
    }
 
    @PostMapping("/execute/{version}")
    @ApiVersion(1)
    public String exportPath(HttpServletRequest request, HttpServletResponse response) {
        try {
 
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
 
            patchExportService.export(fse, response);
            return OK();
 
        } catch (BaseException e) {
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.EXTRACT_FAIL, e);
        }
 
 
    }
}