HomeController.java 65 KB

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