zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
package com.changhong.epc.rely.api.epc.autoForm;
 
import com.alibaba.fastjson.TypeReference;
import com.changhong.epc.bean.form.FormBaseEntity;
import com.changhong.epc.bean.form.FormFieldEntity;
import com.changhong.epc.constter.base.Context;
import com.changhong.epc.constter.system.prop.ChangHongProperties;
import com.changhong.epc.rely.api.epc.BaseApi;
import com.iemsoft.framework.cloud.core.base.ResMsg;
import com.iemsoft.framework.cloud.core.thread.ThreadData;
import com.iemsoft.framework.cloud.core.tools.http.Http;
import lombok.Setter;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
 
import static com.changhong.epc.constter.base.BaseConst.TENANT_ID;
 
@Service
public class FormApi extends BaseApi {
 
    @Resource
    @Setter
    private ChangHongProperties changHongProperties;
 
    /**
     * 获取表单信息
     * @param formId
     * @return
     */
    public FormBaseEntity getFormBaseEntity(String formId){
        return (FormBaseEntity) Http.get(
                String.format("http://%s:%s/autoForm/formbase/getFormInfoService", changHongProperties.getFormServiceUrl(), changHongProperties.getFormServicePost())
                    , ResMsg.class)
                .addUrlParam("formID", formId)
                .addUrlParam("tenantID", Context.getTenantId())
                .addValidate(BaseApi::assertSuccess)
                .execute(new TypeReference<ResMsg<FormBaseEntity>>(){}.getType())
                .map(res->((ResMsg) res).getData())
                .orElse(null);
    }
 
    /**
     * 获取表单控件信息
     * @param formId
     * @return
     */
    public List<FormFieldEntity> getFormFields(String formId){
        return (List<FormFieldEntity>) Http.get(
                String.format("http://%s:%s/autoForm/datamanagement/getFormFieldListService", changHongProperties.getFormServiceUrl(), changHongProperties.getFormServicePost())
                , ResMsg.class)
                .addUrlParam("formID", formId)
                .addUrlParam("tenantID", Context.getTenantId())
                .addValidate(BaseApi::assertSuccess)
                .execute(new TypeReference<ResMsg<List<FormFieldEntity>>>(){}.getType())
                .map(res->((ResMsg) res).getData())
                .orElse(Collections.EMPTY_LIST);
    }
 
    public static void main(String... args){
        FormApi formApi = new FormApi();
        ChangHongProperties c = new ChangHongProperties();
        c.setFormServiceUrl("epcf.chfcloud.com");
        c.setFormServicePost("8081");
        formApi.setChangHongProperties(c);
        ThreadData.set(TENANT_ID, "100000001");
        System.out.println(
//                formApi.getFormBaseEntity("4cf2b58ef36f14d200fbdc308f64b319")
        );
        System.out.println(
                formApi.getFormFields("4cf2b58ef36f14d200fbdc308f64b319")
        );
    }
}