| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- package com.goafanti.common.controller;
- import java.util.Calendar;
- import java.util.Date;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import com.goafanti.cognizance.service.OrgActivityCostService;
- import com.goafanti.cognizance.service.OrgActivityService;
- import com.goafanti.cognizance.service.OrgFinanceService;
- import com.goafanti.cognizance.service.OrgHonorDatumService;
- import com.goafanti.cognizance.service.OrgIntellectualPropertyService;
- import com.goafanti.cognizance.service.OrgRatepayService;
- import com.goafanti.cognizance.service.OrgStandardService;
- import com.goafanti.cognizance.service.OrgTechAchievementService;
- import com.goafanti.cognizance.service.OrgTechCenterDetailService;
- import com.goafanti.cognizance.service.OrgTechProductService;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.enums.AttachmentType;
- import com.goafanti.common.model.OrgActivity;
- import com.goafanti.common.model.OrgActivityCost;
- import com.goafanti.common.model.OrgFinance;
- import com.goafanti.common.model.OrgHonorDatum;
- import com.goafanti.common.model.OrgHumanResource;
- import com.goafanti.common.model.OrgIntellectualProperty;
- import com.goafanti.common.model.OrgRatepay;
- import com.goafanti.common.model.OrgStandard;
- import com.goafanti.common.model.OrgTechAchievement;
- import com.goafanti.common.model.OrgTechCenterDetail;
- import com.goafanti.common.model.OrgTechProduct;
- import com.goafanti.common.model.OrganizationIdentity;
- import com.goafanti.common.model.PatentInfo;
- import com.goafanti.common.model.TechProject;
- import com.goafanti.common.utils.DateUtils;
- import com.goafanti.common.utils.SHA256Util;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.copyright.bo.CopyrightInfoDetail;
- import com.goafanti.copyright.service.CopyrightInfoService;
- import com.goafanti.patent.service.PatentInfoService;
- import com.goafanti.techproject.service.TechProjectService;
- import com.goafanti.user.service.OrgHumanResourceService;
- import com.goafanti.user.service.OrganizationIdentityService;
- import com.goafanti.user.service.UserService;
- @Controller
- @RequestMapping("/open/")
- public class PreviewController extends BaseApiController {
- @Resource
- private PatentInfoService patentInfoService;
- @Resource
- private UserService userService;
- @Resource
- private CopyrightInfoService copyrightInfoService;
- @Resource
- private TechProjectService techProjectService;
- @Resource
- private OrgTechCenterDetailService orgTechCenterDetailService;
- @Resource
- private OrgActivityService orgActivityService;
- @Resource
- private OrgActivityCostService orgActivityCostService;
- @Resource
- private OrgTechProductService orgTechProductService;
- @Resource
- private OrgIntellectualPropertyService orgIntellectualPropertyService;
- @Resource
- private OrgTechAchievementService orgTechAchievementService;
- @Resource
- private OrgRatepayService orgRatepayService;
- @Resource
- private OrgFinanceService orgFinanceService;
- @Resource
- private OrgHumanResourceService OrgHumanResourceService;
- @Resource
- private OrgHonorDatumService OrgHonorDatumService;
- @Resource
- private OrgStandardService orgStandardService;
- @Resource
- private OrganizationIdentityService organizationIdentityService;
- @Value(value = "${aesSecretKey}")
- private String secretKey = null;
- @RequestMapping(value = "/preview", method = RequestMethod.GET)
- public Result preview(HttpServletResponse response, String sign, String temp, String token, String auth) {
- Result res = new Result();
- if (!StringUtils.isNumeric(temp)) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "预览"));
- } else if (DateUtils.truncatedMinuteDiffTo(Calendar.getInstance().getTime(),
- new Date(Long.parseLong(temp))) > 19) {
- res.getError().add(buildError(ErrorConstants.NO_AUTH_ERROR));
- } else if (!SHA256Util.toHash(sign + "|" + token + "|" + secretKey, temp).equals(auth)) {
- res.getError().add(buildError(ErrorConstants.NO_AUTH_ERROR));
- } else {
- AttachmentType attachmentType = AttachmentType.getField(sign);
- switch (attachmentType) {
- case PATENT_PRORY_STATEMENT:
- case PATENT_WRITING:
- case AUTHORIZATION_NOTICE:
- case PATENT_CERTIFICATE:
- PatentInfo pi = patentInfoService.selectByPrimaryKey(token);
- if (pi == null) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handlePatentPreview(response, pi, attachmentType);
- }
- break;
- case LAST_YEAR_RATEPAY:
- case RATEPAY:
- OrgRatepay ratepay = orgRatepayService.selectByPrimaryKey(token);
- if (null == ratepay) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleRatepayPreview(response, ratepay, attachmentType);
- }
- break;
- case COPYRIGHT_AUTH:
- case COPYRIGHT_APPLY:
- CopyrightInfoDetail ci = copyrightInfoService.findByPrimaryKey(token);
- if (null == ci) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleCopyrightPreview(response, ci, attachmentType);
- }
- break;
- case TECH_PROJECT:
- TechProject tp = techProjectService.selectByPrimaryKey(token);
- if (null == tp) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleTechProjectPreview(response, tp, attachmentType);
- }
- break;
- case PROTOCOL:
- OrgTechCenterDetail otcd = orgTechCenterDetailService.selectByPrimaryKey(token);
- if (null == otcd) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleTechCenterDetailPreview(response, otcd, attachmentType);
- }
- break;
- case PROOF:
- OrgActivity oa = orgActivityService.selectOrgActivityByPrimaryKey(token);
- if (null == oa) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleActivityPreview(response, oa, attachmentType);
- }
- break;
- case ACTIVITY_COST_ACCOUNT:
- OrgActivityCost oac = orgActivityCostService.selectByPrimaryKey(token);
- if (null == oac) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleActivityCostPreview(response, oac, attachmentType);
- }
- break;
- case TECH_PRODUCT:
- OrgTechProduct otp = orgTechProductService.selectByPrimaryKey(token);
- if (null == otp) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleTechProductPreview(response, otp, attachmentType);
- }
- break;
- case PROPERTY_RIGHT:
- OrgIntellectualProperty oip = orgIntellectualPropertyService.selectByPrimaryKey(token);
- if (null == oip) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleIntellectualPropertyPreview(response, oip, attachmentType);
- }
- break;
- case ACHIEVEMENT:
- OrgTechAchievement ota = orgTechAchievementService.selectByPrimaryKey(token);
- if (null == ota) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleAchievementPreview(response, ota, attachmentType);
- }
- break;
- case FINANCE:
- OrgFinance of = orgFinanceService.selectByPrimaryKey(token);
- if (null == of) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleFinancePreview(response, of, attachmentType);
- }
- break;
- case ROSTER:
- case SOCIAL_SECURITY:
- OrgHumanResource ohr = OrgHumanResourceService.selectByPrimaryKey(token);
- if (null == ohr) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleHumanResourcePreview(response, ohr, attachmentType);
- }
- break;
- case HONOR:
- OrgHonorDatum ohd = OrgHonorDatumService.selectByPrimaryKey(token);
- if (null == ohd) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleHonorPreview(response, ohd, attachmentType);
- }
- break;
- case STANDARD:
- OrgStandard os = orgStandardService.selectByPrimaryKey(token);
- if (null == os) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "预览"));
- return res;
- } else {
- handleStandardPreview(response, os, attachmentType);
- }
- break;
- default:
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "预览"));
- }
- }
- return res;
- }
- private void handlePatentPreview(HttpServletResponse response, PatentInfo pi, AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.PATENT_PRORY_STATEMENT) {
- OrganizationIdentity oi = organizationIdentityService.selectOrgIdentityByUserId(pi.getUid());
- downloadFile(response, oi.getPatentProryStatementDownloadFileName(), oi.getPatentProryStatementUrl());
- } else if (attachmentType == AttachmentType.PATENT_WRITING) {
- downloadFile(response, pi.getPatentWritingDownloadFileName(), pi.getPatentWritingUrl());
- } else if (attachmentType == AttachmentType.AUTHORIZATION_NOTICE) {
- downloadFile(response, pi.getAuthorizationNoticeDownloadFileName(), pi.getAuthorizationNoticeUrl());
- } else if (attachmentType == AttachmentType.PATENT_CERTIFICATE) {
- downloadFile(response, pi.getPatentCertificateDownloadFileName(), pi.getPatentCertificateUrl());
- }
- }
- private void handleRatepayPreview(HttpServletResponse response, OrgRatepay ratepay, AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.LAST_YEAR_RATEPAY || attachmentType == AttachmentType.RATEPAY) {
- downloadFile(response, ratepay.getTaxReturnDownloadFileName(), ratepay.getTaxReturnUrl());
- }
- }
- private void handleCopyrightPreview(HttpServletResponse response, CopyrightInfoDetail ci,
- AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.COPYRIGHT_AUTH) {
- downloadFile(response, ci.getCertificateUrlDownloadFileName(), ci.getCertificateUrl());
- } else if (attachmentType == AttachmentType.COPYRIGHT_APPLY) {
- downloadFile(response, ci.getApplicationUrlDownloadFileName(), ci.getApplicationUrl());
- }
- }
- private void handleTechProjectPreview(HttpServletResponse response, TechProject tp, AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.TECH_PROJECT) {
- downloadFile(response, tp.getApprovalDownloadFileName(), tp.getApprovalUrl());
- }
- }
- private void handleTechCenterDetailPreview(HttpServletResponse response, OrgTechCenterDetail otcd,
- AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.PROTOCOL) {
- downloadFile(response, otcd.getProtocolDownloadFileName(), otcd.getProtocolUrl());
- }
- }
- private void handleActivityPreview(HttpServletResponse response, OrgActivity oa, AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.PROOF) {
- downloadFile(response, oa.getProofDownloadFileName(), oa.getProofUrl());
- }
- }
- private void handleActivityCostPreview(HttpServletResponse response, OrgActivityCost oac,
- AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.ACTIVITY_COST_ACCOUNT) {
- downloadFile(response, oac.getAccountDownloadFileName(), oac.getAccountUrl());
- }
- }
- private void handleTechProductPreview(HttpServletResponse response, OrgTechProduct otp,
- AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.TECH_PRODUCT) {
- downloadFile(response, otp.getAccountDownloadFileName(), otp.getAccountUrl());
- }
- }
- private void handleIntellectualPropertyPreview(HttpServletResponse response, OrgIntellectualProperty oip,
- AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.PROPERTY_RIGHT) {
- downloadFile(response, oip.getPropertyRightDownloadFileName(), oip.getPropertyRightUrl());
- }
- }
- private void handleAchievementPreview(HttpServletResponse response, OrgTechAchievement ota,
- AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.ACHIEVEMENT) {
- downloadFile(response, ota.getEnclosureDownloadFileName(), ota.getEnclosureUrl());
- }
- }
- private void handleFinancePreview(HttpServletResponse response, OrgFinance of, AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.FINANCE) {
- downloadFile(response, of.getFinanceDownloadFileName(), of.getFinanceUrl());
- }
- }
- private void handleHumanResourcePreview(HttpServletResponse response, OrgHumanResource ohr,
- AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.ROSTER) {
- downloadFile(response, ohr.getRosterDownloadFileName(), ohr.getRosterUrl());
- } else if (attachmentType == AttachmentType.SOCIAL_SECURITY) {
- downloadFile(response, ohr.getSocialSecurityDownloadFileName(), ohr.getSocialSecurityUrl());
- }
- }
- private void handleHonorPreview(HttpServletResponse response, OrgHonorDatum ohd, AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.HONOR) {
- downloadFile(response, ohd.getEnclosureDownloadFileName(), ohd.getEnclosureUrl());
- }
- }
- private void handleStandardPreview(HttpServletResponse response, OrgStandard os, AttachmentType attachmentType) {
- if (attachmentType == AttachmentType.STANDARD) {
- downloadFile(response, os.getStandardDownloadFileName(), os.getEnclosureUrl());
- }
- }
- }
|