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
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
package cn.autoform.web.controller.publish;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import cn.autoform.db.entity.FormBaseEntity;
import cn.autoform.fw.exception.RestResult;
import cn.autoform.fw.utility.RestResultGenerator;
import cn.autoform.web.service.publish.PublishService;
 
@RestController
public class PublishController<T> {
 
    @Autowired
    private PublishService publishService = null;
    
    @Value("${server.publishurl}")
    private String publishurl;
    
    /**
     * 取得表单设置的密码
     * @param tenantID
     * @param formID
     * @return
     */
    @RequestMapping(value = "${requset.publish01}", method = RequestMethod.GET)
    public RestResult<Map<String,String>> getPublishPasswordService(String tenantID, String formID) {
        
        Map<String,String> rsMap = new HashMap<String,String>();
        List<FormBaseEntity> listFormBaseEntity = publishService.getPublishInfo(tenantID, formID);
        rsMap.put("requirepassword", listFormBaseEntity.get(0).getRequirepassword());
        rsMap.put("accesspassword", listFormBaseEntity.get(0).getAccesspassword());
        
        return RestResultGenerator.genSuccessResult(rsMap);
    }
    
    /**
     * 初期化表单发布信息
     * @param tenantID
     * @param formID
     * @return
     */
    @RequestMapping(value = "${requset.publish02}", method = RequestMethod.GET)
    public RestResult<Map<String,Object>> getPublishInfoService(String tenantID, String formID) {
        Map<String,Object> rsMap = new HashMap<String,Object>();
        List<FormBaseEntity> listFormBaseEntity = publishService.getPublishInfo(tenantID, formID);
        String publishURL = publishurl + "/" + tenantID + "/" + formID;
        if(listFormBaseEntity.isEmpty()) {
            FormBaseEntity formBase = new FormBaseEntity();
            formBase.setPublishURL(publishURL);
            formBase.setRequirepassword("0");
            rsMap.put("isPublish", "0");
            rsMap.put("formbase", formBase);
            
        } else {
            
            FormBaseEntity formBase = listFormBaseEntity.get(0);
            if(formBase.getPublishURL() == null){
                
                formBase.setPublishURL(publishURL);
                rsMap.put("isPublish", "0");
                rsMap.put("formbase", formBase);
            } else {
                rsMap.put("isPublish", "1");
                rsMap.put("formbase", formBase);
            }
        }
        
 
        return RestResultGenerator.genSuccessResult(rsMap);
    }
    
    /**
     * 更新表单发布信息
     * @param formBaseEntity
     * @return
     */
    @RequestMapping(value = "${requset.publish03}", method = RequestMethod.POST)
    public RestResult<String> updatePublishInfoService(@RequestBody FormBaseEntity formBaseEntity) {
        int nRs  = publishService.updatePublishInfo(formBaseEntity);
        
        return RestResultGenerator.genSuccessResult(String.valueOf(nRs));
    }
    
    
    
    @RequestMapping(value = "${requset.publish04}", method = RequestMethod.GET)
    public RestResult<String> downloadPageService(String formID,String tenantID) throws IOException {
        String url = publishurl + "/" + tenantID + "/" + formID;
        String path = publishService.downloadPage(url,formID,tenantID);
        
        return RestResultGenerator.genSuccessResult(path);
    }
}