Browse Source

协销展示机构画像

huangzhiguo 2 years ago
parent
commit
5c012fdf6f

+ 58 - 4
src/main/java/com/caimei365/user/controller/ClubApi.java

@@ -1,10 +1,7 @@
 package com.caimei365.user.controller;
 
 import com.caimei365.user.model.ResponseJson;
-import com.caimei365.user.model.dto.ClubRemarksDto;
-import com.caimei365.user.model.dto.ClubUpdateDto;
-import com.caimei365.user.model.dto.DeductionDto;
-import com.caimei365.user.model.dto.JsonParamsDto;
+import com.caimei365.user.model.dto.*;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.ClubService;
 import io.swagger.annotations.Api;
@@ -12,6 +9,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -543,4 +541,60 @@ public class ClubApi {
     public ResponseJson choseSales(Integer clubId, Integer spId, Integer choseServiceId) {
         return clubService.changeSales(clubId, spId, choseServiceId);
     }
+
+    /**
+     * 机构访问记录列表
+     * @param clubId
+     * @return
+     */
+    @GetMapping("/record/list")
+    public ResponseJson accessRecords(Integer clubId) {
+
+        if (null == clubId) {
+            return ResponseJson.error("机构id不能为空");
+        }
+        return clubService.accessRecords(clubId);
+    }
+
+    /**
+     * 机构访问记录详情
+     * @param clubId
+     * @param accessDate
+     * @return
+     */
+    @GetMapping("/record/detail")
+    public ResponseJson recordDetail(Integer clubId, String accessDate,String ip, Integer pageNum, Integer pageSize) {
+        if (null == clubId) {
+            return ResponseJson.error("机构id不能为空",null);
+        }
+        if (!StringUtils.isNotBlank(accessDate)) {
+            return ResponseJson.error("详情时间不能为空",null);
+        }
+        return clubService.recordDetail(clubId, accessDate, ip, pageNum, pageSize);
+    }
+
+    /**
+     * 机构画像
+     * @param cmPortrait
+     * @return
+     */
+    @PostMapping("/clubPortrait")
+    @ResponseBody
+    public ResponseJson clubPortrait(CmPortraitDto cmPortrait) {
+        if (null == cmPortrait.getClubId()) {
+            return ResponseJson.error("机构id不能为空",null);
+        }
+        if (null == cmPortrait.getDateType()) {
+            return ResponseJson.error("时间类型不能为空",null);
+        }
+        if (null == cmPortrait.getType()) {
+            return ResponseJson.error("数据类型不能为空",null);
+        }
+        if (StringUtils.isNotBlank(cmPortrait.getStartTime()) && StringUtils.isNotBlank(cmPortrait.getEndTime())) {
+            if (cmPortrait.getStartTime().compareTo(cmPortrait.getEndTime()) > 0 ) {
+                return ResponseJson.error("开始时间不能大于结束时间",null);
+            }
+        }
+        return clubService.dataList(cmPortrait);
+    }
 }

+ 18 - 0
src/main/java/com/caimei365/user/mapper/ClubMapper.java

@@ -1,7 +1,9 @@
 package com.caimei365.user.mapper;
 
 import com.caimei365.user.model.dto.ClubUpdateDto;
+import com.caimei365.user.model.dto.CmPortraitDto;
 import com.caimei365.user.model.po.ClubRemarksPo;
+import com.caimei365.user.model.po.NewOrderPo;
 import com.caimei365.user.model.po.OperationalLogsPo;
 import com.caimei365.user.model.po.UserPo;
 import com.caimei365.user.model.vo.*;
@@ -324,6 +326,8 @@ public interface ClubMapper {
 
     String serviceProviderNameage(Integer serviceProviderId);
 
+    String selAddTime(@Param("clubId") Integer clubId);
+
     List<ServiceProviderVo> findSales();
 
     Integer findOldSpId(Integer clubId);
@@ -349,4 +353,18 @@ public interface ClubMapper {
     Date findSubmitTime(Integer remarkId);
 
     Integer findLeaderIdBySp(Integer spId);
+
+    List<RecordVo> accessRecords(Integer clubId);
+
+    List<BehaviorRecodeVo> recordDetail(@Param("clubId") Integer clubId, @Param("accessDate") String accessDate);
+
+    List<NewOrderPo> selOrderList(CmPortraitDto cmPortrait);
+
+    List<BehaviorRecodeVo> selBehaviorList(CmPortraitDto cmPortrait);
+
+    List<BehaviorRecodeVo> selRegion(@Param("ip") String ip, @Param("accessDate") String accessDate);
+
+    List<CmClubRemarksVo> selRemarksList(CmPortraitDto cmPortrait);
+
+    List<BehaviorRecodeVo> selBehaviorPageTypeList(CmPortraitDto cmPortrait);
 }

+ 25 - 0
src/main/java/com/caimei365/user/model/dto/ArrDateDto.java

@@ -0,0 +1,25 @@
+package com.caimei365.user.model.dto;
+
+import com.caimei365.user.model.vo.PortraitMap;
+import lombok.Data;
+
+import java.util.ArrayList;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/3/27
+ */
+@Data
+public class ArrDateDto {
+
+    private ArrayList<String> name;
+    private ArrayList<Integer> value;
+
+    private ArrayList<PortraitMap> orderList;
+    private Integer orderTotalNum;
+
+    private String startTime;
+    private String endTime;
+}

+ 105 - 0
src/main/java/com/caimei365/user/model/dto/CmPortraitDto.java

@@ -0,0 +1,105 @@
+package com.caimei365.user.model.dto;
+
+import com.caimei365.user.model.vo.PortraitMap;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/3/27
+ */
+@Data
+public class CmPortraitDto {
+    /**
+     * 机构id
+     */
+    private Integer clubId;
+    /**
+     * 机构名称
+     */
+    private String clubName;
+    /**
+     * 日期类别 0日 1月 2半年 3全年
+     */
+    private Integer dateType;
+    /**
+     * 开始时间
+     */
+    private String startTime;
+    /**
+     * 结束时间
+     */
+    private String endTime;
+    /**
+     * 统计类别 0订单 1搜索关键词 2咨询记录 3访问记录 4初始状态
+     */
+    private Integer type;
+    /**
+     * 时间
+     */
+    private String accessDate;
+    /**
+     * 订单总量
+     */
+    private Integer orderTotal;
+    /**
+     * 当前范围订单总金额
+     */
+    private double orderScopeTotalFee;
+    /**
+     * 当前订单范围总量
+     */
+    private Integer orderScopeNum;
+    /**
+     * 订单总金额
+     */
+    private BigDecimal orderTotalAmount;
+    /**
+     * 订单类型值value  订单类型name
+     */
+    private ArrayList<PortraitMap> orderPortrait;
+    /**
+     * 搜索关键词总数
+     */
+    private Integer totalKeywords;
+    /**
+     * 当前关键词范围总量
+     */
+    private Integer keyWordsScopeNum;
+    /**
+     * 搜索关键词数量
+     */
+    private ArrayList<Integer> behaviorValue;
+    /**
+     * 搜索关键词
+     */
+    private ArrayList<String> behaviorType;
+    /**
+     * 咨询记录总数
+     */
+    private Integer remarksTotal;
+    /**
+     * 当前咨询记录范围总量
+     */
+    private Integer remarksScopeNum;
+    /**
+     * 咨询记录数
+     */
+    private ArrayList<Integer> remarksValue;
+    /**
+     * 咨询记录关键词
+     */
+    private ArrayList<String> remarksType;
+    /**
+     * 访问记录数
+     */
+    private ArrayList<Integer> pageTypeValue;
+    /**
+     * 访问词
+     */
+    private ArrayList<String> pageType;
+}

+ 44 - 0
src/main/java/com/caimei365/user/model/po/NewOrderPo.java

@@ -0,0 +1,44 @@
+package com.caimei365.user.model.po;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/3/27
+ */
+@Data
+public class NewOrderPo {
+    /**
+     * 二手商品订单标识  0非二手商品订单、 1二手商品订单
+     */
+    private String secondHandOrderFlag;
+    /**
+     * 返佣订单标识,0非返佣订单,1返佣订单,2普通订单有返佣服务费
+     */
+    private String rebateFlag;
+    /**
+     * 退货退款类型:1部分退、2全部退
+     */
+    private String refundType;
+    /**
+     * 订单状态
+     */
+    private String status;
+
+    /**
+     * 总数
+     */
+    private Integer numbers;
+    /**
+     * 总金额
+     */
+    private Double totalMoney;
+    /**
+     * 支付金额
+     */
+    private Double payTotalFee;
+}

+ 73 - 0
src/main/java/com/caimei365/user/model/vo/BehaviorRecodeVo.java

@@ -0,0 +1,73 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/3/24
+ */
+@Data
+public class BehaviorRecodeVo {
+
+    /**
+     * 用户Id
+     */
+    private Integer userId;
+    /**
+     * 机构Id
+     */
+    private Integer clubId;
+    /**
+     * 访问记录ip
+     */
+    private String ip;
+    /**
+     * 页面类型
+     */
+    private String pageType;
+    /**
+     * 页面标签
+     */
+    private String pageLabel;
+    /**
+     * 商品图片
+     */
+    private String productImage;
+    /**
+     * 商品名称
+     */
+    private String productName;
+    /**
+     * 访问来源
+     */
+    private String accessSource;
+    /**
+     * 访问客户端
+     */
+    private String accessClient;
+    /**
+     * 访问时间
+     */
+    private Date accessTime;
+    /**
+     * 新访问时间
+     */
+    private String accessNewTime;
+    /**
+     * 访问时长
+     */
+    private String accessDuration;
+    /**
+     * 数量
+     */
+    private Integer number;
+    /**
+     * 访问页面总数
+     */
+    private Integer numbers;
+
+}

+ 21 - 0
src/main/java/com/caimei365/user/model/vo/CmClubRemarksVo.java

@@ -0,0 +1,21 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/3/27
+ */
+@Data
+public class CmClubRemarksVo {
+    /**
+     * 文字备注/关键词
+     */
+    private String remarks;
+    /**
+     * 咨询记录总数
+     */
+    private Integer numbers;
+}

+ 24 - 0
src/main/java/com/caimei365/user/model/vo/CmRecordVo.java

@@ -0,0 +1,24 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/3/24
+ */
+@Data
+public class CmRecordVo {
+    /**
+     * 年份
+     */
+    private String year;
+    /**
+     * 数据
+     */
+    private ArrayList<RecordVo> data;
+}

+ 25 - 0
src/main/java/com/caimei365/user/model/vo/PortraitMap.java

@@ -0,0 +1,25 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/3/24
+ */
+@Data
+public class PortraitMap {
+    /**
+     * 名称
+     */
+    private String name;
+    /**
+     * 数值
+     */
+    private Integer value;
+    /**
+     * 百分比
+     */
+    private String per;
+}

+ 29 - 0
src/main/java/com/caimei365/user/model/vo/RecordVo.java

@@ -0,0 +1,29 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/3/24
+ */
+@Data
+public class RecordVo {
+    /**
+     * 访问记录数
+     */
+    private Integer number;
+    /**
+     * 访问记录时间
+     */
+    private String accessDate;
+    /**
+     * 月份时间
+     */
+    private String monthAndDay;
+    /**
+     * 访问记录用ip
+     */
+    private String ip;
+}

+ 7 - 0
src/main/java/com/caimei365/user/service/ClubService.java

@@ -3,6 +3,7 @@ package com.caimei365.user.service;
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.dto.ClubRemarksDto;
 import com.caimei365.user.model.dto.ClubUpdateDto;
+import com.caimei365.user.model.dto.CmPortraitDto;
 import com.caimei365.user.model.dto.JsonParamsDto;
 import com.caimei365.user.model.vo.*;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -277,4 +278,10 @@ public interface ClubService {
     ResponseJson<List<ServiceProviderVo>> choseSales(Integer spId);
 
     ResponseJson changeSales(Integer clubId, Integer spId, Integer choseServiceId);
+
+    ResponseJson accessRecords(Integer clubId);
+
+    ResponseJson recordDetail(Integer clubId, String accessDate,String ip,Integer pageNum, Integer pageSize);
+
+    ResponseJson dataList(CmPortraitDto cmPortrait);
 }

+ 481 - 3
src/main/java/com/caimei365/user/service/impl/ClubServiceImpl.java

@@ -5,10 +5,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.caimei365.user.components.RedisService;
 import com.caimei365.user.mapper.*;
 import com.caimei365.user.model.ResponseJson;
-import com.caimei365.user.model.dto.ClubUpdateDto;
-import com.caimei365.user.model.dto.SuperVipDto;
+import com.caimei365.user.model.dto.*;
 import com.caimei365.user.model.po.*;
-import com.caimei365.user.model.dto.JsonParamsDto;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.ClubService;
 import com.caimei365.user.service.SellerService;
@@ -17,14 +15,19 @@ import com.caimei365.user.utils.MathUtil;
 import com.caimei365.user.utils.OssUtil;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.text.NumberFormat;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -124,6 +127,27 @@ public class ClubServiceImpl implements ClubService {
         if (club == null) {
             return ResponseJson.error("机构信息不存在", null);
         }
+        // 是否失效 有效时间3天
+        String addTime = clubMapper.selAddTime(clubId);
+        if (StringUtils.isNotBlank(addTime)) {
+            //计算距今时长
+            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date date = null;
+            try {
+                date = dateFormat.parse(addTime);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            long timeOld = calendar.getTime().getTime();
+            calendar.setTime(new Date());
+            long timeNew = calendar.getTime().getTime();
+            int day = (int)(timeNew - timeOld) / 1000 / 60 / 60 / 24;
+            if (day > 3) {
+                return ResponseJson.error("链接时间已过期,请重新生成",null);
+            }
+        }
         if (null != club.getTownId()) {
             TownVo town = baseMapper.getTown(club.getTownId());
             CityVo city = baseMapper.getCity(town.getCityId());
@@ -2017,4 +2041,458 @@ public class ClubServiceImpl implements ClubService {
     }
 
 
+    @Override
+    public ResponseJson accessRecords(Integer clubId) {
+        List<CmRecordVo> data = new ArrayList<>();
+        ArrayList list = new ArrayList<>();
+        ArrayList<String> listYear = new ArrayList<>();
+        CmRecordVo cmRecordVo = new CmRecordVo();
+        List<RecordVo> records = clubMapper.accessRecords(clubId);
+        String substring = "";
+        if (records.size() > 0) {
+            for (RecordVo recordVo : records) {
+                substring = recordVo.getAccessDate().substring(0, 4);
+                if (!listYear.contains(substring)) {
+                    listYear.add(substring);
+                }
+            }
+            for (int i = 0; i < listYear.size() ; i++) {
+                for (RecordVo recordVo : records) {
+                    if (listYear.get(i).equals(recordVo.getAccessDate().substring(0, 4))) {
+                        recordVo.setMonthAndDay(recordVo.getAccessDate().substring(5));
+                        list.add(recordVo);
+                    }
+                }
+                cmRecordVo.setYear(listYear.get(i));
+                cmRecordVo.setData(list);
+                data.add(cmRecordVo);
+            }
+        }
+        return ResponseJson.success(data);
+    }
+
+    @Override
+    public ResponseJson recordDetail(Integer clubId, String accessDate, String ip, Integer pageNum, Integer pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        //访问详情数据
+        List<BehaviorRecodeVo> recordDetail = clubMapper.recordDetail(clubId, accessDate);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        List<BehaviorRecodeVo> region = clubMapper.selRegion(ip,accessDate);
+        String format = "";
+        for(BehaviorRecodeVo record: recordDetail) {
+            // 图片处理
+            if (StringUtils.isNotBlank(record.getProductImage())) {
+                record.setProductImage(ImageUtils.getImageURL("product", record.getProductImage(), 0, wwwDomain));
+            }
+            String time = calculationTime(record.getAccessDuration());
+            record.setAccessDuration(time);
+            record.setAccessNewTime(dateFormat.format(record.getAccessTime()));
+            String s = simpleDateFormat.format(record.getAccessTime());
+
+            // 访问来源
+            if (region.size() != 0) {
+                for (BehaviorRecodeVo behaviorRecord : region) {
+                    format = simpleDateFormat.format(behaviorRecord.getAccessTime());
+                    if (record.getPageType().equals(behaviorRecord.getPageType()) && s.equals(format)) {
+                        record.setAccessSource(behaviorRecord.getAccessSource());
+                    }
+                }
+            }
+        }
+        PageInfo<BehaviorRecodeVo> pageInfo = new PageInfo<>(recordDetail);
+        return ResponseJson.success(pageInfo);
+    }
+
+    @Override
+    public ResponseJson dataList(CmPortraitDto cmPortrait) {
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        Date date = new Date();
+        String endTime = "";
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.add(Calendar.DAY_OF_MONTH, -1);
+        Date time = calendar.getTime();
+        endTime = dateFormat.format(time);
+        String time1 = "";
+        String time2 = "";
+        boolean expty = ObjectUtils.isEmpty(cmPortrait.getStartTime()) && ObjectUtils.isEmpty(cmPortrait.getEndTime());
+        if (expty) {
+            Date start = null;
+            String startTime = "";
+            String format = dateFormat.format(date);
+            cmPortrait.setEndTime(endTime);
+            // 日期参数为    日
+            if (0 ==  cmPortrait.getDateType() || 1 == cmPortrait.getDateType()) {
+                cmPortrait.setAccessDate(endTime);
+                cmPortrait.setStartTime(endTime);
+//                cmPortrait.setEndTime(endTime);
+            }
+            if (1 == cmPortrait.getDateType()) {
+//                cmPortrait.setEndTime(endTime);
+                calendar.setTime(time);
+                calendar.add(Calendar.MONTH, -1);
+                start = calendar.getTime();
+                startTime = dateFormat.format(start);
+                cmPortrait.setStartTime(startTime);
+            }
+            if (2 == cmPortrait.getDateType()) {
+//                cmPortrait.setEndTime(endTime);
+                calendar.setTime(time);
+                calendar.add(Calendar.MONTH, -6);
+                start = calendar.getTime();
+                startTime = dateFormat.format(start);
+                cmPortrait.setStartTime(startTime);
+            }
+            if (3 == cmPortrait.getDateType()) {
+//                cmPortrait.setEndTime(endTime);
+                calendar.setTime(time);
+                calendar.add(Calendar.YEAR, -1);
+                start = calendar.getTime();
+                startTime = dateFormat.format(start);
+                cmPortrait.setStartTime(startTime);
+            }
+        } else {
+            time1 = cmPortrait.getStartTime();
+            time2 = cmPortrait.getEndTime();
+        }
+        // 机构订单
+        if (0 == cmPortrait.getType() || 4 == cmPortrait.getType()) {
+            if ((0 ==  cmPortrait.getDateType() || 1 == cmPortrait.getDateType()) && expty) {
+                cmPortrait.setEndTime(dateFormat.format(date));
+            }
+            if (cmPortrait.getEndTime().equals(endTime)) {
+                cmPortrait.setEndTime(dateFormat.format(date));
+            }
+            int ordinary = 0, secondHand = 0, rebate = 0, partialRefund = 0, fullRefund = 0, closed = 0,total = 0;
+            double orderScopeTotalFee = 0.0;
+            ArrayList<PortraitMap> orderPortraits = new ArrayList<>();
+            PortraitMap orderPortrait = new PortraitMap();
+            List<NewOrderPo> orderList = clubMapper.selOrderList(cmPortrait);
+            int length = orderList.size();
+            NumberFormat instance = NumberFormat.getInstance();
+            instance.setMaximumFractionDigits(2);
+            if (length != 0) {
+                for (NewOrderPo order : orderList) {
+                    // 普通订单
+                    if (("0".equals(order.getSecondHandOrderFlag()) || StringUtils.isEmpty(order.getSecondHandOrderFlag()))
+                            && (!"1".equals(order.getRebateFlag()) || "".equals(order.getRebateFlag()) || StringUtils.isEmpty(order.getRebateFlag()))
+                            && ((!"1".equals(order.getRefundType()) && !"2".equals(order.getRefundType())) || "".equals(order.getRefundType()) || StringUtils.isEmpty(order.getRefundType()))
+                            && !"6".equals(order.getStatus())) {
+                        ordinary++;
+                    }
+                    // 二手订单
+                    if ("1".equals(order.getSecondHandOrderFlag()) && !"1".equals(order.getRebateFlag())
+                            && (!"1".equals(order.getRefundType()) && !"2".equals(order.getRefundType())) && !"6".equals(order.getStatus())) {
+                        secondHand++;
+                    }
+                    // 返佣订单
+                    if ("1".equals(order.getRebateFlag()) &&
+                            (!"1".equals(order.getRefundType()) && !"2".equals(order.getRefundType()) || StringUtils.isEmpty(order.getRefundType())) && !"6".equals(order.getStatus())) {
+                        rebate++;
+                    }
+                    // 部分退款
+                    if ("1".equals(order.getRefundType()) && !"6".equals(order.getStatus())) {
+                        partialRefund++;
+                    }
+                    // 全部退款
+                    if ("2".equals(order.getRefundType()) && !"6".equals(order.getStatus())) {
+                        fullRefund++;
+                    }
+                    // 已关闭
+                    if ("6".equals(order.getStatus()) || StringUtils.isEmpty(order.getStatus())) {
+                        closed++;
+                    }
+                    if (null != order.getPayTotalFee()) {
+                        orderScopeTotalFee += order.getPayTotalFee();
+                    }
+                }
+                cmPortrait.setOrderTotal(length);
+                cmPortrait.setOrderTotalAmount(new BigDecimal(orderList.get(0).getTotalMoney()));
+                // 当前单位订单总额
+                cmPortrait.setOrderScopeTotalFee(Double.valueOf(String.format("%.2f", orderScopeTotalFee)));
+
+                orderPortrait.setValue(ordinary);
+                if (ordinary != 0) {
+                    orderPortrait.setName("普通");
+                    orderPortrait.setPer(instance.format((float)ordinary / (float) length * 100));
+                } else {
+                    orderPortrait.setName("普通");
+                    orderPortrait.setPer("0");
+                }
+                orderPortraits.add(orderPortrait);
+                orderPortrait = new PortraitMap();
+                orderPortrait.setValue(secondHand);
+                if (secondHand != 0) {
+                    orderPortrait.setName("二手");
+                    orderPortrait.setPer(instance.format((float)secondHand / (float) length * 100));
+                } else {
+                    orderPortrait.setName("二手");
+                    orderPortrait.setPer("0");
+                }
+                orderPortraits.add(orderPortrait);
+                orderPortrait = new PortraitMap();
+                orderPortrait.setValue(rebate);
+                if (rebate != 0) {
+                    orderPortrait.setName("返佣");
+                    orderPortrait.setPer(instance.format((float)rebate / (float) length * 100));
+                } else {
+                    orderPortrait.setName("返佣");
+                    orderPortrait.setPer("0");
+                }
+                orderPortraits.add(orderPortrait);
+                orderPortrait = new PortraitMap();
+                orderPortrait.setValue(partialRefund);
+                if (partialRefund != 0) {
+                    orderPortrait.setName("部分退款");
+                    orderPortrait.setPer(instance.format((float)partialRefund / (float) length * 100));
+                } else {
+                    orderPortrait.setName("部分退款");
+                    orderPortrait.setPer("0");
+                }
+                orderPortraits.add(orderPortrait);
+                orderPortrait = new PortraitMap();
+                orderPortrait.setValue(fullRefund);
+                if (fullRefund != 0) {
+                    orderPortrait.setName("全部退款");
+                    orderPortrait.setPer(instance.format((float)fullRefund / (float) length * 100));
+                } else {
+                    orderPortrait.setName("全部退款");
+                    orderPortrait.setPer("0");
+                }
+                orderPortraits.add(orderPortrait);
+                orderPortrait = new PortraitMap();
+                orderPortrait.setValue(closed);
+                if (closed != 0) {
+                    orderPortrait.setName("已关闭");
+                    orderPortrait.setPer(instance.format((float)closed / (float) length * 100));
+                } else {
+                    orderPortrait.setName("已关闭");
+                    orderPortrait.setPer("0");
+                }
+                orderPortraits.add(orderPortrait);
+
+                cmPortrait.setOrderPortrait(orderPortraits);
+            } else {
+                cmPortrait.setOrderTotalAmount(BigDecimal.ZERO);
+            }
+            // 总量
+            total = ordinary + secondHand + rebate + partialRefund + fullRefund + closed;
+            cmPortrait.setOrderScopeNum(total);
+            calendar.setTime(date);
+            calendar.add(Calendar.DAY_OF_MONTH, -1);
+            time = calendar.getTime();
+            endTime = dateFormat.format(time);
+            cmPortrait.setEndTime(endTime);
+        }
+        // 搜索关键词
+        if (1 == cmPortrait.getType() || 4 == cmPortrait.getType()) {
+            List<BehaviorRecodeVo> behaviorRecordList = clubMapper.selBehaviorList(cmPortrait);
+            int keywordsTotal = 0;
+            ArrayList<Integer> integers = new ArrayList<>();
+            ArrayList<String> strings = new ArrayList<>();
+            if (behaviorRecordList.size() != 0) {
+                for (BehaviorRecodeVo record : behaviorRecordList) {
+                    keywordsTotal += record.getNumber();
+                    integers.add(record.getNumber());
+                    if (!ObjectUtils.isEmpty(record.getPageLabel())) {
+                        strings.add(record.getPageLabel());
+                    } else {
+                        strings.add("未知");
+                    }
+                    cmPortrait.setTotalKeywords(behaviorRecordList.get(0).getNumbers());
+                    cmPortrait.setBehaviorValue(integers);
+                    cmPortrait.setBehaviorType(strings);
+
+                }
+            } else {
+                cmPortrait.setTotalKeywords(0);
+            }
+            cmPortrait.setKeyWordsScopeNum(keywordsTotal);
+        }
+        // 咨询记录
+        if (2 == cmPortrait.getType() || 4 == cmPortrait.getType()) {
+            if ((0 ==  cmPortrait.getDateType() || 1 == cmPortrait.getDateType()) && expty) {
+                cmPortrait.setEndTime(dateFormat.format(date));
+            }
+            if (cmPortrait.getEndTime().equals(endTime)) {
+                cmPortrait.setEndTime(dateFormat.format(date));
+            }
+            List<CmClubRemarksVo> remarksList = clubMapper.selRemarksList(cmPortrait);
+//            int remarksTotal = 0;
+            ArrayList<Integer> integers = new ArrayList<>();
+            ArrayList<String> strings = new ArrayList<>();
+            ArrayList<String> strRemark = new ArrayList<>();
+            ArrayList<String> remarkAll = new ArrayList<>();
+            int number = 0;
+            if (remarksList.size() != 0) {
+                for (CmClubRemarksVo remarks: remarksList) {
+                    String[] split = remarks.getRemarks().split(",");
+                    for (String str : split) {
+                        if (!strRemark.contains(str)) {
+                            strRemark.add(str);
+                        }
+                        remarkAll.add(str);
+                    }
+                }
+                for (String str : strRemark) {
+                    for (int i = 0;i < remarkAll.size(); i++) {
+                        if (str.equals(remarkAll.get(i))) {
+                            number++;
+                        }
+                    }
+                    integers.add(number);
+//                    remarksTotal += number;
+                    if (!ObjectUtils.isEmpty(str)) {
+                        strings.add(str);
+                    } else {
+                        strings.add("未知");
+                    }
+                    number = 0;
+                }
+                // 数组根据出现次数排序
+                int temp = 0;
+                String strTemp = "";
+                for (int i = 0; i < integers.size() - 1; i++) {
+                    for (int k = 0; k < integers.size() - 1 - i; k++) {
+                        if (integers.get(k) > integers.get(k+1)) {
+                            temp = integers.get(k);
+                            integers.set(k,integers.get(k+1));
+                            integers.set(k+1,temp);
+
+                            strTemp = strings.get(k);
+                            strings.set(k,strings.get(k+1));
+                            strings.set(k+1,strTemp);
+                        }
+                    }
+                }
+                cmPortrait.setRemarksTotal(remarksList.get(0).getNumbers());
+                cmPortrait.setRemarksValue(integers);
+                cmPortrait.setRemarksType(strings);
+
+                cmPortrait.setRemarksScopeNum(remarksList.size());
+            } else {
+                cmPortrait.setRemarksScopeNum(0);
+                cmPortrait.setRemarksTotal(0);
+            }
+            calendar.setTime(date);
+            calendar.add(Calendar.DAY_OF_MONTH, -1);
+            time = calendar.getTime();
+            endTime = dateFormat.format(time);
+            cmPortrait.setEndTime(endTime);
+        }
+        // 访问记录
+        if (3 == cmPortrait.getType() || 4 == cmPortrait.getType()) {
+            List<BehaviorRecodeVo> pageTypeList = clubMapper.selBehaviorPageTypeList(cmPortrait);
+            ArrayList<Integer> integers = new ArrayList<>();
+            ArrayList<String> strings = new ArrayList<>();
+            if (pageTypeList.size() != 0) {
+                for(BehaviorRecodeVo record : pageTypeList) {
+                    integers.add(record.getNumbers());
+                    strings.add(record.getPageLabel());
+                }
+                cmPortrait.setPageTypeValue(integers);
+                cmPortrait.setPageType(strings);
+            }
+        }
+        if (!expty) {
+            cmPortrait.setStartTime(time1);
+            if ((0 ==  cmPortrait.getDateType() || 1 == cmPortrait.getDateType()) && ObjectUtils.isEmpty(cmPortrait.getStartTime())) {
+                cmPortrait.setStartTime(time2);
+            }
+            cmPortrait.setEndTime(time2);
+        }
+        // 数据返回处理
+        Map<String, Object> map = Maps.newLinkedHashMap();
+        try {
+            ArrDateDto order = new ArrDateDto();
+            ArrDateDto behavior = new ArrDateDto();
+            ArrDateDto remarks = new ArrDateDto();
+            ArrDateDto pageType = new ArrDateDto();
+
+//            ArrayList<OrderPortrait> orderPortrait = portrait.getOrderPortrait();
+            order.setOrderList(cmPortrait.getOrderPortrait());
+            if (cmPortrait.getOrderTotal() == null) {
+                cmPortrait.setOrderTotal(0);
+            }
+            order.setOrderTotalNum(cmPortrait.getOrderTotal());
+            order.setStartTime(cmPortrait.getStartTime());
+            order.setEndTime(cmPortrait.getEndTime());
+            if (order.getOrderTotalNum() == 0) {
+                map.put("order",null);
+            } else {
+                map.put("order",order);
+            }
+            behavior.setName(cmPortrait.getBehaviorType());
+            behavior.setValue(cmPortrait.getBehaviorValue());
+            behavior.setStartTime(cmPortrait.getStartTime());
+            behavior.setEndTime(cmPortrait.getEndTime());
+            if (ObjectUtils.isEmpty(behavior.getValue())) {
+                map.put("behavior",null);
+            } else {
+                map.put("behavior",behavior);
+            }
+            remarks.setName(cmPortrait.getRemarksType());
+            remarks.setValue(cmPortrait.getRemarksValue());
+            remarks.setStartTime(cmPortrait.getStartTime());
+            remarks.setEndTime(cmPortrait.getEndTime());
+            if (ObjectUtils.isEmpty(remarks.getValue())) {
+                map.put("remarks",null);
+            } else {
+                map.put("remarks",remarks);
+            }
+            pageType.setName(cmPortrait.getPageType());
+            pageType.setValue(cmPortrait.getPageTypeValue());
+            pageType.setStartTime(cmPortrait.getStartTime());
+            pageType.setEndTime(cmPortrait.getEndTime());
+            if (ObjectUtils.isEmpty(pageType.getValue())) {
+                map.put("pageType",null);
+            } else {
+                map.put("pageType",pageType);
+            }
+            map.put("portrait",cmPortrait);
+            map.put("code",0);
+        } catch (Exception e) {
+            e.printStackTrace();
+            map.put("code",-1);
+        }
+        return ResponseJson.success(map);
+    }
+    /**
+     * 时间计算
+     * @param recordTime
+     * @return
+     */
+    public String calculationTime(String recordTime){
+        double doc = Double.parseDouble(recordTime);
+        int num = (int)doc;
+        //小时
+        int HH = 0;
+        // 分钟
+        int mm = 0;
+        //秒
+        int ss = 0;
+        int item = num / 1000;
+        if ((item / 60) >0) {
+            mm = item / 60;
+            ss = item % 60;
+        } else {
+            ss = item;
+        }
+        if ((mm / 60) >0) {
+            HH = mm / 60;
+            mm = mm % 60;
+        }
+        String  str= HH+":"+mm+":"+ss;
+        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
+        Date parse = null;
+        try {
+            parse = dateFormat.parse(str);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        String format = dateFormat.format(parse);
+        return format;
+    }
 }

+ 111 - 0
src/main/resources/mapper/ClubMapper.xml

@@ -326,6 +326,7 @@
     <update id="updateClubSpId">
         update club
         set spID=#{spId},
+            newDeal = 1,
             scanFlag=2
         where clubID = #{clubId}
     </update>
@@ -938,6 +939,10 @@
 
     </select>
 
+    <select id="selAddTime" resultType="java.lang.String">
+        select addTime from record_link where clubId = #{clubId} order by addTime desc limit 1
+    </select>
+
     <select id="serviceProviderNameage" resultType="java.lang.String">
         select linkMan
         from `serviceprovider`
@@ -1009,4 +1014,110 @@
         LEFT JOIN cm_serviceteam_group csg ON csr.id=csg.teamId
         WHERE csg.serviceId = #{spId}
     </select>
+    <select id="accessRecords" resultType="com.caimei365.user.model.vo.RecordVo">
+        SELECT accessDate,number,IP as ip FROM cm_behavior_record_index WHERE clubID = #{clubId} AND delFlag = 0
+    </select>
+    <select id="recordDetail" resultType="com.caimei365.user.model.vo.BehaviorRecodeVo">
+        SELECT
+            pt.pageType,
+            b.pageLabel,
+            p.name AS productName,
+            p.mainImage AS productImage,
+            b.accessDuration,
+            b.accessSource,
+            b.accessClient,
+            b.accessTime
+        FROM cm_behavior_record b
+         LEFT JOIN club c ON b.userID = c.userID
+         LEFT JOIN product p ON b.productID = p.productID
+         LEFT JOIN cm_page_type pt ON b.pageType = pt.id
+        WHERE c.clubID = #{clubId} AND b.accessDate = #{accessDate}
+    </select>
+    <select  id="selOrderList" resultType="com.caimei365.user.model.po.NewOrderPo">
+        SELECT
+        (SELECT COUNT(orderID) FROM cm_order WHERE clubID = #{clubId}) as numbers,
+        (SELECT SUM(payTotalFee) FROM cm_order WHERE clubID = #{clubId}) as totalMoney,
+        clubID,
+        secondHandOrderFlag,
+        rebateFlag,
+        refundType,
+        payTotalFee,
+        STATUS,
+        orderTime
+        FROM cm_order
+        <where>
+            clubID = #{clubId}
+            <if test="accessDate != null and accessDate != ''">
+                AND orderTime like concat('%',#{accessDate},'%')
+            </if>
+            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                AND orderTime <![CDATA[ >= ]]> #{startTime} AND orderTime <![CDATA[ <= ]]> #{endTime}
+            </if>
+        </where>
+    </select>
+    <select id="selBehaviorList" resultType="com.caimei365.user.model.vo.BehaviorRecodeVo">
+        SELECT
+        c.clubID,
+        COUNT(cbr.pageLabel) as number,
+        cbr.pageLabel,
+        cbr.accessDate
+        FROM cm_behavior_record cbr LEFT JOIN club c ON cbr.userID = c.userID
+        <where>
+            cbr.pageType IN (8, 9) AND c.clubID = #{clubId} AND cbr.pageLabel IS NOT NULL AND cbr.pageLabel != ''
+            <if test="accessDate != null and accessDate != ''">
+                AND cbr.accessDate = #{accessDate}
+            </if>
+            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                AND cbr.accessDate <![CDATA[ >= ]]> #{startTime} AND cbr.accessDate <![CDATA[ <= ]]> #{endTime}
+            </if>
+        </where>
+        GROUP BY cbr.pageLabel
+        ORDER BY COUNT(cbr.pageLabel) LIMIT 10
+    </select>
+    <select id="selRegion" resultType="com.caimei365.user.model.vo.BehaviorRecodeVo">
+        SELECT
+            IP as ip,
+            accessSource,
+            accessTime,
+            pageType
+        FROM cm_behavior_record_ref WHERE IP = #{ip} AND accessTime like concat('%', #{accessDate} ,'%')
+    </select>
+    <select id="selRemarksList" resultType="com.caimei365.user.model.vo.CmClubRemarksVo">
+        SELECT
+        (SELECT COUNT(remarks) FROM cm_club_remarks WHERE clubID = #{clubId}) as numbers,
+        clubID,
+        COUNT(remarks) as number,
+        remarks,
+        addTime
+        FROM cm_club_remarks
+        <where>
+            clubID = #{clubId}
+            <if test="accessDate != null and accessDate != ''">
+                AND addTime like concat('%', #{accessDate},'%')
+            </if>
+            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                AND addTime <![CDATA[ >= ]]> #{startTime} AND addTime <![CDATA[ <= ]]> #{endTime}
+            </if>
+        </where>
+        GROUP BY remarks ORDER BY COUNT(remarks) LIMIT 10
+    </select>
+    <select id="selBehaviorPageTypeList" resultType="com.caimei365.user.model.vo.BehaviorRecodeVo">
+        SELECT
+        c.clubID,
+        COUNT(cbr.pageType) as numbers,
+        cbr.pageLabel,
+        cbr.accessDate
+        FROM cm_behavior_record cbr
+        LEFT JOIN club c ON cbr.userID = c.userID
+        <where>
+            c.clubID = #{clubId}
+            <if test="accessDate != null and accessDate != ''">
+                AND cbr.accessDate like concat('%', #{accessDate},'%')
+            </if>
+            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                AND cbr.accessDate <![CDATA[ >= ]]> #{startTime} AND cbr.accessDate <![CDATA[ <= ]]> #{endTime}
+            </if>
+        </where>
+        GROUP BY cbr.pageType  ORDER BY COUNT(cbr.pageType) LIMIT 10
+    </select>
 </mapper>