WeChatApiController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. package platform.modules.carrier.web.api;
  2. import com.github.pagehelper.PageInfo;
  3. import com.google.web.bindery.requestfactory.shared.messages.RequestMessage;
  4. import com.xiaoleilu.hutool.crypto.SecureUtil;
  5. import jdk.nashorn.internal.objects.annotations.Getter;
  6. import org.apache.shiro.authc.*;
  7. import org.apache.shiro.crypto.hash.Hash;
  8. import org.apache.shiro.subject.Subject;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.ui.ModelMap;
  11. import org.springframework.web.bind.annotation.*;
  12. import platform.common.Constant;
  13. import platform.common.annotation.OperationLog;
  14. import platform.common.base.controller.BaseController;
  15. import platform.common.base.model.DictionaryItem;
  16. import platform.common.base.service.DictionaryItemService;
  17. import platform.common.util.LetterEnum;
  18. import platform.common.util.ShiroUtils;
  19. import platform.common.util.VerificationCodeUtil;
  20. import platform.modules.build.entity.Company;
  21. import platform.modules.build.entity.CompanyContact;
  22. import platform.modules.build.service.CompanyContactService;
  23. import platform.modules.build.service.CompanyService;
  24. import platform.modules.carrier.dto.*;
  25. import platform.modules.carrier.entity.Building;
  26. import platform.modules.carrier.entity.InvestmentInfo;
  27. import platform.modules.carrier.entity.Park;
  28. import platform.modules.carrier.entity.RentalProject;
  29. import platform.modules.carrier.service.*;
  30. import platform.modules.government.entity.Street;
  31. import platform.modules.government.entity.User;
  32. import platform.modules.government.service.Government;
  33. import platform.modules.government.service.StreetService;
  34. import platform.modules.government.service.UserService;
  35. import platform.modules.sys.entity.ActivityDetail;
  36. import platform.modules.sys.entity.ActivityFavourite;
  37. import platform.modules.sys.entity.ActivityRegistration;
  38. import platform.modules.sys.entity.Message;
  39. import platform.modules.sys.service.ActivityFavouriteService;
  40. import platform.modules.sys.service.ActivityRegistrationService;
  41. import platform.modules.sys.service.ActivityService;
  42. import platform.modules.sys.service.MessageService;
  43. import platform.modules.sys.shiro.UsernamePasswordToken;
  44. import platform.modules.sys.vo.MessageDto;
  45. import platform.modules.sys.web.ResponseMessage;
  46. import sun.misc.BASE64Decoder;
  47. import java.net.Inet4Address;
  48. import java.util.*;
  49. /**
  50. * @author kevin
  51. * @since 2019/7/11 3:36 PM
  52. */
  53. @RestController
  54. @RequestMapping("/wechat")
  55. public class WeChatApiController extends BaseController {
  56. @Autowired
  57. private IcContractService contractService;
  58. @Autowired
  59. private UserService userService;
  60. @Autowired
  61. private BuildingService buildingService;
  62. @Autowired
  63. private StreetService streetService;
  64. @Autowired
  65. private ParkService parkService;
  66. @Autowired
  67. private InvestmentInfoService investmentInfoService;
  68. @Autowired
  69. private RentalProjectService rentalProjectService;
  70. @Autowired
  71. private VerificationCodeUtil verificationCodeUtil;
  72. @Autowired
  73. private CompanyService companyService;
  74. @Autowired
  75. private CarrierStatisticService carrierStatisticService;
  76. @Autowired
  77. private MessageService messageService;
  78. @Autowired
  79. private DictionaryItemService dictionaryItemService;
  80. @Autowired
  81. private ActivityFavouriteService activityFavouriteService;
  82. @Autowired
  83. private ActivityRegistrationService activityRegistrationService;
  84. @Autowired
  85. private ActivityService activityService;
  86. /**
  87. * 用户登陆
  88. * 先根据用户名查询出一条用户记录再对比密码是否正确可以防止sql注入
  89. *
  90. * @return
  91. */
  92. @OperationLog(value = "用户登录")
  93. @PostMapping(value = "/wechatLogin")
  94. public ResponseMessage wechatLogin(@RequestBody WechatLogin wechatLogin) {
  95. String username = wechatLogin.getUsername();
  96. String password = wechatLogin.getPassword();
  97. try {
  98. //获取当前的Subject
  99. Subject currentUser = ShiroUtils.getSubject();
  100. UsernamePasswordToken token = new UsernamePasswordToken(username, password, true, false);
  101. log.info("对用户进行登录验证..验证开始! username = {}", username);
  102. currentUser.login(token);
  103. //验证是否登录成功
  104. if (currentUser.isAuthenticated()) {
  105. log.info("对用户进行登录验证..验证通过! username = {}", username);
  106. ModelMap modelMap = new ModelMap();
  107. //获取token
  108. modelMap.put("token", userService.createToken());
  109. // modelMap.put("user", userService.findByNickName(username));
  110. modelMap.put("user", ShiroUtils.getUserEntity());
  111. return ResponseMessage.success(Constant.USER_LOGIN_IN, modelMap);
  112. }
  113. } catch (UnknownAccountException e) { //账号不存在
  114. log.info("! username = {}", username);
  115. return ResponseMessage.error(Constant.USER_NOT_FIND);
  116. } catch (IncorrectCredentialsException e) {
  117. log.info("对用户进行登录验证..验证未通过,错误的凭证! username = {}", username);
  118. return ResponseMessage.error(Constant.USER_INVALID);
  119. } catch (LockedAccountException e) {
  120. log.info("对用户进行登录验证..验证未通过,账户已锁定! username = {}", username);
  121. return ResponseMessage.error(Constant.USER_HAS_LOCK);
  122. } catch (ExcessiveAttemptsException eae) {
  123. log.info("对用户进行登录验证..验证未通过,错误次数过多! username = {}", username);
  124. return ResponseMessage.error(Constant.USER_ERROR_MANY);
  125. } catch (AuthenticationException e) {
  126. return ResponseMessage.error(Constant.SYSTEM_ERRORS);
  127. } catch (Exception e) {
  128. log.error("对用户进行登录验证失败! username = {} e = {}", username, e);
  129. }
  130. return ResponseMessage.error(Constant.SYSTEM_ERRORS);
  131. }
  132. /**
  133. * 获取街道剩余面积和代租面积
  134. *
  135. * @return
  136. */
  137. @GetMapping("/street/statistic")
  138. public Object getStreetAreaStatistic(
  139. @RequestParam(defaultValue = "1", required = false) Integer pageNum,
  140. @RequestParam(defaultValue = "10", required = false) Integer pageSize
  141. ) {
  142. PageInfo<CarrierLibraryResult> pageInfo = contractService.getStreetAreaStatistic(pageNum, pageSize);
  143. return ResponseMessage.success("success", pageInfo);
  144. }
  145. /**
  146. * 载体查询
  147. *
  148. * @return
  149. */
  150. @RequestMapping("/checkCarrier")
  151. public Object carrierCheck(@RequestBody CarrierQueryDto query) {
  152. PageInfo<Building> pageInfo = buildingService.getBuildingsByQuery(query);
  153. return ResponseMessage.success("success", pageInfo);
  154. }
  155. /**
  156. * 获取所有街道
  157. *
  158. * @return
  159. */
  160. @GetMapping("/streets")
  161. public Object getStreetList() {
  162. Street street = new Street();
  163. street.setIs_start(true);
  164. List<Street> streets = streetService.findListByWhere(street);
  165. return ResponseMessage.success("success", streets);
  166. }
  167. /**
  168. * 获取所有园区
  169. *
  170. * @return
  171. */
  172. @GetMapping("/parkNames")
  173. public Object findParkNames(SearchCondition condition) {
  174. PageInfo<Park> pageInfo = parkService.findParkNames(condition);
  175. return ResponseMessage.success("success", pageInfo);
  176. }
  177. /**
  178. * 载体方案详情
  179. *
  180. * @return
  181. */
  182. @PostMapping("/buildingDetail/{id}")
  183. public Object buildingDetail(@PathVariable Integer id, @RequestBody CarrierQueryDto query) {
  184. Building building = buildingService.findCheckinDetail(id, query);
  185. return ResponseMessage.success("success", building);
  186. }
  187. /**
  188. * 获取详情
  189. *
  190. * @param id
  191. * @return
  192. */
  193. @GetMapping(value = "/investment/{id}")
  194. public ResponseMessage get(@PathVariable Integer id) {
  195. InvestmentInfo res = investmentInfoService.getById(id);
  196. res.setFile_down_url(setFileUrl());
  197. return ResponseMessage.success("success", res);
  198. }
  199. /**
  200. * 查看园区详情(前台)
  201. *
  202. * @return
  203. */
  204. @GetMapping("/front/parkDetail/{id}")
  205. public Object frontParkDetail(@PathVariable Integer id) {
  206. Park park = parkService.frontParkDetailById(id);
  207. park.setFile_down_url(setFileUrl());
  208. return ResponseMessage.success("success", park);
  209. }
  210. /**
  211. * 获取详情
  212. *
  213. * @param id
  214. * @return
  215. */
  216. @GetMapping(value = "/rental/{id}")
  217. public ResponseMessage rental(@PathVariable Integer id) {
  218. RentalProject res = rentalProjectService.getById(id);
  219. res.setFile_down_url(setFileUrl());
  220. return ResponseMessage.success("success", res);
  221. }
  222. /**
  223. * 获取公司第一联系人
  224. *
  225. * @param id
  226. * @return
  227. */
  228. @GetMapping("/firstContact/{id}")
  229. public Object firstCompanyContact(@PathVariable Integer id) {
  230. User firstContact = userService.findFirstContact(id);
  231. return ResponseMessage.success("success", firstContact);
  232. }
  233. /**
  234. * 个人中心
  235. *
  236. * @param id
  237. * @return
  238. */
  239. @GetMapping("/personalCenter/{id}")
  240. public Object personalCenter(@PathVariable Integer id) {
  241. User user = userService.findById(id);
  242. if (user.getUser_type().equals(Constant.UserType.GOVERNMENT)) {
  243. user.setDepartment_name(userService.getGovDepartment(user));
  244. }
  245. if (user.getUser_type().equals(Constant.UserType.COMPANY)) {
  246. user.setDepartment_name(userService.getCompanyDepartment(user));
  247. }
  248. if (user.getUser_type().equals(Constant.UserType.STREET)) {
  249. user.setDepartment_name(userService.getStreetDepartment(user));
  250. }
  251. if (user.getUser_type().equals(Constant.UserType.BUILD)) {
  252. user.setDepartment_name(userService.getBuildDepartment(user));
  253. }
  254. return ResponseMessage.success("success", user);
  255. }
  256. /**
  257. * 修改密码
  258. *
  259. * @param changePassword
  260. * @return
  261. */
  262. @OperationLog(value = "修改密码")
  263. @PostMapping("/changePass")
  264. public Object changePass(@RequestBody ChangePassword changePassword) {
  265. return userService.changePassword(changePassword);
  266. }
  267. /**
  268. * 企业重置密码
  269. *
  270. * @param information
  271. * @return
  272. * @throws Exception
  273. */
  274. @PostMapping("/reset")
  275. public ResponseMessage reset(@RequestBody Company information) {
  276. try {
  277. if (!verificationCodeUtil.validateVerificationCode(information.getPhone(), information.getValidateNum())) {
  278. return ResponseMessage.error("验证码错误!");
  279. }
  280. User user = userService.getUserByNickname(information.getNick_name());
  281. user.setPassword(SecureUtil.md5().digestHex(information.getPassword()));
  282. userService.updateSelective(user);
  283. } catch (Exception e) {
  284. e.printStackTrace();
  285. return ResponseMessage.error("修改失败" + e.getMessage());
  286. }
  287. return ResponseMessage.success("密码修改成功!系统将跳转到登陆页进行登录");
  288. }
  289. /**
  290. * 校验账户名手机号是否匹配后发送验证码
  291. *
  292. * @param changePassword
  293. * @return
  294. * @throws Exception
  295. */
  296. @PostMapping("/sendVerificationCodePhoneAndName")
  297. public ResponseMessage sendVerificationCodePhoneAndName(@RequestBody ChangePassword changePassword) {
  298. User user = userService.getUserByNickname(changePassword.getNickname());
  299. if (null == user) {
  300. //throw new BaseException("该账号名不存在!");
  301. return ResponseMessage.error("该账号名不存在!");
  302. } else if (!changePassword.getPhone().equals(user.getPhone())) {
  303. //throw new BaseException("账号名与手机号码不匹配!");
  304. return ResponseMessage.error("账号名与手机号码不匹配!");
  305. }
  306. int t = verificationCodeUtil.validateVerificationTime(changePassword.getPhone(), 60L);
  307. if (t > 0) {
  308. return ResponseMessage.error("操作过于频繁!请" + t + "秒后再尝试!");
  309. }
  310. verificationCodeUtil.setVerificationCode(changePassword.getPhone());
  311. return ResponseMessage.success("发送成功!请注意查收!");
  312. }
  313. /**
  314. * 企业通讯录
  315. *
  316. * @param letter
  317. * @return
  318. */
  319. @GetMapping("/companyContactList")
  320. public Object companyContact(String letter, String companyName) {
  321. List<CompanyContacts> companyContacts = companyService.findCompanyListByName(letter, companyName);
  322. return ResponseMessage.success("success", companyContacts);
  323. }
  324. public static void main(String[] args) {
  325. for (LetterEnum anEnum : LetterEnum.values()) {
  326. System.out.println(anEnum);
  327. }
  328. }
  329. /**
  330. * 载体库楼栋列表
  331. *
  332. * @return
  333. */
  334. @GetMapping("/buildingStatistic")
  335. public Object getBuildingStatistic(
  336. @RequestParam(defaultValue = "1", required = false) Integer pageNum,
  337. @RequestParam(defaultValue = "10", required = false) Integer pageSize,
  338. SearchCondition condition) {
  339. Map<String, Object> map = carrierStatisticService.getWechatBuildingStatistic(pageNum, pageSize, condition);
  340. return ResponseMessage.success("success", map);
  341. }
  342. /**
  343. * 载体库各街道列表
  344. *
  345. * @return
  346. */
  347. @GetMapping("/streetStatistic")
  348. public Object getStreetStatistic(
  349. @RequestParam(defaultValue = "1", required = false) Integer pageNum,
  350. @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
  351. Map<String, Object> map = carrierStatisticService.getWechatStreetStatistic(pageNum, pageSize);
  352. return ResponseMessage.success("success", map);
  353. }
  354. /**
  355. * 载体各库园区列表
  356. *
  357. * @return
  358. */
  359. @GetMapping("/parkStatistic/{id}")
  360. public Object getParkStatistic(
  361. @RequestParam(defaultValue = "1", required = false) Integer pageNum,
  362. @RequestParam(defaultValue = "10", required = false) Integer pageSize,
  363. @PathVariable Integer id) {
  364. Map<String, Object> map = carrierStatisticService.getWechatParkStatistic(pageNum, pageSize, id);
  365. return ResponseMessage.success("success", map);
  366. }
  367. @OperationLog(value = "查看我的消息列表")
  368. @GetMapping(value = "/myMessage")
  369. public Object list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  370. String queryStr, MessageDto searchCondition) throws Exception {
  371. Map<String, Object> map = new HashMap<>();
  372. try {
  373. log.debug("分页查询消息列表参数! pageNum = {}, keyword = {}", pageNum, queryStr);
  374. PageInfo<Message> pageInfo = messageService.findPage(pageNum, PAGESIZE, queryStr, searchCondition);
  375. log.info("分页查询消息列表结果! pageInfo = {}", pageInfo);
  376. map.put("pageInfo", pageInfo);
  377. map.put("keyword", queryStr);
  378. map.put("searchCondition", searchCondition);
  379. List<DictionaryItem> messageTypes = dictionaryItemService.findListByTypeName(Constant.DictionaryType.MESSAGE_TYPE);
  380. map.put("messageTypeList", messageTypes);
  381. } catch (Exception e) {
  382. e.printStackTrace();
  383. }
  384. return ResponseMessage.success("", map);
  385. }
  386. /**
  387. * 添加收藏
  388. *
  389. * @return
  390. */
  391. @OperationLog(value = "收藏活动")
  392. @ResponseBody
  393. @GetMapping(value = "/addFavourite/{id}")
  394. public ResponseMessage addFavourite(@PathVariable("id") int id, Integer user_id) throws Exception {
  395. log.info("查询是否收藏!id = {}", id);
  396. // if (!ShiroUtils.isLogin()) return ResponseMessage.success("请先登录!", 2);
  397. ActivityFavourite activityFavourite = new ActivityFavourite();
  398. activityFavourite.setActivity_id(id);
  399. activityFavourite.setUser_id(user_id);
  400. int count = activityFavouriteService.saveActivityFavourite(activityFavourite);
  401. if (count > 0) return ResponseMessage.success("收藏成功!");
  402. return ResponseMessage.success("收藏失败!");
  403. }
  404. /**
  405. * 取消收藏
  406. *
  407. * @return
  408. */
  409. @OperationLog(value = "取消收藏活动")
  410. @ResponseBody
  411. @GetMapping(value = "/removeFavourite/{id}")
  412. public ResponseMessage removeFavourite(@PathVariable("id") int id, Integer user_id) throws Exception {
  413. log.info("查询是否收藏!id = {}", id);
  414. boolean b = activityFavouriteService.deleteByActivityIdAndUserId(id + "", user_id + "");
  415. if (b) return ResponseMessage.success("取消收藏成功!");
  416. return ResponseMessage.success("取消收藏失败!");
  417. }
  418. /**
  419. * 获取用户报名各类活动数
  420. *
  421. * @return
  422. */
  423. @GetMapping("activityStatistic/{userId}")
  424. public Object activityStatistic(@PathVariable Integer userId) {
  425. ActivityStatistic statistic = activityRegistrationService.findActivityStatistic(userId);
  426. return ResponseMessage.success("success", statistic);
  427. }
  428. /**
  429. * 获取用户报名各类活动
  430. *
  431. * @return
  432. */
  433. @GetMapping("findTypesActivitys/{userId}")
  434. public Object findTypesActivitys(@PathVariable Integer userId, String type) {
  435. List<ActivityDetail> activitys = activityRegistrationService.findTypesActivitys(type, userId);
  436. for (ActivityDetail activity : activitys) {
  437. List<Integer> userIds = new ArrayList<>();
  438. List<ActivityRegistration> regUsers = activityRegistrationService.getWechatCurrRegUsers(activity.getId() + "", userId);
  439. for (ActivityRegistration regUser : regUsers) {
  440. userIds.add(regUser.getId());
  441. }
  442. activity.setRegUsers(userIds);
  443. }
  444. Map<String, Object> map = new HashMap<>();
  445. map.put("file_url", setFileUrl());
  446. map.put("activitys", activitys);
  447. return ResponseMessage.success("success", map);
  448. }
  449. /**
  450. * 获取已报名的用户
  451. *
  452. * @return
  453. */
  454. @GetMapping(value = "/getRegUsers")
  455. public ResponseMessage getRegUsers(String activity_id, Integer user_id) {
  456. log.info("获取已报名的用户!");
  457. System.out.println(ShiroUtils.getUserEntity());
  458. return ResponseMessage.success("查询成功!", activityRegistrationService.getWechatCurrRegUsers(activity_id, user_id));
  459. }
  460. /**
  461. * 取消报名
  462. *
  463. * @param ids
  464. * @return
  465. */
  466. @PostMapping("/abort")
  467. public Object quert(@RequestBody List<String> ids) {
  468. // List<String> idList = Arrays.asList(ids);
  469. activityRegistrationService.adortRegister(ids);
  470. return ResponseMessage.success("取消成功");
  471. }
  472. /**
  473. * 强烈推荐
  474. *
  475. * @return
  476. */
  477. @GetMapping("/highlyRecommended")
  478. public Object highlyRecommended(
  479. @RequestParam(defaultValue = "1") Integer pageNum,
  480. @RequestParam(defaultValue = "10") Integer pageSize) {
  481. Map<String, Object> map = new HashMap<>();
  482. map.put("file_url", setFileUrl());
  483. map.put("data", activityService.findHighlyRecommended(pageNum, pageSize));
  484. return ResponseMessage.success("success", map);
  485. }
  486. /**
  487. * 我的项目查询
  488. *
  489. * @param condition
  490. * @return
  491. * @throws Exception
  492. */
  493. @PostMapping(value = "/rentals/{userid}")
  494. public ResponseMessage list(@PathVariable Integer userId, @RequestBody CustomSearchCondition condition) throws Exception {
  495. log.info("分页查询招商信息,pageNum = {},condition = {}", condition.getPageNum(), condition.toString(), false);
  496. condition.setFile_url(setFileUrl());
  497. PageInfo<RentalProject> pageInfo = rentalProjectService.findMyList(userId, condition);
  498. log.info("分页查询招商信息列表结果! pageInfo = {}", pageInfo);
  499. return ResponseMessage.success("success", pageInfo);
  500. }
  501. }