HomeController.java 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  1. package platform.modules.home;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.aliyuncs.exceptions.ClientException;
  4. import com.xiaoleilu.hutool.crypto.SecureUtil;
  5. import org.apache.commons.collections.CollectionUtils;
  6. import org.apache.commons.lang3.StringEscapeUtils;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.apache.shiro.authc.*;
  9. import org.apache.shiro.subject.Subject;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
  14. import org.springframework.stereotype.Controller;
  15. import org.springframework.ui.ModelMap;
  16. import org.springframework.web.bind.annotation.*;
  17. import platform.common.Constant;
  18. import platform.common.annotation.OperationLog;
  19. import platform.common.base.controller.BaseController;
  20. import platform.common.base.model.DictionaryItem;
  21. import platform.common.base.service.DictionaryItemService;
  22. import platform.common.exception.BaseException;
  23. import platform.common.util.*;
  24. import platform.modules.api.dto.SyncUserDto;
  25. import platform.modules.api.service.SkyImageApiService;
  26. import platform.modules.build.DTO.HomeSlideDto;
  27. import platform.modules.build.entity.Company;
  28. import platform.modules.build.entity.CompanyContact;
  29. import platform.modules.build.entity.CompanyMaterial;
  30. import platform.modules.build.service.BuildInfoService;
  31. import platform.modules.build.service.CompanyContactService;
  32. import platform.modules.build.service.CompanyMaterialService;
  33. import platform.modules.build.service.CompanyService;
  34. import platform.modules.carrier.entity.Building;
  35. import platform.modules.carrier.service.BuildingService;
  36. import platform.modules.carrier.service.ParkService;
  37. import platform.modules.company.service.CompanyInfoManageService;
  38. import platform.modules.company.service.ProjectApplicationService;
  39. import platform.modules.company.service.StockLandService;
  40. import platform.modules.government.dao.AttachmentDao;
  41. import platform.modules.government.dto.ParamRegistration;
  42. import platform.modules.government.entity.*;
  43. import platform.modules.government.service.*;
  44. import platform.modules.home.request.FindRequest;
  45. import platform.modules.home.response.FindResponse;
  46. import platform.modules.home.response.FindResponseProject;
  47. import platform.modules.home.response.ListResponse;
  48. import platform.modules.home.service.WxMicroappService;
  49. import platform.modules.sys.entity.ActivityDetail;
  50. import platform.modules.sys.entity.ActivityFavourite;
  51. import platform.modules.sys.entity.ActivityRegistration;
  52. import platform.modules.sys.entity.Approval;
  53. import platform.modules.sys.entity.Group;
  54. import platform.modules.sys.entity.UserGroup;
  55. import platform.modules.sys.service.ActivityFavouriteService;
  56. import platform.modules.sys.service.ActivityRegistrationService;
  57. import platform.modules.sys.service.ActivityService;
  58. import platform.modules.sys.service.ApprovalService;
  59. import platform.modules.sys.service.*;
  60. import platform.modules.sys.shiro.UsernamePasswordToken;
  61. import platform.modules.sys.web.ResponseMessage;
  62. import sun.misc.BASE64Decoder;
  63. import javax.annotation.Resource;
  64. import javax.servlet.http.HttpServletRequest;
  65. import javax.servlet.http.HttpServletResponse;
  66. import javax.servlet.http.HttpSession;
  67. import java.io.BufferedInputStream;
  68. import java.io.File;
  69. import java.io.FileInputStream;
  70. import java.io.OutputStream;
  71. import java.util.*;
  72. import static platform.common.Constant.HEAD_SESSION_STATUS_KEY;
  73. import static platform.common.Constant.HEAD_SESSION_STATUS_VALUE;
  74. @Controller
  75. @RequestMapping(value = "/home")
  76. public class HomeController extends BaseController {
  77. private static String profiles;
  78. @Value("${spring.profiles}")
  79. public void setProfiles(String param) {
  80. this.profiles = param;
  81. }
  82. @Autowired
  83. private ContentService contentService;
  84. @Autowired
  85. private CompanyService companyService;
  86. @Autowired
  87. private NavigationService navigationService;
  88. @Autowired
  89. private SlidesService slidesService;
  90. @Autowired
  91. private FriendLinkService friendLinkService;
  92. @Autowired
  93. private LogoService logoService;
  94. @Autowired
  95. private AttachmentService attachmentService;
  96. @Autowired
  97. private BuildInfoService buildInfoService;
  98. @Autowired
  99. StreetService streetService;
  100. @Autowired
  101. DictionaryItemService dictionaryItemService;
  102. @Autowired
  103. CompanyInfoManageService companyInfoManageService;
  104. @Autowired
  105. CompanyContactService companyContactService;
  106. @Autowired
  107. StockLandService stockLandService;
  108. @Autowired
  109. ApprovalService approvalService;
  110. @Autowired
  111. UserService userService;
  112. @Autowired
  113. private ActivityService activityService;
  114. @Autowired
  115. private ActivityFavouriteService activityFavouriteService;
  116. @Autowired
  117. private ActivityRegistrationService activityRegistrationService;
  118. @Autowired
  119. private ProjectDeclarationService projectDeclarationService;
  120. @Autowired
  121. private ProjectApplicationService projectApplicationService;
  122. @Autowired
  123. private ProjectFillingDeclarationService projectFillingDeclarationService;
  124. @Resource
  125. private AttachmentDao attachmentDao;
  126. @Autowired
  127. private CompanyMaterialService companyMaterialService;
  128. @Autowired
  129. private VerificationCodeUtil verificationCodeUtil;
  130. @Autowired
  131. private WaitToDoService waitToDoService;
  132. @Autowired
  133. private StatisticsService statisticsService;
  134. @Autowired
  135. private ProjectProvincesDeclarationService projectProvincesDeclarationService;
  136. @Autowired
  137. private ProjectServiceTypeService projectServiceTypeService;
  138. @Autowired
  139. private ProjectIntelligentDeclarationService projectIntelligentDeclarationService;
  140. @Autowired
  141. private SkyImageApiService skyImageApiService;
  142. @Autowired
  143. private ParkService parkService;
  144. @Autowired
  145. private BuildingService buildingService;
  146. @Autowired
  147. private WxMicroappService wxMicroappService;
  148. // @GetMapping(value = "")
  149. // public String homePage(ModelMap modelMap) throws Exception {
  150. // //获取幻灯片
  151. // List<HomeSlideDto> slideDtoList = slidesService.showHomeSlides();
  152. //
  153. // modelMap.put("slideDtoList", slideDtoList);
  154. // // 获取导航
  155. // List<Navigation> navigations = navigationService.findContents();
  156. // modelMap.put("navigations", navigations);
  157. // this.commonObject(modelMap, false);
  158. // modelMap.put("buildCount", buildInfoService.countAllBuild());
  159. // modelMap.put("companyCount", companyService.countAllCompany());
  160. // modelMap.put("contentCount", contentService.countContent());
  161. // modelMap.put("contentServices", contentService.findContentsByNavigationId());
  162. //
  163. // //服务联盟
  164. // Navigation nav = navigationService.findByName(Constant.Navigation_Name.SERVICE);
  165. // FindRequest request = new FindRequest();
  166. // request.setId(nav.getId());
  167. // modelMap.put("servicesCount", contentService.findContentsCount(request));
  168. // //专题活动
  169. // modelMap.put("activityCount", activityService.getAllActivityCount());
  170. // //项目申报
  171. // modelMap.put("projectCount", projectApplicationService.getPassedProjectTotalNum());
  172. // return BASE_HOME_PATH + "html/home";
  173. // }
  174. @GetMapping(value = "")
  175. public String homePage() {
  176. // LocalStorage.removeItem("INDUSTRIAL_CARRIER");
  177. return "redirect:/index";
  178. }
  179. @GetMapping(value = "/informList/{id}")
  180. public String informList(@PathVariable Integer id, ModelMap modelMap) throws Exception {
  181. try {
  182. // 获取导航
  183. modelMap.put("navigation_id", id);
  184. modelMap.put("navigation_name", navigationService.getName(id));
  185. this.commonObject(modelMap, true);
  186. } catch (Exception e) {
  187. e.printStackTrace();
  188. }
  189. String navigationName = navigationService.getName(id);
  190. if (navigationName.equals(Constant.Navigation_Name.POLICY)) {
  191. return BASE_HOME_PATH + "html/policy/policyIndex";
  192. }
  193. return BASE_HOME_PATH + "html/contents";
  194. }
  195. @GetMapping(value = "/unionCompany")
  196. public String unionCompany(ModelMap modelMap) throws Exception {
  197. Navigation navigation = navigationService.findById(2);
  198. if (null != navigation) {
  199. List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.DH, navigation.getId(), null);
  200. if (null != attachments && attachments.size() > 0) {
  201. FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(), attachments.get(0).getDownload_uri());
  202. navigation.setFileDown(fileDown);
  203. }
  204. }
  205. modelMap.put("navigation", navigation);
  206. modelMap.put("contentServices", contentService.findContentsByNavigationId());
  207. this.commonObject(modelMap, true);
  208. return BASE_HOME_PATH + "html/unionCompany";
  209. }
  210. @PostMapping(value = "/contentList")
  211. @ResponseBody
  212. public ResponseMessage findContents(FindRequest request) throws Exception {
  213. FindResponse response = new FindResponse();
  214. try {
  215. response = contentService.findContents(request);
  216. } catch (Exception e) {
  217. e.printStackTrace();
  218. }
  219. return ResponseMessage.success("查询成功", response);
  220. }
  221. @PostMapping(value = "/activityList")
  222. @ResponseBody
  223. public ResponseMessage findActivity(FindRequest request) throws Exception {
  224. ListResponse response = new ListResponse();
  225. response.setFile_url(setFileUrl());
  226. try {
  227. response = activityService.findContents(request);
  228. List<DictionaryItem> activityTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.ACTIVITY_TYPE);
  229. response.setTypeList(activityTypeList);
  230. } catch (Exception e) {
  231. e.printStackTrace();
  232. }
  233. return ResponseMessage.success("查询成功", response);
  234. }
  235. @PostMapping(value = "/projectList")
  236. @ResponseBody
  237. public ResponseMessage findProject(FindRequest request) {
  238. FindResponseProject response = new FindResponseProject();
  239. try {
  240. response = projectDeclarationService.findProejctsOnHome(request);
  241. List<DictionaryItem> projectSourceList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.PROJECT_SOURCE);
  242. List<DictionaryItem> projectStatusList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.PROJECT_STATUS);
  243. response.setProjectSourceList(projectSourceList);
  244. response.setProjectStatusList(projectStatusList);
  245. } catch (Exception e) {
  246. e.printStackTrace();
  247. }
  248. return ResponseMessage.success("查询成功", response);
  249. }
  250. @GetMapping(value = "/logout")
  251. public String logout(ModelMap modelMap) throws Exception {
  252. ShiroUtils.logout();
  253. this.commonObject(modelMap, true);
  254. return "redirect:/" + BASE_HOME_PATH;
  255. }
  256. /**
  257. * 跳转到内容查看页面
  258. *
  259. * @return
  260. */
  261. @GetMapping(value = "/contentDetail/{id}")
  262. public String check(@PathVariable("id") int id, ModelMap modelMap) throws Exception {
  263. log.info("跳转到内容查看页面!id = {}", id);
  264. Content content = contentService.findById(id);
  265. if (null == content) {
  266. modelMap.put("status", FAILURE);
  267. modelMap.put("message", "内容不存在!");
  268. return BASE_HOME_PATH + "html/informAnnouncement";
  269. }
  270. if (null == content.getBrowse_count()) {
  271. content.setBrowse_count(0);
  272. }
  273. List<Attachment> files = attachmentService.selectByIdAndBusinessId(Constant.Attachment.CONTENT_FILE, content.getId(), null);
  274. if (null != files && files.size() > 0) {
  275. FileDown fileDown = new FileDown(files.get(0).getId(), files.get(0).getFile_name(), files.get(0).getFile_url(), files.get(0).getDownload_uri());
  276. content.setAddFileDown(fileDown);
  277. }
  278. content.setContent(StringEscapeUtils.unescapeHtml4(content.getContent()));
  279. //更新数量
  280. content.setBrowse_count(content.getBrowse_count() + 1);
  281. contentService.updateSelective(content);
  282. modelMap.put("content", content);
  283. // 获取导航
  284. modelMap.put("navigation_id", content.getNavigation_id());
  285. modelMap.put("navigation_name", navigationService.getName(content.getNavigation_id()));
  286. modelMap.addAttribute("navigationList", navigationService.findList());
  287. this.commonObject(modelMap, true);
  288. return BASE_HOME_PATH + "html/contentDetail";
  289. }
  290. /**
  291. * 跳转到内容查看页面
  292. *
  293. * @return
  294. */
  295. @GetMapping(value = "/activityDetail/{id}")
  296. public String activityDetail(@PathVariable("id") int id, ModelMap modelMap) throws Exception {
  297. log.info("跳转到内容查看页面!id = {}", id);
  298. ActivityDetail activityDetail = activityService.findOne(id + "");
  299. Content content = new Content();
  300. content.setTitle("");
  301. content.setCreate_time("");
  302. content.setBrowse_count(0);
  303. content.setResource("");
  304. content.setCreate_name("");
  305. if (!Objects.equals(activityDetail, null)) {
  306. content.setContent(activityDetail.getContent());
  307. }
  308. content.setTitle(id + "");
  309. modelMap.put("content", content);
  310. modelMap.addAttribute("activity", activityDetail);
  311. // 获取导航
  312. modelMap.put("navigation_id", 1);
  313. modelMap.put("navigation_name", navigationService.getName(1));
  314. modelMap.addAttribute("navigationList", navigationService.findList());
  315. this.commonObject(modelMap, true);
  316. return BASE_HOME_PATH + "html/contentDetail";
  317. }
  318. /**
  319. * 跳转到活动日历
  320. *
  321. * @return
  322. */
  323. @GetMapping(value = "/calendar")
  324. public String activityCalendar(ModelMap modelMap) throws Exception {
  325. log.info("跳转到活动日历");
  326. Content content = new Content();
  327. content.setTitle("");
  328. content.setCreate_time("");
  329. content.setBrowse_count(0);
  330. content.setResource("");
  331. content.setCreate_name("");
  332. modelMap.put("content", content);
  333. // 获取导航
  334. modelMap.put("navigation_id", 1);
  335. modelMap.put("navigation_name", navigationService.getName(1));
  336. modelMap.addAttribute("navigationList", navigationService.findList());
  337. this.commonObject(modelMap, true);
  338. return BASE_HOME_PATH + "html/calendar";
  339. }
  340. /**
  341. * 跳转到内容查看页面
  342. *
  343. * @return
  344. */
  345. @ResponseBody
  346. @GetMapping(value = "/activityDetails/{id}")
  347. public ResponseMessage getActivityDetail(@PathVariable("id") int id, ModelMap modelMap) throws Exception {
  348. log.info("跳转到内容查看页面!id = {}", id);
  349. ActivityDetail activityDetail = activityService.findOne(id + "");
  350. activityService.increment(id + "");
  351. List<ActivityRegistration> registrationList = activityRegistrationService.findRegistrationList(id);
  352. int num = 0;
  353. String quota = activityDetail.getActivity_quota();
  354. if (StringUtils.isBlank(quota)) quota = "0";
  355. for (ActivityRegistration activityRegistration : registrationList) {
  356. if (Objects.equals(activityRegistration.getReview_state(), "1")) {
  357. num++;
  358. }
  359. }
  360. int remain = Integer.parseInt(quota) - num;
  361. if (remain < 0) {
  362. remain = 0;
  363. }
  364. activityDetail.setActivity_remain(remain + "");
  365. List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.ACTIVITY, activityDetail.getId(), null);
  366. if (null != attachments && attachments.size() > 0) {
  367. FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(), attachments.get(0).getDownload_uri());
  368. activityDetail.setFileDown(fileDown);
  369. }
  370. return ResponseMessage.success("查询成功!", activityDetail);
  371. }
  372. /**
  373. * 获取已报名的用户
  374. *
  375. * @return
  376. */
  377. @ResponseBody
  378. @GetMapping(value = "/getRegUsers")
  379. public ResponseMessage getRegUsers(@RequestParam("activity_id") String activity_id, ModelMap modelMap) throws Exception {
  380. log.info("获取已报名的用户!");
  381. return ResponseMessage.success("查询成功!", activityRegistrationService.getCurrRegUsers(activity_id));
  382. }
  383. /**
  384. * 查询是否收藏
  385. *
  386. * @return
  387. */
  388. @ResponseBody
  389. @GetMapping(value = "/isFavourite/{id}")
  390. public ResponseMessage isFavourite(@PathVariable("id") int id, ModelMap modelMap) throws Exception {
  391. log.info("查询是否收藏!id = {}", id);
  392. if (!ShiroUtils.isLogin()) return ResponseMessage.success("请先登录!", 2);
  393. ActivityFavourite activityFavourite = activityFavouriteService.selectByActivityIdAndUserId(id + "", ShiroUtils.getUserId() + "");
  394. if (Objects.equals(activityFavourite, null)) return ResponseMessage.success("查询成功!", 1);
  395. return ResponseMessage.success("查询成功!", 0);
  396. }
  397. /**
  398. * 添加收藏
  399. *
  400. * @return
  401. */
  402. @OperationLog(value = "收藏活动")
  403. @ResponseBody
  404. @GetMapping(value = "/addFavourite/{id}")
  405. public ResponseMessage addFavourite(@PathVariable("id") int id, ModelMap modelMap) throws Exception {
  406. log.info("查询是否收藏!id = {}", id);
  407. if (!ShiroUtils.isLogin()) return ResponseMessage.success("请先登录!", 2);
  408. ActivityFavourite activityFavourite = new ActivityFavourite();
  409. activityFavourite.setActivity_id(id);
  410. int count = activityFavouriteService.saveActivityFavourite(activityFavourite);
  411. if (count > 0) return ResponseMessage.success("收藏成功!");
  412. return ResponseMessage.success("收藏失败!");
  413. }
  414. /**
  415. * 取消收藏
  416. *
  417. * @return
  418. */
  419. @OperationLog(value = "取消收藏活动")
  420. @ResponseBody
  421. @GetMapping(value = "/removeFavourite/{id}")
  422. public ResponseMessage removeFavourite(@PathVariable("id") int id, ModelMap modelMap) throws Exception {
  423. log.info("查询是否收藏!id = {}", id);
  424. boolean b = activityFavouriteService.deleteByActivityIdAndUserId(id + "", ShiroUtils.getUserId() + "");
  425. if (b) return ResponseMessage.success("取消收藏成功!");
  426. return ResponseMessage.success("取消收藏失败!");
  427. }
  428. /**
  429. * 检查是否登录
  430. *
  431. * @return
  432. */
  433. @ResponseBody
  434. @GetMapping(value = "/checkLogin")
  435. public ResponseMessage checkLogin(ModelMap modelMap) throws Exception {
  436. log.info("检查是否登录");
  437. if (!ShiroUtils.isLogin()) {
  438. modelMap.put("isLogin", false);
  439. return ResponseMessage.success("请先登录!", false);
  440. }
  441. modelMap.put("isLogin", true);
  442. modelMap.put("userType", ShiroUtils.getUserType());
  443. modelMap.put("userName", ShiroUtils.getNickName());
  444. return ResponseMessage.success("", modelMap);
  445. }
  446. /**
  447. * 活动报名
  448. *
  449. * @return
  450. */
  451. @OperationLog(value = "报名活动")
  452. @PostMapping(value = "/joinActivity")
  453. @ResponseBody
  454. public ResponseMessage joinActivity(@RequestBody ParamRegistration paramRegistration) throws Exception {
  455. log.info("活动报名");
  456. Integer id = paramRegistration.getRegistrationList().get(0).getActivity_id();
  457. Integer userId = paramRegistration.getRegistrationList().get(0).getUser_id();
  458. ActivityDetail activityDetail = activityService.findById(id);
  459. String quota = activityDetail.getActivity_quota();
  460. String isReview = activityDetail.getIs_review();
  461. int registrationNumber = 0;
  462. if (!Objects.equals(quota, null) && !Objects.equals(quota, "")) {
  463. //名额有限
  464. if (Objects.equals(isReview, "1")) {
  465. //需要审核
  466. //已报名人数
  467. registrationNumber = activityRegistrationService.getActivityRegistrationNumber(id);
  468. if (registrationNumber >= Integer.parseInt(quota)) {
  469. return ResponseMessage.success("名额不足,仅剩" + (Integer.parseInt(quota) - registrationNumber) + "个名额,请修改人数!", false);
  470. }
  471. }
  472. }
  473. List<ActivityRegistration> registrationList = paramRegistration.getRegistrationList();
  474. if (!CollectionUtils.isEmpty(registrationList)) {
  475. activityRegistrationService.deleteOldCancelRegist(String.valueOf(id), null, String.valueOf(userId));
  476. for (ActivityRegistration registration : registrationList) {
  477. if (registration.getId() == null) {
  478. activityRegistrationService.saveActivityRegistration(registration);
  479. }
  480. }
  481. List<User> pusers = userService.findUsersByPermission("G_ACTIVITY_MANAGE");
  482. waitToDoService.completeAllTODO(activityDetail.getId(), Constant.DictionaryType.ACTIVITY_APPLICATION);
  483. for (User puser : pusers) {
  484. waitToDoService.newTODO(activityDetail.getActivity_title() + "审核", "/government/activity/review/" + activityDetail.getId(), Constant.WaitToDo_OperType.AUDIT, activityDetail.getId(),
  485. Constant.DictionaryType.ACTIVITY_APPLICATION, null, puser.getId().toString(), Constant.WaitToDo_IsSerial.IS_SERIAL, false);
  486. }
  487. }
  488. if (!Objects.equals(quota, null) && !Objects.equals(quota, "")) {
  489. //名额有限
  490. if (Objects.equals(isReview, "1")) {
  491. //需要审核
  492. //已报名人数
  493. registrationNumber = activityRegistrationService.getActivityRegistrationNumber(id);
  494. return ResponseMessage.success("报名成功,剩余" + (Integer.parseInt(quota) - registrationNumber) + "个名额!", true);
  495. }
  496. }
  497. return ResponseMessage.success("报名成功!", true);
  498. }
  499. /*********************项目申报*************************/
  500. /**
  501. * 跳转到项目申报查看页面
  502. *
  503. * @return
  504. */
  505. @GetMapping(value = "/projectDetail/{id}/{isFilling}")
  506. public String checkProject(@PathVariable("id") int id, @PathVariable("isFilling") int isFilling, ModelMap modelMap) throws Exception {
  507. log.info("跳转到项目申报查看页面!id = {}", id);
  508. //获取导航
  509. Navigation nav = navigationService.findByName(Constant.Navigation_Name.PROJECT);
  510. modelMap.put("navigation_id", nav.getId());
  511. modelMap.put("navigation_name", nav.getName());
  512. modelMap.addAttribute("navigationList", navigationService.findList());
  513. this.commonObject(modelMap, true);
  514. if (isFilling == 0) {
  515. //项目申报
  516. ProjectDeclaration project = projectDeclarationService.selectById(String.valueOf(id));
  517. if (null == project) {
  518. modelMap.put("status", FAILURE);
  519. modelMap.put("message", "内容不存在!");
  520. return BASE_HOME_PATH + "html/informAnnouncement";
  521. }
  522. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, project.getProject_source());
  523. project.setProject_source_name(sourceName);
  524. project.setProject_content(StringEscapeUtils.unescapeHtml4(project.getProject_content()));
  525. if (null == project.getBrowse_count()) {
  526. project.setBrowse_count(0);
  527. }
  528. //更新数量
  529. project.setBrowse_count(project.getBrowse_count() + 1);
  530. projectDeclarationService.updateSelective(project);
  531. modelMap.put("content", project);
  532. return BASE_HOME_PATH + "html/projectDetail";
  533. } else if (isFilling == 2) {
  534. modelMap.put("navigation_id", 77);
  535. modelMap.put("navigation_name", "报表填报");
  536. //项目填报内申报
  537. ProjectFillingDeclaration project = projectFillingDeclarationService.selectById(String.valueOf(id));
  538. if (null == project) {
  539. modelMap.put("status", FAILURE);
  540. modelMap.put("message", "内容不存在!");
  541. return BASE_HOME_PATH + "html/informAnnouncement";
  542. }
  543. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, project.getProject_source());
  544. project.setProject_source_name(sourceName);
  545. project.setProject_content(StringEscapeUtils.unescapeHtml4(project.getProject_content()));
  546. if (null == project.getBrowse_count()) {
  547. project.setBrowse_count(0);
  548. }
  549. //更新数量
  550. project.setBrowse_count(project.getBrowse_count() + 1);
  551. projectFillingDeclarationService.updateSelective(project);
  552. modelMap.put("content", project);
  553. return BASE_HOME_PATH + "html/projectFillingDetail";
  554. } else if (isFilling == 1) {
  555. ProjectProvincesDeclaration provinces = projectProvincesDeclarationService.selectById(String.valueOf(id));
  556. if (null == provinces) {
  557. modelMap.put("status", FAILURE);
  558. modelMap.put("message", "内容不存在!");
  559. return BASE_HOME_PATH + "html/informAnnouncement";
  560. }
  561. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, provinces.getProject_source());
  562. provinces.setProject_source_name(sourceName);
  563. provinces.setContent(StringEscapeUtils.unescapeHtml4(provinces.getContent()));
  564. if (null == provinces.getBrowse_count()) {
  565. provinces.setBrowse_count(0);
  566. }
  567. //更新数量
  568. provinces.setBrowse_count(provinces.getBrowse_count() + 1);
  569. projectProvincesDeclarationService.updateSelective(provinces);
  570. modelMap.put("content", provinces);
  571. return BASE_HOME_PATH + "html/projectProvincesDetail";
  572. } else {
  573. ProjectIntelligentDeclaration intelligentDeclaration = projectIntelligentDeclarationService.selectById(String.valueOf(id));
  574. if (null == intelligentDeclaration) {
  575. modelMap.put("status", FAILURE);
  576. modelMap.put("message", "内容不存在!");
  577. return BASE_HOME_PATH + "html/informAnnouncement";
  578. }
  579. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, intelligentDeclaration.getProject_source());
  580. intelligentDeclaration.setProject_source_name(sourceName);
  581. intelligentDeclaration.setContent(StringEscapeUtils.unescapeHtml4(intelligentDeclaration.getContent()));
  582. if (null == intelligentDeclaration.getBrowse_count()) {
  583. intelligentDeclaration.setBrowse_count(0);
  584. }
  585. //更新数量
  586. intelligentDeclaration.setBrowse_count(intelligentDeclaration.getBrowse_count() + 1);
  587. projectIntelligentDeclarationService.updateSelective(intelligentDeclaration);
  588. modelMap.put("content", intelligentDeclaration);
  589. return BASE_HOME_PATH + "html/projectIntelligentDetail";
  590. }
  591. }
  592. @GetMapping(value = "/ajax/projectDetail/{id}/{isFilling}")
  593. @ResponseBody
  594. public ResponseMessage checkProjectAjax(@PathVariable("id") int id, @PathVariable("isFilling") int isFilling, ModelMap modelMap) throws Exception {
  595. log.info("跳转到项目申报查看页面!id = {}", id);
  596. //获取导航
  597. Navigation nav = navigationService.findByName(Constant.Navigation_Name.PROJECT);
  598. modelMap.put("navigation_id", nav.getId());
  599. modelMap.put("navigation_name", nav.getName());
  600. modelMap.addAttribute("navigationList", navigationService.findList());
  601. this.commonObject(modelMap, true);
  602. if (isFilling == 0) {
  603. //项目申报
  604. ProjectDeclaration project = projectDeclarationService.selectById(String.valueOf(id));
  605. if (null == project) {
  606. modelMap.put("status", FAILURE);
  607. modelMap.put("message", "内容不存在!");
  608. return ResponseMessage.success("success", modelMap);
  609. }
  610. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, project.getProject_source());
  611. project.setProject_source_name(sourceName);
  612. project.setProject_content(StringEscapeUtils.unescapeHtml4(project.getProject_content()));
  613. if (null == project.getBrowse_count()) {
  614. project.setBrowse_count(0);
  615. }
  616. //更新数量
  617. project.setBrowse_count(project.getBrowse_count() + 1);
  618. projectDeclarationService.updateSelective(project);
  619. modelMap.put("content", project);
  620. return ResponseMessage.success("success", modelMap);
  621. } else if (isFilling == 2) {
  622. modelMap.put("navigation_id", 77);
  623. modelMap.put("navigation_name", "报表填报");
  624. //项目填报内申报
  625. ProjectFillingDeclaration project = projectFillingDeclarationService.selectById(String.valueOf(id));
  626. if (null == project) {
  627. modelMap.put("status", FAILURE);
  628. modelMap.put("message", "内容不存在!");
  629. return ResponseMessage.success("success", modelMap);
  630. }
  631. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, project.getProject_source());
  632. project.setProject_source_name(sourceName);
  633. project.setProject_content(StringEscapeUtils.unescapeHtml4(project.getProject_content()));
  634. if (null == project.getBrowse_count()) {
  635. project.setBrowse_count(0);
  636. }
  637. //更新数量
  638. project.setBrowse_count(project.getBrowse_count() + 1);
  639. projectFillingDeclarationService.updateSelective(project);
  640. modelMap.put("content", project);
  641. return ResponseMessage.success("success", modelMap);
  642. } else if (isFilling == 1) {
  643. ProjectProvincesDeclaration provinces = projectProvincesDeclarationService.selectById(String.valueOf(id));
  644. if (null == provinces) {
  645. modelMap.put("status", FAILURE);
  646. modelMap.put("message", "内容不存在!");
  647. return ResponseMessage.success("success", modelMap);
  648. }
  649. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, provinces.getProject_source());
  650. provinces.setProject_source_name(sourceName);
  651. provinces.setContent(StringEscapeUtils.unescapeHtml4(provinces.getContent()));
  652. if (null == provinces.getBrowse_count()) {
  653. provinces.setBrowse_count(0);
  654. }
  655. //更新数量
  656. provinces.setBrowse_count(provinces.getBrowse_count() + 1);
  657. projectProvincesDeclarationService.updateSelective(provinces);
  658. modelMap.put("content", provinces);
  659. return ResponseMessage.success("success", modelMap);
  660. } else {
  661. ProjectIntelligentDeclaration intelligentDeclaration = projectIntelligentDeclarationService.selectById(String.valueOf(id));
  662. if (null == intelligentDeclaration) {
  663. modelMap.put("status", FAILURE);
  664. modelMap.put("message", "内容不存在!");
  665. return ResponseMessage.success("success", modelMap);
  666. }
  667. String sourceName = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, intelligentDeclaration.getProject_source());
  668. intelligentDeclaration.setProject_source_name(sourceName);
  669. intelligentDeclaration.setContent(StringEscapeUtils.unescapeHtml4(intelligentDeclaration.getContent()));
  670. if (null == intelligentDeclaration.getBrowse_count()) {
  671. intelligentDeclaration.setBrowse_count(0);
  672. }
  673. //更新数量
  674. intelligentDeclaration.setBrowse_count(intelligentDeclaration.getBrowse_count() + 1);
  675. projectIntelligentDeclarationService.updateSelective(intelligentDeclaration);
  676. modelMap.put("content", intelligentDeclaration);
  677. return ResponseMessage.success("success", modelMap);
  678. }
  679. }
  680. /*********************项目申报结束*************************/
  681. /**********************政策雷达***********************/
  682. @GetMapping(value = "/policyList")
  683. public String policyList(ModelMap modelMap) throws Exception {
  684. try {
  685. //TODO
  686. //int id=66;
  687. Navigation nav = navigationService.findByName(Constant.Navigation_Name.POLICY);
  688. // 获取导航
  689. modelMap.put("navigation_id", nav.getId());
  690. modelMap.put("navigation_name", nav.getName());
  691. this.commonObject(modelMap, true);
  692. } catch (Exception e) {
  693. e.printStackTrace();
  694. }
  695. return BASE_HOME_PATH + "html/policy/policyList";
  696. }
  697. @GetMapping(value = "/policyDetail")
  698. public String checkPolicy(ModelMap modelMap) throws Exception {
  699. //获取导航
  700. Navigation nav = navigationService.findByName(Constant.Navigation_Name.POLICY);
  701. modelMap.put("navigation_id", nav.getId());
  702. modelMap.put("navigation_name", nav.getName());
  703. modelMap.addAttribute("navigationList", navigationService.findList());
  704. this.commonObject(modelMap, true);
  705. return BASE_HOME_PATH + "html/policy/policyDetail";
  706. }
  707. @GetMapping(value = "/policySpecialDetail")
  708. public String checkSpecialPolicy(ModelMap modelMap) throws Exception {
  709. //log.info("跳转到政策内容查看页面!id = {}", id);
  710. //获取导航
  711. Navigation nav = navigationService.findByName(Constant.Navigation_Name.POLICY);
  712. modelMap.put("navigation_id", nav.getId());
  713. modelMap.put("navigation_name", nav.getName());
  714. modelMap.addAttribute("navigationList", navigationService.findList());
  715. this.commonObject(modelMap, true);
  716. return BASE_HOME_PATH + "html/policy/policySpecialDetail";
  717. }
  718. @GetMapping(value = "/policyQuestionList")
  719. public String policyQuestionList(ModelMap modelMap) throws Exception {
  720. try {
  721. //获取导航
  722. Navigation nav = navigationService.findByName(Constant.Navigation_Name.POLICY);
  723. modelMap.put("navigation_id", nav.getId());
  724. modelMap.put("navigation_name", nav.getName());
  725. this.commonObject(modelMap, true);
  726. } catch (Exception e) {
  727. e.printStackTrace();
  728. }
  729. return BASE_HOME_PATH + "html/policy/policyQuestionList";
  730. }
  731. @GetMapping(value = "/policySearchList")
  732. public String policySearchList(ModelMap modelMap) throws Exception {
  733. try {
  734. //获取导航
  735. Navigation nav = navigationService.findByName(Constant.Navigation_Name.POLICY);
  736. modelMap.put("navigation_id", nav.getId());
  737. modelMap.put("navigation_name", nav.getName());
  738. this.commonObject(modelMap, true);
  739. } catch (Exception e) {
  740. e.printStackTrace();
  741. }
  742. return BASE_HOME_PATH + "html/policy/policySearchList";
  743. }
  744. @GetMapping(value = "/policyQuestDetail")
  745. public String policyQuestDetail(ModelMap modelMap) throws Exception {
  746. //log.info("跳转到政策内容查看页面!id = {}", id);
  747. //获取导航
  748. Navigation nav = navigationService.findByName(Constant.Navigation_Name.POLICY);
  749. modelMap.put("navigation_id", nav.getId());
  750. modelMap.put("navigation_name", nav.getName());
  751. modelMap.addAttribute("navigationList", navigationService.findList());
  752. this.commonObject(modelMap, true);
  753. return BASE_HOME_PATH + "html/policy/policyQuestDetail";
  754. }
  755. /**********************政策雷达***********************/
  756. /**
  757. * 跳转到登录页面
  758. *
  759. * @return
  760. */
  761. @RequestMapping(value = "/login")
  762. public String toLogin(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
  763. log.info("跳转到登录页面!");
  764. //Ajax登录超时校验,如果超时,进行前台响应提示
  765. if (WebUtil.isAjaxRequest(request)) {
  766. response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  767. response.setHeader(HEAD_SESSION_STATUS_KEY, HEAD_SESSION_STATUS_VALUE);
  768. response.setContentType("text/html;charset=utf-8");
  769. }
  770. this.commonObject(modelMap, false);
  771. return BASE_HOME_PATH + "html/login";
  772. // return "/index";
  773. }
  774. /**
  775. * 用户登陆
  776. * 先根据用户名查询出一条用户记录再对比密码是否正确可以防止sql注入
  777. *
  778. * @param username 用户名
  779. * @param password 密码
  780. * @return
  781. */
  782. @OperationLog(value = "用户登录")
  783. @PostMapping(value = "/login")
  784. @ResponseBody
  785. public ResponseMessage login(HttpServletRequest request, String username, String password, Boolean isMobile) {
  786. try {
  787. //changeNewSession(request);
  788. BASE64Decoder decoder = new BASE64Decoder();
  789. username = new String(decoder.decodeBuffer(username), "UTF-8");
  790. password = new String(decoder.decodeBuffer(password), "UTF-8");
  791. //获取当前的Subject
  792. Subject currentUser = ShiroUtils.getSubject();
  793. UsernamePasswordToken token = new UsernamePasswordToken(username, password, isMobile, false);
  794. //在调用了login方法后,SecurityManager会收到AuthenticationToken,并将其发送给已配置的Realm执行必须的认证检查
  795. //每个Realm都能在必要时对提交的AuthenticationTokens作出反应
  796. //所以这一步在调用login(token)方法时,它会走到MyRealm.doGetAuthenticationInfo()方法中,具体验证方式详见此方法
  797. log.info("对用户进行登录验证..验证开始! username = {}", username);
  798. currentUser.login(token);
  799. //验证是否登录成功
  800. if (currentUser.isAuthenticated()) {
  801. log.info("对用户进行登录验证..验证通过! username = {}", username);
  802. ModelMap modelMap = new ModelMap();
  803. this.commonObject(modelMap, false);
  804. //获取token
  805. modelMap.put("token", userService.createToken());
  806. return ResponseMessage.success(Constant.USER_LOGIN_IN, modelMap);
  807. }
  808. } catch (UnknownAccountException e) { //账号不存在
  809. log.info("! username = {}", username);
  810. return ResponseMessage.error(Constant.USER_NOT_FIND);
  811. } catch (IncorrectCredentialsException e) {
  812. log.info("对用户进行登录验证..验证未通过,错误的凭证! username = {}", username);
  813. return ResponseMessage.error(Constant.USER_INVALID);
  814. } catch (LockedAccountException e) {
  815. log.info("对用户进行登录验证..验证未通过,账户已锁定! username = {}", username);
  816. return ResponseMessage.error(Constant.USER_HAS_REGISTERING);
  817. } catch (ExcessiveAttemptsException eae) {
  818. log.info("对用户进行登录验证..验证未通过,错误次数过多! username = {}", username);
  819. return ResponseMessage.error(Constant.USER_ERROR_MANY);
  820. } catch (AuthenticationException e) {
  821. return ResponseMessage.error(Constant.SYSTEM_ERRORS);
  822. } catch (Exception e) {
  823. log.error("对用户进行登录验证失败! username = {} e = {}", username, e);
  824. }
  825. return ResponseMessage.error(Constant.SYSTEM_ERRORS);
  826. }
  827. /**
  828. * 改变session
  829. *
  830. * @param request
  831. */
  832. private void changeNewSession(HttpServletRequest request) {
  833. if (request.getSession() != null) {
  834. //--------复制 session到临时变量
  835. HttpSession session = request.getSession();
  836. HashMap<String, Object> old = new HashMap<String, Object>();
  837. Enumeration keys = session.getAttributeNames();
  838. while (keys.hasMoreElements()) {
  839. String key = (String) keys.nextElement();
  840. old.put(key, session.getAttribute(key));
  841. session.removeAttribute(key);
  842. }
  843. session.invalidate();
  844. session = request.getSession(true);
  845. //-----------------复制session
  846. for (Iterator it = old.entrySet().iterator(); it.hasNext(); ) {
  847. Map.Entry entry = (Map.Entry) it.next();
  848. session.setAttribute((String) entry.getKey(), entry.getValue());
  849. }
  850. }
  851. }
  852. public void commonObject(ModelMap modelMap, Boolean isNav) throws Exception {
  853. Logo logo = logoService.findLogo();
  854. modelMap.put("fileUrl", setFileUrl());
  855. modelMap.put("logo", logo);
  856. modelMap.put("isLogin", ShiroUtils.isLogin());
  857. modelMap.put("userType", ShiroUtils.getUserType());
  858. modelMap.put("userName", ShiroUtils.getNickName());
  859. modelMap.put("userId", ShiroUtils.getUserId());
  860. User user = ShiroUtils.getUserEntity();
  861. if (user != null) {
  862. modelMap.put("firstLogin", user.getFist_login());
  863. if (StringUtils.isBlank(user.getUser_name()) || StringUtils.isBlank(user.getNick_name()) || StringUtils.isBlank(user.getPhone())) {
  864. modelMap.put("isComplete", false);
  865. } else {
  866. modelMap.put("isComplete", true);
  867. }
  868. }
  869. //获取有亲链接
  870. List<FriendLink> friendLinks = friendLinkService.findList();
  871. modelMap.put("friendLinks", friendLinks);
  872. if (isNav) {
  873. // 获取导航
  874. List<Navigation> navigations = navigationService.findList();
  875. modelMap.put("navigations", navigations);
  876. }
  877. }
  878. /**
  879. * 选择注册
  880. *
  881. * @param request
  882. * @param response
  883. * @param modelMap
  884. * @return
  885. * @throws Exception
  886. */
  887. @RequestMapping(value = "/chooseRegister")
  888. public String chooseRegister(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
  889. log.info("跳转到注册页面!");
  890. //Ajax登录超时校验,如果超时,进行前台响应提示
  891. if (WebUtil.isAjaxRequest(request)) {
  892. response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  893. response.setHeader(HEAD_SESSION_STATUS_KEY, HEAD_SESSION_STATUS_VALUE);
  894. response.setContentType("text/html;charset=utf-8");
  895. }
  896. this.commonObject(modelMap, false);
  897. return BASE_HOME_PATH + "html/choose_register";
  898. }
  899. /**
  900. * 个人注册
  901. *
  902. * @param request
  903. * @param response
  904. * @param modelMap
  905. * @return
  906. * @throws Exception
  907. */
  908. @RequestMapping(value = "/personal")
  909. public String persional(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
  910. log.info("跳转到注册页面!");
  911. //Ajax登录超时校验,如果超时,进行前台响应提示
  912. if (WebUtil.isAjaxRequest(request)) {
  913. response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  914. response.setHeader(HEAD_SESSION_STATUS_KEY, HEAD_SESSION_STATUS_VALUE);
  915. response.setContentType("text/html;charset=utf-8");
  916. }
  917. this.commonObject(modelMap, false);
  918. return BASE_HOME_PATH + "html/personal_register";
  919. }
  920. @RequestMapping(value = "/toRegister")
  921. public String toRegister(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
  922. log.info("跳转到注册页面!");
  923. //Ajax登录超时校验,如果超时,进行前台响应提示
  924. if (WebUtil.isAjaxRequest(request)) {
  925. response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  926. response.setHeader(HEAD_SESSION_STATUS_KEY, HEAD_SESSION_STATUS_VALUE);
  927. response.setContentType("text/html;charset=utf-8");
  928. }
  929. List<Street> streetList = streetService.findList();
  930. modelMap.addAttribute("streetList", streetList);
  931. //查询企业性质
  932. List<DictionaryItem> companyTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.COMPANY_TYPE);
  933. modelMap.put("companyTypeList", companyTypeList);
  934. //modelMap.put("companyTypeList", buildTypeService.findList(Constant.DictType.COMPANY));
  935. //查询币种单位数据
  936. List<DictionaryItem> itemList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.CURRENCY_UNIT);
  937. modelMap.put("itemList", itemList);
  938. //查询行业类型
  939. List<DictionaryItem> industryTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.INDUSTRY_TYPE);
  940. modelMap.put("industryTypeList", industryTypeList);
  941. this.commonObject(modelMap, false);
  942. return BASE_HOME_PATH + "html/register";
  943. }
  944. @RequestMapping(value = "/toReset")
  945. public String toReset(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
  946. log.info("跳转到忘记密码页面!");
  947. //Ajax登录超时校验,如果超时,进行前台响应提示
  948. if (WebUtil.isAjaxRequest(request)) {
  949. response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  950. response.setHeader(HEAD_SESSION_STATUS_KEY, HEAD_SESSION_STATUS_VALUE);
  951. response.setContentType("text/html;charset=utf-8");
  952. }
  953. this.commonObject(modelMap, false);
  954. return BASE_HOME_PATH + "html/reset";
  955. }
  956. /**
  957. * 账号名是否存在
  958. */
  959. @ResponseBody
  960. @GetMapping(value = "/getNickName")
  961. public boolean getNickName(@RequestParam("id") String id, @RequestParam("nick_name") String nickName) throws Exception {
  962. boolean flag = true;
  963. log.debug("检验账号名是否存在! id= {}, nickName= {}", id, nickName);
  964. User record = userService.findByNickName(nickName);
  965. if (null != record) {
  966. if (StringUtils.isBlank(id)) {
  967. flag = false;
  968. } else {
  969. if (record.getId() != (Integer.parseInt(id))) {
  970. flag = false;
  971. }
  972. }
  973. }
  974. log.info("检验模板名称是否存在结果! flag = {}", flag);
  975. return flag;
  976. }
  977. /**
  978. * 个人注册
  979. *
  980. * @param userInfo
  981. * @return
  982. */
  983. @RequestMapping("/personalRegister")
  984. @ResponseBody
  985. public ResponseMessage personalRegister(User userInfo) {
  986. try {
  987. if (!Constant.Environment.PROD_TEST.equals(profiles) && !Constant.Environment.TEST.equals(profiles)) {
  988. if (!verificationCodeUtil.validateVerificationCode(userInfo.getPhone(), userInfo.getValidateNum())) {
  989. return ResponseMessage.error("验证码错误!");
  990. }
  991. }
  992. User user = new User();
  993. user.setUser_name(userInfo.getUser_name());
  994. user.setNick_name(userInfo.getNick_name().trim());
  995. user.setPassword(SecureUtil.md5().digestHex(userInfo.getPassword().trim()));
  996. user.setPhone(userInfo.getPhone());
  997. user.setUser_type(Constant.UserType.PERSONAL);
  998. user.setIs_register(1);
  999. user.setFist_login(1);
  1000. user.setIs_start(true);
  1001. user.setIs_admin(false);
  1002. user.setCreate_name(userInfo.getUser_name());
  1003. user.setCreate_time(DateUtil.getTimeString(new Date()));
  1004. userService.insertAndGetId(user);
  1005. } catch (Exception e) {
  1006. e.printStackTrace();
  1007. return ResponseMessage.error("注册失败" + e.getMessage());
  1008. }
  1009. return ResponseMessage.success("注册成功");
  1010. }
  1011. @GetMapping("/validate")
  1012. @ResponseBody
  1013. public ResponseMessage wechatRegist(@RequestParam("phone") String phone, @RequestParam("code") String code) {
  1014. return ResponseMessage.success("请求成功", verificationCodeUtil.validateVerificationCode(phone, code));
  1015. }
  1016. /**
  1017. * 微信注册
  1018. *
  1019. * @param userInfo
  1020. * @return
  1021. */
  1022. @PostMapping("/wechatRegist")
  1023. @ResponseBody
  1024. public ResponseMessage wechatRegist(@RequestBody User userInfo) {
  1025. User user_o = userService.findByMobile(userInfo.getPhone());
  1026. if (user_o != null) {
  1027. return ResponseMessage.success("注册成功", user_o.getId());
  1028. }
  1029. User user = new User();
  1030. user.setUser_name(userInfo.getPhone());
  1031. user.setNick_name(userInfo.getPhone());
  1032. user.setPassword(SecureUtil.md5().digestHex("123456".trim()));
  1033. user.setPhone(userInfo.getPhone());
  1034. user.setUser_type(Constant.UserType.WECHAT);
  1035. user.setIs_register(1);
  1036. user.setFist_login(1);
  1037. user.setIs_start(true);
  1038. user.setIs_admin(false);
  1039. user.setCreate_name("wechat_" + userInfo.getPhone());
  1040. user.setCreate_time(DateUtil.getTimeString(new Date()));
  1041. Integer id = userService.insertAndGetId(user);
  1042. return ResponseMessage.success("注册成功", id);
  1043. }
  1044. /**
  1045. * 微信小程序登录
  1046. */
  1047. @GetMapping("/wxapp/login")
  1048. @ResponseBody
  1049. public ResponseMessage wxAppLogin(
  1050. @RequestParam String code
  1051. ) {
  1052. return ResponseMessage.success("登录成功", wxMicroappService.wxAppLogin(code));
  1053. }
  1054. /**
  1055. * 微信小程序获取用户信息
  1056. */
  1057. @GetMapping("/wxapp/phone")
  1058. @ResponseBody
  1059. public ResponseMessage wxAppUserinfo(
  1060. @RequestParam String code,
  1061. @RequestParam String encryptedData,
  1062. @RequestParam String iv
  1063. ) {
  1064. return ResponseMessage.success("获取用户信息成功", wxMicroappService.getPhoneNumber(code, encryptedData, iv));
  1065. }
  1066. /**
  1067. * 企业注册
  1068. *
  1069. * @param information
  1070. * @param userInfo
  1071. * @return
  1072. * @throws Exception
  1073. */
  1074. @RequestMapping("/register")
  1075. @ResponseBody
  1076. public ResponseMessage register(Company information, User userInfo) throws Exception {
  1077. try {
  1078. Approval approval = new Approval();
  1079. if (!Constant.Environment.PROD_TEST.equals(profiles) && !Constant.Environment.TEST.equals(profiles)) {
  1080. if (!verificationCodeUtil.validateVerificationCode(information.getPhone(), information.getValidateNum())) {
  1081. return ResponseMessage.error("验证码错误!");
  1082. }
  1083. }
  1084. /*
  1085. if (StringUtils.isNotBlank(stockLandService.getCompanyRegister(information.getStreet_id()))) {
  1086. approval.setNextchecker(stockLandService.getCompanyRegister(information.getStreet_id()));
  1087. }
  1088. //20180418-yl- 街道没有审批人也可以注册,分菜单给某角色,某个角色的人就可以审批
  1089. else {
  1090. return ResponseMessage.error("注册失败,本公司所属街道企业注册审核组没有配置人员,请联系街道管理员配置!");
  1091. }*/
  1092. approval.setOper_type(Constant.OperType.SUBMIT);
  1093. approval.setType(Constant.DictionaryType.COMPANY_REGISTER);
  1094. information.setIs_start(false);
  1095. information.setIs_register(0);
  1096. //查看是否已经存在企业
  1097. // Company company = companyService.findByParkIdAndCompanyName(information.getCompany_name(), information.getBuild_id());
  1098. Company company = companyService.findByCompanyName(information.getCompany_name());
  1099. if (company != null) {
  1100. information.setId(company.getId());
  1101. information.setIs_register(0);
  1102. companyService.update(information);
  1103. } else {
  1104. companyService.insertAndGetId(information);
  1105. }
  1106. approval.setApply_id(information.getId());
  1107. approval.setDeal_time(DateUtil.getTimeString(new Date()));
  1108. approval.setDel_flag(false);
  1109. approval.setBefore_approvalstatus("0");
  1110. approval.setCreate_name(information.getUser_name());
  1111. //approvalService.insertAndGetId(approval);
  1112. /*List<CompanyContact> companyContactList = information.getCompanyContacts();
  1113. if (companyContactList != null && companyContactList.size() > 0) {
  1114. for (CompanyContact companyContacts : companyContactList) {
  1115. companyContacts.setCompany_id(information.getId());
  1116. companyContactService.saveSelective(companyContacts);
  1117. }
  1118. }*/
  1119. CompanyContact contact = new CompanyContact();
  1120. contact.setCompany_id(information.getId());
  1121. contact.setContact(information.getUser_name());
  1122. contact.setPhone(information.getPhone());
  1123. contact.setDel_flag(false);
  1124. companyContactService.saveSelective(contact);
  1125. List<CompanyContact> companyContactList = information.getContactList();
  1126. if (companyContactList != null && companyContactList.size() > 0) {
  1127. for (CompanyContact companyContacts : companyContactList) {
  1128. if (companyContacts != null) {
  1129. companyContacts.setCompany_id(information.getId());
  1130. companyContactService.saveSelective(companyContacts);
  1131. }
  1132. }
  1133. }
  1134. List<FileDown> files = information.getFileDownList();
  1135. if (files != null && files.size() > 0) {
  1136. for (FileDown file : files) {
  1137. if (file != null) {
  1138. //attachmentDao.deleteByBusiness(Constant.Attachment.COMPANY_MATERIAL, information.getId());
  1139. attachmentDao.updateAttachment(Constant.Attachment.COMPANY_MATERIAL, information.getId(), file.getFile_id());
  1140. CompanyMaterial companyMaterial = new CompanyMaterial();
  1141. companyMaterial.setAttachment_id(file.getFile_id());
  1142. companyMaterial.setCompany_id(information.getId());
  1143. companyMaterial.setFile_name(file.getFile_name());
  1144. companyMaterialService.insertAndGetId(companyMaterial);
  1145. }
  1146. }
  1147. }
  1148. // todo 创建多个用户可以通过这里去改进
  1149. User user = new User();
  1150. user.setUser_name(information.getUser_name());
  1151. user.setNick_name(information.getNick_name().trim());
  1152. user.setPassword(SecureUtil.md5().digestHex(information.getPassword().trim()));
  1153. user.setPhone(information.getPhone());
  1154. user.setUser_type(Constant.UserType.COMPANY);
  1155. user.setIs_register(0);
  1156. user.setFist_login(1);
  1157. user.setIs_start(false);
  1158. user.setIs_admin(true);
  1159. user.setCompany_id(information.getId());
  1160. user.setCompany_name(information.getCompany_name());
  1161. if (null != information.getBuild_id()) {
  1162. user.setBuild_id(information.getBuild_id());
  1163. user.setBuild_name(information.getBuild_name());
  1164. }
  1165. user.setStreet_id(information.getStreet_id());
  1166. user.setStreet_name(information.getStreet_name());
  1167. user.setCreate_name(information.getUser_name());
  1168. userService.insertAndGetId(user);
  1169. approval.setCreate_by(user.getId());
  1170. approvalService.insertAndGetId(approval);
  1171. information.setCreate_by(user.getId());
  1172. information.setCreate_name(user.getUser_name());
  1173. companyService.updateSelective(information);
  1174. //同步信息天启
  1175. SyncUserDto dto = new SyncUserDto();
  1176. dto.setAction(Constant.METHOD_STATUS.INSERT);
  1177. dto.setOldUserName("");
  1178. dto.setUserName(user.getUser_name());
  1179. dto.setUserLoginName(user.getNick_name());
  1180. dto.setPassword(information.getPassword().trim());
  1181. dto.setCompanyName(information.getCompany_name());
  1182. if (null != information.getStreet_id()) {
  1183. Street street = streetService.findById(information.getStreet_id());
  1184. dto.setStreetName(street.getName());
  1185. }
  1186. dto.setToken(skyImageApiService.accessToken());
  1187. skyImageApiService.syncUserInfo(dto);
  1188. //新增街道待办
  1189. addWaitToDo(information);
  1190. //发送短信
  1191. Map<String, String> params = new HashMap<>();
  1192. params.put("user", user.getNick_name());
  1193. params.put("street", information.getStreet_name());
  1194. String templatCode = Constant.SMS_TemplateCode.REGISTER_REMIND;
  1195. String templateParam = JSONObject.toJSONString(params);
  1196. AlibabaSMSUtil.sendSMS(information.getPhone(), templatCode, Constant.SINGNAMW, templateParam);
  1197. } catch (Exception e) {
  1198. e.printStackTrace();
  1199. return ResponseMessage.error("注册失败" + e.getMessage());
  1200. }
  1201. return ResponseMessage.success("您的申请正在属地审核中,审核通过后,您将收到消息提醒。");
  1202. }
  1203. //企业注册审核待办
  1204. private void addWaitToDo(Company information) {
  1205. if (null != information.getStreet_id()) {
  1206. List<User> users = userService.findUsersByStreetId(information.getStreet_id());
  1207. List<User> pusers = userService.findUsersByPermission("REGISTER_APPROVE");
  1208. for (User user : users) {
  1209. for (User puser : pusers) {
  1210. if (Objects.equals(user.getId(), puser.getId())) {
  1211. waitToDoService.newTODO("企业注册审核", "/register/approval?id=" + information.getId(), Constant.WaitToDo_OperType.AUDIT, information.getId(),
  1212. Constant.DictionaryType.COMPANY_REGISTER, "", user.getId().toString(), Constant.WaitToDo_IsSerial.IS_SERIAL, false);
  1213. //发送短信提醒
  1214. Map<String, String> params = new HashMap<>();
  1215. params.put("companyName", information.getCompany_name());
  1216. String templatCode = Constant.SMS_TemplateCode.S_REGISTER_REMIND;
  1217. String templateParam = JSONObject.toJSONString(params);
  1218. try {
  1219. AlibabaSMSUtil.sendSMS(information.getPhone(), templatCode, Constant.SINGNAMW, templateParam);
  1220. } catch (ClientException | InterruptedException e) {
  1221. e.printStackTrace();
  1222. }
  1223. }
  1224. }
  1225. }
  1226. }
  1227. }
  1228. /**
  1229. * 企业重置密码
  1230. *
  1231. * @param information
  1232. * @param userInfo
  1233. * @return
  1234. * @throws Exception
  1235. */
  1236. @RequestMapping("/reset")
  1237. @ResponseBody
  1238. public ResponseMessage reset(Company information, User userInfo) {
  1239. try {
  1240. if (!verificationCodeUtil.validateVerificationCode(information.getPhone(), information.getValidateNum())) {
  1241. return ResponseMessage.error("验证码错误!");
  1242. }
  1243. User user = userService.getUserByNickname(information.getNick_name());
  1244. user.setPassword(SecureUtil.md5().digestHex(information.getPassword()));
  1245. userService.updateSelective(user);
  1246. // 同步密码到天启
  1247. SyncUserDto dto = new SyncUserDto();
  1248. dto.setAction(Constant.METHOD_STATUS.UPDATE);
  1249. dto.setOldUserName(user.getNick_name());
  1250. dto.setUserName(user.getUser_name());
  1251. dto.setUserLoginName(user.getNick_name());
  1252. dto.setPassword(information.getPassword());
  1253. dto.setToken(skyImageApiService.accessToken());
  1254. skyImageApiService.syncUserInfo(dto);
  1255. } catch (Exception e) {
  1256. e.printStackTrace();
  1257. return ResponseMessage.error("修改失败" + e.getMessage());
  1258. }
  1259. return ResponseMessage.success("密码修改成功!系统将跳转到登陆页进行登录");
  1260. }
  1261. @RequestMapping(value = "/toComplete")
  1262. public String toComplete(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
  1263. log.info("跳转到完成信息页面!");
  1264. //Ajax登录超时校验,如果超时,进行前台响应提示
  1265. if (WebUtil.isAjaxRequest(request)) {
  1266. response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  1267. response.setHeader(HEAD_SESSION_STATUS_KEY, HEAD_SESSION_STATUS_VALUE);
  1268. response.setContentType("text/html;charset=utf-8");
  1269. }
  1270. User user = ShiroUtils.getUserEntity();
  1271. modelMap.put("user", user);
  1272. ShiroUtils.logout();
  1273. return BASE_HOME_PATH + "html/complete";
  1274. }
  1275. @RequestMapping("/complete")
  1276. @ResponseBody
  1277. public ResponseMessage complete(Company information, User userInfo) throws Exception {
  1278. try {
  1279. if (!verificationCodeUtil.validateVerificationCode(information.getPhone(), information.getValidateNum())) {
  1280. return ResponseMessage.error("验证码错误!");
  1281. }
  1282. User user = new User();
  1283. user.setId(Integer.parseInt(information.getUser_id()));
  1284. user.setUser_name(information.getUser_name());
  1285. user.setNick_name(information.getNick_name());
  1286. user.setPhone(information.getPhone());
  1287. userService.updateSelective(user);
  1288. } catch (Exception e) {
  1289. e.printStackTrace();
  1290. return ResponseMessage.error("注册失败" + e.getMessage());
  1291. }
  1292. return ResponseMessage.success("完善信息成功!请重新登录!");
  1293. }
  1294. /**
  1295. * 发送验证码
  1296. *
  1297. * @param phone
  1298. * @return
  1299. * @throws Exception
  1300. */
  1301. @RequestMapping("/sendVerificationCode")
  1302. @ResponseBody
  1303. public ResponseMessage sendVerificationCode(String phone) throws Exception {
  1304. int t = verificationCodeUtil.validateVerificationTime(phone, 60L);
  1305. if (t > 0) {
  1306. return ResponseMessage.error("操作过于频繁!请" + t + "秒后再尝试!");
  1307. }
  1308. /* String phone = user.getPhone();
  1309. String nick_name = user.getNick_name();
  1310. String company_name = user.getCompany_name();
  1311. String templateParam = "{\"nick_name\":\""+nick_name+"\",\"company_name\":\""+company_name+"\"}";
  1312. AlibabaSMSUtil.sendSMS(phone, Constant.SMS_TemplateCode.COMPANY_USER_REGISTER_PASSED, Constant.SINGNAMW,templateParam);*/
  1313. verificationCodeUtil.setVerificationCode(phone);
  1314. return ResponseMessage.success("发送成功!请注意查收!");
  1315. }
  1316. /**
  1317. * 校验账户名手机号是否匹配后发送验证码
  1318. *
  1319. * @param phone
  1320. * @param name
  1321. * @return
  1322. * @throws Exception
  1323. */
  1324. @RequestMapping("/sendVerificationCodePhoneAndName")
  1325. @ResponseBody
  1326. public ResponseMessage sendVerificationCodePhoneAndName(@RequestParam("phone") String phone, @RequestParam("nickname") String name) throws Exception {
  1327. User user = userService.getUserByNickname(name);
  1328. if (null == user) {
  1329. //throw new BaseException("该账号名不存在!");
  1330. return ResponseMessage.error("该账号名不存在!");
  1331. } else if (!phone.equals(user.getPhone())) {
  1332. //throw new BaseException("账号名与手机号码不匹配!");
  1333. return ResponseMessage.error("账号名与手机号码不匹配!");
  1334. }
  1335. int t = verificationCodeUtil.validateVerificationTime(phone, 60L);
  1336. if (t > 0) {
  1337. return ResponseMessage.error("操作过于频繁!请" + t + "秒后再尝试!");
  1338. }
  1339. verificationCodeUtil.setVerificationCode(phone);
  1340. return ResponseMessage.success("发送成功!请注意查收!");
  1341. }
  1342. /**
  1343. * 获取当前用户是否有待办权限
  1344. */
  1345. @RequestMapping("/getWaitToDoPermission")
  1346. @ResponseBody
  1347. public ResponseMessage getWaitToDoPermission() {
  1348. if (ShiroUtils.isLogin()) {
  1349. User usere = ShiroUtils.getUserEntity();
  1350. if (usere.getIs_admin()) {
  1351. return ResponseMessage.success(null, true);
  1352. }
  1353. int userid = ShiroUtils.getUserId();
  1354. Integer usertype = ShiroUtils.getUserType();
  1355. List<User> pusers = new ArrayList<>();
  1356. switch (usertype) {
  1357. case 0:
  1358. pusers = userService.findUsersByPermission("G_WAITTODO");
  1359. break;
  1360. case 4:
  1361. pusers = userService.findUsersByPermission("S_WAITTODO");
  1362. break;
  1363. case 1:
  1364. pusers = userService.findUsersByPermission("Y_WAITTODO");
  1365. break;
  1366. case 3:
  1367. pusers = userService.findUsersByPermission("C_WAITTODO");
  1368. break;
  1369. }
  1370. for (User user : pusers) {
  1371. if (Objects.equals(user.getId(), userid)) return ResponseMessage.success(null, true);
  1372. }
  1373. }
  1374. return ResponseMessage.success(null, false);
  1375. }
  1376. @GetMapping(value = "/mobileIndex")
  1377. public String mobileIndex(ModelMap modelMap) throws Exception {
  1378. return BASE_MOBIl_PATH + "mobileIndex";
  1379. }
  1380. @GetMapping(value = "/mobileProjectIndex")
  1381. public String mobileProjectIndex(ModelMap modelMap) throws Exception {
  1382. return BASE_MOBIl_PATH + "mobileProjectIndex";
  1383. }
  1384. @GetMapping(value = "/serverDetail/{id}")
  1385. public String serverDetail(@PathVariable("id") Integer navigationId, ModelMap modelMap) throws Exception {
  1386. List<ProjectServiceType> projectServiceTypeList = projectServiceTypeService.findBySuperType("3");
  1387. modelMap.put("projectServiceTypeList", projectServiceTypeList);
  1388. //获取导航
  1389. modelMap.put("navigation_id", navigationId);
  1390. modelMap.put("navigation_name", navigationService.getName(navigationId));
  1391. modelMap.addAttribute("navigationList", navigationService.findList());
  1392. this.commonObject(modelMap, true);
  1393. return BASE_HOME_PATH + "html/serverDetail";
  1394. }
  1395. @GetMapping(value = "/statistic")
  1396. @ResponseBody
  1397. public ResponseMessage getStatistic() {
  1398. return ResponseMessage.success(null, statisticsService.getStatistics());
  1399. }
  1400. @GetMapping(value = "/addLiveness")
  1401. @ResponseBody
  1402. public ResponseMessage addLiveness() {
  1403. statisticsService.insertLiveness();
  1404. return ResponseMessage.success(null, null);
  1405. }
  1406. @GetMapping(value = "/wait")
  1407. public String wait(ModelMap modelMap) throws Exception {
  1408. return BASE_SYS_PATH + "wait";
  1409. }
  1410. @Value("${apk_url}")
  1411. private String apk_url;
  1412. @GetMapping(value = "/download/android/latest")
  1413. @ResponseBody
  1414. public void getLatestVersion(HttpServletRequest req, HttpServletResponse response) throws Exception {
  1415. String name = "", version = "", date = "";
  1416. List<DictionaryItem> appInfoList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.APPLICATION_PACKAGE);
  1417. for (DictionaryItem item : appInfoList) {
  1418. if (Objects.equals(Constant.DictionaryType.APPLICATION_NAME, item.getName())) {
  1419. name = item.getValue();
  1420. } else if (Objects.equals(Constant.DictionaryType.APPLICATION_VERSION, item.getName())) {
  1421. version = item.getValue();
  1422. } else if (Objects.equals(Constant.DictionaryType.APPLICATION_DATE, item.getName())) {
  1423. date = item.getValue();
  1424. }
  1425. }
  1426. String filePath = apk_url + name + "-" + version + "-" + date + ".apk";
  1427. File f = new File(filePath);
  1428. OutputStream out = response.getOutputStream();
  1429. if (!f.exists()) {
  1430. response.setCharacterEncoding("UTF-8");
  1431. String notFileHtml = getNotFileHtml();
  1432. out.write(notFileHtml.getBytes("UTF-8"));
  1433. out.flush();
  1434. return;
  1435. }
  1436. String ua = ((HttpServletRequest) req).getHeader("user-agent").toLowerCase();
  1437. if (ua.indexOf("micromessenger") > 0) {// 是微信浏览器
  1438. response.setCharacterEncoding("UTF-8");
  1439. String html = getWeixinTipsHtml();
  1440. out.write(html.getBytes("UTF-8"));
  1441. out.flush();
  1442. return;
  1443. }
  1444. BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
  1445. byte[] buf = new byte[1024];
  1446. int len = 0;
  1447. response.reset(); // 非常重要
  1448. response.setContentType("application/x-msdownload");
  1449. response.setHeader("Content-Disposition", "attachment; filename=" + name + "-" + version + "-" + date + ".apk");
  1450. while ((len = br.read(buf)) > 0)
  1451. out.write(buf, 0, len);
  1452. br.close();
  1453. out.close();
  1454. }
  1455. public static String getNotFileHtml() {
  1456. StringBuffer sb = new StringBuffer();
  1457. sb.append("<html>");
  1458. sb.append("<head>");
  1459. sb.append("<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>");
  1460. sb.append("</head>");
  1461. sb.append("<body>");
  1462. sb.append("<div id='errorInfo' style='font-size: 130px;'>");
  1463. sb.append("文件不存在");
  1464. sb.append("</div>");
  1465. sb.append("</body>");
  1466. sb.append("</html>");
  1467. return sb.toString();
  1468. }
  1469. public static String getWeixinTipsHtml() {
  1470. StringBuffer sb = new StringBuffer();
  1471. sb.append("<html>");
  1472. sb.append("<head>");
  1473. sb.append("<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>");
  1474. sb.append("<style type='text/css'>*{margin:0;padding:0;}a{text-decoration: none;}img{max-width: 100%;height: auto;} .weixin-tip{display: none;position: fixed;" +
  1475. "left:0;top:0;bottom:0;background: rgba(0,0,0,0.8);filter:alpha(opacity=80);height: 100%;width: 100%;z-index: 100;}.weixin-tip p{text-align: center;" +
  1476. "margin-top: 10%;padding:0 5%;}</style>");
  1477. sb.append("</head>");
  1478. sb.append("<body>");
  1479. sb.append("<div class='weixin-tip'><p><img src='../../image/live_weixin.png' alt='微信打开'/></p></div>");
  1480. //sb.append("<div id='errorInfo' style='font-size: 130px;'>");
  1481. //sb.append("请点击右上角,使用浏览器打开");
  1482. //sb.append("</div><img src='../../image/appCode.png'>");
  1483. //sb.append("<script>alert(this.location.href)</script>");
  1484. sb.append("<script src='../../plugin/jquery-1.11.3.min.js' type='text/javascript'></script>");
  1485. sb.append("<script type='text/javascript'>$(window).on('load',function(){var winHeight = $(window).height();function is_weixin() {var ua = navigator.userAgent.toLowerCase();" +
  1486. "if (ua.match(/MicroMessenger/i) == 'micromessenger') {return true;} else {return false;}}var isWeixin = is_weixin();if(isWeixin){$('.weixin-tip').css('height',winHeight);" +
  1487. "$('.weixin-tip').show();}})</script>");
  1488. sb.append("</body>");
  1489. sb.append("</html>");
  1490. return sb.toString();
  1491. }
  1492. }