fanli/src/main/java/com/yeshi/fanli/controller/admin/ArticleOfficialAdminController.java
New file @@ -0,0 +1,154 @@ package com.yeshi.fanli.controller.admin; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.yeshi.utils.JsonUtil; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.yeshi.fanli.entity.dynamic.ArticleOfficial; import com.yeshi.fanli.exception.dynamic.ArticleOfficialException; import com.yeshi.fanli.service.inter.dynamic.ArticleOfficialService; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TimeUtil; import net.sf.json.JSONObject; /** * 轮播图管理 * * @author Administrator * */ @Controller @RequestMapping("admin/new/api/v1/article") public class ArticleOfficialAdminController { @Resource private ArticleOfficialService articleOfficialService; /** * 保存信息 * * @param callback * @param special * @param out */ @RequestMapping(value = "save") public void save(String callback, ArticleOfficial record, HttpServletRequest request, PrintWriter out) { try { if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest) request; articleOfficialService.save(fileRequest.getFile("file"), record); } else { articleOfficialService.save(null, record); } JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功")); } catch (ArticleOfficialException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败")); e.printStackTrace(); } } /** * 删除图片以及信息 * * @param callback * @param idArray * @param out */ @RequestMapping(value = "delete") public void delete(String callback, String idArray, PrintWriter out) { try { if (StringUtil.isNullOrEmpty(idArray)) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择操作的数据")); return; } Gson gson = new Gson(); List<String> list = gson.fromJson(idArray, new TypeToken<ArrayList<String>>() { }.getType()); if (list == null || list.size() == 0) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检测到删除的数据")); return; } articleOfficialService.deleteBatchByPrimaryKey(list); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功")); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败")); e.printStackTrace(); } } /** * 查询 * * @param callback * @param pageIndex * @param pageSize * @param bannerId * @param out */ @RequestMapping(value = "query") public void query(String callback, Integer pageIndex, Integer pageSize, String key, Integer state, PrintWriter out) { if (pageIndex == null || pageIndex < 1) { pageIndex = 1; } if (pageSize == null || pageSize < 1) { pageSize = Constant.PAGE_SIZE; } try { List<ArticleOfficial> list = articleOfficialService.query((pageIndex -1)*pageSize, pageSize, key, state); if (list == null || list.size() == 0) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据")); return; } for (ArticleOfficial article : list) { Date startTime = article.getStartTime(); if (startTime == null) { article.setStartTimeChar(""); } else { article.setStartTimeChar(TimeUtil.formatDateAddT(startTime)); } Date endTime = article.getEndTime(); if (endTime == null) { article.setEndTimeChar(""); } else { article.setEndTimeChar(TimeUtil.formatDateAddT(endTime)); } } long count = articleOfficialService.count(key, state); int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); JSONObject data = new JSONObject(); data.put("pe", pe); data.put("result_list", list); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常")); e.printStackTrace(); } } } fanli/src/main/java/com/yeshi/fanli/controller/client/v2/DynamicControllerV2.java
@@ -24,15 +24,22 @@ import com.yeshi.fanli.entity.bus.clazz.GoodsClass; import com.yeshi.fanli.entity.bus.homemodule.Special; import com.yeshi.fanli.entity.bus.homemodule.SpecialLabel; import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture; import com.yeshi.fanli.entity.common.JumpDetailV2; import com.yeshi.fanli.entity.dynamic.DynamicInfo; import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.dynamic.ArticleOfficialService; import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; import com.yeshi.fanli.service.inter.homemodule.SpecialService; import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService; import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.VersionUtil; import com.yeshi.fanli.util.taobao.DaTaoKeUtil; import com.yeshi.fanli.vo.dynamic.ArticleVO; import com.yeshi.fanli.vo.msg.ClientTextStyleVO; import net.sf.json.JSONObject; @@ -61,130 +68,17 @@ @Resource private SpecialService specialService; @Resource private ArticleOfficialService articleOfficialService; @Resource private SwiperPictureService swiperPictureService; @Resource private ConfigService configService; /** * 动态商品列表 * @param acceptData * @param page * @param cid * @param subId * @param out */ @RequestMapping(value = "getList", method = RequestMethod.POST) public void getList(AcceptData acceptData, Integer page, Long cid, Long subId, PrintWriter out) { if (cid == null) { out.print(JsonUtil.loadFalseResult("主分类id不能为空")); return; } if (cid != null && cid == 5) { // 活动主题 getSpecialList(acceptData, page, subId, out); return; } long count = 0; int platform = 1; if ("ios".equalsIgnoreCase(acceptData.getPlatform())) { platform = 2; } int version = Integer.parseInt(acceptData.getVersion()); List<DynamicInfo> list = dynamicInfoService.queryV2(platform, version, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid, subId); if (list == null) { list = new ArrayList<DynamicInfo>(); } else { count = dynamicInfoService.count(cid, subId); } JSONObject data = new JSONObject(); data.put("count", count); data.put("list", getGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 活动列表 * @param acceptData * @param out */ private void getSpecialList(AcceptData acceptData, Integer page, Long subId, PrintWriter out) { if (subId == null) { out.print(JsonUtil.loadFalseResult("分类id不能为空")); return; } // 平台区分 int platformCode = Constant.getPlatformCode(acceptData.getPlatform()); List<String> listKey = new ArrayList<String>(); if (subId == 1) { // 淘宝 listKey.add("special_channel_tb"); } else if (subId == 2) { // 京东 listKey.add("special_channel_jd"); } else if (subId == 3) { // 拼多多 listKey.add("special_channel_pdd"); } else { // 全部 listKey.add("special_channel_tb"); listKey.add("special_channel_jd"); listKey.add("special_channel_pdd"); } List<Special> list = specialService.listByPlaceKeyHasLabel((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, listKey, platformCode, Integer.parseInt(acceptData.getVersion())); long time = System.currentTimeMillis(); // 删除尚未启用的过期的 for (int i = 0; i < list.size(); i++) { Special special = list.get(i); if (special.getState() == 1L) { list.remove(i--); } else { if (special.getStartTime() != null && special.getEndTime() != null) special.setTimeTask(true); else special.setTimeTask(false); if (special.isTimeTask()) { if (time < special.getStartTime().getTime() || time > special.getEndTime().getTime()) { list.remove(i--); } else// 设置倒计时 { special.setCountDownTime((special.getEndTime().getTime() - time) / 1000); } } List<SpecialLabel> listLabels = special.getListLabels(); if (listLabels != null && !listLabels.isEmpty()) { List<ClientTextStyleVO> labels = new ArrayList<>(); for (SpecialLabel specialLabel: listLabels) { labels.add(new ClientTextStyleVO(specialLabel.getName(), specialLabel.getBgColor())); } special.setLabels(labels); } } } long count = specialService.countByPlaceKeyList( listKey, platformCode, Integer.parseInt(acceptData.getVersion())); GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 查询顶部分类 * @@ -229,19 +123,19 @@ List<GoodsClass> listSub = new ArrayList<GoodsClass>(); listSub.add(new GoodsClass(0L, "今日单品")); listSub.addAll(DaTaoKeUtil.goodsClasses); GoodsClass menu1 = new GoodsClass(1L, "热销"); menu1.setListSub(listSub); GoodsClass menu2 = new GoodsClass(2L, "推荐"); menu2.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu3 = new GoodsClass(3L, "好店"); menu3.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu4 = new GoodsClass(4L, "邀请"); menu4.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu5 = new GoodsClass(5L, "活动"); List<GoodsClass> sub5 = new ArrayList<GoodsClass>(); sub5.add(new GoodsClass(0L, "全部")); @@ -249,28 +143,160 @@ sub5.add(new GoodsClass(2L, "京东")); sub5.add(new GoodsClass(3L, "拼多多")); menu5.setListSub(sub5); GoodsClass menu6 = new GoodsClass(6L, "学院"); menu6.setListSub(new ArrayList<GoodsClass>()); List<GoodsClass> list = new ArrayList<GoodsClass>(); list.add(menu1); list.add(menu5); list.add(menu2); // 2.0.5版本隐藏 好店栏目 if (!VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) { list.add(menu3); } // 2.0.6版本增加 学院栏目 if (VersionUtil.greaterThan_2_0_6(acceptData.getPlatform(), acceptData.getVersion())) { list.add(menu6); } list.add(menu4); JSONObject data = new JSONObject(); data.put("list", JsonUtil.getApiCommonGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 动态商品列表 * * @param acceptData * @param page * @param cid * @param subId * @param out */ @RequestMapping(value = "getList", method = RequestMethod.POST) public void getList(AcceptData acceptData, Integer page, Long cid, Long subId, PrintWriter out) { if (cid == null) { out.print(JsonUtil.loadFalseResult("主分类id不能为空")); return; } if (cid != null) { if (cid == 5) { // 活动主题 getSpecialList(acceptData, page, subId, out); return; } else if (cid == 6) { // 学院 getArticleList(acceptData, page, null, false, out); return; } } long count = 0; int platform = 1; if ("ios".equalsIgnoreCase(acceptData.getPlatform())) { platform = 2; } int version = Integer.parseInt(acceptData.getVersion()); List<DynamicInfo> list = dynamicInfoService.queryV2(platform, version, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid, subId); if (list == null) { list = new ArrayList<DynamicInfo>(); } else { count = dynamicInfoService.count(cid, subId); } JSONObject data = new JSONObject(); data.put("count", count); data.put("list", getGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 活动列表 * * @param acceptData * @param out */ private void getSpecialList(AcceptData acceptData, Integer page, Long subId, PrintWriter out) { if (subId == null) { out.print(JsonUtil.loadFalseResult("分类id不能为空")); return; } // 平台区分 int platformCode = Constant.getPlatformCode(acceptData.getPlatform()); List<String> listKey = new ArrayList<String>(); if (subId == 1) { // 淘宝 listKey.add("special_channel_tb"); } else if (subId == 2) { // 京东 listKey.add("special_channel_jd"); } else if (subId == 3) { // 拼多多 listKey.add("special_channel_pdd"); } else { // 全部 listKey.add("special_channel_tb"); listKey.add("special_channel_jd"); listKey.add("special_channel_pdd"); } List<Special> list = specialService.listByPlaceKeyHasLabel((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, listKey, platformCode, Integer.parseInt(acceptData.getVersion())); long time = System.currentTimeMillis(); // 删除尚未启用的过期的 for (int i = 0; i < list.size(); i++) { Special special = list.get(i); if (special.getState() == 1L) { list.remove(i--); } else { if (special.getStartTime() != null && special.getEndTime() != null) special.setTimeTask(true); else special.setTimeTask(false); if (special.isTimeTask()) { if (time < special.getStartTime().getTime() || time > special.getEndTime().getTime()) { list.remove(i--); } else// 设置倒计时 { special.setCountDownTime((special.getEndTime().getTime() - time) / 1000); } } List<SpecialLabel> listLabels = special.getListLabels(); if (listLabels != null && !listLabels.isEmpty()) { List<ClientTextStyleVO> labels = new ArrayList<>(); for (SpecialLabel specialLabel : listLabels) { labels.add(new ClientTextStyleVO(specialLabel.getName(), specialLabel.getBgColor())); } special.setLabels(labels); } } } long count = specialService.countByPlaceKeyList(listKey, platformCode, Integer.parseInt(acceptData.getVersion())); GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 时间处理 * * @return */ private Gson getGson() { @@ -282,18 +308,18 @@ String desc = ""; if (value != null) { // 判断是否是同一天 Calendar calendar = Calendar.getInstance(); calendar.setTime(value); int y1 = calendar.get(Calendar.YEAR);//获取年份 int d1 = calendar.get(Calendar.DAY_OF_YEAR);//获取年中第几天 int y1 = calendar.get(Calendar.YEAR);// 获取年份 int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 Date nowDate = new Date(); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(nowDate); int y2 = calendar2.get(Calendar.YEAR);//获取年份 int d2 = calendar2.get(Calendar.DAY_OF_YEAR);//获取年中第几天 int y2 = calendar2.get(Calendar.YEAR);// 获取年份 int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 long old = value.getTime(); long now = nowDate.getTime(); if (y1 == y2) { @@ -301,9 +327,9 @@ long cha = now - old; if (cha < 1000 * 60 * 2L) { desc = "刚刚"; }else if (cha < 1000 * 60 * 60L) { } else if (cha < 1000 * 60 * 60L) { desc = (cha / (1000 * 60)) + "分钟前"; }else { } else { desc = (cha / (1000 * 60 * 60)) + "小时前"; } } else if (d2 - d1 == 1) { @@ -333,4 +359,99 @@ Gson gson = gb.create(); return gson; } /** * 活动列表 * * @param acceptData * @param out */ private void getArticleList(AcceptData acceptData, Integer page, String key, boolean search, PrintWriter out) { List<ArticleVO> list = articleOfficialService.queryValid((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, key); if (list != null) { for (ArticleVO article: list) { String tags = article.getTags(); if (!StringUtil.isNullOrEmpty(tags)) { String[] arrayTags = tags.split("\\s+"); List<ClientTextStyleVO> labels = new ArrayList<ClientTextStyleVO>(); String[] arrayTagsColour = null; String tagsColour = article.getTagsColour(); if (!StringUtil.isNullOrEmpty(tagsColour)) { arrayTagsColour = tags.split("\\s+"); } String color = "#FE0014"; for (int i =0; i < arrayTags.length;i ++) { String tag = arrayTags[i]; if (arrayTagsColour.length == arrayTags.length) { color = arrayTagsColour[i]; } ClientTextStyleVO styleVO = new ClientTextStyleVO(); styleVO.setColor(color); styleVO.setContent(tag); labels.add(styleVO); } article.setLabels(labels); } } } GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); if (page == 1 && !search) { List<SwiperPicture> banners = swiperPictureService.getByBannerCardAndVersion("article_banners",acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())); if (banners == null) banners = new ArrayList<>(); data.put("banners", gson.toJson(banners)); List<Special> listSpecial = specialService.listByVersion(0, Integer.MAX_VALUE, "article_specials", acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())); if (listSpecial == null) listSpecial = new ArrayList<>(); for (Special special : listSpecial) { boolean needLogin = special.isJumpLogin(); JumpDetailV2 jumpDetail = special.getJumpDetail(); if (jumpDetail != null) { jumpDetail.setNeedLogin(needLogin); special.setJumpDetail(jumpDetail); } } data.put("specials", gson.toJson(listSpecial)); } data.put("count", articleOfficialService.countValid(key)); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 文章搜索 * @param acceptData * @param page * @param key * @param out */ @RequestMapping(value = "searchArticle", method = RequestMethod.POST) public void searchArticle(AcceptData acceptData, Integer page, String key, PrintWriter out) { getArticleList(acceptData, page, key, true, out); } /** * 文章搜索 * @param acceptData * @param page * @param key * @param out */ @RequestMapping(value = "getArticleHot", method = RequestMethod.POST) public void getArticleHot(AcceptData acceptData, PrintWriter out) { JSONObject data = new JSONObject(); data.put("words", configService.get("article_hot_words")); out.print(JsonUtil.loadTrueResult(data)); } } fanli/src/main/java/com/yeshi/fanli/controller/client/v2/InviteControllerV2.java
@@ -635,20 +635,16 @@ * @param out */ @RequestMapping(value = "tailorCode") public void tailorCode(AcceptData acceptData, Long uid, PrintWriter out) { public void tailorCode(AcceptData acceptData, String callback, Long uid, PrintWriter out) { if (uid == null) { out.print(JsonUtil.loadFalseResult("传递参数缺失")); JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户id缺失")); return; } JSONObject data = new JSONObject(); data.put("num", threeSaleSerivce.countFirstTeam(uid, 1)); data.put("limit", Constant.INVITE_CODRE_TAILOR_LIMIT); data.put("use", "邀请码的作用"); data.put("useInfo", "1.邀请码可帮助好友激活邀请功能;\r\n2.好友通过你的邀请码激活邀请功能后,将成为你的直接粉丝,未来产生的订单你都有奖金;\r\n3.邀请码具有唯一性。"); data.put("merit", "专属邀请码优势"); data.put("meritInfo", "1.你可以自由设置4~12位简单易记的邀请码;\r\n" + "2.专属邀请码是对你和你的团队尊贵身份的彰显。"); out.print(JsonUtil.loadTrueResult(data)); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } fanli/src/main/java/com/yeshi/fanli/dao/ElasticBaseDao.java
@@ -5,6 +5,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.http.HttpHost; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.get.GetRequest; @@ -28,18 +29,37 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.springframework.data.elasticsearch.annotations.Document; @Repository public abstract class ElasticBaseDao<T> { // 地址 private static String host = "192.168.1.200"; // 端口 private static Integer port = 9200; // 数据库名称 public static String index = "order"; // 初始化api客户端 public static RestHighLevelClient client = new RestHighLevelClient( RestClient.builder(new HttpHost(host, port, "http"))); public static RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port,"http")));; /** * 获取index * @param bean * @return */ public String getDocument(Class<?> entityClass) { if (entityClass.isAnnotationPresent(Document.class)) { Document doc = (Document)entityClass.getAnnotation(Document.class); System.out.println(doc.indexName()); return doc.indexName(); } String name = entityClass.getName(); return name.substring(name.lastIndexOf(".") + 1, name.length()); } /** * 插入数据 @@ -48,8 +68,10 @@ * @return */ public void save(T bean) { String document = getDocument(bean.getClass()); String json = JsonUtil.getSimpleGson().toJson(bean); IndexRequest request = new IndexRequest(index); IndexRequest request = new IndexRequest(document); request.source(json, XContentType.JSON); // 同步执行 try { @@ -66,8 +88,10 @@ * @return */ public void save(T bean, String id) { String document = getDocument(bean.getClass()); String json = JsonUtil.getSimpleGson().toJson(bean); IndexRequest request = new IndexRequest(index).id(id); IndexRequest request = new IndexRequest(document).id(id); request.source(json, XContentType.JSON); // 同步执行 try { @@ -83,7 +107,9 @@ * @param bean */ public void update(String id, T bean) { UpdateRequest request = new UpdateRequest(index, id); String document = getDocument(bean.getClass()); UpdateRequest request = new UpdateRequest(document, id); String json = new GsonBuilder().create().toJson(bean); request.doc(json, XContentType.JSON); try { @@ -99,8 +125,9 @@ * * @param Document id */ public void delete(String id) { DeleteRequest request = new DeleteRequest(index, id); public void delete(String id, Class<T> entityClass) { String document = getDocument(entityClass); DeleteRequest request = new DeleteRequest(document, id); try { client.delete(request, RequestOptions.DEFAULT); } catch (IOException e) { @@ -115,7 +142,8 @@ * @return */ public T get(String id, Class<T> entityClass) { GetRequest request = new GetRequest(index, id); String document = getDocument(entityClass); GetRequest request = new GetRequest(document, id); try { GetResponse getResponse = client.get(request, RequestOptions.DEFAULT); if (getResponse.isExists()) { @@ -138,6 +166,7 @@ * @return */ public List<T> query(String document, String key, int start, int count, Class<T> entityClass) { String index = getDocument(entityClass); List<T> list = new ArrayList<>(); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(QueryBuilders.termQuery(document, key)); @@ -163,10 +192,5 @@ } return list; } } fanli/src/main/java/com/yeshi/fanli/dao/dynamic/ArticleOfficialDao.java
New file @@ -0,0 +1,146 @@ package com.yeshi.fanli.dao.dynamic; import java.util.Date; import java.util.List; import java.util.regex.Pattern; import javax.annotation.Resource; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Repository; import com.yeshi.fanli.entity.dynamic.ArticleOfficial; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.vo.dynamic.ArticleVO; @Repository public class ArticleOfficialDao { @Resource private MongoTemplate mongoTemplate; /** * 新增 * * @param record */ public void save(ArticleOfficial record) { if (record == null) { return; } mongoTemplate.save(record); } /** * 根据id查询数据 * * @param id * @return */ public ArticleOfficial getById(String id) { Query query = new Query(); query.addCriteria(Criteria.where("id").is(id)); return mongoTemplate.findOne(query, ArticleOfficial.class); } /** * 删除 * * @param id * @return */ public void deleteById(String id) { ArticleOfficial info = getById(id); if (info == null) { return; } mongoTemplate.remove(info); } /** * 查询 * * @return */ public List<ArticleOfficial> query(int start, int count, String key, Integer state) { Query query = new Query(); if (state != null) { query.addCriteria(Criteria.where("state").is(state)); } if (!StringUtil.isNullOrEmpty(key)) query.addCriteria(new Criteria().orOperator( Criteria.where("title").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)), new Criteria().andOperator(Criteria.where("content").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))), new Criteria().andOperator(Criteria.where("tags").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))) )); // 分页 query.skip(start).limit(count); query.with(new Sort(Sort.Direction.DESC,"weight")); return mongoTemplate.find(query, ArticleOfficial.class); } public long count(String key, Integer state) { Query query = new Query(); if (state != null) { query.addCriteria(Criteria.where("state").is(state)); } if (!StringUtil.isNullOrEmpty(key)) query.addCriteria(new Criteria().orOperator( Criteria.where("title").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)), new Criteria().andOperator(Criteria.where("content").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))), new Criteria().andOperator(Criteria.where("tags").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))) )); return mongoTemplate.count(query, ArticleOfficial.class); } /** * 查询有效 * @param start * @param count * @param key * @return */ public List<ArticleVO> queryValid(int start, int count, String key) { Date now = new Date(); Query query = new Query(); query.addCriteria(Criteria.where("state").is(1)); query.addCriteria(Criteria.where("startTime").lte(now)); query.addCriteria(Criteria.where("endTime").gte(now)); if (!StringUtil.isNullOrEmpty(key)) query.addCriteria(new Criteria().orOperator( Criteria.where("title").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)), new Criteria().andOperator(Criteria.where("content").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))), new Criteria().andOperator(Criteria.where("tags").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))) )); //分页 query.skip(start).limit(count); query.with(new Sort(Sort.Direction.DESC,"weight")).with(new Sort(Sort.Direction.DESC,"createTime")); return mongoTemplate.find(query, ArticleVO.class); } /** * 统计有效 * @param key * @return */ public long countValid(String key) { Date now = new Date(); Query query = new Query(); query.addCriteria(Criteria.where("state").is(1)); query.addCriteria(Criteria.where("startTime").lte(now)); query.addCriteria(Criteria.where("endTime").gte(now)); if (!StringUtil.isNullOrEmpty(key)) query.addCriteria(new Criteria().orOperator( Criteria.where("title").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)), new Criteria().andOperator(Criteria.where("content").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))), new Criteria().andOperator(Criteria.where("tags").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE))) )); return mongoTemplate.count(query, ArticleOfficial.class); } } fanli/src/main/java/com/yeshi/fanli/dao/elastic/ESOrderDao.java
@@ -31,48 +31,6 @@ * @param uid 用户id * @return */ public List<ESOrder> queryMatch(String key, String uid) { List<ESOrder> list = new ArrayList<ESOrder>(); // 商品名称匹配 MatchQueryBuilder match1 = new MatchQueryBuilder("goodsName", key).fuzziness(Fuzziness.AUTO); // 订单号匹配 MatchQueryBuilder match2 = new MatchQueryBuilder("orderNo", key).fuzziness(Fuzziness.AUTO); TermQueryBuilder term1 = QueryBuilders.termQuery("uid", uid); // 上级 TermQueryBuilder term2 = QueryBuilders.termQuery("uidDirect", uid); // 上上级 TermQueryBuilder term3 = QueryBuilders.termQuery("uidIndirect", uid); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(match1).query(match2).query(term1).query(term2).query(term3); SearchRequest searchRequest = new SearchRequest(); searchRequest.indices(index); searchRequest.source(sourceBuilder); try { SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); SearchHits hits = searchResponse.getHits(); SearchHit[] searchHits = hits.getHits(); Gson gson = new Gson(); for (SearchHit hit : searchHits) { String content = hit.getSourceAsString(); list.add(gson.fromJson(content, ESOrder.class)); } } catch (IOException e) { e.printStackTrace(); } return list; } /** * 查询匹配 * * @param key 搜索词 * @param uid 用户id * @return */ public List<ESOrder> query(String key, String uid) { List<ESOrder> list = new ArrayList<ESOrder>(); // 商品名称匹配 @@ -87,7 +45,7 @@ sourceBuilder.query(QueryBuilders.boolQuery().must(should1).must(should2)); SearchRequest searchRequest = new SearchRequest(); searchRequest.indices(index); searchRequest.indices(getDocument(ESOrder.class)); searchRequest.source(sourceBuilder); try { SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); fanli/src/main/java/com/yeshi/fanli/entity/dynamic/ArticleOfficial.java
New file @@ -0,0 +1,217 @@ package com.yeshi.fanli.entity.dynamic; import java.util.Date; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Field; import com.google.gson.annotations.Expose; /** * 文章 * * @author Administrator * */ @Document(collection = "dynamic_article") public class ArticleOfficial { @Expose @Id @Field("id") private String id; // 标题 @Expose @Field("title") private String title; // 内容 @Expose @Field("content") private String content; // 图片 @Expose @Field("picture") private String picture; // 标签 @Field("tags") private String tags; // 标签 -颜色 @Field("tagsColour") private String tagsColour; // 阅读数量 - 虚拟 @Expose @Field("readNum") private Integer readNum; // 阅读数量 - 真实 @Field("readNumReal") private Integer readNumReal; // 是否包含视频 @Expose @Field("videoContain") private Boolean videoContain; @Expose @Field("articlelink") private String articlelink; // 状态 @Field("weight") private Double weight; // 状态 @Field("state") private Integer state; // 起始时间 @Field("startTime") private Date startTime; // 结束时间 @Field("endTime") private Date endTime; @Field("createTime") private Date createTime; private String startTimeChar; private String endTimeChar; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getPicture() { return picture; } public void setPicture(String picture) { this.picture = picture; } public String getTags() { return tags; } public void setTags(String tags) { this.tags = tags; } public Integer getReadNum() { return readNum; } public void setReadNum(Integer readNum) { this.readNum = readNum; } public Integer getReadNumReal() { return readNumReal; } public void setReadNumReal(Integer readNumReal) { this.readNumReal = readNumReal; } public Boolean getVideoContain() { return videoContain; } public void setVideoContain(Boolean videoContain) { this.videoContain = videoContain; } public Integer getState() { return state; } public void setState(Integer state) { this.state = state; } public Date getStartTime() { return startTime; } public void setStartTime(Date startTime) { this.startTime = startTime; } public Date getEndTime() { return endTime; } public void setEndTime(Date endTime) { this.endTime = endTime; } public String getTagsColour() { return tagsColour; } public void setTagsColour(String tagsColour) { this.tagsColour = tagsColour; } public String getStartTimeChar() { return startTimeChar; } public void setStartTimeChar(String startTimeChar) { this.startTimeChar = startTimeChar; } public String getEndTimeChar() { return endTimeChar; } public void setEndTimeChar(String endTimeChar) { this.endTimeChar = endTimeChar; } public String getArticlelink() { return articlelink; } public void setArticlelink(String articlelink) { this.articlelink = articlelink; } public Double getWeight() { return weight; } public void setWeight(Double weight) { this.weight = weight; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } } fanli/src/main/java/com/yeshi/fanli/entity/order/ESOrder.java
@@ -1,20 +1,41 @@ package com.yeshi.fanli.entity.order; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.FieldType; /** * index:是否设置索引, store是否存储数据,type:数据类型,analyzer:分词粒度选择,searchAnalyzer:查询进行分词处理 * ik_smart:进行最小粒度分词,ik_max_word进行最大粒度分词 * @author Derlin * */ @Document(indexName = "order", type = "doc") public class ESOrder { // 订单相关uid @Field(index=true, store = true, type = FieldType.Long) private Long uid; // 上级直接uid @Field(index=true, store = true, type = FieldType.Long) private Long uidDirect; // 上 上级直接uid @Field(index=true, store = true, type = FieldType.Long) private Long uidIndirect; // 商品名称 @Field(index=true, store = true, type = FieldType.Text) private String goodsName; // 订单号 @Field(index=true, store = true, type = FieldType.Text) private String orderNo; // 交易id @Field(index=true, store = true, type = FieldType.Text) private String tradeId; // 交易平台 @Field(index=true, store = true, type = FieldType.Integer) private Integer platform; public Long getUid() { return uid; fanli/src/main/java/com/yeshi/fanli/exception/dynamic/ArticleOfficialException.java
New file @@ -0,0 +1,16 @@ package com.yeshi.fanli.exception.dynamic; import com.yeshi.fanli.exception.BaseException; public class ArticleOfficialException extends BaseException { private static final long serialVersionUID = 1L; public ArticleOfficialException(int code, String msg) { super(code, msg); } public ArticleOfficialException() { super(); } } fanli/src/main/java/com/yeshi/fanli/mapping/redpack/RedPackBalanceMapper.xml
@@ -74,13 +74,17 @@ <select id="query" resultMap="VOResultMap"> SELECT b.*,IFNULL(dd.giveMoney,0)AS giveMoney,IFNULL(dd2.useMoney,0)AS useMoney ,IFNULL(dd3.exchangeMoney,0)AS exchangeMoney ,IFNULL(dd4.totalWin,0)AS totalWin FROM `yeshi_ec_red_pack_balance` b LEFT JOIN (SELECT ABS(SUM(d.`rpd_money`)) AS giveMoney,d.`rpd_uid` FROM `yeshi_ec_red_pack_detail` d WHERE d.`rpd_type` = 'giveOthersSucceed' AND d.`rpd_uid` LIKE '${key}%')dd ON dd.rpd_uid = b.`rpb_uid` WHERE d.`rpd_type` = 'giveOthersSucceed' AND d.`rpd_uid` LIKE '${key}%' GROUP BY d.`rpd_uid` )dd ON dd.rpd_uid = b.`rpb_uid` LEFT JOIN (SELECT ABS(SUM(d.`rpd_money`)) AS useMoney,d.`rpd_uid` FROM `yeshi_ec_red_pack_detail` d WHERE d.`rpd_type` = 'useByShopOrder' AND d.`rpd_uid` LIKE '${key}%')dd2 ON dd2.rpd_uid = b.`rpb_uid` WHERE d.`rpd_type` = 'useByShopOrder' AND d.`rpd_uid` LIKE '${key}%' GROUP BY d.`rpd_uid` )dd2 ON dd2.rpd_uid = b.`rpb_uid` LEFT JOIN (SELECT ABS(SUM(d.`rpd_money`)) AS exchangeMoney,d.`rpd_uid` FROM `yeshi_ec_red_pack_detail` d WHERE d.`rpd_type` = 'redExchangePass' AND d.`rpd_uid` LIKE '${key}%')dd3 ON dd3.rpd_uid = b.`rpb_uid` WHERE d.`rpd_type` = 'redExchangePass' AND d.`rpd_uid` LIKE '${key}%' GROUP BY d.`rpd_uid` )dd3 ON dd3.rpd_uid = b.`rpb_uid` LEFT JOIN (SELECT ABS(SUM(d.`rpd_money`)) AS totalWin,d.`rpd_uid` FROM `yeshi_ec_red_pack_detail` d WHERE d.`rpd_type` IN('newUserReward','invite','increaseReward','seriesReward','giveOthersReceive') AND d.`rpd_uid` LIKE '${key}%')dd4 ON dd4.rpd_uid = b.`rpb_uid` WHERE d.`rpd_type` IN('newUserReward','invite','increaseReward','seriesReward','giveOthersReceive') AND d.`rpd_uid` LIKE '${key}%' GROUP BY d.`rpd_uid` )dd4 ON dd4.rpd_uid = b.`rpb_uid` WHERE b.`rpb_uid` LIKE '${key}%' <if test="state != null"> AND b.rpb_state = #{state} fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/ArticleOfficialServiceImpl.java
New file @@ -0,0 +1,193 @@ package com.yeshi.fanli.service.impl.dynamic; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.UUID; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import org.yeshi.utils.DateUtil; import org.yeshi.utils.tencentcloud.COSManager; import com.yeshi.fanli.dao.dynamic.ArticleOfficialDao; import com.yeshi.fanli.entity.dynamic.ArticleOfficial; import com.yeshi.fanli.exception.dynamic.ArticleOfficialException; import com.yeshi.fanli.service.inter.dynamic.ArticleOfficialService; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.vo.dynamic.ArticleVO; @Service public class ArticleOfficialServiceImpl implements ArticleOfficialService { @Resource private ArticleOfficialDao articleOfficialDao; @Override public void save(MultipartFile file, ArticleOfficial record) throws ArticleOfficialException { Integer state = record.getState(); if (state == null) { state = 0; } String tilte =record.getTitle(); String content = record.getContent(); if (StringUtil.isNullOrEmpty(tilte) || StringUtil.isNullOrEmpty(content)) { throw new ArticleOfficialException(1, "标题、内容不能为空"); } Integer readNum = record.getReadNum(); if (readNum == null) { throw new ArticleOfficialException(1, "请输入浏览数量(虚拟)"); } String tags = record.getTags(); if (!StringUtil.isNullOrEmpty(tags)) { String[] arrayTags = tags.trim().split("\\s+"); String tagsColour = record.getTagsColour(); if (!StringUtil.isNullOrEmpty(tagsColour)) { String[] arrayTagsColour = tagsColour.trim().split("\\s+"); if (arrayTags.length != arrayTagsColour.length) { throw new ArticleOfficialException(1, "标签与标签颜色数量不匹配"); } record.setTagsColour(tagsColour.trim()); } record.setTags(tags.trim()); } String articlelink = record.getArticlelink(); if (StringUtil.isNullOrEmpty(articlelink)) { throw new ArticleOfficialException(1, "文章链接不能为空"); } try { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String startTime_str = record.getStartTimeChar(); if (!StringUtil.isNullOrEmpty(startTime_str)) { startTime_str = startTime_str.replaceAll("T", " "); record.setStartTime(format.parse(startTime_str)); } String endTime_str = record.getEndTimeChar(); if (!StringUtil.isNullOrEmpty(endTime_str)) { endTime_str = endTime_str.replaceAll("T", " "); record.setEndTime(format.parse(endTime_str)); } } catch (Exception e) { throw new ArticleOfficialException(1, "时间格式不正确"); } Date startTime = record.getStartTime(); if (startTime == null) { record.setStartTime(new Date()); } Date endTime = record.getEndTime(); if (endTime == null) { record.setEndTime(DateUtil.plusYears(new Date(), 100)); } Boolean videoContain = record.getVideoContain(); if (videoContain == null) { videoContain = false; } Double weight = record.getWeight(); if (weight == null) record.setWeight(1.1); String picture = null; if (file != null) { try { // 图片上传 picture = uploadPicture(file); } catch (Exception e) { throw new ArticleOfficialException(1, "图片上传失败"); } if (!StringUtil.isNullOrEmpty(picture)) { record.setPicture(picture); } } if (StringUtil.isNullOrEmpty(record.getId())) { record.setId(UUID.randomUUID().toString().replace("-", "")); } else { ArticleOfficial resultObj = articleOfficialDao.getById(record.getId()); if (resultObj == null) throw new ArticleOfficialException(1, "修改内容已不存在"); if (!StringUtil.isNullOrEmpty(resultObj.getPicture())) { if (!StringUtil.isNullOrEmpty(picture)) { COSManager.getInstance().deleteFile(resultObj.getPicture()); } else { record.setPicture(resultObj.getPicture()); } } } articleOfficialDao.save(record); } /** * 上传图片 * * @param file * @return * @throws Exception */ public String uploadPicture(MultipartFile file) throws Exception { // 文件解析 InputStream inputStream = file.getInputStream(); String contentType = file.getContentType(); String type = contentType.substring(contentType.indexOf("/") + 1); // 文件路径 String filePath = "/img/article/" + UUID.randomUUID().toString().replace("-", "") + "." + type; // 执行上传 String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); return fileLink; } @Override public void deleteBatchByPrimaryKey(List<String> list) { if (list == null || list.size() == 0) { return; } for (String id: list) { articleOfficialDao.deleteById(id); } } @Override public ArticleOfficial getById(String id) { return articleOfficialDao.getById(id); } @Override public List<ArticleOfficial> query(int start, int count, String key,Integer state) { return articleOfficialDao.query(start, count, key, state); } @Override public long count(String key, Integer state) { return articleOfficialDao.count(key, state); } @Override public List<ArticleVO> queryValid(int start, int count, String key) { return articleOfficialDao.queryValid(start, count, key); } @Override public long countValid(String key) { return articleOfficialDao.countValid(key); } } fanli/src/main/java/com/yeshi/fanli/service/inter/dynamic/ArticleOfficialService.java
New file @@ -0,0 +1,52 @@ package com.yeshi.fanli.service.inter.dynamic; import java.util.List; import org.springframework.web.multipart.MultipartFile; import com.yeshi.fanli.entity.dynamic.ArticleOfficial; import com.yeshi.fanli.exception.dynamic.ArticleOfficialException; import com.yeshi.fanli.vo.dynamic.ArticleVO; public interface ArticleOfficialService { /** * 插入 * * @param record */ public void save(MultipartFile file, ArticleOfficial record) throws ArticleOfficialException; /** * 根据id查询 * * @param id * @return */ public ArticleOfficial getById(String id); public List<ArticleOfficial> query(int start, int count, String key, Integer state); public long count(String key, Integer state); /** * 查询有效 * * @param start * @param count * @param key * @return */ public List<ArticleVO> queryValid(int start, int count, String key); /** * 统计有效 * * @param key * @return */ public long countValid(String key); public void deleteBatchByPrimaryKey(List<String> list); } fanli/src/main/java/com/yeshi/fanli/vo/dynamic/ArticleVO.java
New file @@ -0,0 +1,22 @@ package com.yeshi.fanli.vo.dynamic; import java.util.List; import com.google.gson.annotations.Expose; import com.yeshi.fanli.entity.dynamic.ArticleOfficial; import com.yeshi.fanli.vo.msg.ClientTextStyleVO; public class ArticleVO extends ArticleOfficial{ @Expose private List<ClientTextStyleVO> labels;// 标签 public List<ClientTextStyleVO> getLabels() { return labels; } public void setLabels(List<ClientTextStyleVO> labels) { this.labels = labels; } }