From 3db7969d47c7bb8a9af9018efdd8affe61fa81a9 Mon Sep 17 00:00:00 2001 From: xyiege Date: Thu, 21 Jul 2022 16:41:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8A=A5=E8=A1=A8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/AdminIndexController.java | 6 +-- .../cn/chjyj/szwh/mapper/GoodsMapper.java | 10 +++++ .../cn/chjyj/szwh/service/IndexService.java | 8 ++-- .../szwh/service/impl/IndexServiceImpl.java | 42 +++++++++++++------ .../cn/chjyj/szwh/utils/RequestUtils.java | 6 ++- .../cn/chjyj/szwh/utils/SzwhApiUtils.java | 3 +- .../resources/mapper/szwh/GoodsMapper.xml | 15 +++---- .../cn/chjyj/szwh/mapper/GoodsMapperTest.java | 13 ++++++ 8 files changed, 74 insertions(+), 29 deletions(-) diff --git a/src/main/java/cn/chjyj/szwh/controller/admin/AdminIndexController.java b/src/main/java/cn/chjyj/szwh/controller/admin/AdminIndexController.java index d21924b..24a4f73 100644 --- a/src/main/java/cn/chjyj/szwh/controller/admin/AdminIndexController.java +++ b/src/main/java/cn/chjyj/szwh/controller/admin/AdminIndexController.java @@ -26,10 +26,8 @@ public class AdminIndexController extends BaseController { String leftDate=request.getString("leftDate"); String rightDate=request.getString("rightDate"); String saleRankingDate = request.getString("saleRankingDate"); - - String dtflag = StringUtils.isEmpty(leftDate)?"":leftDate; -// // 执行查询操作 - Map result =indexService.getCountSys(dtflag); + // 统计查询 + Map result =indexService.getCountSys(leftDate,rightDate,saleRankingDate); // 拼装结果 jsonObject.put("code",200); jsonObject.put("data",result); diff --git a/src/main/java/cn/chjyj/szwh/mapper/GoodsMapper.java b/src/main/java/cn/chjyj/szwh/mapper/GoodsMapper.java index f64efc6..3662242 100644 --- a/src/main/java/cn/chjyj/szwh/mapper/GoodsMapper.java +++ b/src/main/java/cn/chjyj/szwh/mapper/GoodsMapper.java @@ -1,6 +1,7 @@ package cn.chjyj.szwh.mapper; import cn.chjyj.szwh.bean.Goods; +import cn.chjyj.szwh.vo.GoodsDetailVo; import cn.chjyj.szwh.vo.GoodsListVo; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; @@ -91,4 +92,13 @@ public interface GoodsMapper { * @return */ int countGoodsListVo(@Param("map") Map map); + + /** + * 某时间段内委托方的数据 + * @param startdt 时间段 + * @param enddt 组合 + * @return + */ + List goodsUserIslicodeDtzone(@Param("startdt") String startdt, + @Param("enddt") String enddt); } diff --git a/src/main/java/cn/chjyj/szwh/service/IndexService.java b/src/main/java/cn/chjyj/szwh/service/IndexService.java index c818f0d..56bdaae 100644 --- a/src/main/java/cn/chjyj/szwh/service/IndexService.java +++ b/src/main/java/cn/chjyj/szwh/service/IndexService.java @@ -7,9 +7,11 @@ import java.util.Map; */ public interface IndexService { /** - * 统计系统中的相关数据 - * @param dateFlag 传入时间区段 + * 统计系统中的相关信息 + * @param leftDate + * @param rightDate + * @param saleRankingDate * @return */ - Map getCountSys(String dateFlag); + Map getCountSys(String leftDate,String rightDate,String saleRankingDate); } diff --git a/src/main/java/cn/chjyj/szwh/service/impl/IndexServiceImpl.java b/src/main/java/cn/chjyj/szwh/service/impl/IndexServiceImpl.java index 4f58b5f..66b6fb8 100644 --- a/src/main/java/cn/chjyj/szwh/service/impl/IndexServiceImpl.java +++ b/src/main/java/cn/chjyj/szwh/service/impl/IndexServiceImpl.java @@ -4,15 +4,16 @@ import cn.chjyj.szwh.mapper.GoodsMapper; import cn.chjyj.szwh.mapper.OrderGoodsDetailMapper; import cn.chjyj.szwh.mapper.OrderMapper; import cn.chjyj.szwh.service.IndexService; +import cn.chjyj.szwh.utils.SzwhApiUtils; +import cn.chjyj.szwh.vo.GoodsDetailVo; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @Service public class IndexServiceImpl implements IndexService { @@ -24,7 +25,7 @@ public class IndexServiceImpl implements IndexService { private OrderGoodsDetailMapper orderGoodsDetailMapper; @Override - public Map getCountSys(String dateFlag) { + public Map getCountSys(String leftDate,String rightDate,String saleRankingDate) { // 拼装查询结果 Map result = new HashMap<>(); @@ -112,16 +113,33 @@ public class IndexServiceImpl implements IndexService { calendar.add(Calendar.YEAR,-1); String lastyear = sdf.format(calendar.getTime()); // 时刻跨度 - String dtzone = ""; - switch (dateFlag){ - case "year":dtzone=last5years+" and "+nowtime;break; - case "month":dtzone=lastyear+" and "+nowtime;break; - default:dtzone=lastMonth+ " and "+nowtime;break; + String[] dtzone=new String[2]; + switch (rightDate){ + case "year":dtzone[0]=last5years;dtzone[1]=nowtime;break; + case "month":dtzone[0]=lastyear;dtzone[1]=nowtime;break; + default:dtzone[0]=lastMonth;dtzone[1]=nowtime;break; } - //委托方排名 - result.put("entrust_ranking",goodsCount); + List entrustRanking = new ArrayList(); + List tjgoods=goodsMapper.goodsUserIslicodeDtzone(dtzone[0],dtzone[1]); + for(GoodsDetailVo gvo:tjgoods){ + Map fmap =new HashMap<>(); + // 查找对应的用户 + String uislicode = gvo.getUser_islicode(); + JSONObject userjson =SzwhApiUtils.getApiUser(uislicode); + JSONArray ujsonArray = userjson.getJSONArray("data"); + if(ujsonArray==null){ + fmap.put("username",gvo.getUser_islicode()); + }else { + fmap.put("username",ujsonArray.get(1)); + } + fmap.put("count",gvo.getCcount()); + entrustRanking.add(fmap); + } + result.put("entrust_ranking",entrustRanking); + + //委托方销售排序 result.put("entrust_sale_ranking",goodsCount); result.put("treeMap",goodsCount); result.put("label",goodsCount); diff --git a/src/main/java/cn/chjyj/szwh/utils/RequestUtils.java b/src/main/java/cn/chjyj/szwh/utils/RequestUtils.java index f27874e..08ec6c5 100644 --- a/src/main/java/cn/chjyj/szwh/utils/RequestUtils.java +++ b/src/main/java/cn/chjyj/szwh/utils/RequestUtils.java @@ -38,8 +38,10 @@ public class RequestUtils { HttpURLConnection httpcon = (HttpURLConnection) url.openConnection(); // 遍历主机头信息 for(Map.Entry item:map.entrySet()){ - httpcon.addRequestProperty(item.getKey().toString(), - item.getValue().toString()); + httpcon.addRequestProperty( + item.getKey().toString(), + item.getValue().toString() + ); } httpcon.connect(); //获取返回的字符 diff --git a/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java b/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java index 0a0b569..fe0f058 100644 --- a/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java +++ b/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java @@ -1,6 +1,7 @@ package cn.chjyj.szwh.utils; import cn.chjyj.szwh.service.impl.UserServiceImpl; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -13,7 +14,7 @@ import java.util.Map; * 系统操作工具集合 */ public class SzwhApiUtils { - private static Log log = LogFactory.getLog(UserServiceImpl.class); + private static Log log = LogFactory.getLog(SzwhApiUtils.class); /** * 远程获取用户信息 diff --git a/src/main/resources/mapper/szwh/GoodsMapper.xml b/src/main/resources/mapper/szwh/GoodsMapper.xml index 40e6f17..7bfdb33 100644 --- a/src/main/resources/mapper/szwh/GoodsMapper.xml +++ b/src/main/resources/mapper/szwh/GoodsMapper.xml @@ -126,13 +126,14 @@ ; - - + SELECT user_islicode,ANY_VALUE(sale_count+click_count) ccount + FROM goods + WHERE (createtime BETWEEN CAST(#{startdt} AS DATE) AND CAST(#{enddt} AS DATE)) + AND is_deleted=0 + GROUP BY user_islicode + ORDER BY ccount DESC diff --git a/src/test/java/cn/chjyj/szwh/mapper/GoodsMapperTest.java b/src/test/java/cn/chjyj/szwh/mapper/GoodsMapperTest.java index 312d89b..aa0f33f 100644 --- a/src/test/java/cn/chjyj/szwh/mapper/GoodsMapperTest.java +++ b/src/test/java/cn/chjyj/szwh/mapper/GoodsMapperTest.java @@ -1,7 +1,9 @@ package cn.chjyj.szwh.mapper; import cn.chjyj.szwh.bean.Goods; +import cn.chjyj.szwh.bean.GoodsDetail; import cn.chjyj.szwh.constant.ChConstant; +import cn.chjyj.szwh.vo.GoodsDetailVo; import cn.chjyj.szwh.vo.GoodsListVo; import org.junit.Test; import org.junit.runner.RunWith; @@ -95,4 +97,15 @@ public class GoodsMapperTest { System.out.println(gv.getGoods_name()); } } + + @Test + public void goodsUserIslicodeDtzone(){ + String startdt ="2010-07-20 00:00:00"; + String enddt="2022-07-20 23:59:59"; + List sslist = goodsMapper.goodsUserIslicodeDtzone(startdt,enddt); + for(GoodsDetailVo s:sslist){ + System.out.println(s.getUser_islicode()+"+"+s.getCcount()); + } + System.out.println(sslist.size()); + } } \ No newline at end of file