AdminTechProjectApiController.java 18 KB

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