PreviewController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. package com.goafanti.common.controller;
  2. import java.util.Calendar;
  3. import java.util.Date;
  4. import javax.annotation.Resource;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. import com.goafanti.cognizance.service.OrgActivityCostService;
  11. import com.goafanti.cognizance.service.OrgActivityService;
  12. import com.goafanti.cognizance.service.OrgFinanceService;
  13. import com.goafanti.cognizance.service.OrgHonorDatumService;
  14. import com.goafanti.cognizance.service.OrgIntellectualPropertyService;
  15. import com.goafanti.cognizance.service.OrgRatepayService;
  16. import com.goafanti.cognizance.service.OrgStandardService;
  17. import com.goafanti.cognizance.service.OrgTechAchievementService;
  18. import com.goafanti.cognizance.service.OrgTechCenterDetailService;
  19. import com.goafanti.cognizance.service.OrgTechProductService;
  20. import com.goafanti.common.bo.Result;
  21. import com.goafanti.common.constant.ErrorConstants;
  22. import com.goafanti.common.enums.AttachmentType;
  23. import com.goafanti.common.model.OrgActivity;
  24. import com.goafanti.common.model.OrgActivityCost;
  25. import com.goafanti.common.model.OrgFinance;
  26. import com.goafanti.common.model.OrgHonorDatum;
  27. import com.goafanti.common.model.OrgHumanResource;
  28. import com.goafanti.common.model.OrgIntellectualProperty;
  29. import com.goafanti.common.model.OrgRatepay;
  30. import com.goafanti.common.model.OrgStandard;
  31. import com.goafanti.common.model.OrgTechAchievement;
  32. import com.goafanti.common.model.OrgTechCenterDetail;
  33. import com.goafanti.common.model.OrgTechProduct;
  34. import com.goafanti.common.model.OrganizationIdentity;
  35. import com.goafanti.common.model.PatentInfo;
  36. import com.goafanti.common.model.TechProject;
  37. import com.goafanti.common.utils.DateUtils;
  38. import com.goafanti.common.utils.SHA256Util;
  39. import com.goafanti.common.utils.StringUtils;
  40. import com.goafanti.copyright.bo.CopyrightInfoDetail;
  41. import com.goafanti.copyright.service.CopyrightInfoService;
  42. import com.goafanti.patent.service.PatentInfoService;
  43. import com.goafanti.techproject.service.TechProjectService;
  44. import com.goafanti.user.service.OrgHumanResourceService;
  45. import com.goafanti.user.service.OrganizationIdentityService;
  46. import com.goafanti.user.service.UserService;
  47. @Controller
  48. @RequestMapping("/open/")
  49. public class PreviewController extends BaseApiController {
  50. @Resource
  51. private PatentInfoService patentInfoService;
  52. @Resource
  53. private UserService userService;
  54. @Resource
  55. private CopyrightInfoService copyrightInfoService;
  56. @Resource
  57. private TechProjectService techProjectService;
  58. @Resource
  59. private OrgTechCenterDetailService orgTechCenterDetailService;
  60. @Resource
  61. private OrgActivityService orgActivityService;
  62. @Resource
  63. private OrgActivityCostService orgActivityCostService;
  64. @Resource
  65. private OrgTechProductService orgTechProductService;
  66. @Resource
  67. private OrgIntellectualPropertyService orgIntellectualPropertyService;
  68. @Resource
  69. private OrgTechAchievementService orgTechAchievementService;
  70. @Resource
  71. private OrgRatepayService orgRatepayService;
  72. @Resource
  73. private OrgFinanceService orgFinanceService;
  74. @Resource
  75. private OrgHumanResourceService OrgHumanResourceService;
  76. @Resource
  77. private OrgHonorDatumService OrgHonorDatumService;
  78. @Resource
  79. private OrgStandardService orgStandardService;
  80. @Resource
  81. private OrganizationIdentityService organizationIdentityService;
  82. @Value(value = "${aesSecretKey}")
  83. private String secretKey = null;
  84. @RequestMapping(value = "/preview", method = RequestMethod.GET)
  85. public Result preview(HttpServletResponse response, String sign, String temp, String token, String auth) {
  86. Result res = new Result();
  87. if (!StringUtils.isNumeric(temp)) {
  88. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "预览"));
  89. } else if (DateUtils.truncatedMinuteDiffTo(Calendar.getInstance().getTime(),
  90. new Date(Long.parseLong(temp))) > 19) {
  91. res.getError().add(buildError(ErrorConstants.NO_AUTH_ERROR));
  92. } else if (!SHA256Util.toHash(sign + "|" + token + "|" + secretKey, temp).equals(auth)) {
  93. res.getError().add(buildError(ErrorConstants.NO_AUTH_ERROR));
  94. } else {
  95. AttachmentType attachmentType = AttachmentType.getField(sign);
  96. switch (attachmentType) {
  97. case PATENT_PRORY_STATEMENT:
  98. case PATENT_WRITING:
  99. case AUTHORIZATION_NOTICE:
  100. case PATENT_CERTIFICATE:
  101. PatentInfo pi = patentInfoService.selectByPrimaryKey(token);
  102. if (pi == null) {
  103. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  104. return res;
  105. } else {
  106. handlePatentPreview(response, pi, attachmentType);
  107. }
  108. break;
  109. case LAST_YEAR_RATEPAY:
  110. case RATEPAY:
  111. OrgRatepay ratepay = orgRatepayService.selectByPrimaryKey(token);
  112. if (null == ratepay) {
  113. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  114. return res;
  115. } else {
  116. handleRatepayPreview(response, ratepay, attachmentType);
  117. }
  118. break;
  119. case COPYRIGHT_AUTH:
  120. case COPYRIGHT_APPLY:
  121. CopyrightInfoDetail ci = copyrightInfoService.findByPrimaryKey(token);
  122. if (null == ci) {
  123. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  124. return res;
  125. } else {
  126. handleCopyrightPreview(response, ci, attachmentType);
  127. }
  128. break;
  129. case TECH_PROJECT:
  130. TechProject tp = techProjectService.selectByPrimaryKey(token);
  131. if (null == tp) {
  132. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  133. return res;
  134. } else {
  135. handleTechProjectPreview(response, tp, attachmentType);
  136. }
  137. break;
  138. case PROTOCOL:
  139. OrgTechCenterDetail otcd = orgTechCenterDetailService.selectByPrimaryKey(token);
  140. if (null == otcd) {
  141. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  142. return res;
  143. } else {
  144. handleTechCenterDetailPreview(response, otcd, attachmentType);
  145. }
  146. break;
  147. case PROOF:
  148. OrgActivity oa = orgActivityService.selectOrgActivityByPrimaryKey(token);
  149. if (null == oa) {
  150. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  151. return res;
  152. } else {
  153. handleActivityPreview(response, oa, attachmentType);
  154. }
  155. break;
  156. case ACTIVITY_COST_ACCOUNT:
  157. OrgActivityCost oac = orgActivityCostService.selectByPrimaryKey(token);
  158. if (null == oac) {
  159. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  160. return res;
  161. } else {
  162. handleActivityCostPreview(response, oac, attachmentType);
  163. }
  164. break;
  165. case TECH_PRODUCT:
  166. OrgTechProduct otp = orgTechProductService.selectByPrimaryKey(token);
  167. if (null == otp) {
  168. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  169. return res;
  170. } else {
  171. handleTechProductPreview(response, otp, attachmentType);
  172. }
  173. break;
  174. case PROPERTY_RIGHT:
  175. OrgIntellectualProperty oip = orgIntellectualPropertyService.selectByPrimaryKey(token);
  176. if (null == oip) {
  177. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  178. return res;
  179. } else {
  180. handleIntellectualPropertyPreview(response, oip, attachmentType);
  181. }
  182. break;
  183. case ACHIEVEMENT:
  184. OrgTechAchievement ota = orgTechAchievementService.selectByPrimaryKey(token);
  185. if (null == ota) {
  186. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  187. return res;
  188. } else {
  189. handleAchievementPreview(response, ota, attachmentType);
  190. }
  191. break;
  192. case FINANCE:
  193. OrgFinance of = orgFinanceService.selectByPrimaryKey(token);
  194. if (null == of) {
  195. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  196. return res;
  197. } else {
  198. handleFinancePreview(response, of, attachmentType);
  199. }
  200. break;
  201. case ROSTER:
  202. case SOCIAL_SECURITY:
  203. OrgHumanResource ohr = OrgHumanResourceService.selectByPrimaryKey(token);
  204. if (null == ohr) {
  205. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  206. return res;
  207. } else {
  208. handleHumanResourcePreview(response, ohr, attachmentType);
  209. }
  210. break;
  211. case HONOR:
  212. OrgHonorDatum ohd = OrgHonorDatumService.selectByPrimaryKey(token);
  213. if (null == ohd) {
  214. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  215. return res;
  216. } else {
  217. handleHonorPreview(response, ohd, attachmentType);
  218. }
  219. break;
  220. case STANDARD:
  221. OrgStandard os = orgStandardService.selectByPrimaryKey(token);
  222. if (null == os) {
  223. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
  224. return res;
  225. } else {
  226. handleStandardPreview(response, os, attachmentType);
  227. }
  228. break;
  229. default:
  230. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "预览"));
  231. }
  232. }
  233. return res;
  234. }
  235. private void handlePatentPreview(HttpServletResponse response, PatentInfo pi, AttachmentType attachmentType) {
  236. if (attachmentType == AttachmentType.PATENT_PRORY_STATEMENT) {
  237. OrganizationIdentity oi = organizationIdentityService.selectOrgIdentityByUserId(pi.getUid());
  238. downloadFile(response, oi.getPatentProryStatementDownloadFileName(), oi.getPatentProryStatementUrl());
  239. } else if (attachmentType == AttachmentType.PATENT_WRITING) {
  240. downloadFile(response, pi.getPatentWritingDownloadFileName(), pi.getPatentWritingUrl());
  241. } else if (attachmentType == AttachmentType.AUTHORIZATION_NOTICE) {
  242. downloadFile(response, pi.getAuthorizationNoticeDownloadFileName(), pi.getAuthorizationNoticeUrl());
  243. } else if (attachmentType == AttachmentType.PATENT_CERTIFICATE) {
  244. downloadFile(response, pi.getPatentCertificateDownloadFileName(), pi.getPatentCertificateUrl());
  245. }
  246. }
  247. private void handleRatepayPreview(HttpServletResponse response, OrgRatepay ratepay, AttachmentType attachmentType) {
  248. if (attachmentType == AttachmentType.LAST_YEAR_RATEPAY || attachmentType == AttachmentType.RATEPAY) {
  249. downloadFile(response, ratepay.getTaxReturnDownloadFileName(), ratepay.getTaxReturnUrl());
  250. }
  251. }
  252. private void handleCopyrightPreview(HttpServletResponse response, CopyrightInfoDetail ci,
  253. AttachmentType attachmentType) {
  254. if (attachmentType == AttachmentType.COPYRIGHT_AUTH) {
  255. downloadFile(response, ci.getCertificateUrlDownloadFileName(), ci.getCertificateUrl());
  256. } else if (attachmentType == AttachmentType.COPYRIGHT_APPLY) {
  257. downloadFile(response, ci.getApplicationUrlDownloadFileName(), ci.getApplicationUrl());
  258. }
  259. }
  260. private void handleTechProjectPreview(HttpServletResponse response, TechProject tp, AttachmentType attachmentType) {
  261. if (attachmentType == AttachmentType.TECH_PROJECT) {
  262. downloadFile(response, tp.getApprovalDownloadFileName(), tp.getApprovalUrl());
  263. }
  264. }
  265. private void handleTechCenterDetailPreview(HttpServletResponse response, OrgTechCenterDetail otcd,
  266. AttachmentType attachmentType) {
  267. if (attachmentType == AttachmentType.PROTOCOL) {
  268. downloadFile(response, otcd.getProtocolDownloadFileName(), otcd.getProtocolUrl());
  269. }
  270. }
  271. private void handleActivityPreview(HttpServletResponse response, OrgActivity oa, AttachmentType attachmentType) {
  272. if (attachmentType == AttachmentType.PROOF) {
  273. downloadFile(response, oa.getProofDownloadFileName(), oa.getProofUrl());
  274. }
  275. }
  276. private void handleActivityCostPreview(HttpServletResponse response, OrgActivityCost oac,
  277. AttachmentType attachmentType) {
  278. if (attachmentType == AttachmentType.ACTIVITY_COST_ACCOUNT) {
  279. downloadFile(response, oac.getAccountDownloadFileName(), oac.getAccountUrl());
  280. }
  281. }
  282. private void handleTechProductPreview(HttpServletResponse response, OrgTechProduct otp,
  283. AttachmentType attachmentType) {
  284. if (attachmentType == AttachmentType.TECH_PRODUCT) {
  285. downloadFile(response, otp.getAccountDownloadFileName(), otp.getAccountUrl());
  286. }
  287. }
  288. private void handleIntellectualPropertyPreview(HttpServletResponse response, OrgIntellectualProperty oip,
  289. AttachmentType attachmentType) {
  290. if (attachmentType == AttachmentType.PROPERTY_RIGHT) {
  291. downloadFile(response, oip.getPropertyRightDownloadFileName(), oip.getPropertyRightUrl());
  292. }
  293. }
  294. private void handleAchievementPreview(HttpServletResponse response, OrgTechAchievement ota,
  295. AttachmentType attachmentType) {
  296. if (attachmentType == AttachmentType.ACHIEVEMENT) {
  297. downloadFile(response, ota.getEnclosureDownloadFileName(), ota.getEnclosureUrl());
  298. }
  299. }
  300. private void handleFinancePreview(HttpServletResponse response, OrgFinance of, AttachmentType attachmentType) {
  301. if (attachmentType == AttachmentType.FINANCE) {
  302. downloadFile(response, of.getFinanceDownloadFileName(), of.getFinanceUrl());
  303. }
  304. }
  305. private void handleHumanResourcePreview(HttpServletResponse response, OrgHumanResource ohr,
  306. AttachmentType attachmentType) {
  307. if (attachmentType == AttachmentType.ROSTER) {
  308. downloadFile(response, ohr.getRosterDownloadFileName(), ohr.getRosterUrl());
  309. } else if (attachmentType == AttachmentType.SOCIAL_SECURITY) {
  310. downloadFile(response, ohr.getSocialSecurityDownloadFileName(), ohr.getSocialSecurityUrl());
  311. }
  312. }
  313. private void handleHonorPreview(HttpServletResponse response, OrgHonorDatum ohd, AttachmentType attachmentType) {
  314. if (attachmentType == AttachmentType.HONOR) {
  315. downloadFile(response, ohd.getEnclosureDownloadFileName(), ohd.getEnclosureUrl());
  316. }
  317. }
  318. private void handleStandardPreview(HttpServletResponse response, OrgStandard os, AttachmentType attachmentType) {
  319. if (attachmentType == AttachmentType.STANDARD) {
  320. downloadFile(response, os.getStandardDownloadFileName(), os.getEnclosureUrl());
  321. }
  322. }
  323. }