articleTweetAction.java 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  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. if(hotels != null){
  777. List<HotelListVo> hotelDatas = new ArrayList<>();
  778. //region 最低价
  779. List<Integer> managerIds = hotels == null ? new ArrayList<>() : hotels.stream().map(HotelVo::getManagerId).collect(Collectors.toList());
  780. List<HotelPriceDataVo> prices = housePriceService.queryHotelPriceDatas(StringUtils.join(managerIds, ","), TimeExchange.getDateStr());
  781. List<HotelPriceOneDataVo> oneDatas = new ArrayList<>();
  782. //获取当天的
  783. for (HotelPriceDataVo hp : prices) {
  784. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  785. oneData.setSetDate(TimeExchange.getDateStr());
  786. oneData.setCreateDate(hp.getCreateDate());
  787. oneData.setPrice(hp.getPrice());
  788. oneData.setManagerId(hp.getManagerId());
  789. oneDatas.add(oneData);
  790. }
  791. /**
  792. * 根据房型ID处理重复的数据
  793. */
  794. List<HotelPriceOneDataVo> newOneDatas = new ArrayList<>();
  795. if (oneDatas.size() > 0) {
  796. for (Integer managerId : managerIds) {
  797. Optional<HotelPriceOneDataVo> one = oneDatas.stream().filter(e -> e.getManagerId().equals(managerId)).sorted(Comparator.comparing(HotelPriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
  798. if (one != null && one.isPresent()) {
  799. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  800. oneData.setSetDate(one.get().getSetDate());
  801. oneData.setCreateDate(one.get().getCreateDate());
  802. oneData.setPrice(one.get().getPrice());
  803. oneData.setManagerId(one.get().getManagerId());
  804. newOneDatas.add(oneData);
  805. }
  806. }
  807. }
  808. /**
  809. * 获取商家集合中最低房型价格
  810. */
  811. List<PriceHotelDataVo> mins = houseService.gethotelMinPrice(StringUtils.join(managerIds, ","));
  812. DecimalFormat decimalFormat = new DecimalFormat("#####.##");
  813. //endregion
  814. for (HotelVo hotel : hotels) {
  815. HotelListVo hotelData = new HotelListVo();
  816. hotelData.setId(hotel.getId());
  817. hotelData.setName(hotel.getName());
  818. hotelData.setScore(hotel.getScore());
  819. hotelData.setCoverImg(hotel.getCoverImg());
  820. hotelData.setComment(hotel.getComment());
  821. //是否收藏
  822. Optional<String> hotelId = hotelIds.stream().filter(e -> e.equals(hotel.getId().toString())).findFirst();
  823. if (hotelId != null && hotelId.isPresent()) {
  824. hotelData.setIsCollect(1);
  825. } else {
  826. hotelData.setIsCollect(0);
  827. }
  828. hotelData.setType(hotel.getType());
  829. //价格
  830. Optional<HotelPriceOneDataVo> one = newOneDatas.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  831. Optional<PriceHotelDataVo> min = mins.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  832. if (one != null && one.isPresent() && min != null && min.isPresent()) {
  833. if (one.get().getPrice() > min.get().getPrice()) {
  834. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  835. } else {
  836. hotelData.setPrice(decimalFormat.format(one.get().getPrice()));
  837. }
  838. } else {
  839. if (min != null && min.isPresent()) {
  840. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  841. }
  842. }
  843. hotelDatas.add(hotelData);
  844. }
  845. result.setHotels(hotelDatas);
  846. }
  847. //endregion
  848. List<LikeListVo> likes = articleTweetService.queryArticleLikes(articleTweetDto.getId());
  849. if (likes != null && likes.size() > 0) {
  850. Optional<LikeListVo> ownerLikes = likes.stream().filter(e -> e.getId().equals(articleTweetDto.getUserId())).findFirst();
  851. if (ownerLikes != null && ownerLikes.isPresent()) {
  852. result.setIsLike(1);
  853. } else {
  854. result.setIsLike(0);
  855. }
  856. } else {
  857. result.setIsLike(0);
  858. }
  859. result.setLikes(likes == null ? new ArrayList<>() : likes.stream().map(LikeListVo::getImage).limit(10).collect(Collectors.toList()));
  860. result.setLikeNum(likes == null ? 0 : likes.size());
  861. List<ArticleCommentVo> comments = articleTweetService.queryArticleComment(articleTweetDto.getId());
  862. result.setComments(comments);
  863. int total = articleTweetService.queryArticleCommentTotal(articleTweetDto.getId());
  864. result.setCommentNum(total);
  865. result.setCollectNum(data.getCollectNum());
  866. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  867. jsonObject.put("message", "请求成功");
  868. jsonObject.put("data", result);
  869. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  870. return null;
  871. }
  872. /**
  873. * 点赞集合列表
  874. *
  875. * @return
  876. */
  877. public String queryLikes() {
  878. JSONObject jsonObject = new JSONObject();
  879. if (articleTweetDto.getId() == null) {
  880. jsonObject.put("code", 500);
  881. jsonObject.put("message", "推文ID不能为空");
  882. jsonObject.put("data", null);
  883. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  884. return null;
  885. }
  886. IPage<LikeListVo> result = articleTweetService.queryLikesPage(articleTweetDto.getId(), page, rows);
  887. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  888. jsonObject.put("message", "请求成功");
  889. jsonObject.put("data", result);
  890. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  891. return null;
  892. }
  893. /**
  894. * 获取推文详情中民宿分页列表
  895. */
  896. public String queryHotelList() {
  897. JSONObject jsonObject = new JSONObject();
  898. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  899. jsonObject.put("code", 500);
  900. jsonObject.put("message", "推文ID或用户ID不能为空");
  901. jsonObject.put("data", null);
  902. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  903. return null;
  904. }
  905. //查询当前用户
  906. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
  907. if (user == null) {
  908. jsonObject.put("code", 500);
  909. jsonObject.put("message", "用户信息已失效,查看详情失败");
  910. jsonObject.put("data", null);
  911. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  912. return null;
  913. }
  914. //查询推文数据
  915. ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
  916. if (data == null) {
  917. jsonObject.put("code", 500);
  918. jsonObject.put("message", "推文数据已失效,查看详情失败");
  919. jsonObject.put("data", null);
  920. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  921. return null;
  922. }
  923. //region 民宿列表
  924. //根据乡镇ID获取
  925. List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
  926. String sql = "id in (" + data.getHotelId() + ")";
  927. IPage<HotelVo> hotels = articleTweetService.queryHotelPageByHotleId(sql, page, rows);
  928. List<HotelListVo> hotelDatas = new ArrayList<>();
  929. //region 最低价
  930. List<Integer> managerIds = hotels.getPageList().stream().map(HotelVo::getManagerId).collect(Collectors.toList());
  931. List<HotelPriceDataVo> prices = housePriceService.queryHotelPriceDatas(StringUtils.join(managerIds, ","), TimeExchange.getDateStr());
  932. List<HotelPriceOneDataVo> oneDatas = new ArrayList<>();
  933. //获取当天的
  934. for (HotelPriceDataVo hp : prices) {
  935. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  936. oneData.setSetDate(TimeExchange.getDateStr());
  937. oneData.setCreateDate(hp.getCreateDate());
  938. oneData.setPrice(hp.getPrice());
  939. oneData.setManagerId(hp.getManagerId());
  940. oneDatas.add(oneData);
  941. }
  942. /**
  943. * 根据房型ID处理重复的数据
  944. */
  945. List<HotelPriceOneDataVo> newOneDatas = new ArrayList<>();
  946. if (oneDatas.size() > 0) {
  947. for (Integer managerId : managerIds) {
  948. Optional<HotelPriceOneDataVo> one = oneDatas.stream().filter(e -> e.getManagerId().equals(managerId)).sorted(Comparator.comparing(HotelPriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
  949. if (one != null && one.isPresent()) {
  950. HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
  951. oneData.setSetDate(one.get().getSetDate());
  952. oneData.setCreateDate(one.get().getCreateDate());
  953. oneData.setPrice(one.get().getPrice());
  954. oneData.setManagerId(one.get().getManagerId());
  955. newOneDatas.add(oneData);
  956. }
  957. }
  958. }
  959. /**
  960. * 获取商家集合中最低房型价格
  961. */
  962. List<PriceHotelDataVo> mins = houseService.gethotelMinPrice(StringUtils.join(managerIds, ","));
  963. DecimalFormat decimalFormat = new DecimalFormat("#####.##");
  964. //endregion
  965. for (HotelVo hotel : hotels.getPageList()) {
  966. HotelListVo hotelData = new HotelListVo();
  967. hotelData.setId(hotel.getId());
  968. hotelData.setName(hotel.getName());
  969. hotelData.setScore(hotel.getScore());
  970. hotelData.setCoverImg(hotel.getCoverImg());
  971. hotelData.setComment(hotel.getComment());
  972. //是否收藏
  973. Optional<String> hotelId = hotelIds.stream().filter(e -> e.equals(hotel.getId().toString())).findFirst();
  974. if (hotelId != null && hotelId.isPresent()) {
  975. hotelData.setIsCollect(1);
  976. } else {
  977. hotelData.setIsCollect(0);
  978. }
  979. hotelData.setType(hotel.getType());
  980. //价格
  981. Optional<HotelPriceOneDataVo> one = newOneDatas.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  982. Optional<PriceHotelDataVo> min = mins.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
  983. if (one != null && one.isPresent() && min != null && min.isPresent()) {
  984. if (one.get().getPrice() > min.get().getPrice()) {
  985. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  986. } else {
  987. hotelData.setPrice(decimalFormat.format(one.get().getPrice()));
  988. }
  989. } else {
  990. if (min != null && min.isPresent()) {
  991. hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
  992. }
  993. }
  994. hotelDatas.add(hotelData);
  995. }
  996. //endregion
  997. IPage<HotelListVo> result = new IPage<>();
  998. result.setPage(hotels.getPage());
  999. result.setRows(hotels.getRows());
  1000. result.setPageList(hotelDatas);
  1001. result.setTotal(hotels.getTotal());
  1002. result.setTotalPage(hotels.getTotalPage());
  1003. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1004. jsonObject.put("message", "请求成功");
  1005. jsonObject.put("data", result);
  1006. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1007. return null;
  1008. }
  1009. /**
  1010. * 获取推文详情中评论分页列表
  1011. * 先获取一级评论 再区获取对应子级
  1012. */
  1013. public String queryCommentList() {
  1014. JSONObject jsonObject = new JSONObject();
  1015. //推文ID判断
  1016. if (articleTweetDto.getId() == null) {
  1017. jsonObject.put("code", 500);
  1018. jsonObject.put("message", "推文ID不能为空");
  1019. jsonObject.put("data", null);
  1020. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1021. return null;
  1022. }
  1023. //一级分页数据
  1024. IPage<ArticleCommentVo> result = articleTweetService.queryCommentPageByArticle(articleTweetDto.getId(), page, rows);
  1025. //子级评论数据
  1026. List<ArticleCommentVo> childs = articleTweetService.queryCommentsByArticle(articleTweetDto.getId());
  1027. if (childs != null && childs.size() > 0) {
  1028. for (ArticleCommentVo data : result.getPageList()) {
  1029. List<ArticleCommentVo> comments = QueryTreeDatas(data.getId(), data.getUserName(), childs);
  1030. data.setChildrens(comments);
  1031. }
  1032. }
  1033. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1034. jsonObject.put("message", "请求成功");
  1035. jsonObject.put("data", result);
  1036. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1037. return null;
  1038. }
  1039. //region 循环递归获取子级
  1040. /**
  1041. * 根据父类ID获取树形菜单数据
  1042. *
  1043. * @param parentID 父级ID
  1044. * @param lists 数据集合
  1045. * @return
  1046. */
  1047. private List<ArticleCommentVo> QueryTreeDatas(Integer parentID, String parentName, List<ArticleCommentVo> lists) {
  1048. List<ArticleCommentVo> newTrees = new ArrayList<>();
  1049. List<ArticleCommentVo> datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList());
  1050. for (ArticleCommentVo data : datas) {
  1051. data.setParentName(parentName);
  1052. List<ArticleCommentVo> news = QueryTreeDatas(data.getId(), data.getUserName(), lists);
  1053. if (news == null || news.size() == 0) {
  1054. newTrees.add(data);
  1055. continue;
  1056. } else {
  1057. data.setChildrens(news);
  1058. newTrees.add(data);
  1059. }
  1060. }
  1061. return newTrees;
  1062. }
  1063. //endregion
  1064. /**
  1065. * 根据用户ID获取个人主页相关信息
  1066. */
  1067. public String queryUserInfo() {
  1068. JSONObject jsonObject = new JSONObject();
  1069. //用户ID判断
  1070. if (articleTweetDto.getUserId() == null) {
  1071. jsonObject.put("code", 500);
  1072. jsonObject.put("message", "用户ID不能为空");
  1073. jsonObject.put("data", null);
  1074. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1075. return null;
  1076. }
  1077. articleUserVo result = articleTweetService.queryUserInfo(articleTweetDto.getUserId());
  1078. //region 关注
  1079. if (articleTweetDto.getUserId().equals(result.getId())) {
  1080. result.setIsFollow(2);//自己的推文
  1081. } else {
  1082. //是否关注
  1083. UserCollect uc = articleTweetService.queryUserCollect(result.getId(), articleTweetDto.getUserId());
  1084. result.setIsFollow(uc == null ? 0 : 1);//已关注给0;未关注给1
  1085. }
  1086. //endregion
  1087. if (result != null) {
  1088. String descript = "点击这里,填写简介";
  1089. result.setDescript(result.getDescript() == null ? descript : result.getDescript());
  1090. }
  1091. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1092. jsonObject.put("message", "请求成功");
  1093. jsonObject.put("data", result);
  1094. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1095. return null;
  1096. }
  1097. /**
  1098. * 根据用户ID获取用户主页推文列表分页数据
  1099. */
  1100. public String queryOwnerArticlePage() {
  1101. JSONObject jsonObject = new JSONObject();
  1102. //用户ID判断
  1103. if (articleTweetDto.getUserId() == null || articleTweetDto.getType() == null) {
  1104. jsonObject.put("code", 500);
  1105. jsonObject.put("message", "用户ID或类型ID不能为空");
  1106. jsonObject.put("data", null);
  1107. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1108. return null;
  1109. }
  1110. String sqlWhere = "";//全部推文
  1111. if (articleTweetDto.getType().intValue() == 1) {
  1112. sqlWhere = "and at.approve = 1 ";//审核中
  1113. } else if (articleTweetDto.getType().intValue() == 2) {
  1114. sqlWhere = "and at.approve = 3 ";//驳回
  1115. }
  1116. IPage<OwnerArticleVo> result = articleTweetService.queryOwnerArticlePage(articleTweetDto.getUserId(), sqlWhere, page, rows);
  1117. if (result.getPageList().size() > 0) {
  1118. String articleIds = StringUtils.join(result.getPageList().stream().map(OwnerArticleVo::getId).collect(Collectors.toList()), ",");
  1119. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  1120. for (OwnerArticleVo data : result.getPageList()) {
  1121. List<FileInfo> fileInfoList = fileInfos == null ? null : fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  1122. if (fileInfoList != null && fileInfoList.size()>0) {
  1123. for (int i = 0; i < fileInfoList.size(); i++) {
  1124. FileInfo fileInfo = fileInfoList.get(i);
  1125. List<String> fileUrl = new ArrayList<>();
  1126. if (fileInfo.getFileType()==1){
  1127. fileUrl.add(fileInfo.getUrl());
  1128. data.setImages(fileUrl);
  1129. }else {
  1130. data.setVideo(fileInfo.getUrl());
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1137. jsonObject.put("message", "请求成功");
  1138. jsonObject.put("data", result);
  1139. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1140. return null;
  1141. }
  1142. public String getUserContactList() {
  1143. JSONObject jsonObject = new JSONObject();
  1144. if (adminId == null ){
  1145. jsonObject.put("code", 500);
  1146. jsonObject.put("message", "请传入管理员ID");
  1147. jsonObject.put("data", null);
  1148. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1149. return null;
  1150. }
  1151. Admin admin = adminService.getById(Integer.parseInt(adminId));
  1152. if (admin==null || admin.getStatus()==0){
  1153. jsonObject.put("code", 500);
  1154. jsonObject.put("message", "该管理员已删除");
  1155. jsonObject.put("data", null);
  1156. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1157. return null;
  1158. }
  1159. StringBuilder querySql = new StringBuilder("");
  1160. if (!Func.checkNull(articleTweetDto.getUserName())) {
  1161. querySql.append(" and user_name like '%").append(articleTweetDto.getUserName()).append("%' ");
  1162. }
  1163. querySql.append(" and data_type = '").append(DataType.游客数据.toString()).append("' ");
  1164. if (admin.getUserId()!=null && !admin.getUserId().equals("")){
  1165. querySql.append(" and id in ( ").append(admin.getUserId()).append(") ");
  1166. }
  1167. IPage listPage = userService.queryUserPage(querySql.toString(), page, rows); // 查询分页
  1168. ResponseUtil.writeJsonIPage(ServletActionContext.getResponse(), listPage);
  1169. return null;
  1170. }
  1171. public String getAllUserList() {
  1172. JSONObject jsonObject = new JSONObject();
  1173. if (adminId == null ){
  1174. jsonObject.put("code", 500);
  1175. jsonObject.put("message", "请传入管理员ID");
  1176. jsonObject.put("data", null);
  1177. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1178. return null;
  1179. }
  1180. Admin admin = adminService.getById(Integer.parseInt(adminId));
  1181. if (admin==null || admin.getStatus()==0){
  1182. jsonObject.put("code", 500);
  1183. jsonObject.put("message", "该管理员已删除");
  1184. jsonObject.put("data", null);
  1185. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1186. return null;
  1187. }
  1188. StringBuilder querySql = new StringBuilder("");
  1189. if (!Func.checkNull(articleTweetDto.getUserName())) {
  1190. querySql.append(" and user_name like '%").append(articleTweetDto.getUserName()).append("%' ");
  1191. }
  1192. querySql.append(" and data_type = '").append(DataType.游客数据.toString()).append("' ");
  1193. if (admin.getUserId()!=null && admin.getUserId().length()>0){
  1194. querySql.append(" order by case when id in ( ").append(admin.getUserId()).append(") then 0 else 1 end");
  1195. }
  1196. IPage listPage = userService.queryUserPage2(querySql.toString(), page, rows,admin.getUserId()); // 查询分页
  1197. ResponseUtil.writeJsonIPage(ServletActionContext.getResponse(), listPage);
  1198. return null;
  1199. }
  1200. /**
  1201. * 社区首页推文列表
  1202. */
  1203. public String queryArticlePage() {
  1204. JSONObject jsonObject = new JSONObject();
  1205. if (articleTweetDto.getType() == null) {
  1206. jsonObject.put("code", 500);
  1207. jsonObject.put("message", "推文列表类型不能为空");
  1208. jsonObject.put("data", null);
  1209. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1210. return null;
  1211. }
  1212. if (articleTweetDto.getUserId() == null) {
  1213. jsonObject.put("code", 500);
  1214. jsonObject.put("message", "用户ID不能为空");
  1215. jsonObject.put("data", null);
  1216. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1217. return null;
  1218. }
  1219. IPage<ArticleListVo> result = articleTweetService.queryArticlesPage(articleTweetDto.getKeyWord(), articleTweetDto.getTownId().equals("") ? null : articleTweetDto.getTownId(), articleTweetDto.getUserId(), articleTweetDto.getType(), page, rows);
  1220. if (result.getPageList().size() > 0) {
  1221. String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
  1222. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  1223. for (ArticleListVo data : result.getPageList()) {
  1224. if (fileInfos != null) {
  1225. List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  1226. if (fileInfoList.size() > 0) {
  1227. List<String> fileUrl = new ArrayList<>();
  1228. for (int i = 0; i < fileInfoList.size(); i++) {
  1229. FileInfo fileInfo = fileInfoList.get(i);
  1230. if (fileInfo.getFileType()==1){
  1231. fileUrl.add(fileInfo.getUrl());
  1232. data.setImage(fileUrl);
  1233. } else {
  1234. data.setVideo(fileInfo.getUrl());
  1235. }
  1236. }
  1237. }
  1238. }
  1239. }
  1240. }
  1241. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1242. jsonObject.put("message", "请求成功");
  1243. jsonObject.put("data", result);
  1244. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1245. return null;
  1246. }
  1247. /**
  1248. * 点赞数最高的推文
  1249. */
  1250. public String queryMaxArticleLike() {
  1251. JSONObject jsonObject = new JSONObject();
  1252. ArticleLikeMaxVo result = articleTweetService.queryMaxArticleLike();
  1253. if (result != null) {
  1254. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id = " + result.getId() + "");
  1255. if (fileInfos != null) {
  1256. for (int i = 0; i < fileInfos.size(); i++) {
  1257. FileInfo fileInfo = fileInfos.get(i);
  1258. if (fileInfo.getFileType()==1){
  1259. result.setImage(fileInfo.getUrl());
  1260. } else {
  1261. result.setVideo(fileInfo.getUrl());
  1262. }
  1263. }
  1264. }
  1265. }
  1266. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1267. jsonObject.put("message", "请求成功");
  1268. jsonObject.put("data", result);
  1269. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1270. return null;
  1271. }
  1272. /**
  1273. * 相关推文
  1274. */
  1275. public String relatedTweets() {
  1276. JSONObject jsonObject = new JSONObject();
  1277. if (articleTweetDto.getId() == null || articleTweetDto.getTownId() == null || articleTweetDto.getUserId() == null) {
  1278. jsonObject.put("code", 500);
  1279. jsonObject.put("message", "乡镇ID或推文ID或用户ID不能为空");
  1280. jsonObject.put("data", null);
  1281. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1282. return null;
  1283. }
  1284. IPage<ArticleListVo> result = articleTweetService.relatedTweetPage(articleTweetDto.getUserId(), articleTweetDto.getTownId(), articleTweetDto.getId(), page, rows);
  1285. if (result.getPageList().size() > 0) {
  1286. String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
  1287. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
  1288. for (ArticleListVo data : result.getPageList()) {
  1289. List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
  1290. if (fileInfoList.size() > 0) {
  1291. List<String> fileUrl = new ArrayList<>();
  1292. for (int i = 0; i < fileInfoList.size(); i++) {
  1293. FileInfo fileInfo = fileInfoList.get(i);
  1294. if (fileInfo.getFileType()==1){
  1295. fileUrl.add(fileInfo.getUrl());
  1296. data.setImage(fileUrl);
  1297. } else {
  1298. data.setVideo(fileInfo.getUrl());
  1299. }
  1300. }
  1301. }
  1302. }
  1303. }
  1304. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1305. jsonObject.put("message", "请求成功");
  1306. jsonObject.put("data", result);
  1307. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1308. return null;
  1309. }
  1310. //select * from article_tweet where location_id = '' and user_id != 1 and approve = 2
  1311. /**
  1312. * 收藏文章
  1313. */
  1314. public String collectArticle() throws ParseException {
  1315. JSONObject jsonObject = new JSONObject();
  1316. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  1317. jsonObject.put("code", 500);
  1318. jsonObject.put("message", "用户ID或推文ID不能为空");
  1319. jsonObject.put("data", null);
  1320. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1321. return null;
  1322. }
  1323. //查询当前操作人是否已经收藏过这篇文章
  1324. ArticleCollect data = articleTweetService.queryArticleCollect(articleTweetDto.getId(), articleTweetDto.getUserId());
  1325. String actionStr = "收藏";
  1326. if (data != null) {
  1327. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  1328. actionStr = "取消收藏";
  1329. data.setIsLose(1);
  1330. } else {
  1331. data.setIsLose(0);
  1332. }
  1333. } else {
  1334. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  1335. data = new ArticleCollect();
  1336. data.setArticleId(articleTweetDto.getId());
  1337. data.setUserId(articleTweetDto.getUserId());
  1338. data.setIsLose(0);
  1339. data.setCreateId(articleTweetDto.getUserId());
  1340. data.setCreateDate(now);
  1341. data.setStatus(1);
  1342. }
  1343. int m = articleTweetService.updateArticleCollect(data);
  1344. if (m <= 0) {
  1345. String message = actionStr + "失败";
  1346. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1347. put("message", message);
  1348. put("code", 500);
  1349. }}.toString());
  1350. return null;
  1351. }
  1352. String successMessage = actionStr + "成功";
  1353. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1354. put("message", successMessage);
  1355. put("code", 200);
  1356. }}.toString());
  1357. return null;
  1358. }
  1359. /**
  1360. * 评论文章
  1361. */
  1362. public String commentArticle() throws ParseException {
  1363. Gson gson = new Gson();
  1364. JSONObject jsonObject = new JSONObject();
  1365. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  1366. ArticleCommentDto articleCommentDto = gson.fromJson(json.toString(), new TypeToken<ArticleCommentDto>() {
  1367. }.getType());
  1368. if (articleCommentDto.getArticleId() == null || Func.checkNull(articleCommentDto.getContent())
  1369. || articleCommentDto.getParentId() == null || articleCommentDto.getUserId() == null) {
  1370. jsonObject.put("code", 500);
  1371. jsonObject.put("message", "参数不能为空");
  1372. jsonObject.put("data", null);
  1373. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1374. return null;
  1375. }
  1376. //查询操作人身份
  1377. Users user = userService.queryByUserId(String.valueOf(articleCommentDto.getUserId()));
  1378. if (user == null) {
  1379. jsonObject.put("code", 500);
  1380. jsonObject.put("message", "用户信息已失效,评论失败");
  1381. jsonObject.put("data", null);
  1382. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1383. return null;
  1384. }
  1385. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  1386. ArticleComment articleComment = new ArticleComment();
  1387. articleComment.setArticleId(articleCommentDto.getArticleId());
  1388. articleComment.setCommentParentId(articleCommentDto.getParentId());
  1389. articleComment.setCommentId(articleCommentDto.getUserId());
  1390. articleComment.setCommentName(user.getUser_name());
  1391. articleComment.setCommentImage(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  1392. articleComment.setContent(articleCommentDto.getContent());
  1393. articleComment.setCreateId(articleCommentDto.getUserId());
  1394. articleComment.setCreateDate(now);
  1395. articleComment.setStatus(1);
  1396. int num = articleTweetService.insertArticleComment(articleComment);
  1397. if (num <= 0) {
  1398. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1399. put("message", "评论失败");
  1400. put("code", 500);
  1401. }}.toString());
  1402. return null;
  1403. }
  1404. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1405. put("message", "评论成功");
  1406. put("code", 200);
  1407. }}.toString());
  1408. return null;
  1409. }
  1410. /**
  1411. * 关注作者
  1412. */
  1413. public String followAuthor() throws ParseException {
  1414. JSONObject jsonObject = new JSONObject();
  1415. if (articleTweetDto.getAuthorId() == null || articleTweetDto.getUserId() == null) {
  1416. jsonObject.put("code", 500);
  1417. jsonObject.put("message", "作者ID或用户ID不能为空");
  1418. jsonObject.put("data", null);
  1419. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1420. return null;
  1421. }
  1422. //查询当前操作人是否已经关注过作者
  1423. UserCollect data = articleTweetService.queryUserCollectNoLose(articleTweetDto.getAuthorId(), articleTweetDto.getUserId());
  1424. String actionStr = "关注";
  1425. if (data != null) {
  1426. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  1427. actionStr = "取消关注";
  1428. data.setIsLose(1);
  1429. } else {
  1430. data.setIsLose(0);
  1431. }
  1432. } else {
  1433. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  1434. data = new UserCollect();
  1435. data.setParentUserid(articleTweetDto.getAuthorId());
  1436. data.setUserId(articleTweetDto.getUserId());
  1437. data.setIsLose(0);
  1438. data.setCreateId(articleTweetDto.getUserId());
  1439. data.setCreateDate(now);
  1440. data.setStatus(1);
  1441. }
  1442. int m = articleTweetService.updateUserCollect(data);
  1443. if (m <= 0) {
  1444. String message = actionStr + "失败";
  1445. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1446. put("message", message);
  1447. put("code", 500);
  1448. }}.toString());
  1449. return null;
  1450. }
  1451. String successMessage = actionStr + "成功";
  1452. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1453. put("message", successMessage);
  1454. put("code", 200);
  1455. }}.toString());
  1456. return null;
  1457. }
  1458. /**
  1459. * 点赞文章
  1460. */
  1461. public String likeArticle() throws ParseException {
  1462. JSONObject jsonObject = new JSONObject();
  1463. if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
  1464. jsonObject.put("code", 500);
  1465. jsonObject.put("message", "用户ID或推文ID不能为空");
  1466. jsonObject.put("data", null);
  1467. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1468. return null;
  1469. }
  1470. //查询操作人身份
  1471. Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
  1472. if (user == null) {
  1473. jsonObject.put("code", 500);
  1474. jsonObject.put("message", "用户信息已失效,评论失败");
  1475. jsonObject.put("data", null);
  1476. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1477. return null;
  1478. }
  1479. //查询当前操作人是否已经收藏过这篇文章
  1480. ArticleLikes data = articleTweetService.queryArticleLike(articleTweetDto.getId(), articleTweetDto.getUserId());
  1481. String actionStr = "点赞";
  1482. if (data != null) {
  1483. if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
  1484. actionStr = "取消点赞";
  1485. data.setIsLose(1);
  1486. } else {
  1487. data.setIsLose(0);
  1488. }
  1489. } else {
  1490. Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
  1491. data = new ArticleLikes();
  1492. data.setArticleId(articleTweetDto.getId());
  1493. data.setLikeId(articleTweetDto.getUserId());
  1494. data.setLikeName(user.getUser_name());
  1495. data.setLikeImage(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
  1496. data.setIsLose(0);
  1497. data.setCreateId(articleTweetDto.getUserId());
  1498. data.setCreateDate(now);
  1499. data.setStatus(1);
  1500. }
  1501. int m = articleTweetService.updateArticleLike(data);
  1502. if (m <= 0) {
  1503. String message = actionStr + "失败";
  1504. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1505. put("message", message);
  1506. put("code", 500);
  1507. }}.toString());
  1508. return null;
  1509. }
  1510. String successMessage = actionStr + "成功";
  1511. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  1512. put("message", successMessage);
  1513. put("code", 200);
  1514. }}.toString());
  1515. return null;
  1516. }
  1517. /**
  1518. * 获取乡镇列表
  1519. */
  1520. public String townShips() {
  1521. List<HotelDict> hotelDicts = hotelDictService.queryList("and code = 10");
  1522. List<TownshipVo> result = new ArrayList<>();
  1523. for (HotelDict hotelDict : hotelDicts) {
  1524. TownshipVo data = new TownshipVo();
  1525. data.setId(hotelDict.getId());
  1526. data.setName(hotelDict.getName());
  1527. result.add(data);
  1528. }
  1529. JSONObject jsonObject = new JSONObject();
  1530. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1531. jsonObject.put("message", "请求成功");
  1532. jsonObject.put("data", result);
  1533. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1534. return null;
  1535. }
  1536. /**
  1537. * 根据乡镇ID获取民宿列表
  1538. */
  1539. public String hotelByid() {
  1540. JSONObject jsonObject = new JSONObject();
  1541. if (Func.checkNull(articleTweetDto.getTownId())) {
  1542. jsonObject.put("code", ResultStatusCode.BAD_REQUEST.getStatus());
  1543. jsonObject.put("message", ResultStatusCode.BAD_REQUEST.getMsg());
  1544. jsonObject.put("data", null);
  1545. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1546. return null;
  1547. }
  1548. String sql = "hotel_township = '" + articleTweetDto.getTownId() + "'";
  1549. IPage<HotelVo> houseIPage = articleTweetService.queryHotelPage(sql, page, rows);
  1550. jsonObject.put("message", "查询分页成功");
  1551. jsonObject.put("code", 200);
  1552. jsonObject.put("data", houseIPage);
  1553. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1554. return null;
  1555. }
  1556. /**
  1557. * 修改用户简介
  1558. */
  1559. public String updateDescript() {
  1560. JSONObject jsonObject = new JSONObject();
  1561. if (articleTweetDto.getAuthorId() == null || articleTweetDto.getUserId() == null || Func.checkNull(articleTweetDto.getDescript())) {
  1562. jsonObject.put("code", 500);
  1563. jsonObject.put("message", "操作用户ID或主页用户ID或简介不能为空");
  1564. jsonObject.put("data", null);
  1565. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1566. return null;
  1567. }
  1568. if (!articleTweetDto.getAuthorId().equals(articleTweetDto.getUserId())) {
  1569. jsonObject.put("code", 500);
  1570. jsonObject.put("message", "当前用户无法修改其他人的简介信息");
  1571. jsonObject.put("data", null);
  1572. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1573. return null;
  1574. }
  1575. int num = articleTweetService.updateDescript(articleTweetDto.getAuthorId(), articleTweetDto.getDescript());
  1576. jsonObject.put("message", "修改成功");
  1577. jsonObject.put("code", 200);
  1578. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1579. return null;
  1580. }
  1581. /**
  1582. * 攻略分页
  1583. *
  1584. * @return
  1585. */
  1586. public String walkthroughPage() {
  1587. JSONObject jsonObject = new JSONObject();
  1588. StringBuilder strSql = new StringBuilder(" and at.status=1 "); // 推文没删除才显示
  1589. if (!Func.checkNull(key)) {
  1590. strSql.append(" and (at.user_name like '%").append(key).append("%' or at.title like '%").append(key).append("%') ");
  1591. }
  1592. if (!Func.checkNull(startTime) && !Func.checkNull(endTime)) {
  1593. strSql.append(" and at.create_date >= '").append(startTime).append("' ");
  1594. strSql.append(" and at.create_date <= '").append(endTime).append("' ");
  1595. }
  1596. IPage<WalkthroughVo> walkthroughPage = articleTweetService.walkthroughPage(strSql.toString(), page, rows);
  1597. jsonObject.put("message", "查询分页成功");
  1598. jsonObject.put("code", 200);
  1599. jsonObject.put("data", walkthroughPage);
  1600. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1601. return null;
  1602. }
  1603. /**
  1604. * 商品页面
  1605. */
  1606. public String productPage() throws Exception {
  1607. JSONObject jsonObject = new JSONObject();
  1608. // JSONObject jsonBody = new JSONObject();
  1609. // jsonBody.put("username", "admin");
  1610. // jsonBody.put("password", "123456");
  1611. //
  1612. // String url = "https://www.jinganrenjiams.com/cloud-mall/admin/open/login";
  1613. //
  1614. // 构建http请求客户端
  1615. // HttpClient httpclient = HttpClientBuilder.create().useSystemProperties().build();
  1616. // // 构建post请求
  1617. // HttpPost postMethod = new HttpPost(url);
  1618. // // 设置请求头
  1619. // postMethod.addHeader("Content-Type", "application/json");
  1620. // // 设置请求体
  1621. // postMethod.setEntity(new StringEntity(jsonBody.toString()));
  1622. //
  1623. // // 发送请求
  1624. // HttpResponse response = httpclient.execute(postMethod);
  1625. //
  1626. // String s = EntityUtils.toString(response.getEntity());
  1627. //
  1628. // JSONObject postJson = JSONObject.parseObject(s);
  1629. //
  1630. // JSONObject data = postJson.getJSONObject("data");
  1631. //
  1632. // String token = data.getString("token");
  1633. // 构建http请求客户端
  1634. HttpClient httpclient = HttpClientBuilder.create().useSystemProperties().build();
  1635. String getUrl = "";
  1636. if (!Func.checkNull(key)) {
  1637. getUrl = "https://www.jinganrenjiams.com/cloud-mall/goods/open/page?state=1&curPage="+page+"&pageSize="+rows+"&goodsName=" + key;
  1638. } else {
  1639. getUrl = "https://www.jinganrenjiams.com/cloud-mall/goods/open/page?state=1&curPage="+page+"&pageSize="+rows;
  1640. }
  1641. HttpGet httpGet = new HttpGet(getUrl);
  1642. // 设置请求头
  1643. httpGet.addHeader("Content-Type", "application/json");
  1644. // httpGet.addHeader("Mall-Token", token);
  1645. // 发送请求
  1646. HttpResponse execute = httpclient.execute(httpGet);
  1647. String s1 = EntityUtils.toString(execute.getEntity());
  1648. JSONObject getJson = JSONObject.parseObject(s1);
  1649. JSONObject data1 = getJson.getJSONObject("data");
  1650. jsonObject.put("message", "查询分页成功");
  1651. jsonObject.put("code", 200);
  1652. jsonObject.put("data", data1);
  1653. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1654. return null;
  1655. }
  1656. /**
  1657. * 点赞数前三的推文
  1658. */
  1659. public String queryTop3ArticleLike() {
  1660. JSONObject jsonObject = new JSONObject();
  1661. List<ArticleLikeMaxVo> result = articleTweetService.queryTop3ArticleLike();
  1662. if (result != null) {
  1663. for (int i = 0; i < result.size(); i++) {
  1664. List<FileInfo> fileInfos = articleTweetService.queryList("and link_id = " + result.get(i).getId() + "");
  1665. if (fileInfos != null) {
  1666. for (int j = 0; j < fileInfos.size(); j++) {
  1667. FileInfo fileInfo = fileInfos.get(j);
  1668. if (fileInfo.getFileType()==1){
  1669. result.get(i).setImage(fileInfo.getUrl());
  1670. } else {
  1671. result.get(i).setVideo(fileInfo.getUrl());
  1672. }
  1673. }
  1674. }
  1675. }
  1676. }
  1677. jsonObject.put("code", ResultStatusCode.OK.getStatus());
  1678. jsonObject.put("message", "请求成功");
  1679. jsonObject.put("data", result);
  1680. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  1681. return null;
  1682. }
  1683. }