articleTweetAction.java 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. package com.happy.action;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baidubce.model.User;
  5. import com.google.gson.Gson;
  6. import com.google.gson.reflect.TypeToken;
  7. import com.happy.Model.*;
  8. import com.happy.Model.weixin.Users;
  9. import com.happy.Until.*;
  10. import com.happy.common.controller.BaseController;
  11. import com.happy.constant.ConstDefault;
  12. import com.happy.constant.ResultStatusCode;
  13. import com.happy.dto.ArticleCommentDto;
  14. import com.happy.dto.ArticleTweetDto;
  15. import com.happy.dto.IPage;
  16. import com.happy.service.*;
  17. import com.happy.vo.*;
  18. import com.opensymphony.xwork2.ModelDriven;
  19. import lombok.SneakyThrows;
  20. import org.apache.commons.lang.StringUtils;
  21. import org.apache.struts2.ServletActionContext;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import javax.annotation.Resource;
  24. import java.text.DecimalFormat;
  25. import java.text.ParseException;
  26. import java.util.*;
  27. import java.util.stream.Collectors;
  28. public class articleTweetAction extends BaseController implements ModelDriven<ArticleTweetDto> {
  29. private final ArticleTweetDto articleTweetDto = new ArticleTweetDto();
  30. @Override
  31. public ArticleTweetDto getModel() {
  32. return articleTweetDto;
  33. }
  34. @Resource
  35. public ArticleTweetService articleTweetService;
  36. @Resource
  37. public HousePriceService housePriceService;
  38. @Resource
  39. public HotelDictService hotelDictService;
  40. @Resource
  41. public WorkflowService workflowService;
  42. @Resource
  43. public HouseService houseService;
  44. @Resource
  45. public UserService userService;
  46. public String key;
  47. public String startTime;
  48. public String endTime;
  49. public String getKey(){
  50. return key;
  51. }
  52. public void setKey(String key){
  53. this.key=key;
  54. }
  55. public String getStartTime() {
  56. return startTime;
  57. }
  58. public void setStartTime(String startTime) {
  59. this.startTime = startTime;
  60. }
  61. public String getEndTime() {
  62. return endTime;
  63. }
  64. public void setEndTime(String endTime) {
  65. this.endTime = endTime;
  66. }
  67. /**
  68. * 推文发布
  69. */
  70. public String insertArticleTweet() throws ParseException {
  71. Gson gson = new Gson();
  72. JSONObject jsonObject = new JSONObject();
  73. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  74. ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {
  75. }.getType());
  76. //图片和视频判断
  77. if (articleTweetDto.getImages() == null && articleTweetDto.getVideo() == null) {
  78. jsonObject.put("code", 500);
  79. jsonObject.put("message", "请上传图片或视频");
  80. jsonObject.put("data", null);
  81. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  82. return null;
  83. }
  84. //图片最多上传九张
  85. if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 9) {
  86. jsonObject.put("code", 500);
  87. jsonObject.put("message", "最多上传9张图片");
  88. jsonObject.put("data", null);
  89. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  90. return null;
  91. }
  92. //标题、内容、地点、关联民宿不能为空
  93. if (Func.checkNull(articleTweetDto.getTitle()) || Func.checkNull(articleTweetDto.getContent())
  94. || Func.checkNull(articleTweetDto.getTownId()) || articleTweetDto.getHotelIds() == null
  95. || articleTweetDto.getCreateId() == null) {
  96. jsonObject.put("code", 500);
  97. jsonObject.put("message", "参数不能为空");
  98. jsonObject.put("data", null);
  99. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  100. return null;
  101. }
  102. //推文发布参数
  103. System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
  104. //查询当前用户
  105. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
  106. if (user == null) {
  107. jsonObject.put("code", 500);
  108. jsonObject.put("message", "用户信息已失效,查看详情失败");
  109. jsonObject.put("data", null);
  110. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  111. return null;
  112. }
  113. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  114. try {
  115. //添加推文
  116. ArticleTweet data = new ArticleTweet();
  117. data.setUserId(articleTweetDto.getCreateId());
  118. data.setTitle(articleTweetDto.getTitle());
  119. data.setContent(articleTweetDto.getContent());
  120. data.setLocationId(articleTweetDto.getTownId());
  121. data.setHotelId(StringUtils.join(articleTweetDto.getHotelIds(), ","));
  122. data.setCreateId(articleTweetDto.getCreateId());
  123. data.setCreateDate(now);
  124. data.setApprove(1);//正在审批
  125. data.setStatus(1);
  126. data.setUserName(user.getUser_name());
  127. data.setUserPhoto(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  128. int aId = articleTweetService.insert(data);
  129. if (aId <= 0) {
  130. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  131. put("message", "推文发布失败");
  132. put("code", 500);
  133. }}.toString());
  134. return null;
  135. }
  136. //添加附件
  137. List<String> fileStr = new ArrayList<>();
  138. if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0) {
  139. fileStr = articleTweetDto.getImages();
  140. } else {
  141. fileStr.add(articleTweetDto.getVideo());
  142. }
  143. List<ArticleFileInfo> afis = new ArrayList<>();
  144. for (String f : fileStr) {
  145. String[] split = f.split("/");
  146. String fileName = split[split.length - 1];
  147. ArticleFileInfo afi = new ArticleFileInfo();
  148. afi.setLinkId(aId);
  149. afi.setName(fileName);
  150. afi.setType(1);
  151. afi.setUrl(f);
  152. afi.setCreateDate(now);
  153. afis.add(afi);
  154. }
  155. int length = articleTweetService.insertArticleFileBatch(afis);
  156. if (length <= 0) {
  157. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  158. put("message", "推文附件新增失败");
  159. put("code", 500);
  160. }}.toString());
  161. return null;
  162. }
  163. //添加流程
  164. Workflow workflow = new Workflow();
  165. String id = String.valueOf(UUID.randomUUID());
  166. workflow.setLinkId(String.valueOf(aId));//存推文的ID
  167. workflow.setCreateId(String.valueOf(articleTweetDto.getCreateId()));
  168. workflow.setTitle(articleTweetDto.getTitle());
  169. workflow.setRemark(articleTweetDto.getContent());
  170. workflow.setId(id);
  171. workflow.setStatus(1);//1是正在审批
  172. workflow.setType(3);//3是推文
  173. workflow.setCoverImg(articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0 ? articleTweetDto.getImages().get(0) : articleTweetDto.getVideo());
  174. int i = workflowService.insert(workflow);
  175. if (i <= 0) {
  176. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  177. put("message", "推文流程发布失败");
  178. put("code", 500);
  179. }}.toString());
  180. return null;
  181. }
  182. } catch (Exception e) {
  183. System.out.println("推文发布异常:" + e.getMessage());
  184. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  185. put("message", "推文发布异常");
  186. put("code", 500);
  187. }}.toString());
  188. return null;
  189. }
  190. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  191. put("message", "推文发布成功");
  192. put("code", 200);
  193. }}.toString());
  194. return null;
  195. }
  196. /**
  197. * 根据推文数据ID查询推文详情数据
  198. *
  199. * @return
  200. */
  201. public String queryDetail() {
  202. JSONObject jsonObject = new JSONObject();
  203. //图片和视频判断
  204. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  205. jsonObject.put("code", 500);
  206. jsonObject.put("message", "推文ID或用户ID不能为空");
  207. jsonObject.put("data", null);
  208. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  209. return null;
  210. }
  211. //查询当前用户
  212. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
  213. if (user == null) {
  214. jsonObject.put("code", 500);
  215. jsonObject.put("message", "用户信息已失效,查看详情失败");
  216. jsonObject.put("data", null);
  217. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  218. return null;
  219. }
  220. //查询推文数据
  221. ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
  222. if (data == null) {
  223. jsonObject.put("code", 500);
  224. jsonObject.put("message", "推文数据已失效,查看详情失败");
  225. jsonObject.put("data", null);
  226. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  227. return null;
  228. }
  229. ArticleDetailVo result = new ArticleDetailVo();
  230. result.setIsCollect(data.getIsCollect());
  231. result.setId(data.getId());
  232. List<FileInfo> fileInfoList = articleTweetService.queryList("and link_id = '" + articleTweetDto.getId() + "'");
  233. if (fileInfoList != null) {
  234. if (fileInfoList.size() > 1) {
  235. result.setImages(fileInfoList.stream().map(FileInfo::getUrl).collect(Collectors.toList()));
  236. } else if (fileInfoList.size() == 1) {
  237. String url = fileInfoList.get(0).getUrl();
  238. if (!url.endsWith("jpg") && !url.endsWith("png")) {
  239. result.setVideo(fileInfoList.get(0).getUrl());
  240. } else {
  241. List<String> images = new ArrayList<>();
  242. images.add(url);
  243. result.setImages(images);
  244. }
  245. }
  246. }
  247. result.setUserId(data.getUserId());
  248. result.setUserName(data.getUserName());
  249. result.setUserPhoto(data.getUserPhoto() == null ? ConstDefault.DefaultHeadPhoto : data.getUserPhoto());
  250. //region 关注
  251. if (articleTweetDto.getUserId().equals(data.getUserId())) {
  252. result.setIsFollow(2);//自己的推文
  253. } else {
  254. //是否关注
  255. UserCollect uc = articleTweetService.queryUserCollect(data.getUserId(), articleTweetDto.getUserId());
  256. result.setIsFollow(uc == null ? 0 : 1);//已关注给0;未关注给1
  257. }
  258. //endregion
  259. result.setTitle(data.getTitle());
  260. result.setContent(data.getContent());
  261. result.setDateStr(TimeExchange.DateToString(data.getCreateDate(), "yyyy-MM-dd"));
  262. result.setTownId(data.getLocationId());
  263. result.setTownName(data.getLocationName());
  264. //region 民宿列表
  265. //根据乡镇ID获取
  266. List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
  267. String sql = "id in (" + data.getHotelId() + ")";
  268. List<HotelVo> hotels = articleTweetService.queryHotels(sql);
  269. List<HotelListVo> hotelDatas = new ArrayList<>();
  270. //region 最低价
  271. List<Integer> managerIds = hotels.stream().map(HotelVo::getManagerId).collect(Collectors.toList());
  272. List<HotelPriceDataVo> prices = housePriceService.queryHotelPriceDatas(StringUtils.join(managerIds, ","), TimeExchange.getDateStr());
  273. List<HotelPriceOneDataVo> oneDatas = new ArrayList<>();
  274. //获取当天的
  275. for (HotelPriceDataVo hp : prices) {
  276. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  277. oneData.setSetDate(TimeExchange.getDateStr());
  278. oneData.setCreateDate(hp.getCreateDate());
  279. oneData.setPrice(hp.getPrice());
  280. oneData.setManagerId(hp.getManagerId());
  281. oneDatas.add(oneData);
  282. }
  283. /**
  284. * 根据房型ID处理重复的数据
  285. */
  286. List<HotelPriceOneDataVo> newOneDatas = new ArrayList<>();
  287. if (oneDatas.size() > 0) {
  288. for (Integer managerId : managerIds) {
  289. Optional<HotelPriceOneDataVo> one = oneDatas.stream().filter(e -> e.getManagerId().equals(managerId)).sorted(Comparator.comparing(HotelPriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
  290. if (one != null && one.isPresent()) {
  291. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  292. oneData.setSetDate(one.get().getSetDate());
  293. oneData.setCreateDate(one.get().getCreateDate());
  294. oneData.setPrice(one.get().getPrice());
  295. oneData.setManagerId(one.get().getManagerId());
  296. newOneDatas.add(oneData);
  297. }
  298. }
  299. }
  300. /**
  301. * 获取商家集合中最低房型价格
  302. */
  303. List<PriceHotelDataVo> mins = houseService.gethotelMinPrice(StringUtils.join(managerIds, ","));
  304. DecimalFormat decimalFormat = new DecimalFormat("#####.##");
  305. //endregion
  306. for (HotelVo hotel : hotels) {
  307. HotelListVo hotelData = new HotelListVo();
  308. hotelData.setId(hotel.getId());
  309. hotelData.setName(hotel.getName());
  310. hotelData.setScore(hotel.getScore());
  311. hotelData.setCoverImg(hotel.getCoverImg());
  312. hotelData.setComment(hotel.getComment());
  313. //是否收藏
  314. Optional<String> hotelId = hotelIds.stream().filter(e -> e.equals(hotel.getId().toString())).findFirst();
  315. if (hotelId != null && hotelId.isPresent()) {
  316. hotelData.setIsCollect(1);
  317. } else {
  318. hotelData.setIsCollect(0);
  319. }
  320. hotelData.setType(hotel.getType());
  321. //价格
  322. Optional<HotelPriceOneDataVo> one = newOneDatas.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  323. Optional<PriceHotelDataVo> min = mins.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  324. if (one != null && one.isPresent() && min != null && min.isPresent()) {
  325. if(one.get().getPrice() > min.get().getPrice()){
  326. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  327. }else{
  328. hotelData.setPrice(decimalFormat.format(one.get().getPrice()));
  329. }
  330. } else {
  331. if (min != null && min.isPresent()) {
  332. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  333. }
  334. }
  335. hotelDatas.add(hotelData);
  336. }
  337. result.setHotels(hotelDatas);
  338. //endregion
  339. List<LikeListVo> likes = articleTweetService.queryArticleLikes(articleTweetDto.getId());
  340. if (likes != null && likes.size() > 0) {
  341. Optional<LikeListVo> ownerLikes = likes.stream().filter(e -> e.getId().equals(articleTweetDto.getUserId())).findFirst();
  342. if (ownerLikes != null && ownerLikes.isPresent()) {
  343. result.setIsLike(1);
  344. } else {
  345. result.setIsLike(0);
  346. }
  347. } else {
  348. result.setIsLike(0);
  349. }
  350. result.setLikes(likes == null ? new ArrayList<>() : likes.stream().map(LikeListVo::getImage).limit(10).collect(Collectors.toList()));
  351. result.setLikeNum(likes == null ? 0 : likes.size());
  352. List<ArticleCommentVo> comments = articleTweetService.queryArticleComment(articleTweetDto.getId());
  353. result.setComments(comments);
  354. int total = articleTweetService.queryArticleCommentTotal(articleTweetDto.getId());
  355. result.setCommentNum(total);
  356. result.setCollectNum(data.getCollectNum());
  357. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  358. jsonObject.put("message", "请求成功");
  359. jsonObject.put("data", result);
  360. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  361. return null;
  362. }
  363. /**
  364. * 点赞集合列表
  365. *
  366. * @return
  367. */
  368. public String queryLikes() {
  369. JSONObject jsonObject = new JSONObject();
  370. if (articleTweetDto.getId() == null) {
  371. jsonObject.put("code", 500);
  372. jsonObject.put("message", "推文ID不能为空");
  373. jsonObject.put("data", null);
  374. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  375. return null;
  376. }
  377. IPage<LikeListVo> result = articleTweetService.queryLikesPage(articleTweetDto.getId(), page, rows);
  378. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  379. jsonObject.put("message", "请求成功");
  380. jsonObject.put("data", result);
  381. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  382. return null;
  383. }
  384. /**
  385. * 获取推文详情中民宿分页列表
  386. */
  387. public String queryHotelList() {
  388. JSONObject jsonObject = new JSONObject();
  389. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  390. jsonObject.put("code", 500);
  391. jsonObject.put("message", "推文ID或用户ID不能为空");
  392. jsonObject.put("data", null);
  393. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  394. return null;
  395. }
  396. //查询当前用户
  397. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
  398. if (user == null) {
  399. jsonObject.put("code", 500);
  400. jsonObject.put("message", "用户信息已失效,查看详情失败");
  401. jsonObject.put("data", null);
  402. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  403. return null;
  404. }
  405. //查询推文数据
  406. ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
  407. if (data == null) {
  408. jsonObject.put("code", 500);
  409. jsonObject.put("message", "推文数据已失效,查看详情失败");
  410. jsonObject.put("data", null);
  411. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  412. return null;
  413. }
  414. //region 民宿列表
  415. //根据乡镇ID获取
  416. List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
  417. String sql = "id in (" + data.getHotelId() + ")";
  418. IPage<HotelVo> hotels = articleTweetService.queryHotelPageByHotleId(sql, page, rows);
  419. List<HotelListVo> hotelDatas = new ArrayList<>();
  420. //region 最低价
  421. List<Integer> managerIds = hotels.getPageList().stream().map(HotelVo::getManagerId).collect(Collectors.toList());
  422. List<HotelPriceDataVo> prices = housePriceService.queryHotelPriceDatas(StringUtils.join(managerIds, ","), TimeExchange.getDateStr());
  423. List<HotelPriceOneDataVo> oneDatas = new ArrayList<>();
  424. //获取当天的
  425. for (HotelPriceDataVo hp : prices) {
  426. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  427. oneData.setSetDate(TimeExchange.getDateStr());
  428. oneData.setCreateDate(hp.getCreateDate());
  429. oneData.setPrice(hp.getPrice());
  430. oneData.setManagerId(hp.getManagerId());
  431. oneDatas.add(oneData);
  432. }
  433. /**
  434. * 根据房型ID处理重复的数据
  435. */
  436. List<HotelPriceOneDataVo> newOneDatas = new ArrayList<>();
  437. if (oneDatas.size() > 0) {
  438. for (Integer managerId : managerIds) {
  439. Optional<HotelPriceOneDataVo> one = oneDatas.stream().filter(e -> e.getManagerId().equals(managerId)).sorted(Comparator.comparing(HotelPriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
  440. if (one != null && one.isPresent()) {
  441. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  442. oneData.setSetDate(one.get().getSetDate());
  443. oneData.setCreateDate(one.get().getCreateDate());
  444. oneData.setPrice(one.get().getPrice());
  445. oneData.setManagerId(one.get().getManagerId());
  446. newOneDatas.add(oneData);
  447. }
  448. }
  449. }
  450. /**
  451. * 获取商家集合中最低房型价格
  452. */
  453. List<PriceHotelDataVo> mins = houseService.gethotelMinPrice(StringUtils.join(managerIds, ","));
  454. DecimalFormat decimalFormat = new DecimalFormat("#####.##");
  455. //endregion
  456. for (HotelVo hotel : hotels.getPageList()) {
  457. HotelListVo hotelData = new HotelListVo();
  458. hotelData.setId(hotel.getId());
  459. hotelData.setName(hotel.getName());
  460. hotelData.setScore(hotel.getScore());
  461. hotelData.setCoverImg(hotel.getCoverImg());
  462. hotelData.setComment(hotel.getComment());
  463. //是否收藏
  464. Optional<String> hotelId = hotelIds.stream().filter(e -> e.equals(hotel.getId().toString())).findFirst();
  465. if (hotelId != null && hotelId.isPresent()) {
  466. hotelData.setIsCollect(1);
  467. } else {
  468. hotelData.setIsCollect(0);
  469. }
  470. hotelData.setType(hotel.getType());
  471. //价格
  472. Optional<HotelPriceOneDataVo> one = newOneDatas.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  473. Optional<PriceHotelDataVo> min = mins.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  474. if (one != null && one.isPresent() && min != null && min.isPresent()) {
  475. if(one.get().getPrice() > min.get().getPrice()){
  476. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  477. }else{
  478. hotelData.setPrice(decimalFormat.format(one.get().getPrice()));
  479. }
  480. } else {
  481. if (min != null && min.isPresent()) {
  482. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  483. }
  484. }
  485. hotelDatas.add(hotelData);
  486. }
  487. //endregion
  488. IPage<HotelListVo> result = new IPage<>();
  489. result.setPage(hotels.getPage());
  490. result.setRows(hotels.getRows());
  491. result.setPageList(hotelDatas);
  492. result.setTotal(hotels.getTotal());
  493. result.setTotalPage(hotels.getTotalPage());
  494. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  495. jsonObject.put("message", "请求成功");
  496. jsonObject.put("data", result);
  497. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  498. return null;
  499. }
  500. /**
  501. * 获取推文详情中评论分页列表
  502. * 先获取一级评论 再区获取对应子级
  503. */
  504. public String queryCommentList() {
  505. JSONObject jsonObject = new JSONObject();
  506. //推文ID判断
  507. if (articleTweetDto.getId() == null) {
  508. jsonObject.put("code", 500);
  509. jsonObject.put("message", "推文ID不能为空");
  510. jsonObject.put("data", null);
  511. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  512. return null;
  513. }
  514. //一级分页数据
  515. IPage<ArticleCommentVo> result = articleTweetService.queryCommentPageByArticle(articleTweetDto.getId(), page, rows);
  516. //子级评论数据
  517. List<ArticleCommentVo> childs = articleTweetService.queryCommentsByArticle(articleTweetDto.getId());
  518. if (childs != null && childs.size() > 0) {
  519. for (ArticleCommentVo data : result.getPageList()) {
  520. List<ArticleCommentVo> comments = QueryTreeDatas(data.getId(), data.getUserName(), childs);
  521. data.setChildrens(comments);
  522. }
  523. }
  524. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  525. jsonObject.put("message", "请求成功");
  526. jsonObject.put("data", result);
  527. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  528. return null;
  529. }
  530. //region 循环递归获取子级
  531. /**
  532. * 根据父类ID获取树形菜单数据
  533. *
  534. * @param parentID 父级ID
  535. * @param lists 数据集合
  536. * @return
  537. */
  538. private List<ArticleCommentVo> QueryTreeDatas(Integer parentID, String parentName, List<ArticleCommentVo> lists) {
  539. List<ArticleCommentVo> newTrees = new ArrayList<>();
  540. List<ArticleCommentVo> datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList());
  541. for (ArticleCommentVo data : datas) {
  542. data.setParentName(parentName);
  543. List<ArticleCommentVo> news = QueryTreeDatas(data.getId(), data.getUserName(), lists);
  544. if (news == null || news.size() == 0) {
  545. newTrees.add(data);
  546. continue;
  547. } else {
  548. data.setChildrens(news);
  549. newTrees.add(data);
  550. }
  551. }
  552. return newTrees;
  553. }
  554. //endregion
  555. /**
  556. * 根据用户ID获取个人主页相关信息
  557. */
  558. public String queryUserInfo() {
  559. JSONObject jsonObject = new JSONObject();
  560. //用户ID判断
  561. if (articleTweetDto.getUserId() == null) {
  562. jsonObject.put("code", 500);
  563. jsonObject.put("message", "用户ID不能为空");
  564. jsonObject.put("data", null);
  565. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  566. return null;
  567. }
  568. articleUserVo result = articleTweetService.queryUserInfo(articleTweetDto.getUserId());
  569. //region 关注
  570. if (articleTweetDto.getUserId().equals(result.getId())) {
  571. result.setIsFollow(2);//自己的推文
  572. } else {
  573. //是否关注
  574. UserCollect uc = articleTweetService.queryUserCollect(result.getId(), articleTweetDto.getUserId());
  575. result.setIsFollow(uc == null ? 0 : 1);//已关注给0;未关注给1
  576. }
  577. //endregion
  578. if (result != null) {
  579. String descript = "点击这里,填写简介";
  580. result.setDescript(result.getDescript() == null ? descript : result.getDescript());
  581. }
  582. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  583. jsonObject.put("message", "请求成功");
  584. jsonObject.put("data", result);
  585. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  586. return null;
  587. }
  588. /**
  589. * 根据用户ID获取用户主页推文列表分页数据
  590. */
  591. public String queryOwnerArticlePage() {
  592. JSONObject jsonObject = new JSONObject();
  593. //用户ID判断
  594. if (articleTweetDto.getUserId() == null || articleTweetDto.getType() == null) {
  595. jsonObject.put("code", 500);
  596. jsonObject.put("message", "用户ID或类型ID不能为空");
  597. jsonObject.put("data", null);
  598. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  599. return null;
  600. }
  601. String sqlWhere = "";//全部推文
  602. if (articleTweetDto.getType().intValue() == 1) {
  603. sqlWhere = "and at.approve = 1 ";//审核中
  604. } else if (articleTweetDto.getType().intValue() == 2) {
  605. sqlWhere = "and at.approve = 3 ";//驳回
  606. }
  607. IPage<OwnerArticleVo> result = articleTweetService.queryOwnerArticlePage(articleTweetDto.getUserId(), sqlWhere, page, rows);
  608. if (result.getPageList().size() > 0) {
  609. String articleIds = StringUtils.join(result.getPageList().stream().map(OwnerArticleVo::getId).collect(Collectors.toList()), ",");
  610. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  611. for (OwnerArticleVo data : result.getPageList()) {
  612. List<FileInfo> fileInfoList = fileInfos == null ? null : fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  613. if (fileInfoList != null) {
  614. if (fileInfoList.size() > 1) {
  615. data.setImages(fileInfoList.stream().map(FileInfo::getUrl).collect(Collectors.toList()));
  616. } else if (fileInfoList.size() == 1) {
  617. String url = fileInfoList.get(0).getUrl();
  618. if (!url.endsWith("jpg") && !url.endsWith("png")) {
  619. data.setVideo(fileInfoList.get(0).getUrl());
  620. } else {
  621. List<String> images = new ArrayList<>();
  622. images.add(url);
  623. data.setImages(images);
  624. }
  625. }
  626. }
  627. }
  628. }
  629. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  630. jsonObject.put("message", "请求成功");
  631. jsonObject.put("data", result);
  632. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  633. return null;
  634. }
  635. /**
  636. * 社区首页推文列表
  637. */
  638. public String queryArticlePage() {
  639. JSONObject jsonObject = new JSONObject();
  640. if (articleTweetDto.getType() == null) {
  641. jsonObject.put("code", 500);
  642. jsonObject.put("message", "推文列表类型不能为空");
  643. jsonObject.put("data", null);
  644. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  645. return null;
  646. }
  647. if (articleTweetDto.getUserId() == null) {
  648. jsonObject.put("code", 500);
  649. jsonObject.put("message", "用户ID不能为空");
  650. jsonObject.put("data", null);
  651. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  652. return null;
  653. }
  654. IPage<ArticleListVo> result = articleTweetService.queryArticlesPage(articleTweetDto.getKeyWord(), articleTweetDto.getTownId().equals("") ? null : articleTweetDto.getTownId(), articleTweetDto.getUserId(), articleTweetDto.getType(), page, rows);
  655. if (result.getPageList().size() > 0) {
  656. String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
  657. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  658. for (ArticleListVo data : result.getPageList()) {
  659. if(fileInfos != null){
  660. List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  661. if (fileInfoList != null) {
  662. if (fileInfoList.size() > 1) {
  663. data.setImage(fileInfoList.get(0).getUrl());
  664. } else if (fileInfoList.size() == 1) {
  665. String url = fileInfoList.get(0).getUrl();
  666. if (!url.endsWith("jpg") && !url.endsWith("png")) {
  667. data.setVideo(fileInfoList.get(0).getUrl());
  668. } else {
  669. data.setImage(url);
  670. }
  671. }
  672. }
  673. }
  674. }
  675. }
  676. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  677. jsonObject.put("message", "请求成功");
  678. jsonObject.put("data", result);
  679. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  680. return null;
  681. }
  682. /**
  683. * 点赞数最高的推文
  684. */
  685. public String queryMaxArticleLike() {
  686. JSONObject jsonObject = new JSONObject();
  687. ArticleLikeMaxVo result = articleTweetService.queryMaxArticleLike();
  688. if (result != null) {
  689. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id = " + result.getId() + "");
  690. if (fileInfos != null) {
  691. if (fileInfos.size() > 1) {
  692. result.setImage(fileInfos.get(0).getUrl());
  693. } else if (fileInfos.size() == 1) {
  694. String url = fileInfos.get(0).getUrl();
  695. if (!url.endsWith("jpg") && !url.endsWith("png")) {
  696. result.setVideo(fileInfos.get(0).getUrl());
  697. } else {
  698. result.setImage(url);
  699. }
  700. }
  701. }
  702. }
  703. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  704. jsonObject.put("message", "请求成功");
  705. jsonObject.put("data", result);
  706. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  707. return null;
  708. }
  709. /**
  710. * 相关推文
  711. */
  712. public String relatedTweets() {
  713. JSONObject jsonObject = new JSONObject();
  714. if (articleTweetDto.getId() == null || articleTweetDto.getTownId() == null || articleTweetDto.getUserId() == null) {
  715. jsonObject.put("code", 500);
  716. jsonObject.put("message", "乡镇ID或推文ID或用户ID不能为空");
  717. jsonObject.put("data", null);
  718. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  719. return null;
  720. }
  721. IPage<ArticleListVo> result = articleTweetService.relatedTweetPage(articleTweetDto.getUserId(), articleTweetDto.getTownId(), articleTweetDto.getId(), page, rows);
  722. if (result.getPageList().size() > 0) {
  723. String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
  724. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  725. for (ArticleListVo data : result.getPageList()) {
  726. List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  727. if (fileInfoList != null) {
  728. if (fileInfoList.size() > 1) {
  729. data.setImage(fileInfoList.get(0).getUrl());
  730. } else if (fileInfoList.size() == 1) {
  731. String url = fileInfoList.get(0).getUrl();
  732. if (!url.endsWith("jpg") && !url.endsWith("png")) {
  733. data.setVideo(fileInfoList.get(0).getUrl());
  734. } else {
  735. data.setImage(url);
  736. }
  737. }
  738. }
  739. }
  740. }
  741. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  742. jsonObject.put("message", "请求成功");
  743. jsonObject.put("data", result);
  744. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  745. return null;
  746. }
  747. //select * from article_tweet where location_id = '' and user_id != 1 and approve = 2
  748. /**
  749. * 收藏文章
  750. */
  751. public String collectArticle() throws ParseException {
  752. JSONObject jsonObject = new JSONObject();
  753. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  754. jsonObject.put("code", 500);
  755. jsonObject.put("message", "用户ID或推文ID不能为空");
  756. jsonObject.put("data", null);
  757. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  758. return null;
  759. }
  760. //查询当前操作人是否已经收藏过这篇文章
  761. ArticleCollect data = articleTweetService.queryArticleCollect(articleTweetDto.getId(), articleTweetDto.getUserId());
  762. String actionStr = "收藏";
  763. if (data != null) {
  764. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  765. actionStr = "取消收藏";
  766. data.setIsLose(1);
  767. } else {
  768. data.setIsLose(0);
  769. }
  770. } else {
  771. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  772. data = new ArticleCollect();
  773. data.setArticleId(articleTweetDto.getId());
  774. data.setUserId(articleTweetDto.getUserId());
  775. data.setIsLose(0);
  776. data.setCreateId(articleTweetDto.getUserId());
  777. data.setCreateDate(now);
  778. data.setStatus(1);
  779. }
  780. int m = articleTweetService.updateArticleCollect(data);
  781. if (m <= 0) {
  782. String message = actionStr + "失败";
  783. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  784. put("message", message);
  785. put("code", 500);
  786. }}.toString());
  787. return null;
  788. }
  789. String successMessage = actionStr + "成功";
  790. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  791. put("message", successMessage);
  792. put("code", 200);
  793. }}.toString());
  794. return null;
  795. }
  796. /**
  797. * 评论文章
  798. */
  799. public String commentArticle() throws ParseException {
  800. Gson gson = new Gson();
  801. JSONObject jsonObject = new JSONObject();
  802. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  803. ArticleCommentDto articleCommentDto = gson.fromJson(json.toString(), new TypeToken<ArticleCommentDto>() {
  804. }.getType());
  805. if (articleCommentDto.getArticleId() == null || Func.checkNull(articleCommentDto.getContent())
  806. || articleCommentDto.getParentId() == null || articleCommentDto.getUserId() == null) {
  807. jsonObject.put("code", 500);
  808. jsonObject.put("message", "参数不能为空");
  809. jsonObject.put("data", null);
  810. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  811. return null;
  812. }
  813. //查询操作人身份
  814. Users user = userService.queryByUserId(String.valueOf(articleCommentDto.getUserId()));
  815. if (user == null) {
  816. jsonObject.put("code", 500);
  817. jsonObject.put("message", "用户信息已失效,评论失败");
  818. jsonObject.put("data", null);
  819. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  820. return null;
  821. }
  822. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  823. ArticleComment articleComment = new ArticleComment();
  824. articleComment.setArticleId(articleCommentDto.getArticleId());
  825. articleComment.setCommentParentId(articleCommentDto.getParentId());
  826. articleComment.setCommentId(articleCommentDto.getUserId());
  827. articleComment.setCommentName(user.getUser_name());
  828. articleComment.setCommentImage(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  829. articleComment.setContent(articleCommentDto.getContent());
  830. articleComment.setCreateId(articleCommentDto.getUserId());
  831. articleComment.setCreateDate(now);
  832. articleComment.setStatus(1);
  833. int num = articleTweetService.insertArticleComment(articleComment);
  834. if (num <= 0) {
  835. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  836. put("message", "评论失败");
  837. put("code", 500);
  838. }}.toString());
  839. return null;
  840. }
  841. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  842. put("message", "评论成功");
  843. put("code", 200);
  844. }}.toString());
  845. return null;
  846. }
  847. /**
  848. * 关注作者
  849. */
  850. public String followAuthor() throws ParseException {
  851. JSONObject jsonObject = new JSONObject();
  852. if (articleTweetDto.getAuthorId() == null || articleTweetDto.getUserId() == null) {
  853. jsonObject.put("code", 500);
  854. jsonObject.put("message", "作者ID或用户ID不能为空");
  855. jsonObject.put("data", null);
  856. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  857. return null;
  858. }
  859. //查询当前操作人是否已经关注过作者
  860. UserCollect data = articleTweetService.queryUserCollectNoLose(articleTweetDto.getAuthorId(), articleTweetDto.getUserId());
  861. String actionStr = "关注";
  862. if (data != null) {
  863. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  864. actionStr = "取消关注";
  865. data.setIsLose(1);
  866. } else {
  867. data.setIsLose(0);
  868. }
  869. } else {
  870. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  871. data = new UserCollect();
  872. data.setParentUserid(articleTweetDto.getAuthorId());
  873. data.setUserId(articleTweetDto.getUserId());
  874. data.setIsLose(0);
  875. data.setCreateId(articleTweetDto.getUserId());
  876. data.setCreateDate(now);
  877. data.setStatus(1);
  878. }
  879. int m = articleTweetService.updateUserCollect(data);
  880. if (m <= 0) {
  881. String message = actionStr + "失败";
  882. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  883. put("message", message);
  884. put("code", 500);
  885. }}.toString());
  886. return null;
  887. }
  888. String successMessage = actionStr + "成功";
  889. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  890. put("message", successMessage);
  891. put("code", 200);
  892. }}.toString());
  893. return null;
  894. }
  895. /**
  896. * 点赞文章
  897. */
  898. public String likeArticle() throws ParseException {
  899. JSONObject jsonObject = new JSONObject();
  900. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  901. jsonObject.put("code", 500);
  902. jsonObject.put("message", "用户ID或推文ID不能为空");
  903. jsonObject.put("data", null);
  904. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  905. return null;
  906. }
  907. //查询操作人身份
  908. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
  909. if (user == null) {
  910. jsonObject.put("code", 500);
  911. jsonObject.put("message", "用户信息已失效,评论失败");
  912. jsonObject.put("data", null);
  913. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  914. return null;
  915. }
  916. //查询当前操作人是否已经收藏过这篇文章
  917. ArticleLikes data = articleTweetService.queryArticleLike(articleTweetDto.getId(), articleTweetDto.getUserId());
  918. String actionStr = "点赞";
  919. if (data != null) {
  920. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  921. actionStr = "取消点赞";
  922. data.setIsLose(1);
  923. } else {
  924. data.setIsLose(0);
  925. }
  926. } else {
  927. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  928. data = new ArticleLikes();
  929. data.setArticleId(articleTweetDto.getId());
  930. data.setLikeId(articleTweetDto.getUserId());
  931. data.setLikeName(user.getUser_name());
  932. data.setLikeImage(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  933. data.setIsLose(0);
  934. data.setCreateId(articleTweetDto.getUserId());
  935. data.setCreateDate(now);
  936. data.setStatus(1);
  937. }
  938. int m = articleTweetService.updateArticleLike(data);
  939. if (m <= 0) {
  940. String message = actionStr + "失败";
  941. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  942. put("message", message);
  943. put("code", 500);
  944. }}.toString());
  945. return null;
  946. }
  947. String successMessage = actionStr + "成功";
  948. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  949. put("message", successMessage);
  950. put("code", 200);
  951. }}.toString());
  952. return null;
  953. }
  954. /**
  955. * 获取乡镇列表
  956. */
  957. public String townShips() {
  958. List<HotelDict> hotelDicts = hotelDictService.queryList("and code = 10");
  959. List<TownshipVo> result = new ArrayList<>();
  960. for (HotelDict hotelDict : hotelDicts) {
  961. TownshipVo data = new TownshipVo();
  962. data.setId(hotelDict.getId());
  963. data.setName(hotelDict.getName());
  964. result.add(data);
  965. }
  966. JSONObject jsonObject = new JSONObject();
  967. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  968. jsonObject.put("message", "请求成功");
  969. jsonObject.put("data", result);
  970. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  971. return null;
  972. }
  973. /**
  974. * 根据乡镇ID获取民宿列表
  975. */
  976. public String hotelByid() {
  977. JSONObject jsonObject = new JSONObject();
  978. if (Func.checkNull(articleTweetDto.getTownId())) {
  979. jsonObject.put("code", ResultStatusCode.BAD_REQUEST.getStatus());
  980. jsonObject.put("message", ResultStatusCode.BAD_REQUEST.getMsg());
  981. jsonObject.put("data", null);
  982. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  983. return null;
  984. }
  985. String sql = "hotel_township = '" + articleTweetDto.getTownId() + "'";
  986. IPage<HotelVo> houseIPage = articleTweetService.queryHotelPage(sql, page, rows);
  987. jsonObject.put("message", "查询分页成功");
  988. jsonObject.put("code", 200);
  989. jsonObject.put("data", houseIPage);
  990. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  991. return null;
  992. }
  993. /**
  994. * 修改用户简介
  995. */
  996. public String updateDescript() {
  997. JSONObject jsonObject = new JSONObject();
  998. if (articleTweetDto.getAuthorId() == null || articleTweetDto.getUserId() == null || Func.checkNull(articleTweetDto.getDescript())) {
  999. jsonObject.put("code", 500);
  1000. jsonObject.put("message", "操作用户ID或主页用户ID或简介不能为空");
  1001. jsonObject.put("data", null);
  1002. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1003. return null;
  1004. }
  1005. if (!articleTweetDto.getAuthorId().equals(articleTweetDto.getUserId())) {
  1006. jsonObject.put("code", 500);
  1007. jsonObject.put("message", "当前用户无法修改其他人的简介信息");
  1008. jsonObject.put("data", null);
  1009. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1010. return null;
  1011. }
  1012. int num = articleTweetService.updateDescript(articleTweetDto.getAuthorId(), articleTweetDto.getDescript());
  1013. jsonObject.put("message", "修改成功");
  1014. jsonObject.put("code", 200);
  1015. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1016. return null;
  1017. }
  1018. /**
  1019. * 攻略分页
  1020. * @return
  1021. */
  1022. public String walkthroughPage(){
  1023. JSONObject jsonObject = new JSONObject();
  1024. StringBuilder strSql = new StringBuilder(" and at.status=1 "); // 推文没删除才显示
  1025. if (!Func.checkNull(key)){
  1026. strSql.append(" and (at.user_name like '%").append(key).append("%' or at.title like '%").append(key).append("%') ");
  1027. }
  1028. if (!Func.checkNull(startTime) && !Func.checkNull(endTime)){
  1029. strSql.append(" and at.create_date >= '").append(startTime).append("' ");
  1030. strSql.append(" and at.create_date <= '").append(endTime).append("' ");
  1031. }
  1032. IPage<WalkthroughVo> walkthroughPage=articleTweetService.walkthroughPage(strSql.toString(),page, rows);
  1033. jsonObject.put("message", "查询分页成功");
  1034. jsonObject.put("code", 200);
  1035. jsonObject.put("data", walkthroughPage);
  1036. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1037. return null;
  1038. }
  1039. }