AdminTechProjectApiController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. package com.goafanti.admin.controller;
  2. import java.text.ParseException;
  3. import java.util.Arrays;
  4. import java.util.Date;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.TreeMap;
  8. import javax.annotation.Resource;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import javax.validation.Valid;
  12. import org.apache.commons.lang3.time.DateUtils;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.validation.BindingResult;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestMethod;
  19. import org.springframework.web.bind.annotation.RequestParam;
  20. import com.goafanti.admin.service.AdminService;
  21. import com.goafanti.common.bo.Result;
  22. import com.goafanti.common.constant.AFTConstants;
  23. import com.goafanti.common.constant.ErrorConstants;
  24. import com.goafanti.common.controller.CertifyApiController;
  25. import com.goafanti.common.enums.AttachmentType;
  26. import com.goafanti.common.enums.TechProjectFields;
  27. import com.goafanti.common.enums.TechProjectStatus;
  28. import com.goafanti.common.model.Admin;
  29. import com.goafanti.common.model.TechProject;
  30. import com.goafanti.common.model.TechProjectLog;
  31. import com.goafanti.common.model.TechWebsite;
  32. import com.goafanti.common.model.User;
  33. import com.goafanti.common.utils.AesUtils;
  34. import com.goafanti.common.utils.StringUtils;
  35. import com.goafanti.core.mybatis.page.Pagination;
  36. import com.goafanti.core.shiro.token.TokenManager;
  37. import com.goafanti.techproject.bo.InputTechProject;
  38. import com.goafanti.techproject.bo.InputTechWebsite;
  39. import com.goafanti.techproject.bo.TechProjectManageListBo;
  40. import com.goafanti.techproject.bo.TechWebsiteDetailBo;
  41. import com.goafanti.techproject.bo.TechWebsiteListBo;
  42. import com.goafanti.techproject.service.TechProjectLogService;
  43. import com.goafanti.techproject.service.TechProjectService;
  44. import com.goafanti.techproject.service.TechWebsiteService;
  45. import com.goafanti.user.service.UserService;
  46. @Controller
  47. @RequestMapping(value = "/api/admin/techproject")
  48. public class AdminTechProjectApiController extends CertifyApiController {
  49. @Value(value = "${aesSecretKey}")
  50. private String aesSecretKey = null;
  51. @Resource
  52. private TechProjectService techProjectService;
  53. @Resource
  54. private TechWebsiteService techWebsiteService;
  55. @Resource
  56. private TechProjectLogService techProjectLogService;
  57. @Resource
  58. private UserService userService;
  59. @Resource
  60. private AdminService adminService;
  61. /**
  62. * 咨询师下拉列表
  63. *
  64. * @return
  65. */
  66. @RequestMapping(value = "/getConsultant", method = RequestMethod.GET)
  67. public Result getConsultant() {
  68. Result res = new Result();
  69. List<Admin> list = adminService.selectTechprojectConsultant();
  70. Map<String, String> map = new TreeMap<String, String>();
  71. for (Admin o : list) {
  72. map.put(o.getId(), o.getName());
  73. }
  74. res.setData(map);
  75. return res;
  76. }
  77. /**
  78. * 负责人下拉
  79. *
  80. * @return
  81. */
  82. @RequestMapping(value = "/getPrincipal", method = RequestMethod.GET)
  83. public Result getPrincipal() {
  84. Result res = new Result();
  85. List<Admin> list = adminService.selectTechprojectPrincipal();
  86. Map<String, String> map = new TreeMap<String, String>();
  87. for (Admin o : list) {
  88. map.put(o.getId(), o.getName());
  89. }
  90. res.setData(map);
  91. return res;
  92. }
  93. /**
  94. * 科技项目申报列表
  95. *
  96. * @param pageNo
  97. * @param pageSize
  98. * @return
  99. */
  100. @SuppressWarnings("unchecked")
  101. @RequestMapping(value = "/listTechProject", method = RequestMethod.POST)
  102. public Result listTechProject(String province, String unitName, String pageNo, String pageSize) {
  103. Result res = new Result();
  104. Integer pNo = 1;
  105. Integer pSize = 10;
  106. if (StringUtils.isNumeric(pageSize)) {
  107. pSize = Integer.parseInt(pageSize);
  108. }
  109. if (StringUtils.isNumeric(pageNo)) {
  110. pNo = Integer.parseInt(pageNo);
  111. }
  112. Pagination<TechProjectManageListBo> t = techProjectService.listManageTechProject(province, unitName, pNo,
  113. pSize);
  114. if (null != t) {
  115. List<TechProjectManageListBo> l = (List<TechProjectManageListBo>) t.getList();
  116. for (TechProjectManageListBo w : l) {
  117. if (!StringUtils.isBlank(w.getPassword())) {
  118. try {
  119. w.setPassword(AesUtils.decrypt(w.getPassword(), aesSecretKey));
  120. } catch (Exception e) {
  121. }
  122. }
  123. }
  124. t.setList(l);
  125. res.setData(t);
  126. }
  127. return res;
  128. }
  129. /**
  130. * 科技项目申报
  131. *
  132. * @return
  133. */
  134. @RequestMapping(value = "/applyTechProject", method = RequestMethod.POST)
  135. public Result applyTechProject(@Valid InputTechProject techProject, BindingResult bindingResult) {
  136. Result res = new Result();
  137. if (bindingResult.hasErrors()) {
  138. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  139. TechProjectFields.getFieldDesc(bindingResult.getFieldError().getField())));
  140. return res;
  141. }
  142. if (StringUtils.isBlank(techProject.getUid())) {
  143. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  144. return res;
  145. }
  146. User curUser = userService.selectByPrimaryKey(techProject.getUid());
  147. if (!checkCertify(res, curUser)) {
  148. return res;
  149. }
  150. TechProject tp = new TechProject();
  151. BeanUtils.copyProperties(techProject, tp);
  152. techProjectService.saveTechProject(tp, curUser.getAid());
  153. return res;
  154. }
  155. /**
  156. * 科技项目申报详情
  157. *
  158. * @return
  159. */
  160. @RequestMapping(value = "/techProjectDetial", method = RequestMethod.POST)
  161. public Result techProjectDetial(String pid) {
  162. Result res = new Result();
  163. if (StringUtils.isBlank(pid)) {
  164. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "公司"));
  165. } else {
  166. res.setData(techProjectService.selectProjectDetail(pid));
  167. }
  168. return res;
  169. }
  170. /**
  171. * 科技项目状态流转
  172. *
  173. * @param pid
  174. * @return
  175. */
  176. @RequestMapping(value = "/techProjectLog", method = RequestMethod.POST)
  177. public Result techProjectLog(String pid) {
  178. Result res = new Result();
  179. if (StringUtils.isBlank(pid)) {
  180. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "科技项目申报ID"));
  181. } else {
  182. res.setData(techProjectLogService.selectTechProjectLogByPid(pid));
  183. }
  184. return res;
  185. }
  186. /**
  187. * update科技项目
  188. *
  189. * @param t
  190. * @param l
  191. * @param recordTimeFormattedDate
  192. * @return
  193. * @throws ParseException
  194. */
  195. @RequestMapping(value = "/updateTechProject", method = RequestMethod.POST)
  196. public Result updateTechProject(@Valid InputTechProject techProject, BindingResult bindingResult,
  197. String recordTimeFormattedDate) {
  198. Result res = new Result();
  199. if (bindingResult.hasErrors()) {
  200. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  201. TechProjectFields.getFieldDesc(bindingResult.getFieldError().getField())));
  202. return res;
  203. }
  204. if (StringUtils.isBlank(techProject.getId())) {
  205. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到科技申报项目", "科技项目申报ID"));
  206. return res;
  207. }
  208. TechProject t = techProjectService.selectByPrimaryKey(techProject.getId());
  209. if (null == t) {
  210. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "找不到申报项目", "科技项目申报"));
  211. return res;
  212. }
  213. if (TechProjectStatus.CALLBACK.getCode() == t.getState()) {
  214. res.getError().add(buildError(ErrorConstants.RECORD_CALLBACK, "当前记录已退单,无法修改!"));
  215. return res;
  216. }
  217. if (TechProjectStatus.SETTLEMENT.getCode() == t.getState()) {
  218. res.getError().add(buildError(ErrorConstants.RECORD_SETTLEMENT, "当前记录已结款,无法修改!"));
  219. return res;
  220. }
  221. Date recordTime = null;
  222. if (!StringUtils.isBlank(recordTimeFormattedDate)) {
  223. try {
  224. recordTime = DateUtils.parseDate(recordTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS);
  225. } catch (ParseException e) {
  226. }
  227. }
  228. TechProject tp = new TechProject();
  229. TechProjectLog tpl = new TechProjectLog();
  230. BeanUtils.copyProperties(techProject, tp);
  231. BeanUtils.copyProperties(techProject, tpl);
  232. res.setData(techProjectService.updateTechProject(tp, tpl, recordTime));
  233. return res;
  234. }
  235. /**
  236. * 流转状态下拉
  237. *
  238. * @return
  239. */
  240. @RequestMapping(value = "/status", method = RequestMethod.GET)
  241. public Result Status() {
  242. Result res = new Result();
  243. res.setData(disposeStatus());
  244. return res;
  245. }
  246. /**
  247. * 获取科技部门
  248. *
  249. * @return
  250. */
  251. @RequestMapping(value = "/getDepartment", method = RequestMethod.GET)
  252. public Result getDepartment(String uid) {
  253. Result res = new Result();
  254. res.setData(techWebsiteService.getDepartment(uid));
  255. return res;
  256. }
  257. /**
  258. * 删除科技项目记录
  259. *
  260. * @param ids
  261. * @return
  262. */
  263. @RequestMapping(value = "/deleteTechProject", method = RequestMethod.POST)
  264. public Result deleteTechProject(@RequestParam(name = "ids[]", required = false) String[] ids) {
  265. Result res = new Result();
  266. if (!checkAdminLogin(res)) {
  267. return res;
  268. }
  269. if (ids == null || ids.length < 1) {
  270. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
  271. } else {
  272. res.setData(techProjectService.deleteByPrimaryKey(Arrays.asList(ids)));
  273. }
  274. return res;
  275. }
  276. /**
  277. * 删除科技网址记录
  278. *
  279. * @param ids
  280. * @return
  281. */
  282. @RequestMapping(value = "/deleteTechWebsite", method = RequestMethod.POST)
  283. public Result deleteTechWebsite(@RequestParam(name = "ids[]", required = false) String[] ids) {
  284. Result res = new Result();
  285. if (ids == null || ids.length < 1) {
  286. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
  287. } else {
  288. res.setData(techWebsiteService.deleteByPrimaryKey(Arrays.asList(ids)));
  289. }
  290. return res;
  291. }
  292. /**
  293. * 科技单位网址管理list
  294. */
  295. @SuppressWarnings("unchecked")
  296. @RequestMapping(value = "/listTechWebsite", method = RequestMethod.POST)
  297. public Result listTechWebsite(String province, String unitName, String pageNo, String pageSize) {
  298. Result res = new Result();
  299. Integer pNo = 1;
  300. Integer pSize = 10;
  301. if (StringUtils.isNumeric(pageSize)) {
  302. pSize = Integer.parseInt(pageSize);
  303. }
  304. if (StringUtils.isNumeric(pageNo)) {
  305. pNo = Integer.parseInt(pageNo);
  306. }
  307. Pagination<TechWebsiteListBo> t = techWebsiteService.listTechWebsite(province, unitName, pNo, pSize);
  308. if (null != t) {
  309. List<TechWebsiteListBo> l = (List<TechWebsiteListBo>) t.getList();
  310. for (TechWebsiteListBo w : l) {
  311. if (!StringUtils.isBlank(w.getPassword())) {
  312. try {
  313. w.setPassword(AesUtils.decrypt(w.getPassword(), aesSecretKey));
  314. } catch (Exception e) {
  315. }
  316. }
  317. }
  318. t.setList(l);
  319. res.setData(t);
  320. }
  321. return res;
  322. }
  323. /**
  324. * 网址管理详情
  325. *
  326. * @param wid
  327. * @return
  328. */
  329. @RequestMapping(value = "/techWebsiteDetail", method = RequestMethod.POST)
  330. public Result techWebsiteDetail(String id) {
  331. Result res = new Result();
  332. if (StringUtils.isBlank(id)) {
  333. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "公司"));
  334. } else {
  335. TechWebsiteDetailBo w = techWebsiteService.selectTechWebsiteDetail(id);
  336. if (null != w && !StringUtils.isBlank(w.getPassword())) {
  337. try {
  338. w.setPassword(AesUtils.decrypt(w.getPassword(), aesSecretKey));
  339. } catch (Exception e) {
  340. }
  341. }
  342. /*
  343. * if (null != w && !StringUtils.isBlank(w.getPassword())) {
  344. * w.setPassword(Base64Utils.decodeData(w.getPassword())); }
  345. */
  346. res.setData(w);
  347. }
  348. return res;
  349. }
  350. /**
  351. * 科技单位网址add+update
  352. *
  353. * @param t
  354. * @return
  355. */
  356. @RequestMapping(value = "/disposeTechWebsite", method = RequestMethod.POST)
  357. public Result disposeTechWebsite(@Valid InputTechWebsite w, BindingResult bindingResult) {
  358. Result res = new Result();
  359. if (bindingResult.hasErrors()) {
  360. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  361. TechProjectFields.getFieldDesc(bindingResult.getFieldError().getField())));
  362. return res;
  363. }
  364. if (StringUtils.isBlank(w.getUid())) {
  365. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  366. return res;
  367. }
  368. User curUser = userService.selectByPrimaryKey(w.getUid());
  369. if (!checkCertify(res, curUser)) {
  370. return res;
  371. }
  372. if (null != w && null != (w.getPassword())) {
  373. try {
  374. w.setPassword(AesUtils.encrypt(w.getPassword().trim(), aesSecretKey));
  375. } catch (Exception e) {
  376. }
  377. }
  378. TechWebsite tw = new TechWebsite();
  379. BeanUtils.copyProperties(w, tw);
  380. res.setData(techWebsiteService.saveWebsite(tw));
  381. return res;
  382. }
  383. /**
  384. * 科技项目申报材料上传
  385. *
  386. * @param req
  387. * @param uid
  388. * @return
  389. */
  390. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  391. public Result cognizanceFile(HttpServletRequest req, String uid, String id, String sign) {
  392. Result res = new Result();
  393. User curUser = userService.selectByPrimaryKey(uid);
  394. if (!checkCertify(res, curUser)) {
  395. return res;
  396. }
  397. if (StringUtils.isBlank(id)) {
  398. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到科技申报项目", "科技项目申报ID"));
  399. return res;
  400. }
  401. TechProject t = techProjectService.selectByPrimaryKey(id);
  402. if (null == t) {
  403. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "找不到申报项目", "科技项目申报"));
  404. return res;
  405. }
  406. if (TechProjectStatus.CALLBACK.getCode() == t.getState()) {
  407. res.getError().add(buildError(ErrorConstants.RECORD_CALLBACK, "当前记录已退单,无法修改!"));
  408. return res;
  409. }
  410. if (TechProjectStatus.SETTLEMENT.getCode() == t.getState()) {
  411. res.getError().add(buildError(ErrorConstants.RECORD_SETTLEMENT, "当前记录已结款,无法修改!"));
  412. return res;
  413. }
  414. AttachmentType attachmentType = AttachmentType.getField(sign);
  415. if (attachmentType == AttachmentType.TECH_PROJECT) {
  416. res.setData(handleFiles(res, "/techProject/", true, req, sign, uid));
  417. } else {
  418. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  419. }
  420. return res;
  421. }
  422. /**
  423. * 下载科技项目材料
  424. *
  425. * @param response
  426. * @param fileName
  427. * @param path
  428. * @param id
  429. * @return
  430. */
  431. @RequestMapping(value = "/download", method = RequestMethod.GET)
  432. public Result download(HttpServletResponse response, String id) {
  433. Result res = new Result();
  434. if (StringUtils.isEmpty(id)) {
  435. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技项目ID"));
  436. return res;
  437. }
  438. TechProject t = techProjectService.selectByPrimaryKey(id);
  439. if (null == t) {
  440. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技项目ID"));
  441. return res;
  442. }
  443. downloadFile(response, t.getApprovalDownloadFileName(), t.getApprovalUrl());
  444. return res;
  445. }
  446. private Object disposeStatus() {
  447. Map<String, String> status = new TreeMap<String, String>();
  448. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  449. for (TechProjectStatus p : TechProjectStatus.values()) {
  450. status.put(p.getCode().toString(), p.getDesc());
  451. status.remove(TechProjectStatus.OTHER.getCode().toString());
  452. }
  453. } else {
  454. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.CREATE.getCode())) {
  455. status.put(TechProjectStatus.CREATE.getCode().toString(), TechProjectStatus.CREATE.getDesc());
  456. }
  457. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.SIGN.getCode())) {
  458. status.put(TechProjectStatus.SIGN.getCode().toString(), TechProjectStatus.SIGN.getDesc());
  459. }
  460. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.DELIVERD.getCode())) {
  461. status.put(TechProjectStatus.DELIVERD.getCode().toString(), TechProjectStatus.DELIVERD.getDesc());
  462. }
  463. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.CIRCULATION.getCode())) {
  464. status.put(TechProjectStatus.CIRCULATION.getCode().toString(), TechProjectStatus.CIRCULATION.getDesc());
  465. }
  466. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.SUBMIT.getCode())) {
  467. status.put(TechProjectStatus.SUBMIT.getCode().toString(), TechProjectStatus.SUBMIT.getDesc());
  468. }
  469. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.ACCEPT.getCode())) {
  470. status.put(TechProjectStatus.ACCEPT.getCode().toString(), TechProjectStatus.ACCEPT.getDesc());
  471. }
  472. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.APPRVOVED.getCode())) {
  473. status.put(TechProjectStatus.APPRVOVED.getCode().toString(), TechProjectStatus.APPRVOVED.getDesc());
  474. }
  475. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.REJECT.getCode())) {
  476. status.put(TechProjectStatus.REJECT.getCode().toString(), TechProjectStatus.REJECT.getDesc());
  477. }
  478. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.SETTLEMENT.getCode())) {
  479. status.put(TechProjectStatus.SETTLEMENT.getCode().toString(), TechProjectStatus.SETTLEMENT.getDesc());
  480. }
  481. if (TokenManager.hasPermission("TechProjectStatus" + TechProjectStatus.CALLBACK.getCode())) {
  482. status.put(TechProjectStatus.CALLBACK.getCode().toString(), TechProjectStatus.CALLBACK.getDesc());
  483. }
  484. }
  485. return status;
  486. }
  487. }