articleTweetAction.java 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  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.Until.Enum.DataType;
  11. import com.happy.common.controller.BaseController;
  12. import com.happy.common.http.HttpsClient;
  13. import com.happy.constant.ConstDefault;
  14. import com.happy.constant.ResultStatusCode;
  15. import com.happy.dto.ArticleCommentDto;
  16. import com.happy.dto.ArticleTweetDto;
  17. import com.happy.dto.IPage;
  18. import com.happy.service.*;
  19. import com.happy.vo.*;
  20. import com.opensymphony.xwork2.ModelDriven;
  21. import lombok.SneakyThrows;
  22. import org.apache.commons.lang.StringUtils;
  23. import org.apache.http.HttpResponse;
  24. import org.apache.http.client.HttpClient;
  25. import org.apache.http.client.methods.HttpGet;
  26. import org.apache.http.client.methods.HttpPost;
  27. import org.apache.http.entity.StringEntity;
  28. import org.apache.http.impl.client.HttpClientBuilder;
  29. import org.apache.http.util.EntityUtils;
  30. import org.apache.struts2.ServletActionContext;
  31. import org.aspectj.weaver.ast.Var;
  32. import org.springframework.transaction.annotation.Transactional;
  33. import javax.annotation.Resource;
  34. import java.text.DecimalFormat;
  35. import java.text.ParseException;
  36. import java.util.*;
  37. import java.util.stream.Collectors;
  38. import static com.happy.common.http.HttpsClient.httpsRequestReturnString;
  39. public class articleTweetAction extends BaseController implements ModelDriven<ArticleTweetDto> {
  40. private final ArticleTweetDto articleTweetDto = new ArticleTweetDto();
  41. @Override
  42. public ArticleTweetDto getModel() {
  43. return articleTweetDto;
  44. }
  45. @Resource
  46. public ArticleTweetService articleTweetService;
  47. @Resource
  48. public HousePriceService housePriceService;
  49. @Resource
  50. public HotelDictService hotelDictService;
  51. @Resource
  52. public WorkflowService workflowService;
  53. @Resource
  54. public HouseService houseService;
  55. @Resource
  56. public UserService userService;
  57. @Resource
  58. public AdminManagerService adminManagerService;
  59. @Resource
  60. public AdminService adminService;
  61. public String key;
  62. public String startTime;
  63. public String endTime;
  64. public String keyWord;
  65. public String userName;
  66. public String adminId;
  67. public String getKey() {
  68. return key;
  69. }
  70. public void setKey(String key) {
  71. this.key = key;
  72. }
  73. public String getStartTime() {
  74. return startTime;
  75. }
  76. public void setStartTime(String startTime) {
  77. this.startTime = startTime;
  78. }
  79. public String getEndTime() {
  80. return endTime;
  81. }
  82. public void setEndTime(String endTime) {
  83. this.endTime = endTime;
  84. }
  85. public String getKeyWord() {
  86. return keyWord;
  87. }
  88. public void setKeyWord(String keyWord) {
  89. this.keyWord = keyWord;
  90. }
  91. public String getUserName() {
  92. return userName;
  93. }
  94. public void setUserName(String userName) {
  95. this.userName = userName;
  96. }
  97. public String getAdminId() {
  98. return adminId;
  99. }
  100. public void setAdminId(String adminId) {
  101. this.adminId = adminId;
  102. }
  103. /**
  104. * 推文发布
  105. */
  106. public String insertArticleTweet() throws ParseException {
  107. Gson gson = new Gson();
  108. JSONObject jsonObject = new JSONObject();
  109. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  110. ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {
  111. }.getType());
  112. //图片和视频判断
  113. if (articleTweetDto.getImages() == null && articleTweetDto.getVideo() == null) {
  114. jsonObject.put("code", 500);
  115. jsonObject.put("message", "请上传图片或视频");
  116. jsonObject.put("data", null);
  117. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  118. return null;
  119. }
  120. //图片最多上传九张
  121. if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 9) {
  122. jsonObject.put("code", 500);
  123. jsonObject.put("message", "最多上传9张图片");
  124. jsonObject.put("data", null);
  125. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  126. return null;
  127. }
  128. //标题、内容、地点、关联民宿不能为空
  129. if (Func.checkNull(articleTweetDto.getTitle()) || Func.checkNull(articleTweetDto.getContent())
  130. || Func.checkNull(articleTweetDto.getTownId()) || articleTweetDto.getHotelIds() == null
  131. || articleTweetDto.getCreateId() == null) {
  132. jsonObject.put("code", 500);
  133. jsonObject.put("message", "参数不能为空");
  134. jsonObject.put("data", null);
  135. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  136. return null;
  137. }
  138. //推文发布参数
  139. System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
  140. //查询当前用户
  141. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
  142. if (user == null) {
  143. jsonObject.put("code", 500);
  144. jsonObject.put("message", "用户信息已失效,查看详情失败");
  145. jsonObject.put("data", null);
  146. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  147. return null;
  148. }
  149. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  150. try {
  151. //添加推文
  152. ArticleTweet data = new ArticleTweet();
  153. data.setUserId(articleTweetDto.getCreateId());
  154. data.setTitle(articleTweetDto.getTitle());
  155. data.setContent(articleTweetDto.getContent());
  156. data.setLocationId(articleTweetDto.getTownId());
  157. data.setHotelId(StringUtils.join(articleTweetDto.getHotelIds(), ","));
  158. data.setCreateId(articleTweetDto.getCreateId());
  159. data.setCreateDate(now);
  160. data.setApprove(1);//正在审批
  161. data.setStatus(1);
  162. data.setPublishWay("小程序");
  163. data.setIsTop(0);
  164. data.setUserName(user.getUser_name());
  165. data.setUserPhoto(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  166. int aId = articleTweetService.insert(data);
  167. if (aId <= 0) {
  168. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  169. put("message", "推文发布失败");
  170. put("code", 500);
  171. }}.toString());
  172. return null;
  173. }
  174. //添加附件
  175. List<String> fileStr = new ArrayList<>();
  176. if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0) {
  177. fileStr = articleTweetDto.getImages();
  178. }
  179. List<String> fileStrVideo = new ArrayList<>();
  180. if (articleTweetDto.getVideo() != null && articleTweetDto.getVideo().length() > 0) {
  181. fileStrVideo.add(articleTweetDto.getVideo());
  182. }
  183. List<ArticleFileInfo> afis = new ArrayList<>();
  184. for (String f : fileStr) {
  185. String[] split = f.split("/");
  186. String fileName = split[split.length - 1];
  187. ArticleFileInfo afi = new ArticleFileInfo();
  188. afi.setLinkId(aId);
  189. afi.setName(fileName);
  190. afi.setType(1);
  191. afi.setUrl(f);
  192. afi.setCreateDate(now);
  193. afi.setFileType(1);
  194. afis.add(afi);
  195. }
  196. for (String f : fileStrVideo) {
  197. String[] split = f.split("/");
  198. String fileName = split[split.length - 1];
  199. ArticleFileInfo afi = new ArticleFileInfo();
  200. afi.setLinkId(aId);
  201. afi.setName(fileName);
  202. afi.setType(1);
  203. afi.setUrl(f);
  204. afi.setCreateDate(now);
  205. afi.setFileType(2);
  206. afis.add(afi);
  207. }
  208. int length = articleTweetService.insertArticleFileBatch(afis);
  209. if (length <= 0) {
  210. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  211. put("message", "推文附件新增失败");
  212. put("code", 500);
  213. }}.toString());
  214. return null;
  215. }
  216. //添加流程
  217. Workflow workflow = new Workflow();
  218. String id = String.valueOf(UUID.randomUUID());
  219. workflow.setLinkId(String.valueOf(aId));//存推文的ID
  220. workflow.setCreateId(String.valueOf(articleTweetDto.getCreateId()));
  221. workflow.setTitle(articleTweetDto.getTitle());
  222. workflow.setRemark(articleTweetDto.getContent());
  223. workflow.setId(id);
  224. workflow.setStatus(1);//1是正在审批
  225. workflow.setType(3);//3是推文
  226. workflow.setCoverImg(articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0 ? articleTweetDto.getImages().get(0) : articleTweetDto.getVideo());
  227. int i = workflowService.insert(workflow);
  228. if (i <= 0) {
  229. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  230. put("message", "推文流程发布失败");
  231. put("code", 500);
  232. }}.toString());
  233. return null;
  234. }
  235. } catch (Exception e) {
  236. System.out.println("推文发布异常:" + e.getMessage());
  237. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  238. put("message", "推文发布异常");
  239. put("code", 500);
  240. }}.toString());
  241. return null;
  242. }
  243. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  244. put("message", "推文发布成功");
  245. put("code", 200);
  246. }}.toString());
  247. return null;
  248. }
  249. /**
  250. * 管理端推文发布
  251. */
  252. public String insertArticleTweetMana() throws ParseException {
  253. Gson gson = new Gson();
  254. JSONObject jsonObject = new JSONObject();
  255. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  256. ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {
  257. }.getType());
  258. //图片和视频判断
  259. if (articleTweetDto.getImages() == null && articleTweetDto.getVideo() == null) {
  260. jsonObject.put("code", 500);
  261. jsonObject.put("message", "请上传图片或视频");
  262. jsonObject.put("data", null);
  263. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  264. return null;
  265. }
  266. //图片最多上传九张
  267. if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 9) {
  268. jsonObject.put("code", 500);
  269. jsonObject.put("message", "最多上传9张图片");
  270. jsonObject.put("data", null);
  271. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  272. return null;
  273. }
  274. //标题、内容、地点、关联民宿不能为空
  275. if (Func.checkNull(articleTweetDto.getTitle()) || Func.checkNull(articleTweetDto.getContent())
  276. || Func.checkNull(articleTweetDto.getTownId()) || articleTweetDto.getHotelIds() == null
  277. || articleTweetDto.getCreateId() == null) {
  278. jsonObject.put("code", 500);
  279. jsonObject.put("message", "参数不能为空");
  280. jsonObject.put("data", null);
  281. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  282. return null;
  283. }
  284. //推文发布参数
  285. System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
  286. //查询当前用户
  287. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
  288. if (user == null) {
  289. jsonObject.put("code", 500);
  290. jsonObject.put("message", "用户信息已失效,查看详情失败");
  291. jsonObject.put("data", null);
  292. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  293. return null;
  294. }
  295. List<ArticleTweet> articleTweets = articleTweetService.queryTops();
  296. if (articleTweets!=null && articleTweets.size()>=3 && articleTweetDto.getIsTop()==1){
  297. jsonObject.put("code", 500);
  298. jsonObject.put("message", "置顶攻略不可超过3个");
  299. jsonObject.put("data", null);
  300. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  301. return null;
  302. }
  303. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  304. try {
  305. //添加推文
  306. ArticleTweet data = new ArticleTweet();
  307. data.setUserId(articleTweetDto.getCreateId());
  308. data.setTitle(articleTweetDto.getTitle());
  309. data.setContent(articleTweetDto.getContent());
  310. data.setLocationId(articleTweetDto.getTownId());
  311. data.setHotelId(StringUtils.join(articleTweetDto.getHotelIds(), ","));
  312. data.setCreateId(articleTweetDto.getCreateId());
  313. data.setCreateDate(now);
  314. data.setApprove(2);//正在审批
  315. data.setStatus(1);
  316. data.setPublishWay("管理端");
  317. data.setIsTop(articleTweetDto.getIsTop());
  318. data.setUserName(user.getUser_name());
  319. data.setUserPhoto(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  320. int aId = articleTweetService.insert(data);
  321. if (aId <= 0) {
  322. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  323. put("message", "推文发布失败");
  324. put("code", 500);
  325. }}.toString());
  326. return null;
  327. }
  328. //添加附件
  329. List<String> fileStr = new ArrayList<>();
  330. if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0) {
  331. fileStr = articleTweetDto.getImages();
  332. }
  333. List<String> fileStrVideo = new ArrayList<>();
  334. if (articleTweetDto.getVideo() != null && articleTweetDto.getVideo().length() > 0) {
  335. fileStrVideo.add(articleTweetDto.getVideo());
  336. }
  337. List<ArticleFileInfo> afis = new ArrayList<>();
  338. for (String f : fileStr) {
  339. String[] split = f.split("/");
  340. String fileName = split[split.length - 1];
  341. ArticleFileInfo afi = new ArticleFileInfo();
  342. afi.setLinkId(aId);
  343. afi.setName(fileName);
  344. afi.setType(1);
  345. afi.setUrl(f);
  346. afi.setCreateDate(now);
  347. afi.setFileType(1);
  348. afis.add(afi);
  349. }
  350. for (String f : fileStrVideo) {
  351. String[] split = f.split("/");
  352. String fileName = split[split.length - 1];
  353. ArticleFileInfo afi = new ArticleFileInfo();
  354. afi.setLinkId(aId);
  355. afi.setName(fileName);
  356. afi.setType(1);
  357. afi.setUrl(f);
  358. afi.setCreateDate(now);
  359. afi.setFileType(2);
  360. afis.add(afi);
  361. }
  362. int length = articleTweetService.insertArticleFileBatch(afis);
  363. if (length <= 0) {
  364. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  365. put("message", "推文附件新增失败");
  366. put("code", 500);
  367. }}.toString());
  368. return null;
  369. }
  370. //添加流程
  371. Workflow workflow = new Workflow();
  372. String id = String.valueOf(UUID.randomUUID());
  373. workflow.setLinkId(String.valueOf(aId));//存推文的ID
  374. workflow.setCreateId(String.valueOf(articleTweetDto.getCreateId()));
  375. workflow.setTitle(articleTweetDto.getTitle());
  376. workflow.setRemark(articleTweetDto.getContent());
  377. workflow.setId(id);
  378. workflow.setStatus(2);//1是正在审批
  379. workflow.setType(3);//3是推文
  380. workflow.setCoverImg(articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0 ? articleTweetDto.getImages().get(0) : articleTweetDto.getVideo());
  381. int i = workflowService.insert(workflow);
  382. if (i <= 0) {
  383. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  384. put("message", "推文流程发布失败");
  385. put("code", 500);
  386. }}.toString());
  387. return null;
  388. }
  389. } catch (Exception e) {
  390. System.out.println("推文发布异常:" + e.getMessage());
  391. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  392. put("message", "推文发布异常");
  393. put("code", 500);
  394. }}.toString());
  395. return null;
  396. }
  397. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  398. put("message", "推文发布成功");
  399. put("code", 200);
  400. }}.toString());
  401. return null;
  402. }
  403. /**
  404. * 管理端修改推文
  405. */
  406. public String updateArticleTweetMana() throws ParseException {
  407. Gson gson = new Gson();
  408. JSONObject jsonObject = new JSONObject();
  409. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  410. ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {
  411. }.getType());
  412. //图片和视频判断
  413. if (articleTweetDto.getImages() == null && articleTweetDto.getVideo() == null) {
  414. jsonObject.put("code", 500);
  415. jsonObject.put("message", "请上传图片或视频");
  416. jsonObject.put("data", null);
  417. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  418. return null;
  419. }
  420. //图片最多上传九张
  421. if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 9) {
  422. jsonObject.put("code", 500);
  423. jsonObject.put("message", "最多上传9张图片");
  424. jsonObject.put("data", null);
  425. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  426. return null;
  427. }
  428. //标题、内容、地点、关联民宿不能为空
  429. if (Func.checkNull(articleTweetDto.getTitle()) || Func.checkNull(articleTweetDto.getContent())
  430. || Func.checkNull(articleTweetDto.getTownId()) || articleTweetDto.getHotelIds() == null
  431. || articleTweetDto.getCreateId() == null || articleTweetDto.getId()==null) {
  432. jsonObject.put("code", 500);
  433. jsonObject.put("message", "参数不能为空");
  434. jsonObject.put("data", null);
  435. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  436. return null;
  437. }
  438. //推文发布参数
  439. System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
  440. //查询当前用户
  441. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
  442. if (user == null) {
  443. jsonObject.put("code", 500);
  444. jsonObject.put("message", "用户信息已失效,查看详情失败");
  445. jsonObject.put("data", null);
  446. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  447. return null;
  448. }
  449. List<ArticleTweet> articleTweets = articleTweetService.queryTops();
  450. if (articleTweets!=null && articleTweets.size()>=3 && articleTweetDto.getIsTop()==1){
  451. List<Integer> ids = articleTweets.stream().map(ArticleTweet::getId).collect(Collectors.toList());
  452. if (!ids.contains(articleTweetDto.getId())){
  453. jsonObject.put("code", 500);
  454. jsonObject.put("message", "置顶攻略不可超过3个");
  455. jsonObject.put("data", null);
  456. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  457. return null;
  458. }
  459. }
  460. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  461. try {
  462. //添加推文
  463. ArticleTweet data = new ArticleTweet();
  464. data.setId(articleTweetDto.getId());
  465. data.setUserId(articleTweetDto.getCreateId());
  466. data.setTitle(articleTweetDto.getTitle());
  467. data.setContent(articleTweetDto.getContent());
  468. data.setLocationId(articleTweetDto.getTownId());
  469. data.setHotelId(StringUtils.join(articleTweetDto.getHotelIds(), ","));
  470. data.setCreateId(articleTweetDto.getCreateId());
  471. data.setCreateDate(now);
  472. data.setApprove(2);//1正在审批
  473. data.setStatus(1);
  474. data.setPublishWay("管理端");
  475. data.setIsTop(articleTweetDto.getIsTop());
  476. data.setUserName(user.getUser_name());
  477. data.setUserPhoto(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  478. int aId = articleTweetService.update(data);
  479. if (aId <= 0) {
  480. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  481. put("message", "推文发布失败");
  482. put("code", 500);
  483. }}.toString());
  484. return null;
  485. }
  486. articleTweetService.delArticleFile(articleTweetDto.getId());
  487. //添加附件
  488. List<String> fileStr = new ArrayList<>();
  489. if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0) {
  490. fileStr = articleTweetDto.getImages();
  491. }
  492. List<String> fileStrVideo = new ArrayList<>();
  493. if (articleTweetDto.getVideo() != null && articleTweetDto.getVideo().length() > 0) {
  494. fileStrVideo.add(articleTweetDto.getVideo());
  495. }
  496. List<ArticleFileInfo> afis = new ArrayList<>();
  497. for (String f : fileStr) {
  498. String[] split = f.split("/");
  499. String fileName = split[split.length - 1];
  500. ArticleFileInfo afi = new ArticleFileInfo();
  501. afi.setLinkId(aId);
  502. afi.setName(fileName);
  503. afi.setType(1);
  504. afi.setUrl(f);
  505. afi.setCreateDate(now);
  506. afi.setFileType(1);
  507. afis.add(afi);
  508. }
  509. for (String f : fileStrVideo) {
  510. String[] split = f.split("/");
  511. String fileName = split[split.length - 1];
  512. ArticleFileInfo afi = new ArticleFileInfo();
  513. afi.setLinkId(aId);
  514. afi.setName(fileName);
  515. afi.setType(1);
  516. afi.setUrl(f);
  517. afi.setCreateDate(now);
  518. afi.setFileType(2);
  519. afis.add(afi);
  520. }
  521. int length = articleTweetService.insertArticleFileBatch(afis);
  522. if (length <= 0) {
  523. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  524. put("message", "推文附件新增失败");
  525. put("code", 500);
  526. }}.toString());
  527. return null;
  528. }
  529. } catch (Exception e) {
  530. System.out.println("推文发布异常:" + e.getMessage());
  531. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  532. put("message", "推文发布异常");
  533. put("code", 500);
  534. }}.toString());
  535. return null;
  536. }
  537. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  538. put("message", "推文发布成功");
  539. put("code", 200);
  540. }}.toString());
  541. return null;
  542. }
  543. // 操作推文-删除文件
  544. public String delFile(){
  545. JSONObject jsonObject = new JSONObject();
  546. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  547. Integer id = json.getInteger("id");
  548. int m = articleTweetService.delArticleFileBatch(id);
  549. if (m>0){
  550. jsonObject.put("code", 200);
  551. jsonObject.put("message", "删除成功");
  552. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  553. return null;
  554. }
  555. jsonObject.put("code", 500);
  556. jsonObject.put("message", "删除失败");
  557. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  558. return null;
  559. }
  560. // 操作推文-增加文件
  561. public String addFile() throws ParseException {
  562. JSONObject jsonObject = new JSONObject();
  563. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  564. Integer id = json.getInteger("id");
  565. String images = json.getString("images");
  566. String video = json.getString("video");
  567. //图片和视频判断
  568. if (images.equals("") && video.equals("")) {
  569. jsonObject.put("code", 500);
  570. jsonObject.put("message", "请上传图片或视频");
  571. jsonObject.put("data", null);
  572. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  573. return null;
  574. }
  575. String fileStr = "";
  576. if (!images.equals("")) {
  577. fileStr=images;
  578. } else {
  579. fileStr=video;
  580. }
  581. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  582. String[] split = fileStr.split("/");
  583. String fileName = split[split.length - 1];
  584. ArticleFileInfo afi = new ArticleFileInfo();
  585. afi.setLinkId(id);
  586. afi.setName(fileName);
  587. afi.setType(1);
  588. afi.setUrl(fileStr);
  589. afi.setCreateDate(now);
  590. int length = articleTweetService.insertArticleFile(afi);
  591. if (length <= 0) {
  592. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  593. put("message", "新增失败");
  594. put("code", 500);
  595. put("data", null);
  596. }}.toString());
  597. return null;
  598. }
  599. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  600. put("message", "新增成功");
  601. put("code", 200);
  602. put("data", length);
  603. }}.toString());
  604. return null;
  605. }
  606. // 删除推文
  607. public String delArticle(){
  608. JSONObject jsonObject = new JSONObject();
  609. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  610. Integer id = json.getInteger("id");
  611. int m = articleTweetService.delArticle(id);
  612. int n = articleTweetService.delArticleFile(id);
  613. if (m>0 && n>0){
  614. jsonObject.put("code", 200);
  615. jsonObject.put("message", "删除成功");
  616. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  617. return null;
  618. }
  619. jsonObject.put("code", 500);
  620. jsonObject.put("message", "删除失败");
  621. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  622. return null;
  623. }
  624. // 置顶推文
  625. public String topArticle() throws ParseException {
  626. Gson gson = new Gson();
  627. JSONObject jsonObject = new JSONObject();
  628. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  629. ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {}.getType());
  630. List<ArticleTweet> articleTweets = articleTweetService.queryTops();
  631. if (articleTweets!=null && articleTweets.size()>=3 && articleTweetDto.getIsTop()==1){
  632. List<Integer> ids = articleTweets.stream().map(ArticleTweet::getId).collect(Collectors.toList());
  633. if (!ids.contains(articleTweetDto.getId())){
  634. jsonObject.put("code", 500);
  635. jsonObject.put("message", "置顶攻略不可超过3个");
  636. jsonObject.put("data", null);
  637. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  638. return null;
  639. }
  640. }
  641. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  642. articleTweetDto.setCreateDate(now);
  643. int m = articleTweetService.updateArticleTop(articleTweetDto);
  644. if (m>0){
  645. jsonObject.put("code", 200);
  646. jsonObject.put("message", "修改成功");
  647. jsonObject.put("data", null);
  648. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  649. return null;
  650. }
  651. jsonObject.put("code", 500);
  652. jsonObject.put("message", "修改失败");
  653. jsonObject.put("data", null);
  654. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  655. return null;
  656. }
  657. public String queryManageArticlePage() {
  658. JSONObject jsonObject = new JSONObject();
  659. IPage<ArticleListVo> result = articleTweetService.queryManageArticlesPage(articleTweetDto.getKeyWord(), null, page, rows);
  660. if (result.getPageList().size() > 0) {
  661. String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
  662. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  663. for (ArticleListVo data : result.getPageList()) {
  664. if (fileInfos != null) {
  665. List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  666. if (fileInfoList.size()>0) {
  667. List<String> fileUrl = new ArrayList<>();
  668. for (int i = 0; i < fileInfoList.size(); i++) {
  669. FileInfo fileInfo = fileInfoList.get(i);
  670. if (fileInfo.getFileType()==1){
  671. fileUrl.add(fileInfo.getUrl());
  672. data.setImage(fileUrl);
  673. } else {
  674. data.setVideo(fileInfo.getUrl());
  675. }
  676. }
  677. }
  678. }
  679. }
  680. }
  681. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  682. jsonObject.put("message", "请求成功");
  683. jsonObject.put("data", result);
  684. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  685. return null;
  686. }
  687. public String bindUser(){
  688. JSONObject jsonObject = new JSONObject();
  689. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  690. Admin admin = new Admin();
  691. admin.setId(json.getInteger("id"));
  692. admin.setUserId(json.getString("userId"));
  693. int m = articleTweetService.updateUser(admin);
  694. if (m>0){
  695. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  696. jsonObject.put("message", "绑定成功");
  697. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  698. return null;
  699. }
  700. jsonObject.put("code", 500);
  701. jsonObject.put("message", "绑定失败");
  702. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  703. return null;
  704. }
  705. /**
  706. * 根据推文数据ID查询推文详情数据
  707. *
  708. * @return
  709. */
  710. public String queryDetail() {
  711. JSONObject jsonObject = new JSONObject();
  712. //图片和视频判断
  713. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  714. jsonObject.put("code", 500);
  715. jsonObject.put("message", "推文ID或用户ID不能为空");
  716. jsonObject.put("data", null);
  717. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  718. return null;
  719. }
  720. //查询当前用户
  721. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
  722. if (user == null) {
  723. jsonObject.put("code", 500);
  724. jsonObject.put("message", "用户信息已失效,查看详情失败");
  725. jsonObject.put("data", null);
  726. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  727. return null;
  728. }
  729. //查询推文数据
  730. ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
  731. if (data == null) {
  732. jsonObject.put("code", 500);
  733. jsonObject.put("message", "推文数据已失效,查看详情失败");
  734. jsonObject.put("data", null);
  735. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  736. return null;
  737. }
  738. ArticleDetailVo result = new ArticleDetailVo();
  739. result.setIsCollect(data.getIsCollect());
  740. result.setId(data.getId());
  741. List<FileInfo> fileInfoList = articleTweetService.queryList("and link_id = '" + articleTweetDto.getId() + "'");
  742. if (fileInfoList != null && fileInfoList.size()>0) {
  743. List<String> fileUrl = new ArrayList<>();
  744. for (int i = 0; i < fileInfoList.size(); i++) {
  745. FileInfo fileInfo = fileInfoList.get(i);
  746. if (fileInfo.getFileType()==1){
  747. fileUrl.add(fileInfo.getUrl());
  748. result.setImages(fileUrl);
  749. } else {
  750. result.setVideo(fileInfo.getUrl());
  751. }
  752. }
  753. }
  754. result.setUserId(data.getUserId());
  755. result.setUserName(data.getUserName());
  756. result.setUserPhoto(data.getUserPhoto() == null ? ConstDefault.DefaultHeadPhoto : data.getUserPhoto());
  757. //region 关注
  758. if (articleTweetDto.getUserId().equals(data.getUserId())) {
  759. result.setIsFollow(2);//自己的推文
  760. } else {
  761. //是否关注
  762. UserCollect uc = articleTweetService.queryUserCollect(data.getUserId(), articleTweetDto.getUserId());
  763. result.setIsFollow(uc == null ? 0 : 1);//已关注给0;未关注给1
  764. }
  765. //endregion
  766. result.setTitle(data.getTitle());
  767. result.setContent(data.getContent());
  768. result.setDateStr(TimeExchange.DateToString(data.getCreateDate(), "yyyy-MM-dd"));
  769. result.setTownId(data.getLocationId());
  770. result.setTownName(data.getLocationName());
  771. //region 民宿列表
  772. //根据乡镇ID获取
  773. List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
  774. String sql = "id in (" + data.getHotelId() + ")";
  775. List<HotelVo> hotels = articleTweetService.queryHotels(sql);
  776. List<HotelListVo> hotelDatas = new ArrayList<>();
  777. //region 最低价
  778. List<Integer> managerIds = hotels.stream().map(HotelVo::getManagerId).collect(Collectors.toList());
  779. List<HotelPriceDataVo> prices = housePriceService.queryHotelPriceDatas(StringUtils.join(managerIds, ","), TimeExchange.getDateStr());
  780. List<HotelPriceOneDataVo> oneDatas = new ArrayList<>();
  781. //获取当天的
  782. for (HotelPriceDataVo hp : prices) {
  783. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  784. oneData.setSetDate(TimeExchange.getDateStr());
  785. oneData.setCreateDate(hp.getCreateDate());
  786. oneData.setPrice(hp.getPrice());
  787. oneData.setManagerId(hp.getManagerId());
  788. oneDatas.add(oneData);
  789. }
  790. /**
  791. * 根据房型ID处理重复的数据
  792. */
  793. List<HotelPriceOneDataVo> newOneDatas = new ArrayList<>();
  794. if (oneDatas.size() > 0) {
  795. for (Integer managerId : managerIds) {
  796. Optional<HotelPriceOneDataVo> one = oneDatas.stream().filter(e -> e.getManagerId().equals(managerId)).sorted(Comparator.comparing(HotelPriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
  797. if (one != null && one.isPresent()) {
  798. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  799. oneData.setSetDate(one.get().getSetDate());
  800. oneData.setCreateDate(one.get().getCreateDate());
  801. oneData.setPrice(one.get().getPrice());
  802. oneData.setManagerId(one.get().getManagerId());
  803. newOneDatas.add(oneData);
  804. }
  805. }
  806. }
  807. /**
  808. * 获取商家集合中最低房型价格
  809. */
  810. List<PriceHotelDataVo> mins = houseService.gethotelMinPrice(StringUtils.join(managerIds, ","));
  811. DecimalFormat decimalFormat = new DecimalFormat("#####.##");
  812. //endregion
  813. for (HotelVo hotel : hotels) {
  814. HotelListVo hotelData = new HotelListVo();
  815. hotelData.setId(hotel.getId());
  816. hotelData.setName(hotel.getName());
  817. hotelData.setScore(hotel.getScore());
  818. hotelData.setCoverImg(hotel.getCoverImg());
  819. hotelData.setComment(hotel.getComment());
  820. //是否收藏
  821. Optional<String> hotelId = hotelIds.stream().filter(e -> e.equals(hotel.getId().toString())).findFirst();
  822. if (hotelId != null && hotelId.isPresent()) {
  823. hotelData.setIsCollect(1);
  824. } else {
  825. hotelData.setIsCollect(0);
  826. }
  827. hotelData.setType(hotel.getType());
  828. //价格
  829. Optional<HotelPriceOneDataVo> one = newOneDatas.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  830. Optional<PriceHotelDataVo> min = mins.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  831. if (one != null && one.isPresent() && min != null && min.isPresent()) {
  832. if (one.get().getPrice() > min.get().getPrice()) {
  833. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  834. } else {
  835. hotelData.setPrice(decimalFormat.format(one.get().getPrice()));
  836. }
  837. } else {
  838. if (min != null && min.isPresent()) {
  839. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  840. }
  841. }
  842. hotelDatas.add(hotelData);
  843. }
  844. result.setHotels(hotelDatas);
  845. //endregion
  846. List<LikeListVo> likes = articleTweetService.queryArticleLikes(articleTweetDto.getId());
  847. if (likes != null && likes.size() > 0) {
  848. Optional<LikeListVo> ownerLikes = likes.stream().filter(e -> e.getId().equals(articleTweetDto.getUserId())).findFirst();
  849. if (ownerLikes != null && ownerLikes.isPresent()) {
  850. result.setIsLike(1);
  851. } else {
  852. result.setIsLike(0);
  853. }
  854. } else {
  855. result.setIsLike(0);
  856. }
  857. result.setLikes(likes == null ? new ArrayList<>() : likes.stream().map(LikeListVo::getImage).limit(10).collect(Collectors.toList()));
  858. result.setLikeNum(likes == null ? 0 : likes.size());
  859. List<ArticleCommentVo> comments = articleTweetService.queryArticleComment(articleTweetDto.getId());
  860. result.setComments(comments);
  861. int total = articleTweetService.queryArticleCommentTotal(articleTweetDto.getId());
  862. result.setCommentNum(total);
  863. result.setCollectNum(data.getCollectNum());
  864. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  865. jsonObject.put("message", "请求成功");
  866. jsonObject.put("data", result);
  867. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  868. return null;
  869. }
  870. /**
  871. * 点赞集合列表
  872. *
  873. * @return
  874. */
  875. public String queryLikes() {
  876. JSONObject jsonObject = new JSONObject();
  877. if (articleTweetDto.getId() == null) {
  878. jsonObject.put("code", 500);
  879. jsonObject.put("message", "推文ID不能为空");
  880. jsonObject.put("data", null);
  881. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  882. return null;
  883. }
  884. IPage<LikeListVo> result = articleTweetService.queryLikesPage(articleTweetDto.getId(), page, rows);
  885. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  886. jsonObject.put("message", "请求成功");
  887. jsonObject.put("data", result);
  888. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  889. return null;
  890. }
  891. /**
  892. * 获取推文详情中民宿分页列表
  893. */
  894. public String queryHotelList() {
  895. JSONObject jsonObject = new JSONObject();
  896. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  897. jsonObject.put("code", 500);
  898. jsonObject.put("message", "推文ID或用户ID不能为空");
  899. jsonObject.put("data", null);
  900. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  901. return null;
  902. }
  903. //查询当前用户
  904. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
  905. if (user == null) {
  906. jsonObject.put("code", 500);
  907. jsonObject.put("message", "用户信息已失效,查看详情失败");
  908. jsonObject.put("data", null);
  909. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  910. return null;
  911. }
  912. //查询推文数据
  913. ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
  914. if (data == null) {
  915. jsonObject.put("code", 500);
  916. jsonObject.put("message", "推文数据已失效,查看详情失败");
  917. jsonObject.put("data", null);
  918. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  919. return null;
  920. }
  921. //region 民宿列表
  922. //根据乡镇ID获取
  923. List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
  924. String sql = "id in (" + data.getHotelId() + ")";
  925. IPage<HotelVo> hotels = articleTweetService.queryHotelPageByHotleId(sql, page, rows);
  926. List<HotelListVo> hotelDatas = new ArrayList<>();
  927. //region 最低价
  928. List<Integer> managerIds = hotels.getPageList().stream().map(HotelVo::getManagerId).collect(Collectors.toList());
  929. List<HotelPriceDataVo> prices = housePriceService.queryHotelPriceDatas(StringUtils.join(managerIds, ","), TimeExchange.getDateStr());
  930. List<HotelPriceOneDataVo> oneDatas = new ArrayList<>();
  931. //获取当天的
  932. for (HotelPriceDataVo hp : prices) {
  933. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  934. oneData.setSetDate(TimeExchange.getDateStr());
  935. oneData.setCreateDate(hp.getCreateDate());
  936. oneData.setPrice(hp.getPrice());
  937. oneData.setManagerId(hp.getManagerId());
  938. oneDatas.add(oneData);
  939. }
  940. /**
  941. * 根据房型ID处理重复的数据
  942. */
  943. List<HotelPriceOneDataVo> newOneDatas = new ArrayList<>();
  944. if (oneDatas.size() > 0) {
  945. for (Integer managerId : managerIds) {
  946. Optional<HotelPriceOneDataVo> one = oneDatas.stream().filter(e -> e.getManagerId().equals(managerId)).sorted(Comparator.comparing(HotelPriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
  947. if (one != null && one.isPresent()) {
  948. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  949. oneData.setSetDate(one.get().getSetDate());
  950. oneData.setCreateDate(one.get().getCreateDate());
  951. oneData.setPrice(one.get().getPrice());
  952. oneData.setManagerId(one.get().getManagerId());
  953. newOneDatas.add(oneData);
  954. }
  955. }
  956. }
  957. /**
  958. * 获取商家集合中最低房型价格
  959. */
  960. List<PriceHotelDataVo> mins = houseService.gethotelMinPrice(StringUtils.join(managerIds, ","));
  961. DecimalFormat decimalFormat = new DecimalFormat("#####.##");
  962. //endregion
  963. for (HotelVo hotel : hotels.getPageList()) {
  964. HotelListVo hotelData = new HotelListVo();
  965. hotelData.setId(hotel.getId());
  966. hotelData.setName(hotel.getName());
  967. hotelData.setScore(hotel.getScore());
  968. hotelData.setCoverImg(hotel.getCoverImg());
  969. hotelData.setComment(hotel.getComment());
  970. //是否收藏
  971. Optional<String> hotelId = hotelIds.stream().filter(e -> e.equals(hotel.getId().toString())).findFirst();
  972. if (hotelId != null && hotelId.isPresent()) {
  973. hotelData.setIsCollect(1);
  974. } else {
  975. hotelData.setIsCollect(0);
  976. }
  977. hotelData.setType(hotel.getType());
  978. //价格
  979. Optional<HotelPriceOneDataVo> one = newOneDatas.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  980. Optional<PriceHotelDataVo> min = mins.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  981. if (one != null && one.isPresent() && min != null && min.isPresent()) {
  982. if (one.get().getPrice() > min.get().getPrice()) {
  983. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  984. } else {
  985. hotelData.setPrice(decimalFormat.format(one.get().getPrice()));
  986. }
  987. } else {
  988. if (min != null && min.isPresent()) {
  989. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  990. }
  991. }
  992. hotelDatas.add(hotelData);
  993. }
  994. //endregion
  995. IPage<HotelListVo> result = new IPage<>();
  996. result.setPage(hotels.getPage());
  997. result.setRows(hotels.getRows());
  998. result.setPageList(hotelDatas);
  999. result.setTotal(hotels.getTotal());
  1000. result.setTotalPage(hotels.getTotalPage());
  1001. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1002. jsonObject.put("message", "请求成功");
  1003. jsonObject.put("data", result);
  1004. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1005. return null;
  1006. }
  1007. /**
  1008. * 获取推文详情中评论分页列表
  1009. * 先获取一级评论 再区获取对应子级
  1010. */
  1011. public String queryCommentList() {
  1012. JSONObject jsonObject = new JSONObject();
  1013. //推文ID判断
  1014. if (articleTweetDto.getId() == null) {
  1015. jsonObject.put("code", 500);
  1016. jsonObject.put("message", "推文ID不能为空");
  1017. jsonObject.put("data", null);
  1018. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1019. return null;
  1020. }
  1021. //一级分页数据
  1022. IPage<ArticleCommentVo> result = articleTweetService.queryCommentPageByArticle(articleTweetDto.getId(), page, rows);
  1023. //子级评论数据
  1024. List<ArticleCommentVo> childs = articleTweetService.queryCommentsByArticle(articleTweetDto.getId());
  1025. if (childs != null && childs.size() > 0) {
  1026. for (ArticleCommentVo data : result.getPageList()) {
  1027. List<ArticleCommentVo> comments = QueryTreeDatas(data.getId(), data.getUserName(), childs);
  1028. data.setChildrens(comments);
  1029. }
  1030. }
  1031. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1032. jsonObject.put("message", "请求成功");
  1033. jsonObject.put("data", result);
  1034. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1035. return null;
  1036. }
  1037. //region 循环递归获取子级
  1038. /**
  1039. * 根据父类ID获取树形菜单数据
  1040. *
  1041. * @param parentID 父级ID
  1042. * @param lists 数据集合
  1043. * @return
  1044. */
  1045. private List<ArticleCommentVo> QueryTreeDatas(Integer parentID, String parentName, List<ArticleCommentVo> lists) {
  1046. List<ArticleCommentVo> newTrees = new ArrayList<>();
  1047. List<ArticleCommentVo> datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList());
  1048. for (ArticleCommentVo data : datas) {
  1049. data.setParentName(parentName);
  1050. List<ArticleCommentVo> news = QueryTreeDatas(data.getId(), data.getUserName(), lists);
  1051. if (news == null || news.size() == 0) {
  1052. newTrees.add(data);
  1053. continue;
  1054. } else {
  1055. data.setChildrens(news);
  1056. newTrees.add(data);
  1057. }
  1058. }
  1059. return newTrees;
  1060. }
  1061. //endregion
  1062. /**
  1063. * 根据用户ID获取个人主页相关信息
  1064. */
  1065. public String queryUserInfo() {
  1066. JSONObject jsonObject = new JSONObject();
  1067. //用户ID判断
  1068. if (articleTweetDto.getUserId() == null) {
  1069. jsonObject.put("code", 500);
  1070. jsonObject.put("message", "用户ID不能为空");
  1071. jsonObject.put("data", null);
  1072. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1073. return null;
  1074. }
  1075. articleUserVo result = articleTweetService.queryUserInfo(articleTweetDto.getUserId());
  1076. //region 关注
  1077. if (articleTweetDto.getUserId().equals(result.getId())) {
  1078. result.setIsFollow(2);//自己的推文
  1079. } else {
  1080. //是否关注
  1081. UserCollect uc = articleTweetService.queryUserCollect(result.getId(), articleTweetDto.getUserId());
  1082. result.setIsFollow(uc == null ? 0 : 1);//已关注给0;未关注给1
  1083. }
  1084. //endregion
  1085. if (result != null) {
  1086. String descript = "点击这里,填写简介";
  1087. result.setDescript(result.getDescript() == null ? descript : result.getDescript());
  1088. }
  1089. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1090. jsonObject.put("message", "请求成功");
  1091. jsonObject.put("data", result);
  1092. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1093. return null;
  1094. }
  1095. /**
  1096. * 根据用户ID获取用户主页推文列表分页数据
  1097. */
  1098. public String queryOwnerArticlePage() {
  1099. JSONObject jsonObject = new JSONObject();
  1100. //用户ID判断
  1101. if (articleTweetDto.getUserId() == null || articleTweetDto.getType() == null) {
  1102. jsonObject.put("code", 500);
  1103. jsonObject.put("message", "用户ID或类型ID不能为空");
  1104. jsonObject.put("data", null);
  1105. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1106. return null;
  1107. }
  1108. String sqlWhere = "";//全部推文
  1109. if (articleTweetDto.getType().intValue() == 1) {
  1110. sqlWhere = "and at.approve = 1 ";//审核中
  1111. } else if (articleTweetDto.getType().intValue() == 2) {
  1112. sqlWhere = "and at.approve = 3 ";//驳回
  1113. }
  1114. IPage<OwnerArticleVo> result = articleTweetService.queryOwnerArticlePage(articleTweetDto.getUserId(), sqlWhere, page, rows);
  1115. if (result.getPageList().size() > 0) {
  1116. String articleIds = StringUtils.join(result.getPageList().stream().map(OwnerArticleVo::getId).collect(Collectors.toList()), ",");
  1117. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  1118. for (OwnerArticleVo data : result.getPageList()) {
  1119. List<FileInfo> fileInfoList = fileInfos == null ? null : fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  1120. if (fileInfoList != null && fileInfoList.size()>0) {
  1121. for (int i = 0; i < fileInfoList.size(); i++) {
  1122. FileInfo fileInfo = fileInfoList.get(i);
  1123. List<String> fileUrl = new ArrayList<>();
  1124. if (fileInfo.getFileType()==1){
  1125. fileUrl.add(fileInfo.getUrl());
  1126. data.setImages(fileUrl);
  1127. }else {
  1128. data.setVideo(fileInfo.getUrl());
  1129. }
  1130. }
  1131. }
  1132. }
  1133. }
  1134. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1135. jsonObject.put("message", "请求成功");
  1136. jsonObject.put("data", result);
  1137. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1138. return null;
  1139. }
  1140. public String getUserContactList() {
  1141. JSONObject jsonObject = new JSONObject();
  1142. if (adminId == null ){
  1143. jsonObject.put("code", 500);
  1144. jsonObject.put("message", "请传入管理员ID");
  1145. jsonObject.put("data", null);
  1146. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1147. return null;
  1148. }
  1149. Admin admin = adminService.getById(Integer.parseInt(adminId));
  1150. if (admin==null || admin.getStatus()==0){
  1151. jsonObject.put("code", 500);
  1152. jsonObject.put("message", "该管理员已删除");
  1153. jsonObject.put("data", null);
  1154. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1155. return null;
  1156. }
  1157. StringBuilder querySql = new StringBuilder("");
  1158. if (!Func.checkNull(articleTweetDto.getUserName())) {
  1159. querySql.append(" and user_name like '%").append(articleTweetDto.getUserName()).append("%' ");
  1160. }
  1161. querySql.append(" and data_type = '").append(DataType.游客数据.toString()).append("' ");
  1162. if (admin.getUserId()!=null && !admin.getUserId().equals("")){
  1163. querySql.append(" and id in ( ").append(admin.getUserId()).append(") ");
  1164. }
  1165. IPage listPage = userService.queryUserPage(querySql.toString(), page, rows); // 查询分页
  1166. ResponseUtil.writeJsonIPage(ServletActionContext.getResponse(), listPage);
  1167. return null;
  1168. }
  1169. /**
  1170. * 社区首页推文列表
  1171. */
  1172. public String queryArticlePage() {
  1173. JSONObject jsonObject = new JSONObject();
  1174. if (articleTweetDto.getType() == null) {
  1175. jsonObject.put("code", 500);
  1176. jsonObject.put("message", "推文列表类型不能为空");
  1177. jsonObject.put("data", null);
  1178. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1179. return null;
  1180. }
  1181. if (articleTweetDto.getUserId() == null) {
  1182. jsonObject.put("code", 500);
  1183. jsonObject.put("message", "用户ID不能为空");
  1184. jsonObject.put("data", null);
  1185. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1186. return null;
  1187. }
  1188. IPage<ArticleListVo> result = articleTweetService.queryArticlesPage(articleTweetDto.getKeyWord(), articleTweetDto.getTownId().equals("") ? null : articleTweetDto.getTownId(), articleTweetDto.getUserId(), articleTweetDto.getType(), page, rows);
  1189. if (result.getPageList().size() > 0) {
  1190. String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
  1191. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  1192. for (ArticleListVo data : result.getPageList()) {
  1193. if (fileInfos != null) {
  1194. List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  1195. if (fileInfoList.size() > 0) {
  1196. List<String> fileUrl = new ArrayList<>();
  1197. for (int i = 0; i < fileInfoList.size(); i++) {
  1198. FileInfo fileInfo = fileInfoList.get(i);
  1199. if (fileInfo.getFileType()==1){
  1200. fileUrl.add(fileInfo.getUrl());
  1201. data.setImage(fileUrl);
  1202. } else {
  1203. data.setVideo(fileInfo.getUrl());
  1204. }
  1205. }
  1206. }
  1207. }
  1208. }
  1209. }
  1210. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1211. jsonObject.put("message", "请求成功");
  1212. jsonObject.put("data", result);
  1213. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1214. return null;
  1215. }
  1216. /**
  1217. * 点赞数最高的推文
  1218. */
  1219. public String queryMaxArticleLike() {
  1220. JSONObject jsonObject = new JSONObject();
  1221. ArticleLikeMaxVo result = articleTweetService.queryMaxArticleLike();
  1222. if (result != null) {
  1223. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id = " + result.getId() + "");
  1224. if (fileInfos != null) {
  1225. for (int i = 0; i < fileInfos.size(); i++) {
  1226. FileInfo fileInfo = fileInfos.get(i);
  1227. if (fileInfo.getFileType()==1){
  1228. result.setImage(fileInfo.getUrl());
  1229. } else {
  1230. result.setVideo(fileInfo.getUrl());
  1231. }
  1232. }
  1233. }
  1234. }
  1235. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1236. jsonObject.put("message", "请求成功");
  1237. jsonObject.put("data", result);
  1238. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1239. return null;
  1240. }
  1241. /**
  1242. * 相关推文
  1243. */
  1244. public String relatedTweets() {
  1245. JSONObject jsonObject = new JSONObject();
  1246. if (articleTweetDto.getId() == null || articleTweetDto.getTownId() == null || articleTweetDto.getUserId() == null) {
  1247. jsonObject.put("code", 500);
  1248. jsonObject.put("message", "乡镇ID或推文ID或用户ID不能为空");
  1249. jsonObject.put("data", null);
  1250. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1251. return null;
  1252. }
  1253. IPage<ArticleListVo> result = articleTweetService.relatedTweetPage(articleTweetDto.getUserId(), articleTweetDto.getTownId(), articleTweetDto.getId(), page, rows);
  1254. if (result.getPageList().size() > 0) {
  1255. String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
  1256. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  1257. for (ArticleListVo data : result.getPageList()) {
  1258. List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  1259. if (fileInfoList.size() > 0) {
  1260. List<String> fileUrl = new ArrayList<>();
  1261. for (int i = 0; i < fileInfoList.size(); i++) {
  1262. FileInfo fileInfo = fileInfoList.get(i);
  1263. if (fileInfo.getFileType()==1){
  1264. fileUrl.add(fileInfo.getUrl());
  1265. data.setImage(fileUrl);
  1266. } else {
  1267. data.setVideo(fileInfo.getUrl());
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1274. jsonObject.put("message", "请求成功");
  1275. jsonObject.put("data", result);
  1276. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1277. return null;
  1278. }
  1279. //select * from article_tweet where location_id = '' and user_id != 1 and approve = 2
  1280. /**
  1281. * 收藏文章
  1282. */
  1283. public String collectArticle() throws ParseException {
  1284. JSONObject jsonObject = new JSONObject();
  1285. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  1286. jsonObject.put("code", 500);
  1287. jsonObject.put("message", "用户ID或推文ID不能为空");
  1288. jsonObject.put("data", null);
  1289. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1290. return null;
  1291. }
  1292. //查询当前操作人是否已经收藏过这篇文章
  1293. ArticleCollect data = articleTweetService.queryArticleCollect(articleTweetDto.getId(), articleTweetDto.getUserId());
  1294. String actionStr = "收藏";
  1295. if (data != null) {
  1296. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  1297. actionStr = "取消收藏";
  1298. data.setIsLose(1);
  1299. } else {
  1300. data.setIsLose(0);
  1301. }
  1302. } else {
  1303. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  1304. data = new ArticleCollect();
  1305. data.setArticleId(articleTweetDto.getId());
  1306. data.setUserId(articleTweetDto.getUserId());
  1307. data.setIsLose(0);
  1308. data.setCreateId(articleTweetDto.getUserId());
  1309. data.setCreateDate(now);
  1310. data.setStatus(1);
  1311. }
  1312. int m = articleTweetService.updateArticleCollect(data);
  1313. if (m <= 0) {
  1314. String message = actionStr + "失败";
  1315. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1316. put("message", message);
  1317. put("code", 500);
  1318. }}.toString());
  1319. return null;
  1320. }
  1321. String successMessage = actionStr + "成功";
  1322. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1323. put("message", successMessage);
  1324. put("code", 200);
  1325. }}.toString());
  1326. return null;
  1327. }
  1328. /**
  1329. * 评论文章
  1330. */
  1331. public String commentArticle() throws ParseException {
  1332. Gson gson = new Gson();
  1333. JSONObject jsonObject = new JSONObject();
  1334. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  1335. ArticleCommentDto articleCommentDto = gson.fromJson(json.toString(), new TypeToken<ArticleCommentDto>() {
  1336. }.getType());
  1337. if (articleCommentDto.getArticleId() == null || Func.checkNull(articleCommentDto.getContent())
  1338. || articleCommentDto.getParentId() == null || articleCommentDto.getUserId() == null) {
  1339. jsonObject.put("code", 500);
  1340. jsonObject.put("message", "参数不能为空");
  1341. jsonObject.put("data", null);
  1342. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1343. return null;
  1344. }
  1345. //查询操作人身份
  1346. Users user = userService.queryByUserId(String.valueOf(articleCommentDto.getUserId()));
  1347. if (user == null) {
  1348. jsonObject.put("code", 500);
  1349. jsonObject.put("message", "用户信息已失效,评论失败");
  1350. jsonObject.put("data", null);
  1351. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1352. return null;
  1353. }
  1354. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  1355. ArticleComment articleComment = new ArticleComment();
  1356. articleComment.setArticleId(articleCommentDto.getArticleId());
  1357. articleComment.setCommentParentId(articleCommentDto.getParentId());
  1358. articleComment.setCommentId(articleCommentDto.getUserId());
  1359. articleComment.setCommentName(user.getUser_name());
  1360. articleComment.setCommentImage(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  1361. articleComment.setContent(articleCommentDto.getContent());
  1362. articleComment.setCreateId(articleCommentDto.getUserId());
  1363. articleComment.setCreateDate(now);
  1364. articleComment.setStatus(1);
  1365. int num = articleTweetService.insertArticleComment(articleComment);
  1366. if (num <= 0) {
  1367. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1368. put("message", "评论失败");
  1369. put("code", 500);
  1370. }}.toString());
  1371. return null;
  1372. }
  1373. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1374. put("message", "评论成功");
  1375. put("code", 200);
  1376. }}.toString());
  1377. return null;
  1378. }
  1379. /**
  1380. * 关注作者
  1381. */
  1382. public String followAuthor() throws ParseException {
  1383. JSONObject jsonObject = new JSONObject();
  1384. if (articleTweetDto.getAuthorId() == null || articleTweetDto.getUserId() == null) {
  1385. jsonObject.put("code", 500);
  1386. jsonObject.put("message", "作者ID或用户ID不能为空");
  1387. jsonObject.put("data", null);
  1388. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1389. return null;
  1390. }
  1391. //查询当前操作人是否已经关注过作者
  1392. UserCollect data = articleTweetService.queryUserCollectNoLose(articleTweetDto.getAuthorId(), articleTweetDto.getUserId());
  1393. String actionStr = "关注";
  1394. if (data != null) {
  1395. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  1396. actionStr = "取消关注";
  1397. data.setIsLose(1);
  1398. } else {
  1399. data.setIsLose(0);
  1400. }
  1401. } else {
  1402. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  1403. data = new UserCollect();
  1404. data.setParentUserid(articleTweetDto.getAuthorId());
  1405. data.setUserId(articleTweetDto.getUserId());
  1406. data.setIsLose(0);
  1407. data.setCreateId(articleTweetDto.getUserId());
  1408. data.setCreateDate(now);
  1409. data.setStatus(1);
  1410. }
  1411. int m = articleTweetService.updateUserCollect(data);
  1412. if (m <= 0) {
  1413. String message = actionStr + "失败";
  1414. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1415. put("message", message);
  1416. put("code", 500);
  1417. }}.toString());
  1418. return null;
  1419. }
  1420. String successMessage = actionStr + "成功";
  1421. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1422. put("message", successMessage);
  1423. put("code", 200);
  1424. }}.toString());
  1425. return null;
  1426. }
  1427. /**
  1428. * 点赞文章
  1429. */
  1430. public String likeArticle() throws ParseException {
  1431. JSONObject jsonObject = new JSONObject();
  1432. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  1433. jsonObject.put("code", 500);
  1434. jsonObject.put("message", "用户ID或推文ID不能为空");
  1435. jsonObject.put("data", null);
  1436. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1437. return null;
  1438. }
  1439. //查询操作人身份
  1440. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
  1441. if (user == null) {
  1442. jsonObject.put("code", 500);
  1443. jsonObject.put("message", "用户信息已失效,评论失败");
  1444. jsonObject.put("data", null);
  1445. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1446. return null;
  1447. }
  1448. //查询当前操作人是否已经收藏过这篇文章
  1449. ArticleLikes data = articleTweetService.queryArticleLike(articleTweetDto.getId(), articleTweetDto.getUserId());
  1450. String actionStr = "点赞";
  1451. if (data != null) {
  1452. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  1453. actionStr = "取消点赞";
  1454. data.setIsLose(1);
  1455. } else {
  1456. data.setIsLose(0);
  1457. }
  1458. } else {
  1459. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  1460. data = new ArticleLikes();
  1461. data.setArticleId(articleTweetDto.getId());
  1462. data.setLikeId(articleTweetDto.getUserId());
  1463. data.setLikeName(user.getUser_name());
  1464. data.setLikeImage(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  1465. data.setIsLose(0);
  1466. data.setCreateId(articleTweetDto.getUserId());
  1467. data.setCreateDate(now);
  1468. data.setStatus(1);
  1469. }
  1470. int m = articleTweetService.updateArticleLike(data);
  1471. if (m <= 0) {
  1472. String message = actionStr + "失败";
  1473. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1474. put("message", message);
  1475. put("code", 500);
  1476. }}.toString());
  1477. return null;
  1478. }
  1479. String successMessage = actionStr + "成功";
  1480. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1481. put("message", successMessage);
  1482. put("code", 200);
  1483. }}.toString());
  1484. return null;
  1485. }
  1486. /**
  1487. * 获取乡镇列表
  1488. */
  1489. public String townShips() {
  1490. List<HotelDict> hotelDicts = hotelDictService.queryList("and code = 10");
  1491. List<TownshipVo> result = new ArrayList<>();
  1492. for (HotelDict hotelDict : hotelDicts) {
  1493. TownshipVo data = new TownshipVo();
  1494. data.setId(hotelDict.getId());
  1495. data.setName(hotelDict.getName());
  1496. result.add(data);
  1497. }
  1498. JSONObject jsonObject = new JSONObject();
  1499. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1500. jsonObject.put("message", "请求成功");
  1501. jsonObject.put("data", result);
  1502. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1503. return null;
  1504. }
  1505. /**
  1506. * 根据乡镇ID获取民宿列表
  1507. */
  1508. public String hotelByid() {
  1509. JSONObject jsonObject = new JSONObject();
  1510. if (Func.checkNull(articleTweetDto.getTownId())) {
  1511. jsonObject.put("code", ResultStatusCode.BAD_REQUEST.getStatus());
  1512. jsonObject.put("message", ResultStatusCode.BAD_REQUEST.getMsg());
  1513. jsonObject.put("data", null);
  1514. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1515. return null;
  1516. }
  1517. String sql = "hotel_township = '" + articleTweetDto.getTownId() + "'";
  1518. IPage<HotelVo> houseIPage = articleTweetService.queryHotelPage(sql, page, rows);
  1519. jsonObject.put("message", "查询分页成功");
  1520. jsonObject.put("code", 200);
  1521. jsonObject.put("data", houseIPage);
  1522. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1523. return null;
  1524. }
  1525. /**
  1526. * 修改用户简介
  1527. */
  1528. public String updateDescript() {
  1529. JSONObject jsonObject = new JSONObject();
  1530. if (articleTweetDto.getAuthorId() == null || articleTweetDto.getUserId() == null || Func.checkNull(articleTweetDto.getDescript())) {
  1531. jsonObject.put("code", 500);
  1532. jsonObject.put("message", "操作用户ID或主页用户ID或简介不能为空");
  1533. jsonObject.put("data", null);
  1534. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1535. return null;
  1536. }
  1537. if (!articleTweetDto.getAuthorId().equals(articleTweetDto.getUserId())) {
  1538. jsonObject.put("code", 500);
  1539. jsonObject.put("message", "当前用户无法修改其他人的简介信息");
  1540. jsonObject.put("data", null);
  1541. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1542. return null;
  1543. }
  1544. int num = articleTweetService.updateDescript(articleTweetDto.getAuthorId(), articleTweetDto.getDescript());
  1545. jsonObject.put("message", "修改成功");
  1546. jsonObject.put("code", 200);
  1547. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1548. return null;
  1549. }
  1550. /**
  1551. * 攻略分页
  1552. *
  1553. * @return
  1554. */
  1555. public String walkthroughPage() {
  1556. JSONObject jsonObject = new JSONObject();
  1557. StringBuilder strSql = new StringBuilder(" and at.status=1 "); // 推文没删除才显示
  1558. if (!Func.checkNull(key)) {
  1559. strSql.append(" and (at.user_name like '%").append(key).append("%' or at.title like '%").append(key).append("%') ");
  1560. }
  1561. if (!Func.checkNull(startTime) && !Func.checkNull(endTime)) {
  1562. strSql.append(" and at.create_date >= '").append(startTime).append("' ");
  1563. strSql.append(" and at.create_date <= '").append(endTime).append("' ");
  1564. }
  1565. IPage<WalkthroughVo> walkthroughPage = articleTweetService.walkthroughPage(strSql.toString(), page, rows);
  1566. jsonObject.put("message", "查询分页成功");
  1567. jsonObject.put("code", 200);
  1568. jsonObject.put("data", walkthroughPage);
  1569. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1570. return null;
  1571. }
  1572. /**
  1573. * 商品页面
  1574. */
  1575. public String productPage() throws Exception {
  1576. JSONObject jsonObject = new JSONObject();
  1577. // JSONObject jsonBody = new JSONObject();
  1578. // jsonBody.put("username", "admin");
  1579. // jsonBody.put("password", "123456");
  1580. //
  1581. // String url = "https://www.jinganrenjiams.com/cloud-mall/admin/open/login";
  1582. //
  1583. // 构建http请求客户端
  1584. // HttpClient httpclient = HttpClientBuilder.create().useSystemProperties().build();
  1585. // // 构建post请求
  1586. // HttpPost postMethod = new HttpPost(url);
  1587. // // 设置请求头
  1588. // postMethod.addHeader("Content-Type", "application/json");
  1589. // // 设置请求体
  1590. // postMethod.setEntity(new StringEntity(jsonBody.toString()));
  1591. //
  1592. // // 发送请求
  1593. // HttpResponse response = httpclient.execute(postMethod);
  1594. //
  1595. // String s = EntityUtils.toString(response.getEntity());
  1596. //
  1597. // JSONObject postJson = JSONObject.parseObject(s);
  1598. //
  1599. // JSONObject data = postJson.getJSONObject("data");
  1600. //
  1601. // String token = data.getString("token");
  1602. // 构建http请求客户端
  1603. HttpClient httpclient = HttpClientBuilder.create().useSystemProperties().build();
  1604. String getUrl = "";
  1605. if (!Func.checkNull(key)) {
  1606. getUrl = "https://www.jinganrenjiams.com/cloud-mall/goods/open/page?state=1&curPage="+page+"&pageSize="+rows+"&goodsName=" + key;
  1607. } else {
  1608. getUrl = "https://www.jinganrenjiams.com/cloud-mall/goods/open/page?state=1&curPage="+page+"&pageSize="+rows;
  1609. }
  1610. HttpGet httpGet = new HttpGet(getUrl);
  1611. // 设置请求头
  1612. httpGet.addHeader("Content-Type", "application/json");
  1613. // httpGet.addHeader("Mall-Token", token);
  1614. // 发送请求
  1615. HttpResponse execute = httpclient.execute(httpGet);
  1616. String s1 = EntityUtils.toString(execute.getEntity());
  1617. JSONObject getJson = JSONObject.parseObject(s1);
  1618. JSONObject data1 = getJson.getJSONObject("data");
  1619. jsonObject.put("message", "查询分页成功");
  1620. jsonObject.put("code", 200);
  1621. jsonObject.put("data", data1);
  1622. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1623. return null;
  1624. }
  1625. /**
  1626. * 点赞数前三的推文
  1627. */
  1628. public String queryTop3ArticleLike() {
  1629. JSONObject jsonObject = new JSONObject();
  1630. List<ArticleLikeMaxVo> result = articleTweetService.queryTop3ArticleLike();
  1631. if (result != null) {
  1632. for (int i = 0; i < result.size(); i++) {
  1633. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id = " + result.get(i).getId() + "");
  1634. if (fileInfos != null) {
  1635. for (int j = 0; j < fileInfos.size(); j++) {
  1636. FileInfo fileInfo = fileInfos.get(j);
  1637. if (fileInfo.getFileType()==1){
  1638. result.get(i).setImage(fileInfo.getUrl());
  1639. } else {
  1640. result.get(i).setVideo(fileInfo.getUrl());
  1641. }
  1642. }
  1643. }
  1644. }
  1645. }
  1646. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1647. jsonObject.put("message", "请求成功");
  1648. jsonObject.put("data", result);
  1649. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1650. return null;
  1651. }
  1652. }