View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2014-7-1 上午10:35:30
4    */
5   package gboat2.example.action;
6   
7   import gboat2.attachment.model.AttachConfig;
8   import gboat2.attachment.model.AttachmentVO;
9   import gboat2.base.core.web.BaseActionSupport;
10  
11  import java.text.ParseException;
12  import java.util.ArrayList;
13  import java.util.Arrays;
14  import java.util.LinkedHashMap;
15  import java.util.List;
16  import java.util.Map;
17  
18  import org.apache.commons.lang3.time.DateUtils;
19  
20  /**
21   * 附件上传组件的示例 Action
22   * 
23   * @date 2014-7-1
24   * @author <a href="mailto:[email protected]">何明旺</a>
25   * @since 3.0
26   */
27  public class AttachAction extends BaseActionSupport {
28  
29      private static final long serialVersionUID = 1L;
30  
31  	private Map<AttachConfig, List<AttachmentVO>> attachMap;
32  	private String oldVersionJsonStr;
33  	
34  	private String SID;
35  	private String[] attachIds;
36  	
37  	private AttachConfig attachConfig;
38  	private List<AttachmentVO> uploadeds;
39  	
40  	private void initTestData(){
41  	    SID = "f39ca1b445d192210145da904de813fd";
42          oldVersionJsonStr =
43                  "{" +
44                  "    'types' : [ {" + 
45                  "        'configId' : 'ff8080813d9f4e69013da061cf1f01d9'," + 
46                  "        'attachType' : '中标通知书'," + 
47                  "        'required' : 'true'," + 
48                  "        'maxFileCount' : -1," + 
49                  "        'fileFilters' : null," + 
50                  "        'maxFileSize' : null" + 
51                  "    }, {" + 
52                  "        'configId' : 'ff8080813d9f4e69013da0620f0b01da'," + 
53                  "        'attachType' : '合同协议书'," + 
54                  "        'required' : 'false'," + 
55                  "        'maxFileCount' : -1," + 
56                  "        'fileFilters' : null," + 
57                  "        'maxFileSize' : null" + 
58                  "    }, {" + 
59                  "        'configId' : 'ff8080813d9f4e69013da0624eb601db'," + 
60                  "        'attachType' : '竣工验收证书或证明材料'," + 
61                  "        'required' : 'false'," + 
62                  "        'maxFileCount' : -1," +
63                  "        'fileFilters' : null," + 
64                  "        'maxFileSize' : null" + 
65                  "    } ]," + 
66                  "    'uploadeds' : [ {" + 
67                  "        'attachCode' : 'ATTACH_ENTERPRISE_PERFORMANCE'," + 
68                  "        'attachId' : 'f39ca1b441a203d10141a2206bc4005f'," + 
69                  "        'attachName' : '中标通知书'," + 
70                  "        'attachOrder' : '1.0'," + 
71                  "        'attachType' : ''," +
72                  "        'belongId' : 'f39ca1b441a203d10141a220c9a90067'," + 
73                  "        'changeId' : ''," + 
74                  "        'configAttachType' : '中标通知书'," + 
75                  "        'configId' : 'ff8080813d9f4e69013da0624eb601db'," + 
76                  "        'downloadUrl' : '/upload/20131010/13814045357393966.jpg'," + 
77                  "        'originalName' : '特殊符号.jpg'," + 
78                  "        'required' : ''," + 
79                  "        'savePath' : '20131010/13814045357393966.jpg'," + 
80                  "        'size' : 3541," + 
81                  "        'uploadDate' : '2013-10-10 19:28:55'," + 
82                  "        'uploaderId' : '广联达软件股份有限公司'," +
83                  "        'validateCode' : '770d608ca218a548182f7f26b31768aa'," + 
84                  "        'watermarkFailed' : '1'" +
85                  "    } ]" + 
86                  "}";
87          
88          attachConfig = new AttachConfig();
89          attachConfig.setAttachCode("ATTACH_ENTERPRISE_PERFORMANCE");
90          attachConfig.setAttachOrder(1);
91          attachConfig.setAttachType("中标通知书");
92          attachConfig.setAvaliable("true");
93          attachConfig.setConfigId("ff8080813d9f4e69013da061cf1f01d9");
94          attachConfig.setFileFilters("doc,docx,jpg,png");
95          attachConfig.setMaxFileCount(3);
96          attachConfig.setModuleName("企业业绩管理");
97          attachConfig.setRequired("true");
98          
99          AttachConfig config_2 = new AttachConfig();
100         config_2.setAttachCode("ATTACH_ENTERPRISE_PERFORMANCE");
101         config_2.setAttachOrder(2);
102         config_2.setAttachType("合同协议书");
103         config_2.setAvaliable("true");
104         config_2.setConfigId("ff8080813d9f4e69013da0620f0b01da");
105         config_2.setModuleName("企业业绩管理");
106         config_2.setRequired("false");
107         
108         AttachmentVO attachmentVo = new AttachmentVO();
109         attachmentVo.setAttachId("8aa18a9946fb69ad0146fb6f78b90004");
110         attachmentVo.setAttachName("中标通知书");
111         attachmentVo.setAttachOrder(1.0f);
112         attachmentVo.setAttachType("");
113         attachmentVo.setBelongId("f39ca1b441a203d10141a220c9a90067");
114         attachmentVo.setChangeId("");
115         attachmentVo.setConfigAttachType("中标通知书");
116         attachmentVo.setConfigId("ff8080813d9f4e69013da061cf1f01d9");
117         attachmentVo.setDownloadUrl("/upload/20131010/13814045357393966.jpg");
118         attachmentVo.setOriginalName("特殊符号.jpg");
119         attachmentVo.setRequired("");
120         attachmentVo.setSavePath("20131010/13814045357393966.jpg");
121         attachmentVo.setSize(3541l);
122         try {
123             attachmentVo.setUploadDate(DateUtils.parseDate("2013-10-10 19:28:55", "yyyy-MM-dd HH:mm:ss"));
124         } catch (ParseException e) {
125             e.printStackTrace();
126         }
127         attachmentVo.setUploaderId("广联达软件股份有限公司");
128         attachmentVo.setValidateCode("770d608ca218a548182f7f26b31768aa");
129         attachmentVo.setWatermarkFailed("1");
130         uploadeds = new ArrayList<AttachmentVO>(1);
131         uploadeds.add(attachmentVo);
132     
133         attachMap = new LinkedHashMap<AttachConfig, List<AttachmentVO>>(2);
134         attachMap.put(attachConfig, uploadeds);
135         attachMap.put(config_2, new ArrayList<AttachmentVO>(0));
136 	}
137 	
138 	@Override
139 	public String execute(){
140 	    initTestData();
141 	    return "attach";
142 	}
143 	
144 	public String photo(){
145 	    initTestData();
146         return "photo";
147 	}
148 
149 	@Override
150     public String save() {
151         System.out.println("需要关联的附件 ID: " + Arrays.toString(attachIds));
152         return null;
153     }
154 	
155 	@Override
156 	public String list() {
157         initTestData();
158         return "sequence";
159 	}
160 
161     @Override
162     public String getSID() {
163         return SID;
164     }
165 
166     public Map<AttachConfig, List<AttachmentVO>> getAttachMap() {
167         return attachMap;
168     }
169 
170     public String getOldVersionJsonStr() {
171         return oldVersionJsonStr;
172     }
173 
174     public void setAttachIds(String[] attachIds) {
175         this.attachIds = attachIds;
176     }
177 
178     public AttachConfig getAttachConfig() {
179         return attachConfig;
180     }
181 
182     public List<AttachmentVO> getUploadeds() {
183         return uploadeds;
184     }
185 
186 }