123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682 |
- package com.ruixuan.isc.service.impl;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.google.gson.Gson;
- import com.kuaidi100.sdk.api.Subscribe;
- import com.kuaidi100.sdk.contant.ApiInfoConstant;
- import com.kuaidi100.sdk.core.IBaseClient;
- import com.kuaidi100.sdk.request.SubscribeParam;
- import com.kuaidi100.sdk.request.SubscribeParameters;
- import com.kuaidi100.sdk.request.SubscribeReq;
- import com.ruixuan.common.core.domain.entity.SysUser;
- import com.ruixuan.common.utils.Check;
- import com.ruixuan.common.utils.DateUtils;
- import com.ruixuan.common.utils.PageUtils;
- import com.ruixuan.isc.entity.KuaishouItemCollectSampleExpress;
- import com.ruixuan.isc.entity.KuaishouItemCollectSampleLog;
- import com.ruixuan.isc.entity.KuaishouItemCollectSamples;
- import com.ruixuan.isc.mapper.KuaishouItemCollectSamplesMapper;
- import com.ruixuan.isc.service.IKuaishouItemCollectSamplesService;
- import com.ruixuan.isc.service.IKuaishouPromoterService;
- import com.ruixuan.isc.service.ISupplyChainService;
- import com.ruixuan.system.service.ISysDeptService;
- import com.ruixuan.system.service.ISysUserService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * 【请填写功能名称】Service业务层处理
- *
- * @author ruoyi
- * @date 2023-02-08
- */
- @Service
- public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemCollectSamplesService {
- @Autowired
- private KuaishouItemCollectSamplesMapper kuaishouItemCollectSamplesMapper;
- @Autowired
- private ISysUserService userService;
- @Autowired
- private IKuaishouPromoterService promoterService;
- @Autowired
- private ISupplyChainService supplyChainService;
- @Autowired
- private ISysDeptService deptService;
- /**
- * 查询【请填写功能名称】
- *
- * @param id 【请填写功能名称】主键
- * @return 【请填写功能名称】
- */
- @Override
- public KuaishouItemCollectSamples selectKuaishouItemCollectSamplesById(Long id) {
- return kuaishouItemCollectSamplesMapper.selectKuaishouItemCollectSamplesById(id);
- }
- /**
- * 查询【请填写功能名称】列表
- *
- * @param requestMap 【请填写功能名称】
- * @return 【请填写功能名称】
- */
- @Override
- public List<KuaishouItemCollectSamples> selectKuaishouItemCollectSamplesList(Map<String, Object> requestMap) {
- List<KuaishouItemCollectSamples> kuaishouItemCollectSamples = kuaishouItemCollectSamplesMapper.selectKuaishouItemCollectSamplesList(requestMap);
- Map<Long, JSONObject> dataMap = new HashMap<>();
- if (!Check.isNull(kuaishouItemCollectSamples)) {
- Map<Long, Long> map = new HashMap<>();
- for (KuaishouItemCollectSamples samples : kuaishouItemCollectSamples) {
- map.put(samples.getPromoterId(), samples.getPromoterId());
- }
- List<JSONObject> promoterList = kuaishouItemCollectSamplesMapper.selectPromoterInfo(map);
- for (int i = 0; i < promoterList.size(); i++) {
- JSONObject jsonObject = promoterList.get(i);
- dataMap.put(jsonObject.getLong("promoterId"), jsonObject);
- }
- }
- if (!Check.isNull(kuaishouItemCollectSamples)) {
- for (KuaishouItemCollectSamples samples : kuaishouItemCollectSamples) {
- Long promoterId = samples.getPromoterId();
- JSONObject jsonObject = dataMap.get(promoterId);
- if (!Check.isNull(jsonObject)) {
- samples.setValidAmount(jsonObject.getLong("validAmount"));
- samples.setValidOrderNum(jsonObject.getLong("validOrderNum"));
- }
- }
- }
- return kuaishouItemCollectSamples;
- }
- /**
- * 新增【请填写功能名称】
- *
- * @param kuaishouItemCollectSamples 【请填写功能名称】
- * @return 结果
- */
- @Override
- public int insertKuaishouItemCollectSamples(KuaishouItemCollectSamples kuaishouItemCollectSamples) {
- kuaishouItemCollectSamples.setCreateTime(DateUtils.getNowDate());
- return kuaishouItemCollectSamplesMapper.insertKuaishouItemCollectSamples(kuaishouItemCollectSamples);
- }
- /**
- * 修改【请填写功能名称】
- *
- * @param kuaishouItemCollectSamples 【请填写功能名称】
- * @return 结果
- */
- @Override
- public int updateKuaishouItemCollectSamples(KuaishouItemCollectSamples kuaishouItemCollectSamples) {
- kuaishouItemCollectSamples.setUpdateTime(DateUtils.getNowDate());
- return kuaishouItemCollectSamplesMapper.updateKuaishouItemCollectSamples(kuaishouItemCollectSamples);
- }
- /**
- * 批量删除【请填写功能名称】
- *
- * @param ids 需要删除的【请填写功能名称】主键
- * @return 结果
- */
- @Override
- public int deleteKuaishouItemCollectSamplesByIds(Long[] ids) {
- return kuaishouItemCollectSamplesMapper.deleteKuaishouItemCollectSamplesByIds(ids);
- }
- /**
- * 删除【请填写功能名称】信息
- *
- * @param id 【请填写功能名称】主键
- * @return 结果
- */
- @Override
- public int deleteKuaishouItemCollectSamplesById(Long id) {
- return kuaishouItemCollectSamplesMapper.deleteKuaishouItemCollectSamplesById(id);
- }
- @Override
- public JSONObject preview(Long userId, String nickName, JSONArray itemIds, JSONArray promoterIds) {
- JSONObject previewJson = new JSONObject();
- List<JSONObject> itemList = kuaishouItemCollectSamplesMapper.getItemList(itemIds);
- Map<Long, JSONObject> itemMap = new HashMap<>();
- for (int i = 0; i < itemList.size(); i++) {
- JSONObject itemJson = itemList.get(i);
- itemMap.put(itemJson.getLong("itemId"), itemJson);
- }
- Map<Long, JSONObject> promoterMap = new HashMap<>();
- List<JSONObject> promoterList = kuaishouItemCollectSamplesMapper.promoterList(promoterIds);
- for (int i = 0; i < promoterList.size(); i++) {
- JSONObject promoterJson = promoterList.get(i);
- promoterMap.put(promoterJson.getLong("promoterId"), promoterJson);
- }
- Integer sampleReceivedCount = 0;
- List<JSONObject> samples = new ArrayList<>();
- for (int i = 0; i < itemIds.size(); i++) {
- Long itemId = itemIds.getLong(i);
- JSONObject itemJson = itemMap.get(itemId);
- for (int j = 0; j < promoterIds.size(); j++) {
- Long promoterId = promoterIds.getLong(j);
- Integer count = kuaishouItemCollectSamplesMapper.check(itemId, promoterId);
- if (count > 0) {
- sampleReceivedCount++;
- continue;
- }
- JSONObject sampleJson = new JSONObject();
- sampleJson.put("itemId", itemJson.getLong("itemId"));
- sampleJson.put("itemTitle", itemJson.getString("itemTitle"));
- sampleJson.put("itemPrice", itemJson.getLong("itemPrice"));
- sampleJson.put("itemImgUrl", itemJson.getString("itemImgUrl"));
- sampleJson.put("commissionRate", itemJson.getLong("commissionRate"));
- sampleJson.put("regimentalPromotion", itemJson.getLong("regimentalPromotion"));
- sampleJson.put("itemCreateId", itemJson.getLong("userId"));
- sampleJson.put("itemCreateName", itemJson.getString("userName"));
- sampleJson.put("collectSampleId", userId);
- sampleJson.put("collectSampleName", nickName);
- JSONObject promoterJson = promoterMap.get(promoterId);
- sampleJson.put("promoterId", promoterJson.getLong("promoterId"));
- sampleJson.put("promoterNickName", promoterJson.getString("promoterNickName"));
- sampleJson.put("promoterPhone", promoterJson.getString("promoterPhone"));
- sampleJson.put("promoterAddress", promoterJson.getString("promoterAddress"));
- sampleJson.put("consignee", promoterJson.getString("consignee"));
- sampleJson.put("promoterUrl", promoterJson.getString("promoterUrl"));
- sampleJson.put("collectSampleStatus", 1);
- sampleJson.put("collectSampleDesc", "待招商审核");
- samples.add(sampleJson);
- }
- previewJson.put("sampleReceivedCount", sampleReceivedCount);
- previewJson.put("samples", samples);
- }
- return previewJson;
- }
- @Override
- public void batchAdd(JSONArray temCollectSamples) {
- List<KuaishouItemCollectSamples> adds = new ArrayList<>();
- for (int i = 0; i < temCollectSamples.size(); i++) {
- JSONObject sampleJson = temCollectSamples.getJSONObject(i);
- KuaishouItemCollectSamples sample = new KuaishouItemCollectSamples();
- sample.setItemId(sampleJson.getLong("itemId"));
- sample.setItemTitle(sampleJson.getString("itemTitle"));
- sample.setItemPrice(sampleJson.getLong("itemPrice"));
- sample.setItemImgUrl(sampleJson.getString("itemImgUrl"));
- sample.setItemDesc(sampleJson.getString("itemDesc"));
- sample.setCommissionRate(sampleJson.getLong("commissionRate"));
- sample.setRegimentalPromotion(sampleJson.getLong("regimentalPromotion"));
- sample.setSampleCount(sampleJson.getInteger("sampleCount"));
- sample.setSampleRequirement(sampleJson.getString("sampleRequirement"));
- sample.setItemCreateId(sampleJson.getLong("itemCreateId"));
- sample.setItemCreateName(sampleJson.getString("itemCreateName"));
- sample.setCollectSampleId(sampleJson.getLong("collectSampleId"));
- sample.setCollectSampleName(sampleJson.getString("collectSampleName"));
- sample.setPartnerRecommendText(sampleJson.getString("partnerRecommendText"));
- sample.setPromoterId(sampleJson.getLong("promoterId"));
- sample.setPromoterPhone(sampleJson.getString("promoterPhone"));
- sample.setPromoterAddress(sampleJson.getString("promoterAddress"));
- sample.setConsignee(sampleJson.getString("consignee"));
- sample.setCollectSampleStatus(sampleJson.getInteger("collectSampleStatus"));
- sample.setCollectSampleDesc(sampleJson.getString("collectSampleDesc"));
- sample.setPromoterNickName(sampleJson.getString("promoterNickName"));
- sample.setPromoterUrl(sampleJson.getString("promoterUrl"));
- adds.add(sample);
- }
- if (!Check.isNull(adds)) {
- kuaishouItemCollectSamplesMapper.batchAdd(adds);
- }
- }
- @Override
- public void subscribe(Long id, String courierNumber, String code) throws Exception {
- KuaishouItemCollectSamples samples = kuaishouItemCollectSamplesMapper.selectKuaishouItemCollectSamplesById(id);
- SubscribeParameters subscribeParameters = new SubscribeParameters();
- subscribeParameters.setCallbackurl("http://ruixuan.api.tjyourong.com.cn/itemCollectSamples/callback");
- subscribeParameters.setPhone(samples.getPromoterPhone());
- SubscribeParam subscribeParam = new SubscribeParam();
- subscribeParam.setParameters(subscribeParameters);
- subscribeParam.setCompany(code);
- subscribeParam.setNumber(courierNumber);
- subscribeParam.setKey("BPEQUJxB9244");
- SubscribeReq subscribeReq = new SubscribeReq();
- subscribeReq.setSchema(ApiInfoConstant.SUBSCRIBE_SCHEMA);
- subscribeReq.setParam(new Gson().toJson(subscribeParam));
- IBaseClient subscribe = new Subscribe();
- JSONObject jsonObject = JSONObject.parseObject(subscribe.execute(subscribeReq).getBody());
- String returnCode = jsonObject.getString("returnCode");
- KuaishouItemCollectSamples updateSample = new KuaishouItemCollectSamples();
- updateSample.setId(id);
- if ("200".equals(returnCode)) {
- updateSample.setCollectSampleDesc("快递推送订阅成功");
- } else {
- updateSample.setCollectSampleStatus(3);
- updateSample.setCollectSampleDesc("快递推送订阅失败,失败原因:" + jsonObject.getString("message"));
- }
- kuaishouItemCollectSamplesMapper.updateKuaishouItemCollectSamples(updateSample);
- }
- @Override
- public void updateByNum(KuaishouItemCollectSamples updateSample) {
- kuaishouItemCollectSamplesMapper.updateByNum(updateSample);
- }
- @Override
- public void replaceExpress(KuaishouItemCollectSampleExpress express) {
- kuaishouItemCollectSamplesMapper.replaceExpress(express);
- }
- @Override
- public JSONObject getDetail(Long id) {
- JSONObject json = new JSONObject();
- KuaishouItemCollectSamples sample = kuaishouItemCollectSamplesMapper.selectKuaishouItemCollectSamplesById(id);
- KuaishouItemCollectSampleLog log = new KuaishouItemCollectSampleLog();
- log.setCollectSampleStatus(1);
- log.setUserId(sample.getCollectSampleId());
- log.setUserName(sample.getCollectSampleName());
- log.setSampleId(sample.getId());
- log.setCreateTime(sample.getCreateTime());
- log.setUpdateTime(sample.getCreateTime());
- kuaishouItemCollectSamplesMapper.insertLog(log);
- json.put("sample", sample);
- if (!Check.isNull(sample.getCourierNumber())) {
- KuaishouItemCollectSampleExpress express = kuaishouItemCollectSamplesMapper.getExpress(sample.getCourierNumber());
- if (!Check.isNull(express)) {
- json.put("express", express);
- }
- }
- List<KuaishouItemCollectSampleLog> logs = kuaishouItemCollectSamplesMapper.getLogList(id);
- if (!Check.isNull(logs)) {
- json.put("logs", logs);
- }
- return json;
- }
- @Override
- public Integer getStatusByCourierNumbe(String nu) {
- return kuaishouItemCollectSamplesMapper.getStatusByCourierNumbe(nu);
- }
- @Override
- public JSONObject courierNumberInfo(String courierNumber) {
- return kuaishouItemCollectSamplesMapper.courierNumberInfo(courierNumber);
- }
- @Override
- public void insertLog(KuaishouItemCollectSampleLog sampleLog) {
- kuaishouItemCollectSamplesMapper.insertLog(sampleLog);
- }
- @Override
- public void cleanLogs(Long id, Integer status) {
- kuaishouItemCollectSamplesMapper.cleanLogs(id, status);
- }
- @Override
- public List<JSONObject> exportCollectSamples(Map<String, Object> requestMap) {
- return kuaishouItemCollectSamplesMapper.exportCollectSamples(requestMap);
- }
- @Override
- public JSONObject getCollectSampleInfo(Long itemId) {
- return kuaishouItemCollectSamplesMapper.getCollectSampleInfo(itemId);
- }
- @Override
- public JSONObject getCopyInfo(Long promoterId) {
- JSONObject returnJson = kuaishouItemCollectSamplesMapper.promoterInfo(promoterId);
- return returnJson;
- }
- @Override
- public Long getItemIdById(Long id) {
- return kuaishouItemCollectSamplesMapper.getItemIdById(id);
- }
- @Override
- public JSONObject getPersonalInfo(Long userId, String type) {
- String roleKey = userService.getRoleKeyByUserId(String.valueOf(userId));
- List<Long> userList = null;
- if ("courtshipManager".equals(roleKey) || "bdManager".equals(roleKey) || "associationManager".equals(roleKey)) {
- Long deptId = deptService.getDeptIdByUserId(userId);
- userList = deptService.getDeptUserListByDeptId(deptId);
- } else {
- userList = Arrays.asList(userId);
- }
- int userType = 1;
- if (!"1".equals(type)) {
- userType = 2;
- if ("supplyChainAdmin".equals(roleKey)) {
- //供应链管理员查看 招商人员数据
- userList = deptService.getDeptUserListByDeptId(150200L);
- }
- }
- JSONObject returnJson = new JSONObject();
- JSONObject data = new JSONObject();
- SysUser sysUser = userService.selectUserById(userId);
- if (Check.isNotNull(sysUser)) {
- data.put("userName", sysUser.getNickName());
- }
- Integer status = 1; //待审核领样数
- data.put("toBeReviewed", kuaishouItemCollectSamplesMapper.getSampleCountByUserId(userList, userType, status));
- status = 3;//待发货领样数
- data.put("toBeShipped", kuaishouItemCollectSamplesMapper.getSampleCountByUserId(userList, userType, status));
- status = 6;//作业上传成功待招商审核
- data.put("toBeUploaded", kuaishouItemCollectSamplesMapper.getSampleCountByUserId(userList, userType, status));
- returnJson.put("code", 0);
- returnJson.put("message", "调用成功");
- returnJson.put("data", data);
- return returnJson;
- }
- @Override
- public JSONObject getOrderData(Long userId, String startDate, String endDate, String type) {
- String roleKey = userService.getRoleKeyByUserId(String.valueOf(userId));
- List<Long> userList = null;
- if ("courtshipManager".equals(roleKey) || "bdManager".equals(roleKey) || "associationManager".equals(roleKey)) {
- Long deptId = deptService.getDeptIdByUserId(userId);
- userList = deptService.getDeptUserListByDeptId(deptId);
- } else {
- userList = Arrays.asList(userId);
- }
- JSONObject returnJson = new JSONObject();
- returnJson.put("code", 0);
- returnJson.put("message", "调用成功");
- if ("1".equals(type)) {
- returnJson.put("data", getgetOrderDataByChannel(userList, startDate, endDate));
- } else {
- if ("supplyChainAdmin".equals(roleKey)) {
- //供应链管理员查看 招商人员数据
- userList = deptService.getDeptUserListByDeptId(150200L);
- }
- returnJson.put("data", getgetOrderDataByAttractInvestment(userList, startDate, endDate));
- }
- return returnJson;
- }
- //渠道数据
- private JSONObject getgetOrderDataByChannel(List<Long> userList, String startDate, String endDate) {
- JSONObject data = new JSONObject();
- List<Long> promoterIds = promoterService.selectPromoterIdList(userList);
- if (Check.isNotNull(promoterIds)) {
- data.put("promoterCount", promoterIds.size());//达人总数
- JSONObject Sample = kuaishouItemCollectSamplesMapper.queryTheNumberOfCompletedJobs(promoterIds, startDate, endDate);
- data.put("completeCount", Sample.getInteger("completeCount"));//完成作业数
- data.put("completeRate", Sample.getString("completeRate"));//合格作业率
- JSONObject order = supplyChainService.selectOrderInfo(promoterIds, startDate, endDate);
- data.put("allNumber", order.getInteger("allNumber"));//订单总数
- data.put("validOrderNUm", order.getInteger("validOrderNUm"));//有效订单数
- data.put("inValidOrderNUm", order.getInteger("allNumber") - order.getInteger("validOrderNUm"));//失效订单数
- data.put("orderAmount", order.getInteger("orderAmount"));//订单金额
- data.put("regimentalPromotionAmount", order.getInteger("regimentalPromotionAmount"));//预估服务费
- data.put("baseAmount", order.getInteger("baseAmount"));//累计货贷基数
- //当天
- String today = DateUtils.getNowDateStr();
- Date date = new Date();
- //昨天
- String yesterday = DateUtils.getSubtractTime(date, 1);
- //上周的同一天(上个近七天的结束日期)
- String todayOfLastWeek = DateUtils.getSubtractTime(date, 7);
- //当前近七天的开始日期
- String start = DateUtils.getSubtractTime(date, 6);
- //上个近七天的开始日期
- String LastStart = DateUtils.getSubtractTime(date, 13);
- //当天数据
- JSONObject toData = supplyChainService.selectOrderRate(promoterIds, null, today, today);
- //昨日数据
- JSONObject yesData = supplyChainService.selectOrderRate(promoterIds, null, yesterday, yesterday);
- //上周当日数据
- JSONObject weeklyDayData = supplyChainService.selectOrderRate(promoterIds, null, todayOfLastWeek, todayOfLastWeek);
- //当前近七天的数据
- JSONObject inDayData = supplyChainService.selectOrderRate(promoterIds, null, start, today);
- //上个近七天的数据
- JSONObject lastDayData = supplyChainService.selectOrderRate(promoterIds, null, LastStart, todayOfLastWeek);
- //日环比 (今天-昨天)/昨天*100%
- BigDecimal dateOrder = toData.getBigDecimal("allNumber").subtract(yesData.getBigDecimal("allNumber")).divide(yesData.getBigDecimal("allNumber"), 4, RoundingMode.HALF_UP);
- BigDecimal dateAmount = toData.getBigDecimal("orderAmount").subtract(yesData.getBigDecimal("orderAmount")).divide(yesData.getBigDecimal("orderAmount"), 4, RoundingMode.HALF_UP);
- data.put("dateOrderRate", dateOrder);
- data.put("dateAmountRate", dateAmount);
- //周同比
- BigDecimal monthOrder = toData.getBigDecimal("allNumber").subtract(weeklyDayData.getBigDecimal("allNumber")).divide(weeklyDayData.getBigDecimal("allNumber"), 4, RoundingMode.HALF_UP);
- BigDecimal monthAmount = toData.getBigDecimal("orderAmount").subtract(weeklyDayData.getBigDecimal("orderAmount")).divide(weeklyDayData.getBigDecimal("orderAmount"), 4, RoundingMode.HALF_UP);
- data.put("monthOrderRate", monthOrder);
- data.put("monthAmountRate", monthAmount);
- //数据对比
- BigDecimal dataOrder = inDayData.getBigDecimal("allNumber").subtract(lastDayData.getBigDecimal("allNumber")).divide(lastDayData.getBigDecimal("allNumber"), 4, RoundingMode.HALF_UP);
- BigDecimal dataAmount = inDayData.getBigDecimal("orderAmount").subtract(lastDayData.getBigDecimal("orderAmount")).divide(lastDayData.getBigDecimal("orderAmount"), 4, RoundingMode.HALF_UP);
- data.put("dataOrderRate", dataOrder);
- data.put("dataAmountRate", dataAmount);
- }
- return data;
- }
- //招商数据
- private JSONObject getgetOrderDataByAttractInvestment(List<Long> userList, String startDate, String endDate) {
- JSONObject data = new JSONObject();
- List<Long> promoterIds = promoterService.selectPromoterIdList(null);
- if (Check.isNotNull(promoterIds)) {
- data.put("promoterCount", promoterIds.size());//达人总数
- }
- //查询登录人(创建人)的所有商品
- List<Long> itemIds = kuaishouItemCollectSamplesMapper.getItemIdsByCreateId(userList);
- if (Check.isNotNull(itemIds)) {
- JSONObject order = supplyChainService.selectOrderInfoByItemIds(itemIds, startDate, endDate);
- data.put("sendCount", order.getInteger("sendCount"));//发货数
- data.put("sendRate", order.getString("sendRate"));//订单发货率
- data.put("allNumber", order.getInteger("allNumber"));//订单总数
- data.put("validOrderNUm", order.getInteger("validOrderNUm"));//有效订单数
- data.put("inValidOrderNUm", order.getInteger("allNumber") - order.getInteger("validOrderNUm"));//失效订单数
- data.put("orderAmount", order.getInteger("orderAmount"));//订单金额
- data.put("regimentalPromotionAmount", order.getInteger("regimentalPromotionAmount"));//预估服务费
- data.put("baseAmount", order.getInteger("baseAmount"));//累计货贷基数
- //当天
- String today = DateUtils.getNowDateStr();
- Date date = new Date();
- //昨天
- String yesterday = DateUtils.getSubtractTime(date, 1);
- //上周的同一天(上个近七天的结束日期)
- String todayOfLastWeek = DateUtils.getSubtractTime(date, 7);
- //当前近七天的开始日期
- String start = DateUtils.getSubtractTime(date, 6);
- //上个近七天的开始日期
- String LastStart = DateUtils.getSubtractTime(date, 13);
- //当天数据
- JSONObject toData = supplyChainService.selectOrderRate(null, itemIds, today, today);
- //昨日数据
- JSONObject yesData = supplyChainService.selectOrderRate(null, itemIds, yesterday, yesterday);
- //上周当日数据
- JSONObject weeklyDayData = supplyChainService.selectOrderRate(null, itemIds, todayOfLastWeek, todayOfLastWeek);
- //当前近七天的数据
- JSONObject inDayData = supplyChainService.selectOrderRate(null, itemIds, start, today);
- //上个近七天的数据
- JSONObject lastDayData = supplyChainService.selectOrderRate(null, itemIds, LastStart, todayOfLastWeek);
- //日环比 (今天-昨天)/昨天*100%
- BigDecimal dateOrder = toData.getBigDecimal("allNumber").subtract(yesData.getBigDecimal("allNumber")).divide(yesData.getBigDecimal("allNumber"), 4, RoundingMode.HALF_UP);
- BigDecimal dateAmount = toData.getBigDecimal("orderAmount").subtract(yesData.getBigDecimal("orderAmount")).divide(yesData.getBigDecimal("orderAmount"), 4, RoundingMode.HALF_UP);
- data.put("dateOrderRate", dateOrder);
- data.put("dateAmountRate", dateAmount);
- //周同比
- BigDecimal monthOrder = toData.getBigDecimal("allNumber").subtract(weeklyDayData.getBigDecimal("allNumber")).divide(weeklyDayData.getBigDecimal("allNumber"), 4, RoundingMode.HALF_UP);
- BigDecimal monthAmount = toData.getBigDecimal("orderAmount").subtract(weeklyDayData.getBigDecimal("orderAmount")).divide(weeklyDayData.getBigDecimal("orderAmount"), 4, RoundingMode.HALF_UP);
- data.put("monthOrderRate", monthOrder);
- data.put("monthAmountRate", monthAmount);
- //数据对比
- BigDecimal dataOrder = inDayData.getBigDecimal("allNumber").subtract(lastDayData.getBigDecimal("allNumber")).divide(lastDayData.getBigDecimal("allNumber"), 4, RoundingMode.HALF_UP);
- BigDecimal dataAmount = inDayData.getBigDecimal("orderAmount").subtract(lastDayData.getBigDecimal("orderAmount")).divide(lastDayData.getBigDecimal("orderAmount"), 4, RoundingMode.HALF_UP);
- data.put("dataOrderRate", dataOrder);
- data.put("dataAmountRate", dataAmount);
- }
- return data;
- }
- @Override
- public JSONObject getDataAnalysis(Long userId, String type) {
- String roleKey = userService.getRoleKeyByUserId(String.valueOf(userId));
- List<Long> userList = null;
- if ("courtshipManager".equals(roleKey) || "bdManager".equals(roleKey) || "associationManager".equals(roleKey)) {
- Long deptId = deptService.getDeptIdByUserId(userId);
- userList = deptService.getDeptUserListByDeptId(deptId);
- } else {
- userList = Arrays.asList(userId);
- }
- JSONObject returnJson = new JSONObject();
- returnJson.put("code", 0);
- returnJson.put("message", "调用成功");
- if ("1".equals(type)) {
- returnJson.put("data", getDataAnalysisByChannel(userList));
- } else {
- if ("supplyChainAdmin".equals(roleKey)) {
- //供应链管理员查看 招商人员数据
- userList = deptService.getDeptUserListByDeptId(150200L);
- }
- returnJson.put("data", getDataAnalysisByAttractInvestment(userList));
- }
- return returnJson;
- }
- @Override
- public List<JSONObject> queryProductList(Map<String, Object> map) {
- PageUtils.startPage();
- return kuaishouItemCollectSamplesMapper.queryProductList(map);
- }
- // 渠道—数据分析
- private JSONObject getDataAnalysisByChannel(List<Long> userList) {
- JSONObject data = new JSONObject();
- List<Long> promoterIds = promoterService.selectPromoterIdList(userList);
- if (Check.isNotNull(promoterIds)) {
- //当天
- String end = DateUtils.getNowDateStr();
- //当前月份第一天
- String start = DateUtils.getFirstDayByMonth();
- Map<String, Object> map = new HashMap<>();
- map.put("start", start);
- map.put("end", end);
- map.put("userList", userList);
- map.put("promoterIds", promoterIds);
- map.put("startLong", DateUtils.getStartLongTime(start));
- map.put("endLong", DateUtils.getEndLongTime(end));
- List<JSONObject> list = supplyChainService.getMonthOrderAmount(map);
- List<String> allDates = DateUtils.getAllDatesOfTwoTimes(start, end);
- if (Check.isNull(list) || list.size() != allDates.size()) {
- String orderAmountStr = JSONObject.toJSONString(list);
- for (String date : allDates) {
- if (!orderAmountStr.contains(date)) {
- JSONObject obj = new JSONObject();
- obj.put("date", date);
- obj.put("orderAmount", 0);
- obj.put("totalRegimentalSettleAmount", 0);
- obj.put("promoterCount", 0);
- list.add(obj);
- }
- }
- //排序
- Collections.sort(list, new Comparator<JSONObject>() {
- @Override
- public int compare(JSONObject o1, JSONObject o2) {
- return o1.getString("date").compareTo(o2.getString("date"));
- }
- });
- }
- data.put("list", list);
- map.put("toStartLong", DateUtils.getStartLongTime(end));
- JSONObject amount = supplyChainService.getMonthOrderAmountTotal(map);
- if (Check.isNotNull(amount)) {
- data.put("orderAmount", amount.getInteger("orderAmount"));
- data.put("totalRegimentalSettleAmount", amount.getInteger("totalRegimentalSettleAmount"));
- data.put("orderAmountRate", amount.getString("orderAmountRate"));
- data.put("totalRegimentalSettleAmountRate", amount.getString("totalRegimentalSettleAmountRate"));
- }
- JSONObject promoter = promoterService.getgetMonthPromoterTotal(userList, start, end);
- if (Check.isNotNull(promoter)) {
- data.put("promoterCount", promoter.getString("count"));
- data.put("promoterRate", promoter.getString("rate"));
- }
- }
- return data;
- }
- // 招商—数据分析
- private JSONObject getDataAnalysisByAttractInvestment(List<Long> userList) {
- JSONObject data = new JSONObject();
- //查询登录人(创建人)的所有商品
- List<Long> itemIds = kuaishouItemCollectSamplesMapper.getItemIdsByCreateId(userList);
- if (Check.isNotNull(itemIds)) {
- //当天
- String end = DateUtils.getNowDateStr();
- //当前月份第一天
- String start = DateUtils.getFirstDayByMonth();
- Map<String, Object> map = new HashMap<>();
- map.put("start", start);
- map.put("end", end);
- map.put("itemIds", itemIds);
- map.put("startLong", DateUtils.getStartLongTime(start));
- map.put("toStartLong", DateUtils.getStartLongTime(end));
- map.put("endLong", DateUtils.getEndLongTime(end));
- List<JSONObject> list = supplyChainService.getMonthOrderAmountByItems(map);
- List<String> allDates = DateUtils.getAllDatesOfTwoTimes(start, end);
- if (Check.isNull(list) || list.size() != allDates.size()) {
- String orderAmountStr = JSONObject.toJSONString(list);
- for (String date : allDates) {
- if (!orderAmountStr.contains(date)) {
- JSONObject obj = new JSONObject();
- obj.put("date", date);
- obj.put("orderAmount", 0);
- obj.put("totalRegimentalSettleAmount", 0);
- obj.put("orderCount", 0);
- list.add(obj);
- }
- }
- //排序
- Collections.sort(list, new Comparator<JSONObject>() {
- @Override
- public int compare(JSONObject o1, JSONObject o2) {
- return o1.getString("date").compareTo(o2.getString("date"));
- }
- });
- }
- data.put("list", list);
- JSONObject amount = supplyChainService.getMonthOrderAmountTotalByItems(map);
- if (Check.isNotNull(amount)) {
- data.put("orderAmount", amount.getInteger("orderAmount"));
- data.put("totalRegimentalSettleAmount", amount.getInteger("totalRegimentalSettleAmount"));
- data.put("orderAmountRate", amount.getString("orderAmountRate"));
- data.put("totalRegimentalSettleAmountRate", amount.getString("totalRegimentalSettleAmountRate"));
- data.put("orderCount", amount.getString("orderCount"));
- data.put("orderCountRate", amount.getString("orderCountRate"));
- }
- }
- return data;
- }
- }
|