AdminTechProjectController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. package com.goafanti.admin.controller;
  2. import java.io.IOException;
  3. import java.text.ParseException;
  4. import java.util.Arrays;
  5. import java.util.Date;
  6. import java.util.List;
  7. import javax.annotation.Resource;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.validation.Valid;
  10. import org.apache.commons.lang3.time.DateUtils;
  11. import org.springframework.beans.BeanUtils;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.validation.BindingResult;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import com.goafanti.common.bo.Result;
  20. import com.goafanti.common.constant.AFTConstants;
  21. import com.goafanti.common.constant.ErrorConstants;
  22. import com.goafanti.common.controller.CertifyApiController;
  23. import com.goafanti.common.enums.CopyrightFields;
  24. import com.goafanti.common.model.TechProject;
  25. import com.goafanti.common.model.TechProjectLog;
  26. import com.goafanti.common.model.TechWebsite;
  27. import com.goafanti.common.model.User;
  28. import com.goafanti.common.utils.AesUtils;
  29. import com.goafanti.common.utils.Base64Utils;
  30. import com.goafanti.common.utils.FileUtils;
  31. import com.goafanti.common.utils.LoggerUtils;
  32. import com.goafanti.common.utils.StringUtils;
  33. import com.goafanti.core.mybatis.page.Pagination;
  34. import com.goafanti.core.shiro.token.TokenManager;
  35. import com.goafanti.techproject.bo.InputTechProject;
  36. import com.goafanti.techproject.bo.InputTechProjectLog;
  37. import com.goafanti.techproject.bo.InputTechWebsite;
  38. import com.goafanti.techproject.bo.TechProjectManageListBo;
  39. import com.goafanti.techproject.bo.TechWebsiteDetailBo;
  40. import com.goafanti.techproject.bo.TechWebsiteListBo;
  41. import com.goafanti.techproject.service.TechProjectLogService;
  42. import com.goafanti.techproject.service.TechProjectService;
  43. import com.goafanti.techproject.service.TechWebsiteService;
  44. import com.goafanti.user.service.UserService;
  45. @Controller
  46. @RequestMapping(value = "/api/admintechproject")
  47. public class AdminTechProjectController extends CertifyApiController {
  48. @Value(value = "${aesSecretKey}")
  49. private String aesSecretKey = null;
  50. @Resource
  51. private TechProjectService techProjectService;
  52. @Resource
  53. private TechWebsiteService techWebsiteService;
  54. @Resource
  55. private TechProjectLogService techProjectLogService;
  56. @Resource
  57. private UserService userService;
  58. /**
  59. * 科技项目申报列表
  60. *
  61. * @param pageNo
  62. * @param pageSize
  63. * @return
  64. */
  65. @SuppressWarnings("unchecked")
  66. @RequestMapping(value = "/listTechProject", method = RequestMethod.POST)
  67. public Result listClientTechProject(String province, String unitName, String pageNo, String pageSize) {
  68. Result res = new Result();
  69. if (!checkAdminLogin(res)) {
  70. return res;
  71. }
  72. Integer pNo = 1;
  73. Integer pSize = 10;
  74. if (StringUtils.isNumeric(pageSize)) {
  75. pSize = Integer.parseInt(pageSize);
  76. }
  77. if (StringUtils.isNumeric(pageNo)) {
  78. pNo = Integer.parseInt(pageNo);
  79. }
  80. Pagination<TechProjectManageListBo> t = techProjectService.listManageTechProject(province, unitName, pNo,
  81. pSize);
  82. if (null != t) {
  83. List<TechProjectManageListBo> l = (List<TechProjectManageListBo>) t.getList();
  84. for (TechProjectManageListBo w : l) {
  85. if (!StringUtils.isBlank(w.getPassword())) {
  86. w.setPassword(Base64Utils.decodeData(w.getPassword()));
  87. }
  88. }
  89. t.setList(l);
  90. res.setData(t);
  91. }
  92. return res;
  93. }
  94. /**
  95. * 科技项目申报
  96. *
  97. * @return
  98. */
  99. @RequestMapping(value = "/applyTechProject", method = RequestMethod.POST)
  100. public Result applyTechProject(@Valid InputTechProject techProject, BindingResult bindingResult) {
  101. Result res = new Result();
  102. if (bindingResult.hasErrors()) {
  103. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  104. CopyrightFields.getFieldDesc(bindingResult.getFieldError().getField())));
  105. return res;
  106. }
  107. if (!checkAdminLogin(res)) {
  108. return res;
  109. }
  110. if (StringUtils.isBlank(techProject.getUid())) {
  111. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  112. return res;
  113. }
  114. User curUser = userService.selectByPrimaryKey(techProject.getUid());
  115. if (!checkCertify(res, curUser)) {
  116. return res;
  117. }
  118. TechProject tp = new TechProject();
  119. BeanUtils.copyProperties(techProject, tp);
  120. techProjectService.saveTechProject(tp, userService.selectByPrimaryKey(tp.getUid()).getAid());
  121. return res;
  122. }
  123. /**
  124. * 科技项目申报详情
  125. *
  126. * @return
  127. */
  128. @RequestMapping(value = "/techProjectDetial", method = RequestMethod.POST)
  129. public Result techProjectDetial(String pid) {
  130. Result res = new Result();
  131. if (!checkAdminLogin(res)) {
  132. return res;
  133. }
  134. if (StringUtils.isBlank(pid)) {
  135. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "公司"));
  136. } else {
  137. res.setData(techProjectService.selectProjectDetail(pid));
  138. }
  139. return res;
  140. }
  141. /**
  142. * 科技项目状态流转
  143. *
  144. * @param pid
  145. * @return
  146. */
  147. @RequestMapping(value = "/techProjectLog", method = RequestMethod.POST)
  148. public Result techProjectLog(String pid) {
  149. Result res = new Result();
  150. if (!checkAdminLogin(res)) {
  151. return res;
  152. }
  153. if (StringUtils.isBlank(pid)) {
  154. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "科技项目申报ID"));
  155. } else {
  156. res.setData(techProjectLogService.selectTechProjectLogByPid(pid));
  157. }
  158. return res;
  159. }
  160. /**
  161. * update科技项目
  162. *
  163. * @param t
  164. * @param l
  165. * @param recordTimeFormattedDate
  166. * @return
  167. * @throws ParseException
  168. */
  169. @RequestMapping(value = "/updateTechProject", method = RequestMethod.POST)
  170. public Result updateTechProject(@Valid InputTechProject techProject, @Valid InputTechProjectLog log, BindingResult bindingResult, String recordTimeFormattedDate) {
  171. Result res = new Result();
  172. if (bindingResult.hasErrors()) {
  173. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  174. CopyrightFields.getFieldDesc(bindingResult.getFieldError().getField())));
  175. return res;
  176. }
  177. if (!checkAdminLogin(res)) {
  178. return res;
  179. }
  180. if (StringUtils.isBlank(techProject.getId())) {
  181. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到科技申报项目", "科技项目申报ID"));
  182. return res;
  183. }
  184. TechProject t = techProjectService.selectByPrimaryKey(techProject.getId());
  185. if (null == t){
  186. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "找不到申报项目", "科技项目申报"));
  187. return res;
  188. }
  189. Date recordTime = null;
  190. if (!StringUtils.isBlank(recordTimeFormattedDate)) {
  191. try {
  192. recordTime = DateUtils.parseDate(recordTimeFormattedDate, AFTConstants.YYYYMMDD);
  193. } catch (ParseException e) {
  194. }
  195. }
  196. TechProject tp = new TechProject();
  197. TechProjectLog tpl = new TechProjectLog();
  198. tp.setId(techProject.getId());
  199. BeanUtils.copyProperties(techProject, tp);
  200. BeanUtils.copyProperties(log, tpl);
  201. res.setData(techProjectService.updateTechProject(tp, tpl, recordTime));
  202. return res;
  203. }
  204. /**
  205. * 删除科技项目记录
  206. *
  207. * @param ids
  208. * @return
  209. */
  210. @RequestMapping(value = "/deleteTechProject", method = RequestMethod.POST)
  211. public Result deleteTechProject(@RequestParam(name = "ids[]", required = false) String[] ids) {
  212. Result res = new Result();
  213. if (!checkAdminLogin(res)) {
  214. return res;
  215. }
  216. if (ids == null || ids.length < 1) {
  217. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
  218. } else {
  219. res.setData(techProjectService.deleteByPrimaryKey(Arrays.asList(ids)));
  220. }
  221. return res;
  222. }
  223. /**
  224. * 删除科技网址记录
  225. *
  226. * @param ids
  227. * @return
  228. */
  229. @RequestMapping(value = "/deleteTechWebsite", method = RequestMethod.POST)
  230. public Result deleteTechWebsite(@RequestParam(name = "ids[]", required = false) String[] ids) {
  231. Result res = new Result();
  232. if (!checkAdminLogin(res)) {
  233. return res;
  234. }
  235. if (ids == null || ids.length < 1) {
  236. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
  237. } else {
  238. res.setData(techWebsiteService.deleteByPrimaryKey(Arrays.asList(ids)));
  239. }
  240. return res;
  241. }
  242. /**
  243. * 科技单位网址管理list
  244. */
  245. @SuppressWarnings("unchecked")
  246. @RequestMapping(value = "/listTechWebsite", method = RequestMethod.POST)
  247. public Result listTechWebsite(String province, String unitName, String pageNo, String pageSize) {
  248. Result res = new Result();
  249. if (!checkAdminLogin(res)) {
  250. return res;
  251. }
  252. Integer pNo = 1;
  253. Integer pSize = 10;
  254. if (StringUtils.isNumeric(pageSize)) {
  255. pSize = Integer.parseInt(pageSize);
  256. }
  257. if (StringUtils.isNumeric(pageNo)) {
  258. pNo = Integer.parseInt(pageNo);
  259. }
  260. Pagination<TechWebsiteListBo> t = techWebsiteService.listTechWebsite(province, unitName, pNo, pSize);
  261. if (null != t) {
  262. List<TechWebsiteListBo> l = (List<TechWebsiteListBo>) t.getList();
  263. for (TechWebsiteListBo w : l) {
  264. if (!StringUtils.isBlank(w.getPassword())) {
  265. try {
  266. w.setPassword(AesUtils.decrypt(w.getPassword(), aesSecretKey));
  267. } catch (Exception e) {
  268. }
  269. //w.setPassword(Base64Utils.decodeData(w.getPassword()));
  270. }
  271. }
  272. t.setList(l);
  273. res.setData(t);
  274. }
  275. return res;
  276. }
  277. /**
  278. * 网址管理详情
  279. *
  280. * @param wid
  281. * @return
  282. */
  283. @RequestMapping(value = "/techWebsiteDetail", method = RequestMethod.POST)
  284. public Result techWebsiteDetail(String id) {
  285. Result res = new Result();
  286. if (!checkAdminLogin(res)) {
  287. return res;
  288. }
  289. if (StringUtils.isBlank(id)) {
  290. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "公司"));
  291. } else {
  292. TechWebsiteDetailBo w = techWebsiteService.selectTechWebsiteDetail(id);
  293. if (null != w && !StringUtils.isBlank(w.getPassword())) {
  294. try {
  295. w.setPassword(AesUtils.decrypt(w.getPassword(), aesSecretKey));
  296. } catch (Exception e) {
  297. }
  298. }
  299. /*if (null != w && !StringUtils.isBlank(w.getPassword())) {
  300. w.setPassword(Base64Utils.decodeData(w.getPassword()));
  301. }*/
  302. res.setData(w);
  303. }
  304. return res;
  305. }
  306. /**
  307. * 科技单位网址add+update
  308. *
  309. * @param t
  310. * @return
  311. */
  312. @RequestMapping(value = "/disposeTechWebsite", method = RequestMethod.POST)
  313. public Result disposeTechWebsite(@Valid InputTechWebsite w, BindingResult bindingResult) {
  314. Result res = new Result();
  315. if (bindingResult.hasErrors()) {
  316. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  317. CopyrightFields.getFieldDesc(bindingResult.getFieldError().getField())));
  318. return res;
  319. }
  320. if (!checkAdminLogin(res)) {
  321. return res;
  322. }
  323. if (StringUtils.isBlank(w.getUid())) {
  324. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
  325. return res;
  326. }
  327. User curUser = userService.selectByPrimaryKey(w.getUid());
  328. if (!checkCertify(res, curUser)) {
  329. return res;
  330. }
  331. /*if (null != w && null != (w.getPassword())) {
  332. w.setPassword(Base64Utils.encodeData(w.getPassword().trim()));
  333. }*/
  334. if (null != w && null != (w.getPassword())) {
  335. try {
  336. w.setPassword(AesUtils.encrypt(w.getPassword().trim(), aesSecretKey));
  337. } catch (Exception e) {
  338. }
  339. }
  340. TechWebsite tw = new TechWebsite();
  341. BeanUtils.copyProperties(w, tw);
  342. res.setData(techWebsiteService.saveWebsite(tw));
  343. return res;
  344. }
  345. /**
  346. * 科技项目申报材料上传
  347. * @param req
  348. * @param uid
  349. * @return
  350. */
  351. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  352. public Result cognizanceFile(HttpServletRequest req, String uid) {
  353. Result res = new Result();
  354. if (!checkAdminLogin(res)) {
  355. return res;
  356. }
  357. User curUser = userService.selectByPrimaryKey(uid);
  358. if (!checkCertify(res, curUser)) {
  359. return res;
  360. }
  361. String sign = "tech_project";
  362. res.setData(handleFile(res, "/techProject/", true, req, sign, uid));
  363. return res;
  364. }
  365. private String handleFile(Result res, String path, boolean isPrivate, HttpServletRequest req, String sign,
  366. String uid) {
  367. List<MultipartFile> files = getFiles(req);
  368. MultipartFile mf = files.get(0);
  369. String fileName = FileUtils.mosaicFileName(mf, isPrivate, sign, path,
  370. StringUtils.isBlank(uid) ? TokenManager.getUserId() : uid);
  371. if (!files.isEmpty()) {
  372. try {
  373. mf.transferTo(toPrivateFile(fileName));
  374. LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
  375. } catch (IllegalStateException | IOException e) {
  376. LoggerUtils.error(getClass(), "文件上传失败", e);
  377. res.getError().add(buildError("", "文件上传失败!"));
  378. return "";
  379. }
  380. } else {
  381. res.getError().add(buildError("", "文件上传失败!"));
  382. return "";
  383. }
  384. return fileName;
  385. }
  386. }