PatentApiController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. package com.goafanti.patent.controller;
  2. import java.util.LinkedHashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import java.util.TreeMap;
  6. import javax.annotation.Resource;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import javax.validation.Valid;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.validation.BindingResult;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import com.goafanti.admin.service.AdminService;
  17. import com.goafanti.admin.service.AftFileService;
  18. import com.goafanti.cognizance.service.OrgIntellectualPropertyService;
  19. import com.goafanti.common.bo.Result;
  20. import com.goafanti.common.constant.ErrorConstants;
  21. import com.goafanti.common.controller.CertifyApiController;
  22. import com.goafanti.common.enums.AttachmentType;
  23. import com.goafanti.common.enums.PatentInfoFields;
  24. import com.goafanti.common.enums.PatentInfoStatus;
  25. import com.goafanti.common.model.Admin;
  26. import com.goafanti.common.model.AftFile;
  27. import com.goafanti.common.model.OrganizationIdentity;
  28. import com.goafanti.common.model.PatentInfo;
  29. import com.goafanti.common.model.PatentLog;
  30. import com.goafanti.common.model.User;
  31. import com.goafanti.common.utils.StringUtils;
  32. import com.goafanti.core.mybatis.page.Pagination;
  33. import com.goafanti.core.shiro.token.TokenManager;
  34. import com.goafanti.patent.bo.InputPatentInfo;
  35. import com.goafanti.patent.service.PatentCostService;
  36. import com.goafanti.patent.service.PatentInfoService;
  37. import com.goafanti.patent.service.PatentLogService;
  38. import com.goafanti.patent.service.PatentRegistrationService;
  39. import com.goafanti.user.service.OrganizationIdentityService;
  40. import com.goafanti.user.service.UserService;
  41. @Controller
  42. @RequestMapping(value = "/techservice/patent")
  43. public class PatentApiController extends CertifyApiController {
  44. @Resource
  45. private PatentInfoService patentInfoService;
  46. @Resource
  47. private PatentLogService patentLogService;
  48. @Resource
  49. private OrganizationIdentityService organizationIdentityServivce;
  50. @Resource
  51. private PatentCostService patentCostService;
  52. @Resource
  53. private PatentRegistrationService patentRegistrationService;
  54. @Resource
  55. private AdminService adminService;
  56. @Resource
  57. private OrgIntellectualPropertyService orgIntellectualPropertyService;
  58. @Resource
  59. private UserService userService;
  60. @Resource
  61. private AftFileService aftFileService;
  62. @Value(value = "${upload.private.path}")
  63. private String uploadPrivatePath = null;
  64. /**
  65. * 专利相关材料上传
  66. *
  67. * @param req
  68. * @param uid
  69. * @param sign
  70. * @return
  71. */
  72. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  73. public Result upload(HttpServletRequest req, String sign) {
  74. Result res = new Result();
  75. if (!checkUserLogin(res)) {
  76. return res;
  77. }
  78. User curUser = TokenManager.getUserToken();
  79. if (!checkCertify(res, curUser)) {
  80. return res;
  81. }
  82. AttachmentType attachmentType = AttachmentType.getField(sign);
  83. if (attachmentType == AttachmentType.PATENT_PRORY_STATEMENT || attachmentType == AttachmentType.PATENT_WRITING
  84. || attachmentType == AttachmentType.AUTHORIZATION_NOTICE
  85. || attachmentType == AttachmentType.PATENT_CERTIFICATE) {
  86. res.setData(handleFiles(res, "/patent/", true, req, sign, TokenManager.getUserId()));
  87. } else {
  88. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  89. }
  90. return res;
  91. }
  92. /**
  93. * 下载专利相关材料
  94. *
  95. * @param id
  96. * @param sign
  97. * @param response
  98. * @return
  99. */
  100. @RequestMapping(value = "/download", method = RequestMethod.GET)
  101. public Result download(String id, String sign, HttpServletResponse response) {
  102. Result res = new Result();
  103. if (!checkAdminLogin(res)) {
  104. return res;
  105. }
  106. if (StringUtils.isEmpty(id)) {
  107. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "专利id"));
  108. return res;
  109. }
  110. PatentInfo pi = patentInfoService.selectByPrimaryKey(id);
  111. if (pi == null) {
  112. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "专利id"));
  113. return res;
  114. }
  115. AttachmentType attachmentType = AttachmentType.getField(sign);
  116. if (attachmentType == AttachmentType.PATENT_PRORY_STATEMENT || attachmentType == AttachmentType.PATENT_WRITING
  117. || attachmentType == AttachmentType.AUTHORIZATION_NOTICE
  118. || attachmentType == AttachmentType.PATENT_CERTIFICATE) {
  119. if (attachmentType == AttachmentType.PATENT_PRORY_STATEMENT) {
  120. downloadFile(response, pi.getPatentProryStatementDownloadFileName(), pi.getPatentProryStatementUrl());
  121. } else if (attachmentType == AttachmentType.PATENT_WRITING) {
  122. downloadFile(response, pi.getPatentWritingDownloadFileName(), pi.getPatentWritingUrl());
  123. } else if (attachmentType == AttachmentType.AUTHORIZATION_NOTICE) {
  124. downloadFile(response, pi.getAuthorizationNoticeDownloadFileName(), pi.getAuthorizationNoticeUrl());
  125. } else if (attachmentType == AttachmentType.PATENT_CERTIFICATE) {
  126. downloadFile(response, pi.getPatentCertificateDownloadFileName(), pi.getPatentCertificateUrl());
  127. }
  128. } else {
  129. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  130. }
  131. return res;
  132. }
  133. /**
  134. * 下载模版文件(专利代理委托书)
  135. *
  136. * @param response
  137. * @return
  138. */
  139. @RequestMapping(value = "/downloadTemplateFile", method = RequestMethod.GET)
  140. public Result downloadTemplateFile(HttpServletResponse response, String sign) {
  141. Result res = new Result();
  142. if (!checkAdminLogin(res)) {
  143. return res;
  144. }
  145. AttachmentType attachmentType = AttachmentType.getField(sign);
  146. if (attachmentType == AttachmentType.PATENT_PRORY_STATEMENT) {
  147. String fileName = "";
  148. AftFile af = aftFileService.selectAftFileBySign(sign);
  149. if (null == af) {
  150. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "找不到", "文件"));
  151. } else {
  152. String path = af.getFilePath();
  153. String suffix = path.substring(path.lastIndexOf("."));
  154. fileName = "专利代理委托书模版" + suffix;
  155. downloadFile(response, fileName, path);
  156. }
  157. } else {
  158. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "专利代理委托书标示"));
  159. }
  160. return res;
  161. }
  162. /**
  163. * 用户端专利申请
  164. */
  165. @RequestMapping(value = "/clientApplyPatent", method = RequestMethod.POST)
  166. public Result clientApplyPatent(@Valid InputPatentInfo patentInfo, BindingResult bindingResult) {
  167. Result res = new Result();
  168. if (bindingResult.hasErrors()) {
  169. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  170. PatentInfoFields.getFieldDesc(bindingResult.getFieldError().getField())));
  171. return res;
  172. }
  173. if (!checkUserLogin(res)) {
  174. return res;
  175. }
  176. User curUser = TokenManager.getUserToken();
  177. if (!checkCertify(res, curUser)) {
  178. return res;
  179. }
  180. String aid = curUser.getAid();
  181. PatentInfo pi = new PatentInfo();
  182. BeanUtils.copyProperties(patentInfo, pi);
  183. pi.setUid(TokenManager.getUserId());
  184. res.setData(patentInfoService.savePatentInfo(pi, aid));
  185. return res;
  186. }
  187. /**
  188. * 用户端专利详情
  189. *
  190. */
  191. @RequestMapping(value = "/clientPatentInfo", method = RequestMethod.GET)
  192. public Result clientPatentInfo(String pid) {
  193. Result res = new Result();
  194. if (!checkUserLogin(res)) {
  195. return res;
  196. }
  197. if (StringUtils.isBlank(pid)) {
  198. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "专利ID"));
  199. } else {
  200. PatentInfo pi = patentInfoService.selectByPrimaryKey(pid);
  201. if (null != pi.getUid() && pi.getUid().equals(TokenManager.getUserId())) {
  202. res.setData(pi);
  203. } else {
  204. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "专利ID"));
  205. }
  206. }
  207. res.setData(patentInfoService.selectByPrimaryKey(pid));
  208. return res;
  209. }
  210. /**
  211. * 用户端申请专利列表
  212. */
  213. @RequestMapping(value = "/clientApplyList", method = RequestMethod.GET)
  214. public Result clientApplyList(String patentNumber, String patentName, Integer patentCatagory, Integer patentState,
  215. String pageNo, String pageSize) {
  216. Result res = new Result();
  217. if (!checkUserLogin(res)) {
  218. return res;
  219. }
  220. Integer pNo = 1;
  221. Integer pSize = 10;
  222. if (StringUtils.isNumeric(pageSize)) {
  223. pSize = Integer.parseInt(pageSize);
  224. }
  225. if (StringUtils.isNumeric(pageNo)) {
  226. pNo = Integer.parseInt(pageNo);
  227. }
  228. res.setData(getClientApplyList(res, patentNumber, patentName, patentCatagory, patentState, pNo, pSize));
  229. return res;
  230. }
  231. /**
  232. * 用户端logs
  233. */
  234. @RequestMapping(value = "/patentProcess", method = RequestMethod.GET)
  235. public Result patentProcess(String pid) {
  236. Result res = new Result();
  237. if (!checkUserLogin(res)) {
  238. return res;
  239. }
  240. if (StringUtils.isBlank(pid)) {
  241. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "专利ID"));
  242. return res;
  243. }
  244. PatentInfo pi = patentInfoService.selectByPrimaryKey(pid);
  245. if (null != pi.getUid() && pi.getUid().equals(TokenManager.getUserId())) {
  246. List<PatentLog> list = patentLogService.selectProcessByPid(pid);
  247. for (PatentLog log : list) {
  248. if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.SIGN) {
  249. log.setState(PatentInfoStatus.CREATE.getCode());
  250. }
  251. if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.CIRCULATION) {
  252. log.setState(PatentInfoStatus.DELIVERD.getCode());
  253. }
  254. if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.SETTLEMENT) {
  255. log.setState(PatentInfoStatus.LICENSE.getCode());
  256. }
  257. }
  258. res.setData(list);
  259. } else {
  260. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "专利d"));
  261. }
  262. return res;
  263. }
  264. /**
  265. * 用户确认申报材料
  266. *
  267. * @return
  268. */
  269. @RequestMapping(value = "/clientConfirm", method = RequestMethod.POST)
  270. public Result clientConfirmApplicationMaterials(String pid) {
  271. Result res = new Result();
  272. if (!checkUserLogin(res)) {
  273. return res;
  274. }
  275. if (StringUtils.isBlank(pid)) {
  276. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "专利d"));
  277. return res;
  278. }
  279. PatentInfo p = new PatentInfo();
  280. p.setId(pid);
  281. p.setConfirmState(1);
  282. res.setData(patentInfoService.updateByPrimaryKeySelective(p));
  283. return res;
  284. }
  285. /**
  286. * 获取公司
  287. */
  288. @RequestMapping(value = "/getUnitNames", method = RequestMethod.GET)
  289. public Result getUnitNames() {
  290. Result res = new Result();
  291. List<OrganizationIdentity> list = organizationIdentityServivce.selectAllOrgIndentity();
  292. Map<String, String> map = new TreeMap<String, String>();
  293. for (OrganizationIdentity o : list) {
  294. map.put(o.getUid(), o.getUnitName());
  295. }
  296. res.setData(map);
  297. return res;
  298. }
  299. /**
  300. * 获取管理员
  301. */
  302. @RequestMapping(value = "/getAdmin", method = RequestMethod.GET)
  303. public Result getAdmin() {
  304. Result res = new Result();
  305. List<Admin> admin = adminService.selectAllAdmin();
  306. Map<String, String> map = new LinkedHashMap<String, String>();
  307. for (Admin a : admin) {
  308. map.put(a.getId(), a.getName());
  309. }
  310. res.setData(map);
  311. return res;
  312. }
  313. // 用户端申请专利列表
  314. private Pagination<PatentInfo> getClientApplyList(Result res, String patentNumber, String patentName,
  315. Integer patentCatagory, Integer patentState, Integer pNo, Integer pSize) {
  316. return patentInfoService.getClientApplyList(TokenManager.getUserId(), patentNumber, patentName, patentCatagory,
  317. patentState, pNo, pSize);
  318. }
  319. }