| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202 |
- package com.happy.action;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.baidubce.model.User;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.happy.Model.*;
- import com.happy.Model.weixin.Users;
- import com.happy.Until.*;
- import com.happy.common.controller.BaseController;
- import com.happy.constant.ConstDefault;
- import com.happy.constant.ResultStatusCode;
- import com.happy.dto.ArticleCommentDto;
- import com.happy.dto.ArticleTweetDto;
- import com.happy.dto.IPage;
- import com.happy.service.*;
- import com.happy.vo.*;
- import com.opensymphony.xwork2.ModelDriven;
- import lombok.SneakyThrows;
- import org.apache.commons.lang.StringUtils;
- import org.apache.struts2.ServletActionContext;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- import java.util.*;
- import java.util.stream.Collectors;
- public class articleTweetAction extends BaseController implements ModelDriven<ArticleTweetDto> {
- private final ArticleTweetDto articleTweetDto = new ArticleTweetDto();
- @Override
- public ArticleTweetDto getModel() {
- return articleTweetDto;
- }
- @Resource
- public ArticleTweetService articleTweetService;
- @Resource
- public HousePriceService housePriceService;
- @Resource
- public HotelDictService hotelDictService;
- @Resource
- public WorkflowService workflowService;
- @Resource
- public HouseService houseService;
- @Resource
- public UserService userService;
- public String key;
- public String startTime;
- public String endTime;
- public String getKey(){
- return key;
- }
- public void setKey(String key){
- this.key=key;
- }
- public String getStartTime() {
- return startTime;
- }
- public void setStartTime(String startTime) {
- this.startTime = startTime;
- }
- public String getEndTime() {
- return endTime;
- }
- public void setEndTime(String endTime) {
- this.endTime = endTime;
- }
- /**
- * 推文发布
- */
- public String insertArticleTweet() throws ParseException {
- Gson gson = new Gson();
- JSONObject jsonObject = new JSONObject();
- com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
- ArticleTweetDto articleTweetDto = gson.fromJson(json.toString(), new TypeToken<ArticleTweetDto>() {
- }.getType());
- //图片和视频判断
- if (articleTweetDto.getImages() == null && articleTweetDto.getVideo() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "请上传图片或视频");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //图片最多上传九张
- if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 9) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "最多上传9张图片");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //标题、内容、地点、关联民宿不能为空
- if (Func.checkNull(articleTweetDto.getTitle()) || Func.checkNull(articleTweetDto.getContent())
- || Func.checkNull(articleTweetDto.getTownId()) || articleTweetDto.getHotelIds() == null
- || articleTweetDto.getCreateId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "参数不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //推文发布参数
- System.out.println("推文发布参数:" + JSON.toJSON(articleTweetDto));
- //查询当前用户
- Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getCreateId()));
- if (user == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户信息已失效,查看详情失败");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
- try {
- //添加推文
- ArticleTweet data = new ArticleTweet();
- data.setUserId(articleTweetDto.getCreateId());
- data.setTitle(articleTweetDto.getTitle());
- data.setContent(articleTweetDto.getContent());
- data.setLocationId(articleTweetDto.getTownId());
- data.setHotelId(StringUtils.join(articleTweetDto.getHotelIds(), ","));
- data.setCreateId(articleTweetDto.getCreateId());
- data.setCreateDate(now);
- data.setApprove(1);//正在审批
- data.setStatus(1);
- data.setUserName(user.getUser_name());
- data.setUserPhoto(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
- int aId = articleTweetService.insert(data);
- if (aId <= 0) {
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", "推文发布失败");
- put("code", 500);
- }}.toString());
- return null;
- }
- //添加附件
- List<String> fileStr = new ArrayList<>();
- if (articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0) {
- fileStr = articleTweetDto.getImages();
- } else {
- fileStr.add(articleTweetDto.getVideo());
- }
- List<ArticleFileInfo> afis = new ArrayList<>();
- for (String f : fileStr) {
- String[] split = f.split("/");
- String fileName = split[split.length - 1];
- ArticleFileInfo afi = new ArticleFileInfo();
- afi.setLinkId(aId);
- afi.setName(fileName);
- afi.setType(1);
- afi.setUrl(f);
- afi.setCreateDate(now);
- afis.add(afi);
- }
- int length = articleTweetService.insertArticleFileBatch(afis);
- if (length <= 0) {
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", "推文附件新增失败");
- put("code", 500);
- }}.toString());
- return null;
- }
- //添加流程
- Workflow workflow = new Workflow();
- String id = String.valueOf(UUID.randomUUID());
- workflow.setLinkId(String.valueOf(aId));//存推文的ID
- workflow.setCreateId(String.valueOf(articleTweetDto.getCreateId()));
- workflow.setTitle(articleTweetDto.getTitle());
- workflow.setRemark(articleTweetDto.getContent());
- workflow.setId(id);
- workflow.setStatus(1);//1是正在审批
- workflow.setType(3);//3是推文
- workflow.setCoverImg(articleTweetDto.getImages() != null && articleTweetDto.getImages().size() > 0 ? articleTweetDto.getImages().get(0) : articleTweetDto.getVideo());
- int i = workflowService.insert(workflow);
- if (i <= 0) {
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", "推文流程发布失败");
- put("code", 500);
- }}.toString());
- return null;
- }
- } catch (Exception e) {
- System.out.println("推文发布异常:" + e.getMessage());
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", "推文发布异常");
- put("code", 500);
- }}.toString());
- return null;
- }
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", "推文发布成功");
- put("code", 200);
- }}.toString());
- return null;
- }
- /**
- * 根据推文数据ID查询推文详情数据
- *
- * @return
- */
- public String queryDetail() {
- JSONObject jsonObject = new JSONObject();
- //图片和视频判断
- if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "推文ID或用户ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询当前用户
- Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
- if (user == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户信息已失效,查看详情失败");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询推文数据
- ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
- if (data == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "推文数据已失效,查看详情失败");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- ArticleDetailVo result = new ArticleDetailVo();
- result.setIsCollect(data.getIsCollect());
- result.setId(data.getId());
- List<FileInfo> fileInfoList = articleTweetService.queryList("and link_id = '" + articleTweetDto.getId() + "'");
- if (fileInfoList != null) {
- if (fileInfoList.size() > 1) {
- result.setImages(fileInfoList.stream().map(FileInfo::getUrl).collect(Collectors.toList()));
- } else if (fileInfoList.size() == 1) {
- String url = fileInfoList.get(0).getUrl();
- if (!url.endsWith("jpg") && !url.endsWith("png")) {
- result.setVideo(fileInfoList.get(0).getUrl());
- } else {
- List<String> images = new ArrayList<>();
- images.add(url);
- result.setImages(images);
- }
- }
- }
- result.setUserId(data.getUserId());
- result.setUserName(data.getUserName());
- result.setUserPhoto(data.getUserPhoto() == null ? ConstDefault.DefaultHeadPhoto : data.getUserPhoto());
- //region 关注
- if (articleTweetDto.getUserId().equals(data.getUserId())) {
- result.setIsFollow(2);//自己的推文
- } else {
- //是否关注
- UserCollect uc = articleTweetService.queryUserCollect(data.getUserId(), articleTweetDto.getUserId());
- result.setIsFollow(uc == null ? 0 : 1);//已关注给0;未关注给1
- }
- //endregion
- result.setTitle(data.getTitle());
- result.setContent(data.getContent());
- result.setDateStr(TimeExchange.DateToString(data.getCreateDate(), "yyyy-MM-dd"));
- result.setTownId(data.getLocationId());
- result.setTownName(data.getLocationName());
- //region 民宿列表
- //根据乡镇ID获取
- List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
- String sql = "id in (" + data.getHotelId() + ")";
- List<HotelVo> hotels = articleTweetService.queryHotels(sql);
- List<HotelListVo> hotelDatas = new ArrayList<>();
- //region 最低价
- List<Integer> managerIds = hotels.stream().map(HotelVo::getManagerId).collect(Collectors.toList());
- List<HotelPriceDataVo> prices = housePriceService.queryHotelPriceDatas(StringUtils.join(managerIds, ","), TimeExchange.getDateStr());
- List<HotelPriceOneDataVo> oneDatas = new ArrayList<>();
- //获取当天的
- for (HotelPriceDataVo hp : prices) {
- HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
- oneData.setSetDate(TimeExchange.getDateStr());
- oneData.setCreateDate(hp.getCreateDate());
- oneData.setPrice(hp.getPrice());
- oneData.setManagerId(hp.getManagerId());
- oneDatas.add(oneData);
- }
- /**
- * 根据房型ID处理重复的数据
- */
- List<HotelPriceOneDataVo> newOneDatas = new ArrayList<>();
- if (oneDatas.size() > 0) {
- for (Integer managerId : managerIds) {
- Optional<HotelPriceOneDataVo> one = oneDatas.stream().filter(e -> e.getManagerId().equals(managerId)).sorted(Comparator.comparing(HotelPriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
- if (one != null && one.isPresent()) {
- HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
- oneData.setSetDate(one.get().getSetDate());
- oneData.setCreateDate(one.get().getCreateDate());
- oneData.setPrice(one.get().getPrice());
- oneData.setManagerId(one.get().getManagerId());
- newOneDatas.add(oneData);
- }
- }
- }
- /**
- * 获取商家集合中最低房型价格
- */
- List<PriceHotelDataVo> mins = houseService.gethotelMinPrice(StringUtils.join(managerIds, ","));
- DecimalFormat decimalFormat = new DecimalFormat("#####.##");
- //endregion
- for (HotelVo hotel : hotels) {
- HotelListVo hotelData = new HotelListVo();
- hotelData.setId(hotel.getId());
- hotelData.setName(hotel.getName());
- hotelData.setScore(hotel.getScore());
- hotelData.setCoverImg(hotel.getCoverImg());
- hotelData.setComment(hotel.getComment());
- //是否收藏
- Optional<String> hotelId = hotelIds.stream().filter(e -> e.equals(hotel.getId().toString())).findFirst();
- if (hotelId != null && hotelId.isPresent()) {
- hotelData.setIsCollect(1);
- } else {
- hotelData.setIsCollect(0);
- }
- hotelData.setType(hotel.getType());
- //价格
- Optional<HotelPriceOneDataVo> one = newOneDatas.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
- Optional<PriceHotelDataVo> min = mins.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
- if (one != null && one.isPresent() && min != null && min.isPresent()) {
- if(one.get().getPrice() > min.get().getPrice()){
- hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
- }else{
- hotelData.setPrice(decimalFormat.format(one.get().getPrice()));
- }
- } else {
- if (min != null && min.isPresent()) {
- hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
- }
- }
- hotelDatas.add(hotelData);
- }
- result.setHotels(hotelDatas);
- //endregion
- List<LikeListVo> likes = articleTweetService.queryArticleLikes(articleTweetDto.getId());
- if (likes != null && likes.size() > 0) {
- Optional<LikeListVo> ownerLikes = likes.stream().filter(e -> e.getId().equals(articleTweetDto.getUserId())).findFirst();
- if (ownerLikes != null && ownerLikes.isPresent()) {
- result.setIsLike(1);
- } else {
- result.setIsLike(0);
- }
- } else {
- result.setIsLike(0);
- }
- result.setLikes(likes == null ? new ArrayList<>() : likes.stream().map(LikeListVo::getImage).limit(10).collect(Collectors.toList()));
- result.setLikeNum(likes == null ? 0 : likes.size());
- List<ArticleCommentVo> comments = articleTweetService.queryArticleComment(articleTweetDto.getId());
- result.setComments(comments);
- int total = articleTweetService.queryArticleCommentTotal(articleTweetDto.getId());
- result.setCommentNum(total);
- result.setCollectNum(data.getCollectNum());
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 点赞集合列表
- *
- * @return
- */
- public String queryLikes() {
- JSONObject jsonObject = new JSONObject();
- if (articleTweetDto.getId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "推文ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- IPage<LikeListVo> result = articleTweetService.queryLikesPage(articleTweetDto.getId(), page, rows);
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 获取推文详情中民宿分页列表
- */
- public String queryHotelList() {
- JSONObject jsonObject = new JSONObject();
- if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "推文ID或用户ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询当前用户
- Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
- if (user == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户信息已失效,查看详情失败");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询推文数据
- ArticleTweet data = articleTweetService.queryArticleById(String.valueOf(articleTweetDto.getId()), articleTweetDto.getUserId());
- if (data == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "推文数据已失效,查看详情失败");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //region 民宿列表
- //根据乡镇ID获取
- List<String> hotelIds = user.getCollect_hotel() == null ? new ArrayList<>() : Arrays.asList(user.getCollect_hotel().split(","));
- String sql = "id in (" + data.getHotelId() + ")";
- IPage<HotelVo> hotels = articleTweetService.queryHotelPageByHotleId(sql, page, rows);
- List<HotelListVo> hotelDatas = new ArrayList<>();
- //region 最低价
- List<Integer> managerIds = hotels.getPageList().stream().map(HotelVo::getManagerId).collect(Collectors.toList());
- List<HotelPriceDataVo> prices = housePriceService.queryHotelPriceDatas(StringUtils.join(managerIds, ","), TimeExchange.getDateStr());
- List<HotelPriceOneDataVo> oneDatas = new ArrayList<>();
- //获取当天的
- for (HotelPriceDataVo hp : prices) {
- HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
- oneData.setSetDate(TimeExchange.getDateStr());
- oneData.setCreateDate(hp.getCreateDate());
- oneData.setPrice(hp.getPrice());
- oneData.setManagerId(hp.getManagerId());
- oneDatas.add(oneData);
- }
- /**
- * 根据房型ID处理重复的数据
- */
- List<HotelPriceOneDataVo> newOneDatas = new ArrayList<>();
- if (oneDatas.size() > 0) {
- for (Integer managerId : managerIds) {
- Optional<HotelPriceOneDataVo> one = oneDatas.stream().filter(e -> e.getManagerId().equals(managerId)).sorted(Comparator.comparing(HotelPriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
- if (one != null && one.isPresent()) {
- HotelPriceOneDataVo oneData = new HotelPriceOneDataVo();
- oneData.setSetDate(one.get().getSetDate());
- oneData.setCreateDate(one.get().getCreateDate());
- oneData.setPrice(one.get().getPrice());
- oneData.setManagerId(one.get().getManagerId());
- newOneDatas.add(oneData);
- }
- }
- }
- /**
- * 获取商家集合中最低房型价格
- */
- List<PriceHotelDataVo> mins = houseService.gethotelMinPrice(StringUtils.join(managerIds, ","));
- DecimalFormat decimalFormat = new DecimalFormat("#####.##");
- //endregion
- for (HotelVo hotel : hotels.getPageList()) {
- HotelListVo hotelData = new HotelListVo();
- hotelData.setId(hotel.getId());
- hotelData.setName(hotel.getName());
- hotelData.setScore(hotel.getScore());
- hotelData.setCoverImg(hotel.getCoverImg());
- hotelData.setComment(hotel.getComment());
- //是否收藏
- Optional<String> hotelId = hotelIds.stream().filter(e -> e.equals(hotel.getId().toString())).findFirst();
- if (hotelId != null && hotelId.isPresent()) {
- hotelData.setIsCollect(1);
- } else {
- hotelData.setIsCollect(0);
- }
- hotelData.setType(hotel.getType());
- //价格
- Optional<HotelPriceOneDataVo> one = newOneDatas.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
- Optional<PriceHotelDataVo> min = mins.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
- if (one != null && one.isPresent() && min != null && min.isPresent()) {
- if(one.get().getPrice() > min.get().getPrice()){
- hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
- }else{
- hotelData.setPrice(decimalFormat.format(one.get().getPrice()));
- }
- } else {
- if (min != null && min.isPresent()) {
- hotelData.setPrice(decimalFormat.format(min.get().getPrice()));
- }
- }
- hotelDatas.add(hotelData);
- }
- //endregion
- IPage<HotelListVo> result = new IPage<>();
- result.setPage(hotels.getPage());
- result.setRows(hotels.getRows());
- result.setPageList(hotelDatas);
- result.setTotal(hotels.getTotal());
- result.setTotalPage(hotels.getTotalPage());
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 获取推文详情中评论分页列表
- * 先获取一级评论 再区获取对应子级
- */
- public String queryCommentList() {
- JSONObject jsonObject = new JSONObject();
- //推文ID判断
- if (articleTweetDto.getId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "推文ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //一级分页数据
- IPage<ArticleCommentVo> result = articleTweetService.queryCommentPageByArticle(articleTweetDto.getId(), page, rows);
- //子级评论数据
- List<ArticleCommentVo> childs = articleTweetService.queryCommentsByArticle(articleTweetDto.getId());
- if (childs != null && childs.size() > 0) {
- for (ArticleCommentVo data : result.getPageList()) {
- List<ArticleCommentVo> comments = QueryTreeDatas(data.getId(), data.getUserName(), childs);
- data.setChildrens(comments);
- }
- }
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //region 循环递归获取子级
- /**
- * 根据父类ID获取树形菜单数据
- *
- * @param parentID 父级ID
- * @param lists 数据集合
- * @return
- */
- private List<ArticleCommentVo> QueryTreeDatas(Integer parentID, String parentName, List<ArticleCommentVo> lists) {
- List<ArticleCommentVo> newTrees = new ArrayList<>();
- List<ArticleCommentVo> datas = lists.stream().filter(e -> e.getParentId().equals(parentID)).collect(Collectors.toList());
- for (ArticleCommentVo data : datas) {
- data.setParentName(parentName);
- List<ArticleCommentVo> news = QueryTreeDatas(data.getId(), data.getUserName(), lists);
- if (news == null || news.size() == 0) {
- newTrees.add(data);
- continue;
- } else {
- data.setChildrens(news);
- newTrees.add(data);
- }
- }
- return newTrees;
- }
- //endregion
- /**
- * 根据用户ID获取个人主页相关信息
- */
- public String queryUserInfo() {
- JSONObject jsonObject = new JSONObject();
- //用户ID判断
- if (articleTweetDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- articleUserVo result = articleTweetService.queryUserInfo(articleTweetDto.getUserId());
- //region 关注
- if (articleTweetDto.getUserId().equals(result.getId())) {
- result.setIsFollow(2);//自己的推文
- } else {
- //是否关注
- UserCollect uc = articleTweetService.queryUserCollect(result.getId(), articleTweetDto.getUserId());
- result.setIsFollow(uc == null ? 0 : 1);//已关注给0;未关注给1
- }
- //endregion
- if (result != null) {
- String descript = "点击这里,填写简介";
- result.setDescript(result.getDescript() == null ? descript : result.getDescript());
- }
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 根据用户ID获取用户主页推文列表分页数据
- */
- public String queryOwnerArticlePage() {
- JSONObject jsonObject = new JSONObject();
- //用户ID判断
- if (articleTweetDto.getUserId() == null || articleTweetDto.getType() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户ID或类型ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- String sqlWhere = "";//全部推文
- if (articleTweetDto.getType().intValue() == 1) {
- sqlWhere = "and at.approve = 1 ";//审核中
- } else if (articleTweetDto.getType().intValue() == 2) {
- sqlWhere = "and at.approve = 3 ";//驳回
- }
- IPage<OwnerArticleVo> result = articleTweetService.queryOwnerArticlePage(articleTweetDto.getUserId(), sqlWhere, page, rows);
- if (result.getPageList().size() > 0) {
- String articleIds = StringUtils.join(result.getPageList().stream().map(OwnerArticleVo::getId).collect(Collectors.toList()), ",");
- List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
- for (OwnerArticleVo data : result.getPageList()) {
- List<FileInfo> fileInfoList = fileInfos == null ? null : fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
- if (fileInfoList != null) {
- if (fileInfoList.size() > 1) {
- data.setImages(fileInfoList.stream().map(FileInfo::getUrl).collect(Collectors.toList()));
- } else if (fileInfoList.size() == 1) {
- String url = fileInfoList.get(0).getUrl();
- if (!url.endsWith("jpg") && !url.endsWith("png")) {
- data.setVideo(fileInfoList.get(0).getUrl());
- } else {
- List<String> images = new ArrayList<>();
- images.add(url);
- data.setImages(images);
- }
- }
- }
- }
- }
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 社区首页推文列表
- */
- public String queryArticlePage() {
- JSONObject jsonObject = new JSONObject();
- if (articleTweetDto.getType() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "推文列表类型不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- if (articleTweetDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- IPage<ArticleListVo> result = articleTweetService.queryArticlesPage(articleTweetDto.getKeyWord(), articleTweetDto.getTownId().equals("") ? null : articleTweetDto.getTownId(), articleTweetDto.getUserId(), articleTweetDto.getType(), page, rows);
- if (result.getPageList().size() > 0) {
- String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
- List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
- for (ArticleListVo data : result.getPageList()) {
- if(fileInfos != null){
- List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
- if (fileInfoList != null) {
- if (fileInfoList.size() > 1) {
- data.setImage(fileInfoList.get(0).getUrl());
- } else if (fileInfoList.size() == 1) {
- String url = fileInfoList.get(0).getUrl();
- if (!url.endsWith("jpg") && !url.endsWith("png")) {
- data.setVideo(fileInfoList.get(0).getUrl());
- } else {
- data.setImage(url);
- }
- }
- }
- }
- }
- }
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 点赞数最高的推文
- */
- public String queryMaxArticleLike() {
- JSONObject jsonObject = new JSONObject();
- ArticleLikeMaxVo result = articleTweetService.queryMaxArticleLike();
- if (result != null) {
- List<FileInfo> fileInfos = articleTweetService.queryList("and link_id = " + result.getId() + "");
- if (fileInfos != null) {
- if (fileInfos.size() > 1) {
- result.setImage(fileInfos.get(0).getUrl());
- } else if (fileInfos.size() == 1) {
- String url = fileInfos.get(0).getUrl();
- if (!url.endsWith("jpg") && !url.endsWith("png")) {
- result.setVideo(fileInfos.get(0).getUrl());
- } else {
- result.setImage(url);
- }
- }
- }
- }
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 相关推文
- */
- public String relatedTweets() {
- JSONObject jsonObject = new JSONObject();
- if (articleTweetDto.getId() == null || articleTweetDto.getTownId() == null || articleTweetDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "乡镇ID或推文ID或用户ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- IPage<ArticleListVo> result = articleTweetService.relatedTweetPage(articleTweetDto.getUserId(), articleTweetDto.getTownId(), articleTweetDto.getId(), page, rows);
- if (result.getPageList().size() > 0) {
- String articleIds = StringUtils.join(result.getPageList().stream().map(ArticleListVo::getId).collect(Collectors.toList()), ",");
- List<FileInfo> fileInfos = articleTweetService.queryList("and link_id in (" + articleIds + ")");
- for (ArticleListVo data : result.getPageList()) {
- List<FileInfo> fileInfoList = fileInfos.stream().filter(e -> e.getLinkId().equals(data.getId().toString())).collect(Collectors.toList());
- if (fileInfoList != null) {
- if (fileInfoList.size() > 1) {
- data.setImage(fileInfoList.get(0).getUrl());
- } else if (fileInfoList.size() == 1) {
- String url = fileInfoList.get(0).getUrl();
- if (!url.endsWith("jpg") && !url.endsWith("png")) {
- data.setVideo(fileInfoList.get(0).getUrl());
- } else {
- data.setImage(url);
- }
- }
- }
- }
- }
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //select * from article_tweet where location_id = '' and user_id != 1 and approve = 2
- /**
- * 收藏文章
- */
- public String collectArticle() throws ParseException {
- JSONObject jsonObject = new JSONObject();
- if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户ID或推文ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询当前操作人是否已经收藏过这篇文章
- ArticleCollect data = articleTweetService.queryArticleCollect(articleTweetDto.getId(), articleTweetDto.getUserId());
- String actionStr = "收藏";
- if (data != null) {
- if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
- actionStr = "取消收藏";
- data.setIsLose(1);
- } else {
- data.setIsLose(0);
- }
- } else {
- Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
- data = new ArticleCollect();
- data.setArticleId(articleTweetDto.getId());
- data.setUserId(articleTweetDto.getUserId());
- data.setIsLose(0);
- data.setCreateId(articleTweetDto.getUserId());
- data.setCreateDate(now);
- data.setStatus(1);
- }
- int m = articleTweetService.updateArticleCollect(data);
- if (m <= 0) {
- String message = actionStr + "失败";
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", message);
- put("code", 500);
- }}.toString());
- return null;
- }
- String successMessage = actionStr + "成功";
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", successMessage);
- put("code", 200);
- }}.toString());
- return null;
- }
- /**
- * 评论文章
- */
- public String commentArticle() throws ParseException {
- Gson gson = new Gson();
- JSONObject jsonObject = new JSONObject();
- com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
- ArticleCommentDto articleCommentDto = gson.fromJson(json.toString(), new TypeToken<ArticleCommentDto>() {
- }.getType());
- if (articleCommentDto.getArticleId() == null || Func.checkNull(articleCommentDto.getContent())
- || articleCommentDto.getParentId() == null || articleCommentDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "参数不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询操作人身份
- Users user = userService.queryByUserId(String.valueOf(articleCommentDto.getUserId()));
- if (user == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户信息已失效,评论失败");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
- ArticleComment articleComment = new ArticleComment();
- articleComment.setArticleId(articleCommentDto.getArticleId());
- articleComment.setCommentParentId(articleCommentDto.getParentId());
- articleComment.setCommentId(articleCommentDto.getUserId());
- articleComment.setCommentName(user.getUser_name());
- articleComment.setCommentImage(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
- articleComment.setContent(articleCommentDto.getContent());
- articleComment.setCreateId(articleCommentDto.getUserId());
- articleComment.setCreateDate(now);
- articleComment.setStatus(1);
- int num = articleTweetService.insertArticleComment(articleComment);
- if (num <= 0) {
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", "评论失败");
- put("code", 500);
- }}.toString());
- return null;
- }
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", "评论成功");
- put("code", 200);
- }}.toString());
- return null;
- }
- /**
- * 关注作者
- */
- public String followAuthor() throws ParseException {
- JSONObject jsonObject = new JSONObject();
- if (articleTweetDto.getAuthorId() == null || articleTweetDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "作者ID或用户ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询当前操作人是否已经关注过作者
- UserCollect data = articleTweetService.queryUserCollectNoLose(articleTweetDto.getAuthorId(), articleTweetDto.getUserId());
- String actionStr = "关注";
- if (data != null) {
- if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
- actionStr = "取消关注";
- data.setIsLose(1);
- } else {
- data.setIsLose(0);
- }
- } else {
- Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
- data = new UserCollect();
- data.setParentUserid(articleTweetDto.getAuthorId());
- data.setUserId(articleTweetDto.getUserId());
- data.setIsLose(0);
- data.setCreateId(articleTweetDto.getUserId());
- data.setCreateDate(now);
- data.setStatus(1);
- }
- int m = articleTweetService.updateUserCollect(data);
- if (m <= 0) {
- String message = actionStr + "失败";
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", message);
- put("code", 500);
- }}.toString());
- return null;
- }
- String successMessage = actionStr + "成功";
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", successMessage);
- put("code", 200);
- }}.toString());
- return null;
- }
- /**
- * 点赞文章
- */
- public String likeArticle() throws ParseException {
- JSONObject jsonObject = new JSONObject();
- if (articleTweetDto.getId() == null || articleTweetDto.getUserId() == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户ID或推文ID不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询操作人身份
- Users user = userService.queryByUserId(String.valueOf(articleTweetDto.getUserId()));
- if (user == null) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "用户信息已失效,评论失败");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- //查询当前操作人是否已经收藏过这篇文章
- ArticleLikes data = articleTweetService.queryArticleLike(articleTweetDto.getId(), articleTweetDto.getUserId());
- String actionStr = "点赞";
- if (data != null) {
- if (data.getIsLose().intValue() == 0) {//说明原来是未失效,现在要取消
- actionStr = "取消点赞";
- data.setIsLose(1);
- } else {
- data.setIsLose(0);
- }
- } else {
- Date now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
- data = new ArticleLikes();
- data.setArticleId(articleTweetDto.getId());
- data.setLikeId(articleTweetDto.getUserId());
- data.setLikeName(user.getUser_name());
- data.setLikeImage(user.getHeadPhoto() == null ? ConstDefault.DefaultHeadPhoto : user.getHeadPhoto());
- data.setIsLose(0);
- data.setCreateId(articleTweetDto.getUserId());
- data.setCreateDate(now);
- data.setStatus(1);
- }
- int m = articleTweetService.updateArticleLike(data);
- if (m <= 0) {
- String message = actionStr + "失败";
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", message);
- put("code", 500);
- }}.toString());
- return null;
- }
- String successMessage = actionStr + "成功";
- ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
- put("message", successMessage);
- put("code", 200);
- }}.toString());
- return null;
- }
- /**
- * 获取乡镇列表
- */
- public String townShips() {
- List<HotelDict> hotelDicts = hotelDictService.queryList("and code = 10");
- List<TownshipVo> result = new ArrayList<>();
- for (HotelDict hotelDict : hotelDicts) {
- TownshipVo data = new TownshipVo();
- data.setId(hotelDict.getId());
- data.setName(hotelDict.getName());
- result.add(data);
- }
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code", ResultStatusCode.OK.getStatus());
- jsonObject.put("message", "请求成功");
- jsonObject.put("data", result);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 根据乡镇ID获取民宿列表
- */
- public String hotelByid() {
- JSONObject jsonObject = new JSONObject();
- if (Func.checkNull(articleTweetDto.getTownId())) {
- jsonObject.put("code", ResultStatusCode.BAD_REQUEST.getStatus());
- jsonObject.put("message", ResultStatusCode.BAD_REQUEST.getMsg());
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- String sql = "hotel_township = '" + articleTweetDto.getTownId() + "'";
- IPage<HotelVo> houseIPage = articleTweetService.queryHotelPage(sql, page, rows);
- jsonObject.put("message", "查询分页成功");
- jsonObject.put("code", 200);
- jsonObject.put("data", houseIPage);
- ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 修改用户简介
- */
- public String updateDescript() {
- JSONObject jsonObject = new JSONObject();
- if (articleTweetDto.getAuthorId() == null || articleTweetDto.getUserId() == null || Func.checkNull(articleTweetDto.getDescript())) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "操作用户ID或主页用户ID或简介不能为空");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- if (!articleTweetDto.getAuthorId().equals(articleTweetDto.getUserId())) {
- jsonObject.put("code", 500);
- jsonObject.put("message", "当前用户无法修改其他人的简介信息");
- jsonObject.put("data", null);
- ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- int num = articleTweetService.updateDescript(articleTweetDto.getAuthorId(), articleTweetDto.getDescript());
- jsonObject.put("message", "修改成功");
- jsonObject.put("code", 200);
- ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- /**
- * 攻略分页
- * @return
- */
- public String walkthroughPage(){
- JSONObject jsonObject = new JSONObject();
- StringBuilder strSql = new StringBuilder(" and at.status=1 "); // 推文没删除才显示
- if (!Func.checkNull(key)){
- strSql.append(" and (at.user_name like '%").append(key).append("%' or at.title like '%").append(key).append("%') ");
- }
- if (!Func.checkNull(startTime) && !Func.checkNull(endTime)){
- strSql.append(" and at.create_date >= '").append(startTime).append("' ");
- strSql.append(" and at.create_date <= '").append(endTime).append("' ");
- }
- IPage<WalkthroughVo> walkthroughPage=articleTweetService.walkthroughPage(strSql.toString(),page, rows);
- jsonObject.put("message", "查询分页成功");
- jsonObject.put("code", 200);
- jsonObject.put("data", walkthroughPage);
- ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
- return null;
- }
- }
|