PublicController.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. package com.goafanti.common.controller;
  2. import java.io.*;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.UUID;
  8. import javax.annotation.Resource;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import com.goafanti.common.dao.TOrderMidMapper;
  12. import com.goafanti.common.dao.TOrderTaskMapper;
  13. import com.goafanti.common.model.TOrderMid;
  14. import com.goafanti.common.model.TOrderTask;
  15. import com.goafanti.common.utils.excel.Excel;
  16. import com.goafanti.order.bo.TOrderTaskBo;
  17. import com.goafanti.order.enums.NewProjectStatus;
  18. import com.goafanti.order.enums.ProjectStage;
  19. import com.goafanti.order.enums.ProjectType;
  20. import com.goafanti.order.service.OrderProjectService;
  21. import org.apache.commons.collections4.map.HashedMap;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.apache.poi.ss.usermodel.Cell;
  24. import org.apache.poi.ss.usermodel.Row;
  25. import org.apache.poi.ss.usermodel.Sheet;
  26. import org.apache.poi.ss.usermodel.Workbook;
  27. import org.apache.poi.ss.util.CellRangeAddress;
  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 com.goafanti.admin.service.AdminService;
  41. import com.goafanti.admin.service.AttachmentService;
  42. import com.goafanti.common.bo.Error;
  43. import com.goafanti.common.bo.OutUser;
  44. import com.goafanti.common.bo.Result;
  45. import com.goafanti.common.constant.AFTConstants;
  46. import com.goafanti.common.constant.ErrorConstants;
  47. import com.goafanti.common.enums.UserType;
  48. import com.goafanti.common.model.User;
  49. import com.goafanti.common.service.DistrictGlossoryService;
  50. import com.goafanti.common.service.FieldGlossoryService;
  51. import com.goafanti.common.service.IndustryCategoryService;
  52. import com.goafanti.common.utils.DateUtils;
  53. import com.goafanti.common.utils.LoggerUtils;
  54. import com.goafanti.common.utils.MobileMessageUtils;
  55. import com.goafanti.common.utils.PasswordUtil;
  56. import com.goafanti.common.utils.PictureUtils;
  57. import com.goafanti.common.utils.TimeUtils;
  58. import com.goafanti.common.utils.VerifyCodeUtils;
  59. import com.goafanti.common.utils.excel.FileUtils;
  60. import com.goafanti.common.utils.excel.NewExcelUtil;
  61. import com.goafanti.core.shiro.token.TokenManager;
  62. import com.goafanti.core.websocket.SystemWebSocketHandler;
  63. import com.goafanti.patent.bo.PatentNewBo;
  64. import com.goafanti.user.service.UserService;
  65. @Controller
  66. @Scope(value = "prototype")
  67. @RequestMapping("/open")
  68. public class PublicController extends CertifyApiController {
  69. @Value(value = "${accessKey}")
  70. private String accessKey = null;
  71. @Value(value = "${accessSecret}")
  72. private String accessSecret = null;
  73. @Value(value = "${upload.path}")
  74. private String uploadPath = null;
  75. @Value(value = "${upload.private.path}")
  76. private String uploadPrivatePath = null;
  77. @Value(value = "${static.host}")
  78. private String staticHost = null;
  79. @Value(value = "${mobileCodeTemplate}")
  80. private String mobileCodeTemplate = null;
  81. @Value(value = "${mobileRemindCodeTemplate}")
  82. private String mobileRemindCodeTemplate = null;
  83. @Value(value = "${wx.clockInRange}")
  84. private Integer clockInRange;
  85. @Resource
  86. private UserService userService;
  87. @Resource
  88. private AttachmentService aftFileService;
  89. @Resource
  90. private AdminService adminService;
  91. @Resource
  92. private TOrderMidMapper tOrderMidMapper;
  93. @Autowired
  94. private IndustryCategoryService industryCategoryService;
  95. @Autowired
  96. private DistrictGlossoryService districtGlossoryService;
  97. @Autowired
  98. private OrderProjectService orderProjectService;
  99. @Value(value = "${patentTemplate}")
  100. private String patentTemplate = null;
  101. @Resource(name = "passwordUtil")
  102. private PasswordUtil passwordUtil;
  103. /** 上传图片 **/
  104. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  105. public Result uploadOrderInvoiceFile(HttpServletRequest req){
  106. Result res = new Result();
  107. res.setData(handleFile(res, "/publicRelease/", false, req, "publicRelease"));
  108. return res;
  109. }
  110. /**
  111. * 获取验证码
  112. *
  113. * @param response
  114. */
  115. @RequestMapping(value = "/getVCode", method = RequestMethod.GET)
  116. public void getVCode(HttpServletResponse response, HttpServletRequest request) {
  117. try {
  118. response.setHeader("Pragma", "No-cache");
  119. response.setHeader("Cache-Control", "no-cache");
  120. response.setDateHeader("Expires", 0);
  121. response.setContentType("image/jpg");
  122. // 生成随机字串
  123. String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
  124. // 存入Shiro会话session
  125. TokenManager.setVal2Session(VerifyCodeUtils.V_CODE, verifyCode.toLowerCase());
  126. // 生成图片
  127. int w = 146, h = 33;
  128. VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
  129. } catch (Exception e) {
  130. LoggerUtils.fmtError(getClass(), e, "获取验证码异常:%s", e.getMessage());
  131. }
  132. }
  133. /**
  134. * 手机验证码
  135. *
  136. * @param mobile
  137. * @param sign
  138. * 是否用与找回密码
  139. * @param type
  140. * @return
  141. */
  142. @RequestMapping(value = "/getMCode", method = RequestMethod.GET)
  143. @ResponseBody
  144. public Result getMcode(String mobile, boolean sign, Integer type, String verificationCode) {
  145. Result res = new Result();
  146. // 用于找回密码
  147. if (sign) {
  148. if (null == userService.selectByMobieAndType(mobile.trim(), type)) {
  149. res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
  150. return res;
  151. }
  152. }
  153. if (!sign) {
  154. if (StringUtils.isBlank(verificationCode)) {
  155. res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR, "", "图像验证码不能为空!"));
  156. return res;
  157. }
  158. if (!VerifyCodeUtils.verifyCode(verificationCode)) {
  159. res.getError().add(buildError(ErrorConstants.VCODE_ERROR, "", "图形验证码输入错误!"));
  160. return res;
  161. }
  162. }
  163. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
  164. || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
  165. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  166. } else if (TimeUtils.checkOverTime("getMCode")) {
  167. VerifyCodeUtils.clearMobileCode();
  168. VerifyCodeUtils.clearMobileCodeTime();
  169. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  170. } else {
  171. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  172. }
  173. return res;
  174. }
  175. /**
  176. *
  177. * @param mobile
  178. * @param res
  179. * @return
  180. */
  181. private Result sendMessage(String mobile, Result res,String codeType) {
  182. String mobileVerifyCode = VerifyCodeUtils.generateMobileVerifyCode(6); // 生成随机字串
  183. if(VerifyCodeUtils.M_CODE.equals(codeType)){
  184. TokenManager.setVal2Session(VerifyCodeUtils.M_CODE, mobileVerifyCode);// 存入Shiro会话session
  185. TokenManager.setVal2Session(VerifyCodeUtils.M_CODE_TIME, System.currentTimeMillis());
  186. }else if(VerifyCodeUtils.RESET_CODE.equals(codeType)){
  187. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, mobileVerifyCode);// 存入Shiro会话session
  188. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  189. }
  190. String paramString = "{\"code\":\"" + mobileVerifyCode + "\",\"product\":\"技淘网\"}";
  191. String ret = MobileMessageUtils.sendMessage(mobileCodeTemplate, paramString, mobile, accessKey, accessSecret);
  192. if (StringUtils.isNotBlank(ret)) {
  193. res.getError().add(buildError(ErrorConstants.M_CODE_ERROR));
  194. }
  195. return res;
  196. }
  197. /**
  198. * 下载图片
  199. *
  200. * @param response
  201. * @param path
  202. * @param request
  203. */
  204. @RequestMapping(value = "/downLoadPicture", method = RequestMethod.GET)
  205. public Result downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request) {
  206. Result res = new Result();
  207. if (StringUtils.isBlank(path)) {
  208. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT));
  209. return res;
  210. }
  211. String filename = Long.toString(System.nanoTime()) + ".jpg";
  212. InputStream in = null;
  213. OutputStream out = null;
  214. byte[] buffer = new byte[8 * 1024];
  215. String fileSaveRootPath = "";
  216. try {
  217. fileSaveRootPath = uploadPrivatePath + path;
  218. File file = new File(fileSaveRootPath);
  219. in = new FileInputStream(file);
  220. out = response.getOutputStream();
  221. // 设置文件MIME类型
  222. response.setContentType("application/octet-stream");
  223. response.setHeader("Content-Disposition", "attachment; filename=" + filename);
  224. for (;;) {
  225. int bytes = in.read(buffer);
  226. if (bytes == -1) {
  227. break;
  228. }
  229. out.write(buffer, 0, bytes);
  230. }
  231. } catch (IOException e) {
  232. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  233. } finally {
  234. try {
  235. if (null != in) {
  236. in.close();
  237. }
  238. } catch (IOException e) {
  239. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  240. }
  241. try {
  242. if (null != out) {
  243. out.close();
  244. }
  245. } catch (IOException e) {
  246. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  247. }
  248. }
  249. return res;
  250. }
  251. /**
  252. * 删除图片文件(public图片)
  253. *
  254. * @param path
  255. * @return
  256. */
  257. @RequestMapping(value = "/deleteUploadPicture", method = RequestMethod.POST)
  258. public boolean deleteUploadPicture(String path) {
  259. boolean flag = false;
  260. path = uploadPath + path;
  261. File file = new File(path);
  262. // 判断目录或文件是否存在
  263. if (!file.exists() || !file.isFile()) { // 不存在返回 false
  264. return flag;
  265. } else {
  266. return file.delete();
  267. }
  268. }
  269. /**
  270. * 获取并输出private图片
  271. */
  272. @RequestMapping(value = "/writeImage", method = RequestMethod.GET)
  273. public void writeImage(HttpServletResponse response, HttpServletRequest request, String path) {
  274. try {
  275. String realPath = uploadPrivatePath + path;
  276. PictureUtils.outputImage(response, realPath);
  277. } catch (IOException e) {
  278. LoggerUtils.fmtError(getClass(), e, "获取图片异常:%s", e.getMessage());
  279. }
  280. }
  281. /**
  282. * 下载文件
  283. *
  284. * @param fileName
  285. * @param response
  286. * @param path
  287. * @return
  288. */
  289. @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
  290. public Result downloadFile(String fileName, HttpServletResponse response, String path) {
  291. Result res = new Result();
  292. return handleDownloadFile(response, fileName, path, res);
  293. }
  294. /**
  295. * 下载模版文件
  296. *
  297. * @param response
  298. * @return
  299. */
  300. @RequestMapping(value = "/downloadTemplateFile", method = RequestMethod.GET)
  301. public Result downloadTemplateFile(HttpServletResponse response, String sign) {
  302. Result res = new Result();
  303. String fileName = "";
  304. String path = aftFileService.selectAftFileBySign(sign).getFilePath();
  305. String suffix = path.substring(path.lastIndexOf("."));
  306. if (sign.equals("patent_prory_statement")) {
  307. fileName = "专利代理委托书模版" + suffix;
  308. } else {
  309. fileName = System.nanoTime() + " ";
  310. }
  311. if (!StringUtils.isBlank(path)) {
  312. return handleDownloadFile(response, fileName, path, res);
  313. } else {
  314. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "下载文件不存在!"));
  315. return res;
  316. }
  317. }
  318. private Result handleDownloadFile(HttpServletResponse response, String fileName, String path, Result res) {
  319. String fileSaveRootPath = uploadPrivatePath + path;
  320. InputStream in = null;
  321. OutputStream out = null;
  322. byte[] buffer = new byte[8 * 1024];
  323. try {
  324. File file = new File(fileSaveRootPath);
  325. in = new FileInputStream(file);
  326. out = response.getOutputStream();
  327. response.setContentType("multipart/form-data");
  328. fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
  329. response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
  330. for (;;) {
  331. int bytes = in.read(buffer);
  332. if (bytes == -1) {
  333. break;
  334. }
  335. out.write(buffer, 0, bytes);
  336. }
  337. } catch (IOException e) {
  338. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  339. } finally {
  340. try {
  341. in.close();
  342. } catch (IOException e) {
  343. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  344. }
  345. try {
  346. out.close();
  347. } catch (IOException e) {
  348. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  349. }
  350. }
  351. return res;
  352. }
  353. @RequestMapping(value = "/findIndustryCategory", method = RequestMethod.GET)
  354. @ResponseBody
  355. public Result findIndustryCategory(String id, String noCache) {
  356. Integer pid = 0;
  357. if (StringUtils.isNumeric(id)) {
  358. try {
  359. pid = Integer.parseInt(id);
  360. } catch (Exception e) {
  361. pid = 0;
  362. }
  363. }
  364. if (StringUtils.isNotBlank(noCache)) {
  365. industryCategoryService.clear(pid);
  366. }
  367. return new Result().data(industryCategoryService.list(pid));
  368. }
  369. @RequestMapping(value = "/findDistrict", method = RequestMethod.GET)
  370. @ResponseBody
  371. public Result findDistrictGlossory(String id, String noCache) {
  372. Integer pid = 0;
  373. if (StringUtils.isNumeric(id)) {
  374. try {
  375. pid = Integer.parseInt(id);
  376. } catch (Exception e) {
  377. pid = 0;
  378. }
  379. }
  380. if (StringUtils.isNotBlank(noCache)) {
  381. districtGlossoryService.clear(pid);
  382. }
  383. return new Result().data(districtGlossoryService.list(pid));
  384. }
  385. /**
  386. *
  387. * @param mobileCode
  388. * @return
  389. */
  390. @RequestMapping(value = "/checkMCode", method = RequestMethod.POST)
  391. @ResponseBody
  392. public Result checkMCode(String mobileCode) {
  393. Result res = new Result();
  394. if (StringUtils.isBlank(mobileCode)) {
  395. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机验证码"));
  396. return res;
  397. }
  398. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  399. res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
  400. VerifyCodeUtils.clearMobileCode();
  401. VerifyCodeUtils.clearMobileCodeTime();
  402. return res;
  403. }
  404. if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
  405. res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码错误"));
  406. return res;
  407. }
  408. // resetCode
  409. if (res.getError().isEmpty()) {
  410. String resetCode = UUID.randomUUID().toString();
  411. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
  412. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  413. res.setData(resetCode);
  414. }
  415. return res;
  416. }
  417. /**
  418. * 重置密码
  419. *
  420. * @param resetCode
  421. * @param mobile
  422. * @param type
  423. * @param newPwd
  424. * @return
  425. */
  426. @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
  427. @ResponseBody
  428. public Result resetPwd(String resetCode, String mobile, Integer type, String newPwd) {
  429. Result res = new Result();
  430. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  431. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  432. cleanCodeSession();
  433. return res;
  434. }
  435. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  436. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  437. cleanCodeSession();
  438. return res;
  439. }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
  440. res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
  441. cleanCodeSession();
  442. return res;
  443. }
  444. if (StringUtils.isBlank(newPwd)) {
  445. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  446. return res;
  447. }
  448. if (StringUtils.isBlank(mobile)) {
  449. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
  450. return res;
  451. }
  452. if (!UserType.ORGANIZATION.getCode().equals(type) && !UserType.PERSONAL.getCode().equals(type)) {
  453. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
  454. return res;
  455. }
  456. User user = userService.selectByMobieAndType(mobile, type);
  457. if (null == user) {
  458. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "mobile"));
  459. return res;
  460. }
  461. user.setPassword(newPwd);
  462. user.setPassword(passwordUtil.getEncryptPwd(user));
  463. userService.updateByPrimaryKeySelective(user);
  464. VerifyCodeUtils.clearResetCode();
  465. VerifyCodeUtils.clearResetCodeTime();
  466. return res;
  467. }
  468. private void cleanCodeSession() {
  469. VerifyCodeUtils.clearResetCode();
  470. VerifyCodeUtils.clearResetCodeTime();
  471. VerifyCodeUtils.clearMobileCode();
  472. VerifyCodeUtils.clearMobileCodeTime();
  473. }
  474. @RequestMapping(value = "/getRegisterMCode", method = RequestMethod.GET )
  475. @ResponseBody
  476. public Result getRegisterMCode(String mobile){
  477. Result res = new Result();
  478. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
  479. || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
  480. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  481. } else if (TimeUtils.checkOverTime("getMCode")) {
  482. VerifyCodeUtils.clearMobileCode();
  483. VerifyCodeUtils.clearMobileCodeTime();
  484. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  485. } else {
  486. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  487. }
  488. return res;
  489. }
  490. @RequestMapping(value = "/getResetMCode", method = RequestMethod.GET )
  491. @ResponseBody
  492. public Result getResetMCode(String mobile, Integer type) {
  493. Result res = new Result();
  494. if (null == userService.selectByMobieAndType(mobile.trim(), type)) {
  495. res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
  496. return res;
  497. }
  498. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == null
  499. || TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == "") {
  500. sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
  501. } else if (TimeUtils.checkOverTime("resetCode")) {
  502. VerifyCodeUtils.clearMobileCode();
  503. VerifyCodeUtils.clearMobileCodeTime();
  504. sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
  505. } else {
  506. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  507. }
  508. return res;
  509. }
  510. /** 省市区查询 **/
  511. @RequestMapping(value = "/listAllProvince" , method = RequestMethod.POST)
  512. @ResponseBody
  513. public Result listAllProvince(){
  514. Result res = new Result();
  515. res.setData(districtGlossoryService.getProvince());
  516. return res;
  517. }
  518. @RequestMapping(value = "/listDefaultPassword" , method = RequestMethod.GET)
  519. @ResponseBody
  520. public Result listDefaultPassword(String depId){
  521. Result res=new Result();
  522. res.setData(adminService.getListDefaultPassword(depId));
  523. return res;
  524. }
  525. /** 省市区查询 **/
  526. @RequestMapping(value = "/sendWeb" , method = RequestMethod.POST)
  527. @ResponseBody
  528. public Result sendWeb(String str){
  529. Result res = new Result();
  530. SystemWebSocketHandler sys=new SystemWebSocketHandler();
  531. TextMessage text=new TextMessage(str.getBytes());
  532. sys.sendMessageToUsers(text);
  533. res.setData(1);
  534. return res;
  535. }
  536. /**
  537. * 导入流水
  538. * @param file
  539. * @param request
  540. * @return
  541. */
  542. @SuppressWarnings("unchecked")
  543. @RequestMapping(value = "/import" , method = RequestMethod.POST)
  544. @ResponseBody
  545. public Result importTeacher(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request) {
  546. Result res=new Result();
  547. String fileName = file.getOriginalFilename();
  548. if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
  549. res.error(new Error("", "格式不正确"));
  550. }
  551. //检查文件
  552. try {
  553. checkFile(file);
  554. } catch (IOException e) {
  555. e.printStackTrace();
  556. }
  557. //获得Workbook工作薄对象
  558. Workbook workbook = getWorkBook(file);
  559. //创建返回对象,把每行中的值作为一个数组,所有行作为一个集合返回
  560. List<List<String>> list = new ArrayList<>();
  561. if(workbook != null){
  562. for(int sheetNum = 0;sheetNum < workbook.getNumberOfSheets();sheetNum++){
  563. //获得当前sheet工作表
  564. Sheet sheet = workbook.getSheetAt(sheetNum);
  565. if(sheet == null){
  566. continue;
  567. }
  568. //获得当前sheet的开始行
  569. int firstRowNum = sheet.getFirstRowNum();
  570. //获得当前sheet的结束行
  571. int lastRowNum = sheet.getLastRowNum();
  572. //循环除了第2行的所有行
  573. for(int rowNum = firstRowNum+2;rowNum <= lastRowNum;rowNum++){
  574. //获得当前行
  575. Row row = sheet.getRow(rowNum);
  576. if(row == null){
  577. continue;
  578. }
  579. //获得当前行的开始列
  580. int firstCellNum = row.getFirstCellNum();
  581. //获得当前行的列数
  582. int lastCellNum = row.getLastCellNum();
  583. @SuppressWarnings("rawtypes")
  584. ArrayList arrayList = new ArrayList();
  585. //循环当前行 cellNum = (firstCellNum+1) 则是除开第一例
  586. for(int cellNum = (firstCellNum); cellNum < lastCellNum;cellNum++){
  587. Cell cell = row.getCell(cellNum);
  588. arrayList.add(getCellValue(cell));
  589. }
  590. list.add(arrayList);
  591. }
  592. }
  593. }
  594. return res;
  595. }
  596. public static void checkFile(MultipartFile file) throws IOException{
  597. //判断文件是否存在
  598. if(null == file){
  599. throw new FileNotFoundException("文件不存在!");
  600. }
  601. //获得文件名
  602. String fileName = file.getOriginalFilename();
  603. //判断文件是否是excel文件
  604. if(!fileName.endsWith("xls") && !fileName.endsWith("xlsx")){
  605. throw new IOException(fileName + "不是excel文件");
  606. }
  607. }
  608. public static Workbook getWorkBook(MultipartFile file) {
  609. //创建Workbook工作薄对象,表示整个excel
  610. Workbook workbook = null;
  611. try {
  612. //获取excel文件的io流
  613. InputStream is = file.getInputStream();
  614. //如果是xls,使用HSSFWorkbook;如果是xlsx,使用XSSFWorkbook
  615. workbook = new XSSFWorkbook(is);
  616. } catch (IOException e) {
  617. }
  618. return workbook;
  619. }
  620. @SuppressWarnings("deprecation")
  621. public static String getCellValue(Cell cell){
  622. String cellValue = "";
  623. if(cell == null){
  624. return cellValue;
  625. }
  626. //把数字当成String来读,避免出现1读成1.0的情况
  627. if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
  628. cell.setCellType(Cell.CELL_TYPE_STRING);
  629. }
  630. //判断数据的类型
  631. switch (cell.getCellType()){
  632. case Cell.CELL_TYPE_NUMERIC: //数字
  633. cellValue = String.valueOf(cell.getNumericCellValue());
  634. break;
  635. case Cell.CELL_TYPE_STRING: //字符串
  636. cellValue = String.valueOf(cell.getStringCellValue());
  637. break;
  638. case Cell.CELL_TYPE_BOOLEAN: //Boolean
  639. cellValue = String.valueOf(cell.getBooleanCellValue());
  640. break;
  641. case Cell.CELL_TYPE_FORMULA: //公式
  642. cellValue = String.valueOf(cell.getCellFormula());
  643. break;
  644. case Cell.CELL_TYPE_BLANK: //空值
  645. cellValue = "未知";
  646. break;
  647. case Cell.CELL_TYPE_ERROR: //故障
  648. cellValue = "非法字符";
  649. break;
  650. default:
  651. cellValue = "未知类型";
  652. break;
  653. }
  654. return cellValue;
  655. }
  656. /**
  657. * 通用下载请求
  658. *
  659. * @param fileName 文件名称
  660. * @param delete 是否删除
  661. */
  662. @RequestMapping("/download")
  663. public void fileDownload(String fileName, Boolean delete,String attName,
  664. HttpServletResponse response, HttpServletRequest request)
  665. {
  666. try
  667. {
  668. if (!FileUtils.checkAllowDownload(fileName))
  669. {
  670. throw new Exception("文件名称非法,不允许下载。 ");
  671. }
  672. String realFileName =DateUtils.parseDateToStr(AFTConstants.YYYYMMDDHHMMSS, new Date())+fileName.substring(fileName.indexOf("_") + 1);
  673. String filePath = uploadPath +"/"+ fileName;
  674. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  675. FileUtils.setAttachmentResponseHeader(response, realFileName,attName);
  676. FileUtils.writeBytes(filePath, response.getOutputStream());
  677. if(delete==null)delete=true;
  678. if (delete)
  679. {
  680. FileUtils.deleteFile(filePath);
  681. }
  682. }
  683. catch (Exception e)
  684. {
  685. LoggerUtils.error(PublicController.class,"下载文件失败", e);
  686. }
  687. }
  688. @RequestMapping("/getWxConfig")
  689. public Result getWxConfig() {
  690. Result res =new Result();
  691. Map<String, Object> config=new HashedMap<String, Object>();
  692. config.put("clockInRange", clockInRange);
  693. res.data(config);
  694. return res;
  695. }
  696. @RequestMapping("/getUser")
  697. public Result getUser() {
  698. List<OutUser> list=userService.getuser();
  699. NewExcelUtil<OutUser> excel=new NewExcelUtil<OutUser>(OutUser.class);
  700. return excel.exportExcel(list, "客户列表",uploadPath);
  701. }
  702. @RequestMapping("/pushOrderMid")
  703. public Result pushOrderMid() {
  704. List<TOrderMid> list = tOrderMidMapper.selectAll();
  705. for (TOrderMid mid : list) {
  706. tOrderMidMapper.updateCostAmount(mid.getOrderNo());
  707. orderProjectService.updateMidServiceProject(mid.getOrderNo());
  708. }
  709. return new Result().data(1);
  710. }
  711. }