许鹏程
2024-11-26 29f1a0a5d9bc184fa497a88ec11c37f10a45df92
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.product.face.controller;
 
import com.drew.metadata.Face;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.config.CoreConst;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.face.config.ErrorCode;
import com.product.face.config.FaceConst;
import com.product.face.service.FaceDesignService;
import com.product.face.service.ide.IFaceDesignService;
import com.product.module.sys.version.ApiVersion;
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.util.*;
 
/**
 * @Author cheng
 * @Date 2023/4/21 17:43
 * @Desc 表单设计
 */
@RestController
@RequestMapping("/api/face-design")
public class FaceDesignController extends AbstractBaseController {
 
    @Resource
    private IFaceDesignService faceDesignService;
 
    /**
     * 表单列表左侧树
     *
     * @return
     */
    @PostMapping("/tree-face/{version}")
    @ApiVersion(1)
    public String faceListTree() {
        DataTableEntity tableInfoData = DataPoolCacheImpl.getInstance().getCacheData("所有表信息");
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (!DataTableEntity.isEmpty(tableInfoData)) {
            for (int i = 0; i < tableInfoData.getRows(); i++) {
                FieldSetEntity fse = tableInfoData.getFieldSetEntity(i);
                Map<String, Object> record = new HashMap<>();
                String tableName = fse.getString(FaceConst.FIELD_TABLE_NAME);
                String value = fse.getString(FaceConst.UUID);
                String tableType = fse.getString(FaceConst.FIELD_TABLE_TYPE);
                String tableDescription = fse.getString("table_description");
                record.put("value", value);
                record.put(FaceConst.FIELD_TABLE_NAME, tableName);
                record.put(FaceConst.FIELD_TABLE_TYPE, tableType);
                record.put("table_description", tableDescription);
                resultList.add(record);
            }
            resultList.sort(Comparator.comparing(o -> o.get(FaceConst.FIELD_TABLE_TYPE).toString()));
        }
        return success(resultList);
    }
 
 
    /**
     * 查询表单设计数据详情
     *
     * @param request
     * @return
     */
    @PostMapping("/find-face-config/{version}")
    @ApiVersion(1)
    public String findFaceConfig(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, FaceConst.TABLE_FACE_CONFIG);
            String uuid = fse.getUUID();
            return faceDesignService.getFaceConfigInfo(uuid);
        } catch (BaseException e) {
            e.printStackTrace();
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.SAVE_FACE_FAIL, e);
        }
    }
 
    /**
     * 保存表单设计数据
     *
     * @param request
     * @return
     */
    @PostMapping("/save-face/{version}")
    @ApiVersion(1)
    public String saveFaceData(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, FaceConst.TABLE_FACE_CONFIG);
            IFaceDesignService proxy = getProxy();
            return OK_List(proxy.saveFaceData(fse));
        } catch (BaseException e) {
            e.printStackTrace();
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.SAVE_FACE_FAIL, e);
        }
    }
 
    /**
     * 删除表单设计
     *
     * @param request
     * @return
     */
    @PostMapping("/delete-face/{version}")
    @ApiVersion(1)
    public String deleteFace(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, FaceConst.TABLE_FACE_CONFIG);
            IFaceDesignService proxy = getProxy();
            proxy.deleteFace(fse);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.DELETE_FACE_FAIL, e);
        }
    }
 
    /**
     * 获取事务代理
     *
     * @return
     */
    private IFaceDesignService getProxy() {
        return (IFaceDesignService) getProxyInstance(faceDesignService);
    }
 
 
}