PublicController.java 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. package com.goafanti.common.controller;
  2. import com.goafanti.admin.service.AdminService;
  3. import com.goafanti.admin.service.AttachmentService;
  4. import com.goafanti.common.bo.Error;
  5. import com.goafanti.common.bo.*;
  6. import com.goafanti.common.constant.AFTConstants;
  7. import com.goafanti.common.constant.ErrorConstants;
  8. import com.goafanti.common.enums.UserType;
  9. import com.goafanti.common.model.User;
  10. import com.goafanti.common.service.DistrictGlossoryService;
  11. import com.goafanti.common.service.ImageService;
  12. import com.goafanti.common.service.IndustryCategoryService;
  13. import com.goafanti.common.service.PovertyService;
  14. import com.goafanti.common.utils.*;
  15. import com.goafanti.common.utils.excel.FileUtils;
  16. import com.goafanti.common.utils.excel.NewExcelUtil;
  17. import com.goafanti.core.mybatis.JDBCIdGenerator;
  18. import com.goafanti.core.shiro.token.TokenManager;
  19. import com.goafanti.core.websocket.SystemWebSocketHandler;
  20. import com.goafanti.customer.service.UserOutboundService;
  21. import com.goafanti.expenseAccount.service.ExpenseAccountService;
  22. import com.goafanti.order.service.OrderNewService;
  23. import com.goafanti.order.service.OrderProjectService;
  24. import com.goafanti.user.service.UserService;
  25. import org.apache.commons.collections4.map.HashedMap;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.apache.poi.ss.usermodel.Cell;
  28. import org.apache.poi.ss.usermodel.Row;
  29. import org.apache.poi.ss.usermodel.Sheet;
  30. import org.apache.poi.ss.usermodel.Workbook;
  31. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.beans.factory.annotation.Value;
  34. import org.springframework.context.annotation.Scope;
  35. import org.springframework.http.MediaType;
  36. import org.springframework.stereotype.Controller;
  37. import org.springframework.web.bind.annotation.*;
  38. import org.springframework.web.multipart.MultipartFile;
  39. import org.springframework.web.socket.TextMessage;
  40. import javax.annotation.Resource;
  41. import javax.servlet.http.HttpServletRequest;
  42. import javax.servlet.http.HttpServletResponse;
  43. import java.io.*;
  44. import java.util.*;
  45. @Controller
  46. @Scope(value = "prototype")
  47. @RequestMapping("/open")
  48. public class PublicController extends CertifyApiController {
  49. @Value(value = "${accessKey}")
  50. private String accessKey = null;
  51. @Value(value = "${accessSecret}")
  52. private String accessSecret = null;
  53. @Value(value = "${upload.path}")
  54. private String uploadPath = null;
  55. @Value(value = "${upload.private.path}")
  56. private String uploadPrivatePath = null;
  57. @Value(value = "${static.host}")
  58. private String staticHost = null;
  59. @Value(value = "${mobileCodeTemplate}")
  60. private String mobileCodeTemplate = null;
  61. @Value(value = "${mobileRemindCodeTemplate}")
  62. private String mobileRemindCodeTemplate = null;
  63. @Value(value = "${wx.clockInRange}")
  64. private Integer clockInRange;
  65. @Resource
  66. private UserService userService;
  67. @Resource
  68. private AttachmentService aftFileService;
  69. @Resource
  70. private AdminService adminService;
  71. @Resource
  72. private PovertyService povertyService;
  73. @Autowired
  74. private IndustryCategoryService industryCategoryService;
  75. @Autowired
  76. private DistrictGlossoryService districtGlossoryService;
  77. @Autowired
  78. private ExpenseAccountService expenseAccountService;
  79. @Autowired
  80. private OrderNewService orderNewService;
  81. @Autowired
  82. private OrderProjectService orderProjectService;
  83. @Resource
  84. private UserOutboundService userOutboundService;
  85. @Resource
  86. private ImageService imageService;
  87. @Value(value = "${patentTemplate}")
  88. private String patentTemplate = null;
  89. @Autowired
  90. private JDBCIdGenerator jdbcIdGenerator;
  91. @Resource(name = "passwordUtil")
  92. private PasswordUtil passwordUtil;
  93. /** 上传图片 **/
  94. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  95. public Result uploadOrderInvoiceFile(HttpServletRequest req){
  96. Result res = new Result();
  97. res.setData(handleFile(res, "/publicRelease/", false, req, "publicRelease"));
  98. return res;
  99. }
  100. /**
  101. * 获取验证码
  102. *
  103. * @param response
  104. */
  105. @RequestMapping(value = "/getVCode", method = RequestMethod.GET)
  106. public void getVCode(HttpServletResponse response, HttpServletRequest request) {
  107. try {
  108. response.setHeader("Pragma", "No-cache");
  109. response.setHeader("Cache-Control", "no-cache");
  110. response.setDateHeader("Expires", 0);
  111. response.setContentType("image/jpg");
  112. // 生成随机字串
  113. String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
  114. // 存入Shiro会话session
  115. TokenManager.setVal2Session(VerifyCodeUtils.V_CODE, verifyCode.toLowerCase());
  116. // 生成图片
  117. int w = 146, h = 33;
  118. VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
  119. } catch (Exception e) {
  120. LoggerUtils.fmtError(getClass(), e, "获取验证码异常:%s", e.getMessage());
  121. }
  122. }
  123. /**
  124. * 手机验证码
  125. *
  126. * @param mobile
  127. * @param sign
  128. * 是否用与找回密码
  129. * @param type
  130. * @return
  131. */
  132. @RequestMapping(value = "/getMCode", method = RequestMethod.GET)
  133. @ResponseBody
  134. public Result getMcode(String mobile, boolean sign, Integer type, String verificationCode) {
  135. Result res = new Result();
  136. // 用于找回密码
  137. if (sign) {
  138. if (null == userService.selectByMobieAndType(mobile.trim(), type)) {
  139. res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
  140. return res;
  141. }
  142. }
  143. if (!sign) {
  144. if (StringUtils.isBlank(verificationCode)) {
  145. res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR, "", "图像验证码不能为空!"));
  146. return res;
  147. }
  148. if (!VerifyCodeUtils.verifyCode(verificationCode)) {
  149. res.getError().add(buildError(ErrorConstants.VCODE_ERROR, "", "图形验证码输入错误!"));
  150. return res;
  151. }
  152. }
  153. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
  154. || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
  155. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  156. } else if (TimeUtils.checkOverTime("getMCode")) {
  157. VerifyCodeUtils.clearMobileCode();
  158. VerifyCodeUtils.clearMobileCodeTime();
  159. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  160. } else {
  161. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  162. }
  163. return res;
  164. }
  165. /**
  166. *
  167. * @param mobile
  168. * @param res
  169. * @return
  170. */
  171. private Result sendMessage(String mobile, Result res,String codeType) {
  172. String mobileVerifyCode = VerifyCodeUtils.generateMobileVerifyCode(6); // 生成随机字串
  173. if(VerifyCodeUtils.M_CODE.equals(codeType)){
  174. TokenManager.setVal2Session(VerifyCodeUtils.M_CODE, mobileVerifyCode);// 存入Shiro会话session
  175. TokenManager.setVal2Session(VerifyCodeUtils.M_CODE_TIME, System.currentTimeMillis());
  176. }else if(VerifyCodeUtils.RESET_CODE.equals(codeType)){
  177. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, mobileVerifyCode);// 存入Shiro会话session
  178. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  179. }
  180. String paramString = "{\"code\":\"" + mobileVerifyCode + "\",\"product\":\"技淘网\"}";
  181. String ret = MobileMessageUtils.sendMessage(mobileCodeTemplate, paramString, mobile, accessKey, accessSecret);
  182. if (StringUtils.isNotBlank(ret)) {
  183. res.getError().add(buildError(ErrorConstants.M_CODE_ERROR));
  184. }
  185. return res;
  186. }
  187. /**
  188. * 下载图片
  189. *
  190. * @param response
  191. * @param path
  192. * @param request
  193. */
  194. @RequestMapping(value = "/downLoadPicture", method = RequestMethod.GET)
  195. public Result downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request) {
  196. Result res = new Result();
  197. if (StringUtils.isBlank(path)) {
  198. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT));
  199. return res;
  200. }
  201. String filename = Long.toString(System.nanoTime()) + ".jpg";
  202. InputStream in = null;
  203. OutputStream out = null;
  204. byte[] buffer = new byte[8 * 1024];
  205. String fileSaveRootPath = "";
  206. try {
  207. fileSaveRootPath = uploadPrivatePath + path;
  208. File file = new File(fileSaveRootPath);
  209. in = new FileInputStream(file);
  210. out = response.getOutputStream();
  211. // 设置文件MIME类型
  212. response.setContentType("application/octet-stream");
  213. response.setHeader("Content-Disposition", "attachment; filename=" + filename);
  214. for (;;) {
  215. int bytes = in.read(buffer);
  216. if (bytes == -1) {
  217. break;
  218. }
  219. out.write(buffer, 0, bytes);
  220. }
  221. } catch (IOException e) {
  222. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  223. } finally {
  224. try {
  225. if (null != in) {
  226. in.close();
  227. }
  228. } catch (IOException e) {
  229. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  230. }
  231. try {
  232. if (null != out) {
  233. out.close();
  234. }
  235. } catch (IOException e) {
  236. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  237. }
  238. }
  239. return res;
  240. }
  241. /**
  242. * 删除图片文件(public图片)
  243. *
  244. * @param path
  245. * @return
  246. */
  247. @RequestMapping(value = "/deleteUploadPicture", method = RequestMethod.POST)
  248. public boolean deleteUploadPicture(String path) {
  249. boolean flag = false;
  250. path = uploadPath + path;
  251. File file = new File(path);
  252. // 判断目录或文件是否存在
  253. if (!file.exists() || !file.isFile()) { // 不存在返回 false
  254. return flag;
  255. } else {
  256. return file.delete();
  257. }
  258. }
  259. /**
  260. * 获取并输出private图片
  261. */
  262. @RequestMapping(value = "/writeImage", method = RequestMethod.GET)
  263. public void writeImage(HttpServletResponse response, HttpServletRequest request, String path) {
  264. try {
  265. String realPath = uploadPrivatePath + path;
  266. PictureUtils.outputImage(response, realPath);
  267. } catch (IOException e) {
  268. LoggerUtils.fmtError(getClass(), e, "获取图片异常:%s", e.getMessage());
  269. }
  270. }
  271. /**
  272. * 下载文件
  273. *
  274. * @param fileName
  275. * @param response
  276. * @param path
  277. * @return
  278. */
  279. @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
  280. public Result downloadFile(String fileName, HttpServletResponse response, String path) {
  281. Result res = new Result();
  282. return handleDownloadFile(response, fileName, path, res);
  283. }
  284. /**
  285. * 下载模版文件
  286. *
  287. * @param response
  288. * @return
  289. */
  290. @RequestMapping(value = "/downloadTemplateFile", method = RequestMethod.GET)
  291. public Result downloadTemplateFile(HttpServletResponse response, String sign) {
  292. Result res = new Result();
  293. String fileName = "";
  294. String path = aftFileService.selectAftFileBySign(sign).getFilePath();
  295. String suffix = path.substring(path.lastIndexOf("."));
  296. if (sign.equals("patent_prory_statement")) {
  297. fileName = "专利代理委托书模版" + suffix;
  298. } else {
  299. fileName = System.nanoTime() + " ";
  300. }
  301. if (!StringUtils.isBlank(path)) {
  302. return handleDownloadFile(response, fileName, path, res);
  303. } else {
  304. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "下载文件不存在!"));
  305. return res;
  306. }
  307. }
  308. private Result handleDownloadFile(HttpServletResponse response, String fileName, String path, Result res) {
  309. String fileSaveRootPath = uploadPrivatePath + path;
  310. InputStream in = null;
  311. OutputStream out = null;
  312. byte[] buffer = new byte[8 * 1024];
  313. try {
  314. File file = new File(fileSaveRootPath);
  315. in = new FileInputStream(file);
  316. out = response.getOutputStream();
  317. response.setContentType("multipart/form-data");
  318. fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
  319. response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
  320. for (;;) {
  321. int bytes = in.read(buffer);
  322. if (bytes == -1) {
  323. break;
  324. }
  325. out.write(buffer, 0, bytes);
  326. }
  327. } catch (IOException e) {
  328. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  329. } finally {
  330. try {
  331. in.close();
  332. } catch (IOException e) {
  333. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  334. }
  335. try {
  336. out.close();
  337. } catch (IOException e) {
  338. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  339. }
  340. }
  341. return res;
  342. }
  343. @RequestMapping(value = "/findIndustryCategory", method = RequestMethod.GET)
  344. @ResponseBody
  345. public Result findIndustryCategory(String id, String noCache) {
  346. Integer pid = 0;
  347. if (StringUtils.isNumeric(id)) {
  348. try {
  349. pid = Integer.parseInt(id);
  350. } catch (Exception e) {
  351. pid = 0;
  352. }
  353. }
  354. if (StringUtils.isNotBlank(noCache)) {
  355. industryCategoryService.clear(pid);
  356. }
  357. return new Result().data(industryCategoryService.list(pid));
  358. }
  359. @RequestMapping(value = "/findDistrict", method = RequestMethod.GET)
  360. @ResponseBody
  361. public Result findDistrictGlossory(String id, String noCache) {
  362. Integer pid = 0;
  363. if (StringUtils.isNumeric(id)) {
  364. try {
  365. pid = Integer.parseInt(id);
  366. } catch (Exception e) {
  367. pid = 0;
  368. }
  369. }
  370. if (StringUtils.isNotBlank(noCache)) {
  371. districtGlossoryService.clear(pid);
  372. }
  373. return new Result().data(districtGlossoryService.list(pid));
  374. }
  375. /**
  376. *
  377. * @param mobileCode
  378. * @return
  379. */
  380. @RequestMapping(value = "/checkMCode", method = RequestMethod.POST)
  381. @ResponseBody
  382. public Result checkMCode(String mobileCode) {
  383. Result res = new Result();
  384. if (StringUtils.isBlank(mobileCode)) {
  385. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机验证码"));
  386. return res;
  387. }
  388. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  389. res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
  390. VerifyCodeUtils.clearMobileCode();
  391. VerifyCodeUtils.clearMobileCodeTime();
  392. return res;
  393. }
  394. if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
  395. res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码错误"));
  396. return res;
  397. }
  398. // resetCode
  399. if (res.getError().isEmpty()) {
  400. String resetCode = UUID.randomUUID().toString();
  401. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
  402. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  403. res.setData(resetCode);
  404. }
  405. return res;
  406. }
  407. /**
  408. * 重置密码
  409. *
  410. * @param resetCode
  411. * @param mobile
  412. * @param type
  413. * @param newPwd
  414. * @return
  415. */
  416. @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
  417. @ResponseBody
  418. public Result resetPwd(String resetCode, String mobile, Integer type, String newPwd) {
  419. Result res = new Result();
  420. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  421. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  422. cleanCodeSession();
  423. return res;
  424. }
  425. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  426. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  427. cleanCodeSession();
  428. return res;
  429. }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
  430. res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
  431. cleanCodeSession();
  432. return res;
  433. }
  434. if (StringUtils.isBlank(newPwd)) {
  435. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  436. return res;
  437. }
  438. if (StringUtils.isBlank(mobile)) {
  439. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
  440. return res;
  441. }
  442. if (!UserType.ORGANIZATION.getCode().equals(type) && !UserType.PERSONAL.getCode().equals(type)) {
  443. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
  444. return res;
  445. }
  446. User user = userService.selectByMobieAndType(mobile, type);
  447. if (null == user) {
  448. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "mobile"));
  449. return res;
  450. }
  451. user.setPassword(newPwd);
  452. user.setPassword(passwordUtil.getEncryptPwd(user));
  453. userService.updateByPrimaryKeySelective(user);
  454. VerifyCodeUtils.clearResetCode();
  455. VerifyCodeUtils.clearResetCodeTime();
  456. return res;
  457. }
  458. private void cleanCodeSession() {
  459. VerifyCodeUtils.clearResetCode();
  460. VerifyCodeUtils.clearResetCodeTime();
  461. VerifyCodeUtils.clearMobileCode();
  462. VerifyCodeUtils.clearMobileCodeTime();
  463. }
  464. @RequestMapping(value = "/getRegisterMCode", method = RequestMethod.GET )
  465. @ResponseBody
  466. public Result getRegisterMCode(String mobile){
  467. Result res = new Result();
  468. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
  469. || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
  470. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  471. } else if (TimeUtils.checkOverTime("getMCode")) {
  472. VerifyCodeUtils.clearMobileCode();
  473. VerifyCodeUtils.clearMobileCodeTime();
  474. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  475. } else {
  476. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  477. }
  478. return res;
  479. }
  480. @RequestMapping(value = "/getResetMCode", method = RequestMethod.GET )
  481. @ResponseBody
  482. public Result getResetMCode(String mobile, Integer type) {
  483. Result res = new Result();
  484. if (null == userService.selectByMobieAndType(mobile.trim(), type)) {
  485. res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
  486. return res;
  487. }
  488. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == null
  489. || TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == "") {
  490. sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
  491. } else if (TimeUtils.checkOverTime("resetCode")) {
  492. VerifyCodeUtils.clearMobileCode();
  493. VerifyCodeUtils.clearMobileCodeTime();
  494. sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
  495. } else {
  496. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  497. }
  498. return res;
  499. }
  500. /** 省市区查询 **/
  501. @RequestMapping(value = "/listAllProvince" , method = RequestMethod.POST)
  502. @ResponseBody
  503. public Result listAllProvince(){
  504. Result res = new Result();
  505. res.setData(districtGlossoryService.getProvince());
  506. return res;
  507. }
  508. @RequestMapping(value = "/listDefaultPassword" , method = RequestMethod.GET)
  509. @ResponseBody
  510. public Result listDefaultPassword(String depId){
  511. Result res=new Result();
  512. res.setData(adminService.getListDefaultPassword(depId));
  513. return res;
  514. }
  515. /** 省市区查询 **/
  516. @RequestMapping(value = "/sendWeb" , method = RequestMethod.POST)
  517. @ResponseBody
  518. public Result sendWeb(String str){
  519. Result res = new Result();
  520. SystemWebSocketHandler sys=new SystemWebSocketHandler();
  521. TextMessage text=new TextMessage(str.getBytes());
  522. sys.sendMessageToUsers(text);
  523. res.setData(1);
  524. return res;
  525. }
  526. /**
  527. * 导入流水
  528. * @param file
  529. * @param request
  530. * @return
  531. */
  532. @SuppressWarnings("unchecked")
  533. @RequestMapping(value = "/import" , method = RequestMethod.POST)
  534. @ResponseBody
  535. public Result importTeacher(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request) {
  536. Result res=new Result();
  537. String fileName = file.getOriginalFilename();
  538. if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
  539. res.error(new Error("", "格式不正确"));
  540. }
  541. //检查文件
  542. try {
  543. checkFile(file);
  544. } catch (IOException e) {
  545. e.printStackTrace();
  546. }
  547. //获得Workbook工作薄对象
  548. Workbook workbook = getWorkBook(file);
  549. //创建返回对象,把每行中的值作为一个数组,所有行作为一个集合返回
  550. List<List<String>> list = new ArrayList<>();
  551. if(workbook != null){
  552. for(int sheetNum = 0;sheetNum < workbook.getNumberOfSheets();sheetNum++){
  553. //获得当前sheet工作表
  554. Sheet sheet = workbook.getSheetAt(sheetNum);
  555. if(sheet == null){
  556. continue;
  557. }
  558. //获得当前sheet的开始行
  559. int firstRowNum = sheet.getFirstRowNum();
  560. //获得当前sheet的结束行
  561. int lastRowNum = sheet.getLastRowNum();
  562. //循环除了第2行的所有行
  563. for(int rowNum = firstRowNum+2;rowNum <= lastRowNum;rowNum++){
  564. //获得当前行
  565. Row row = sheet.getRow(rowNum);
  566. if(row == null){
  567. continue;
  568. }
  569. //获得当前行的开始列
  570. int firstCellNum = row.getFirstCellNum();
  571. //获得当前行的列数
  572. int lastCellNum = row.getLastCellNum();
  573. @SuppressWarnings("rawtypes")
  574. ArrayList arrayList = new ArrayList();
  575. //循环当前行 cellNum = (firstCellNum+1) 则是除开第一例
  576. for(int cellNum = (firstCellNum); cellNum < lastCellNum;cellNum++){
  577. Cell cell = row.getCell(cellNum);
  578. arrayList.add(getCellValue(cell));
  579. }
  580. list.add(arrayList);
  581. }
  582. }
  583. }
  584. return res;
  585. }
  586. public static void checkFile(MultipartFile file) throws IOException{
  587. //判断文件是否存在
  588. if(null == file){
  589. throw new FileNotFoundException("文件不存在!");
  590. }
  591. //获得文件名
  592. String fileName = file.getOriginalFilename();
  593. //判断文件是否是excel文件
  594. if(!fileName.endsWith("xls") && !fileName.endsWith("xlsx")){
  595. throw new IOException(fileName + "不是excel文件");
  596. }
  597. }
  598. public static Workbook getWorkBook(MultipartFile file) {
  599. //创建Workbook工作薄对象,表示整个excel
  600. Workbook workbook = null;
  601. try {
  602. //获取excel文件的io流
  603. InputStream is = file.getInputStream();
  604. //如果是xls,使用HSSFWorkbook;如果是xlsx,使用XSSFWorkbook
  605. workbook = new XSSFWorkbook(is);
  606. } catch (IOException e) {
  607. }
  608. return workbook;
  609. }
  610. @SuppressWarnings("deprecation")
  611. public static String getCellValue(Cell cell){
  612. String cellValue = "";
  613. if(cell == null){
  614. return cellValue;
  615. }
  616. //把数字当成String来读,避免出现1读成1.0的情况
  617. if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
  618. cell.setCellType(Cell.CELL_TYPE_STRING);
  619. }
  620. //判断数据的类型
  621. switch (cell.getCellType()){
  622. case Cell.CELL_TYPE_NUMERIC: //数字
  623. cellValue = String.valueOf(cell.getNumericCellValue());
  624. break;
  625. case Cell.CELL_TYPE_STRING: //字符串
  626. cellValue = String.valueOf(cell.getStringCellValue());
  627. break;
  628. case Cell.CELL_TYPE_BOOLEAN: //Boolean
  629. cellValue = String.valueOf(cell.getBooleanCellValue());
  630. break;
  631. case Cell.CELL_TYPE_FORMULA: //公式
  632. cellValue = String.valueOf(cell.getCellFormula());
  633. break;
  634. case Cell.CELL_TYPE_BLANK: //空值
  635. cellValue = "未知";
  636. break;
  637. case Cell.CELL_TYPE_ERROR: //故障
  638. cellValue = "非法字符";
  639. break;
  640. default:
  641. cellValue = "未知类型";
  642. break;
  643. }
  644. return cellValue;
  645. }
  646. /**
  647. * 通用下载请求
  648. *
  649. * @param fileName 文件名称
  650. * @param delete 是否删除
  651. */
  652. @RequestMapping("/download")
  653. public void fileDownload(String fileName, Boolean delete,String attName,
  654. HttpServletResponse response, HttpServletRequest request)
  655. {
  656. try
  657. {
  658. if (!FileUtils.checkAllowDownload(fileName))
  659. {
  660. throw new Exception("文件名称非法,不允许下载。 ");
  661. }
  662. String realFileName =DateUtils.parseDateToStr(AFTConstants.YYYYMMDDHHMMSS, new Date())+fileName.substring(fileName.indexOf("_") + 1);
  663. String filePath = uploadPath +"/"+ fileName;
  664. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  665. FileUtils.setAttachmentResponseHeader(response, realFileName,attName);
  666. FileUtils.writeBytes(filePath, response.getOutputStream());
  667. if(delete==null)delete=true;
  668. if (delete)
  669. {
  670. FileUtils.deleteFile(filePath);
  671. }
  672. }
  673. catch (Exception e)
  674. {
  675. LoggerUtils.error(PublicController.class,"下载文件失败", e);
  676. }
  677. }
  678. /**
  679. * 通用下载请求
  680. *
  681. * @param fileName 文件名称
  682. */
  683. @RequestMapping("/deleteFile")
  684. public Result deleteFile(String fileName) {
  685. Result res = new Result();
  686. if (StringUtils.isBlank(fileName)) {
  687. res.getError().add(buildError("文件路径错误"));
  688. return res;
  689. }
  690. try {
  691. if (!FileUtils.checkAllowDownload(fileName)) {
  692. throw new Exception("文件名称非法,不允许删除。 ");
  693. }
  694. String filePath = uploadPath + "/" + fileName;
  695. FileUtils.deleteFile(filePath);
  696. res.setData(1);
  697. } catch (Exception e) {
  698. LoggerUtils.error(PublicController.class, "删除文件失败", e);
  699. }
  700. return res;
  701. }
  702. @RequestMapping("/getWxConfig")
  703. public Result getWxConfig() {
  704. Result res =new Result();
  705. Map<String, Object> config= new HashedMap<>();
  706. config.put("clockInRange", clockInRange);
  707. res.data(config);
  708. return res;
  709. }
  710. @RequestMapping("/getUser")
  711. public Result getUser() {
  712. List<OutUser> list=userService.getuser();
  713. NewExcelUtil<OutUser> excel=new NewExcelUtil<OutUser>(OutUser.class);
  714. return excel.exportExcel(list, "客户列表",uploadPath);
  715. }
  716. /**
  717. * 补充发票报销查询编号
  718. */
  719. @RequestMapping("/supplementCheckNo")
  720. public Result supplementCheckNo() {
  721. Result res=new Result();
  722. res.data(expenseAccountService.pushSupplementCheckNo());
  723. return res;
  724. }
  725. /**
  726. * 查询贫困信息
  727. */
  728. @RequestMapping("/selectPoverty")
  729. public Result selectPoverty(@RequestParam(value = "file", required = false) MultipartFile file) {
  730. Result res=new Result();
  731. //判断文件是否存在
  732. if(null == file){
  733. res.getError().add(buildError("文件不存在!","文件不存在!"));
  734. return res;
  735. }
  736. String fileName = file.getOriginalFilename();
  737. if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
  738. res.getError().add(buildError("格式不正确","格式不正确"));
  739. return res;
  740. }
  741. String id = jdbcIdGenerator.generateId().toString();
  742. res.data(povertyService.selectPoverty(file,id));
  743. return res;
  744. }
  745. /**
  746. * 查询贫困信息
  747. * @param id 贫困信息编号
  748. * @param type 0=所有 ,1=只看有效数据
  749. */
  750. @RequestMapping("/selectPovertyById/export")
  751. public Result selectPovertyByIdExport(String id,Integer type) {
  752. Map<String,Object> o = povertyService.selectPoverty(null, id);
  753. if (type==null)type=0;
  754. List<OutPoverty> resList=new ArrayList<>();
  755. if (type==1){
  756. List<OutPoverty> list = (List<OutPoverty>) o.get("list");
  757. for (OutPoverty outPoverty : list) {
  758. if (com.goafanti.common.utils.StringUtils.isNotEmpty(outPoverty.getId())){
  759. resList.add(outPoverty);
  760. }
  761. }
  762. }else {
  763. resList = (List<OutPoverty>) o.get("list");
  764. }
  765. NewExcelUtil<OutPoverty> newExcelUtil=new NewExcelUtil<>(OutPoverty.class);
  766. return newExcelUtil.exportExcel(resList,"广西贫困信息表",uploadPath);
  767. }
  768. @RequestMapping("/selectPovertyById")
  769. public Result selectPovertyById(String id,Integer type) {
  770. Result res=new Result();
  771. Map<String,Object> o = povertyService.selectPoverty(null, id);
  772. if (type==null)type=0;
  773. if (type==1){
  774. List<OutPoverty> list = (List<OutPoverty>) o.get("list");
  775. List<OutPoverty> resList=new ArrayList<>();
  776. for (OutPoverty outPoverty : list) {
  777. if (com.goafanti.common.utils.StringUtils.isNotEmpty(outPoverty.getId())){
  778. resList.add(outPoverty);
  779. }
  780. }
  781. o.remove("list");
  782. o.put("list",resList);
  783. }
  784. res.data(o);
  785. return res;
  786. }
  787. /**
  788. * 批量导入回款模版
  789. *
  790. */
  791. @RequestMapping(value = "/downloadPovertyTemplate", method = RequestMethod.GET)
  792. public void downloadTemplate(HttpServletResponse response) {
  793. StringBuilder url= new StringBuilder(uploadPath);
  794. url.append("/tmp").append("/poverty_template.xls");
  795. try {
  796. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  797. FileUtils.setAttachmentResponseHeader(response, url.toString(),"poverty导入模版.xls");
  798. FileUtils.writeBytes(url.toString(), response.getOutputStream());
  799. }
  800. catch (Exception e) {
  801. LoggerUtils.error(PublicController.class,"下载文件失败", e);
  802. }
  803. }
  804. /**
  805. * 查询贫困信息
  806. */
  807. @RequestMapping("/selectFlag")
  808. public Result selectFlag(@RequestParam(value = "file", required = false) MultipartFile file) {
  809. Result res=new Result();
  810. //判断文件是否存在
  811. if(null == file){
  812. res.getError().add(buildError("文件不存在!","文件不存在!"));
  813. return res;
  814. }
  815. String fileName = file.getOriginalFilename();
  816. if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
  817. res.getError().add(buildError("格式不正确","格式不正确"));
  818. return res;
  819. }
  820. String id = jdbcIdGenerator.generateId().toString();
  821. Map<String, Object> map = povertyService.selectFlag(file, id);
  822. List<OutPovertyFlag> falseList = (List<OutPovertyFlag>) map.get("falseList");
  823. List<OutPovertyFlag> list = (List<OutPovertyFlag>) map.get("trueList");
  824. list.addAll(falseList);
  825. map.put("list",list);
  826. map.remove("falseList");
  827. map.remove("trueList");
  828. res.data(map);
  829. return res;
  830. }
  831. /**
  832. * 查询贫困信息
  833. * @param id 贫困信息编号
  834. * @param type 0=所有 ,1=只看有效数据
  835. */
  836. @RequestMapping("/selectPovertyFlagById")
  837. public Result selectPovertyFlagById(String id,Integer type) {
  838. Result res =new Result();
  839. Map<String,Object> map = povertyService.selectFlag(null, id);
  840. if (type==null)type=0;
  841. if (type==1){
  842. map.put("list",map.get("trueList"));
  843. }else {
  844. map.put("list",map.get("falseList"));
  845. }
  846. map.remove("trueList");
  847. map.remove("falseList");
  848. return res.data(map);
  849. }
  850. /**
  851. * 查询贫困信息
  852. * @param id 贫困信息编号
  853. * @param type 0=所有 ,1=只看有效数据
  854. */
  855. @RequestMapping("/selectPovertyFlagById/export")
  856. public Result selectPovertyFlagByIdExport(String id,Integer type) {
  857. Map<String,Object> map = povertyService.selectFlag(null, id);
  858. if (type==null)type=0;
  859. List<OutPovertyFlag> resList=new ArrayList<>();
  860. if (type==1){
  861. map.put("list",map.get("trueList"));
  862. }else {
  863. map.put("list",map.get("falseList"));
  864. }
  865. map.remove("trueList");
  866. map.remove("falseList");
  867. NewExcelUtil<OutPovertyFlag> newExcelUtil=new NewExcelUtil<>(OutPovertyFlag.class);
  868. return newExcelUtil.exportExcel(resList,"全国贫困信息表",uploadPath);
  869. }
  870. @RequestMapping("/pushStatistics3")
  871. public Result pushStatistics (){
  872. Result res =new Result();
  873. res.data(adminService.pushStatistics());
  874. return res;
  875. }
  876. /**
  877. * 处理催款节点详情
  878. */
  879. @RequestMapping(value = "/pushDunNodeContent",method = RequestMethod.GET)
  880. @ResponseBody
  881. public Result pushDunNodeContent(){
  882. Result res =new Result();
  883. orderNewService.pushDunNodeContent();
  884. res.data("ok");
  885. return res;
  886. }
  887. /**
  888. * 处理项目完成时间
  889. */
  890. @RequestMapping(value = "/pushProjectCompleteDate",method = RequestMethod.GET)
  891. @ResponseBody
  892. public Result pushProjectCompleteDate(){
  893. Result res =new Result();
  894. orderProjectService.pushProjectCompleteDate();
  895. res.data("ok");
  896. return res;
  897. }
  898. /**
  899. * 处理订单最大公出小时
  900. */
  901. @RequestMapping(value = "/pushOrderMaxDuration",method = RequestMethod.GET)
  902. @ResponseBody
  903. public Result pushOrderMaxDuration(){
  904. Result res =new Result();
  905. orderNewService.pushOrderMaxDuration();
  906. res.data("ok");
  907. return res;
  908. }
  909. /**
  910. * 呼叫完成回调
  911. *
  912. */
  913. @PostMapping("/callCompleted")
  914. @ResponseBody
  915. public Result callCompleted(@RequestBody InputCallCompleter in) {
  916. System.out.println(in);
  917. return new Result<>().data(userOutboundService.pushCallCompleted(in));
  918. }
  919. // /**
  920. // * OCR识别
  921. // */
  922. // @PostMapping("/OCR")
  923. // @ResponseBody
  924. // public Result ImageOCR(@RequestParam(value = "file", required = false) MultipartFile file) {
  925. //
  926. // return new Result<>().data(imageService.ImageOCR(file));
  927. // }
  928. }