articleTweetAction.java 52 KB

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