PreviewController.java 14 KB

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