PublicController.java 31 KB

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