Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.nebula.boxes.iface.facet.GrowthIFaceImpl Maven / Gradle / Ivy
package com.nebula.boxes.iface.facet;
import com.nebula.boxes.iface.model.view.BoardView;
import com.nebula.boxes.iface.model.view.JCharView;
import com.nebula.boxes.iface.server.GrowthIFace;
import com.nebula.boxes.mould.entity.Firm;
import com.nebula.boxes.mould.entity.Location;
import com.nebula.boxes.mould.fetcher.async.*;
import com.nebula.boxes.iface.enums.WorkWageEnum;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.spring.boxes.dollar.$;
import com.spring.boxes.dollar.enums.EducationEnum;
import com.spring.boxes.dollar.enums.InjectTypeEnum;
import com.spring.boxes.dollar.enums.WorkYearEnum;
import com.spring.boxes.dollar.enums.YesOrNoEnum;
import com.spring.boxes.dollar.support.EnumType;
import com.spring.boxes.dollar.support.EnumWrap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
// https://blog.csdn.net/zsj777/article/details/80800377
@Slf4j
@Service
public class GrowthIFaceImpl implements GrowthIFace {
@Autowired
private FirmTrunkApi firmTrunkApi;
@Autowired
private FirmStaffTrunkApi firmStaffTrunkApi;
@Autowired
private PersonTrunkApi personTrunkApi;
@Autowired
private RecruitTrunkApi recruitTrunkApi;
@Autowired
private LocationTrunkApi locationTrunkApi;
@Autowired
private FsFileTrunkApi fsFileTrunkApi;
@Autowired
private RecruitInputTrunkApi recruitInputTrunkApi;
@Override
public BoardView selectBoardView() throws Exception {
BoardView boardView = new BoardView();
boardView.setMetadataTotal(selectMetadataTotal());
boardView.setRecruitFirmTop(selectFirmTopTotal());
boardView.setRecruitCityTop(selectWorkCityTopTotal());
boardView.setRecruitWorkEdu(selectWorkEduTotal());
boardView.setRecruitWorkWage(selectWorkWageTotal());
boardView.setRecruitWorkYear(selectWorkYearTotal());
boardView.setUserInjectTotal(selectUserInjectTotal());
boardView.setUserInjectRadar(setUserInjectRadar());
// boardView.setOfferTotalMonthZone(selectOfferMonthTotalZone());
boardView.setUserInjectMonthZone(selectUserInjectMonthZone());
boardView.setCompanyTotalMonthZone(selectCompanyMonthTotalZone());
boardView.setRecruitTotalMonthZone(selectRecruitMonthTotalZone());
boardView.setFsResumeTotalMonthZone(selectFsResumeMonthTotalZone());
boardView.setFirmStaffMonthTotalZone(selectFirmStaffMonthTotalZone());
boardView.setRecruitInputTotalMonthZone(selectRecruitInputMonthTotalZone());
return boardView;
}
/**
* 获取月维度用户增长
*
* @return 图标渲染结果
* @throws Exception 异常
*/
private JCharView.ZoneGroupView selectUserInjectMonthZone() throws Exception {
List> monthUInjectFuture = personTrunkApi.selectMonthUserInjectGroupBy().get();
if (CollectionUtils.isEmpty(monthUInjectFuture)) {
return null;
}
List injectEnumList = InjectTypeEnum.Opt.INSTANCE().valueList();
List zoneX = getMonthXLabel();
List zoneDataList = Lists.newArrayList();
for (InjectTypeEnum injectEnum : injectEnumList) {
JCharView.ZoneDataView zoneDataView = new JCharView.ZoneDataView<>();
zoneDataView.setName(injectEnum.getLabel());
String color = randomColor();
zoneDataView.setBdColor(color);
zoneDataView.setBgColor(color);
List total = Lists.newArrayList(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
for (Map map : monthUInjectFuture) {
// 相同指标
if (injectEnum.getValue() == Integer.parseInt(String.valueOf(map.get("item")))) {
for (int i = 0; i < zoneX.size(); i++) {
// 月份存在的对应月份位赋值
if (zoneX.get(i).equalsIgnoreCase(String.valueOf(map.get("date")))) {
total.set(i, (Long) map.get("total"));
}
}
}
}
zoneDataView.setData(total);
zoneDataList.add(zoneDataView);
}
return new JCharView.ZoneGroupView(zoneX, zoneDataList);
}
/**
* 获取月维度职位增长
*
* @return 图标渲染结果
* @throws Exception 异常
*/
private JCharView.ZoneGroupView selectRecruitMonthTotalZone() throws Exception {
Map monthTotalF = recruitTrunkApi.selectMonthTotalGroupBy().get();
return selectEachMonthTotalZone("职位数量", monthTotalF);
}
/**
* 获取月维度职位增长
*
* @return 图标渲染结果
* @throws Exception 异常
*/
private JCharView.ZoneGroupView selectCompanyMonthTotalZone() throws Exception {
Map monthTotalF = firmTrunkApi.selectMonthTotalGroupBy().get();
return selectEachMonthTotalZone("企业数量", monthTotalF);
}
/**
* 获取月维度职位增长
*
* @return 图标渲染结果
* @throws Exception 异常
*/
private JCharView.ZoneGroupView selectFsResumeMonthTotalZone() throws Exception {
Map monthTotalF = fsFileTrunkApi.selectMonthTotalGroupBy("hunts").get();
return selectEachMonthTotalZone("云简历数量", monthTotalF);
}
/**
* 获取月维度职位增长
*
* @return 图标渲染结果
* @throws Exception 异常
*/
private JCharView.ZoneGroupView selectRecruitInputMonthTotalZone() throws Exception {
Map monthTotalF = recruitInputTrunkApi.selectMonthTotalGroupBy().get();
return selectEachMonthTotalZone("投递数量", monthTotalF);
}
/**
* 获取月维度职位增长
*
* @return 图标渲染结果
* @throws Exception 异常
*/
private JCharView.ZoneGroupView selectFirmStaffMonthTotalZone() throws Exception {
Map monthTotalF = firmStaffTrunkApi.selectMonthTotalGroupBy().get();
return selectEachMonthTotalZone("职员认证数量", monthTotalF);
}
/**
* 获取月维度职位增长
*
* @return 图标渲染结果
* @throws Exception 异常
*/
/*private JCharView.ZoneGroupView selectOfferMonthTotalZone() throws Exception {
Map monthTotalF = offerTrunkApi.selectMonthTotalGroupBy().get();
return selectEachMonthTotalZone("Offer数量", monthTotalF);
}
*/
/**
* 构建12个月份的维度增长图标
*
* @return 图标渲染结果
* @throws Exception 异常
*/
private JCharView.ZoneGroupView selectEachMonthTotalZone(String title, Map map) {
if ($.isEmpty(map)) {
return new JCharView.ZoneGroupView();
}
List zoneX = getMonthXLabel();
List zoneDataList = Lists.newArrayList();
JCharView.ZoneDataView zoneDataView = new JCharView.ZoneDataView<>();
String color = randomColor();
zoneDataView.setName($.val(title));
zoneDataView.setBdColor(color);
zoneDataView.setBgColor(color);
List total = Lists.newArrayList(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
map.forEach((k, v) -> {
for (int i = 0; i < zoneX.size(); i++) {
if (zoneX.get(i).equalsIgnoreCase(String.valueOf(k))) {
total.set(i, $.val((Long) v));
}
}
});
zoneDataView.setData(total);
zoneDataList.add(zoneDataView);
return new JCharView.ZoneGroupView(zoneX, zoneDataList);
}
/**
* 获取格式化后的12个月份时间戳
*
* @return 12个月份时间戳
*/
private List getMonthXLabel() {
List zoneList = getNowYearFirstDayOfEachMonth();
List zoneX = Lists.newArrayList();
for (Date date : zoneList) {
String dateX = $.format(date, "yyyy/MM");
zoneX.add(dateX);
}
return zoneX;
}
/**
* 查询用户雷达统计
*
* @return 图标渲染结果
* @throws Exception 异常
*/
private JCharView.RadarView, List> setUserInjectRadar() throws Exception {
Future> personTotalFuture = personTrunkApi.selectUserInjectGroupBy();
List> originList = groupViewWithGroupMap(personTotalFuture.get());
List labelList = Lists.newArrayList();
List dataList = Lists.newArrayList();
for (JCharView.GroupView groupView : originList) {
String item = groupView.getName();
InjectTypeEnum injectEnum = InjectTypeEnum.Opt.INSTANCE().valueGet(Integer.parseInt(item));
if (null == injectEnum) {
continue;
}
labelList.add(injectEnum.getLabel());
dataList.add(groupView.getTotal());
}
List> items = Lists.newArrayList();
items.add(dataList);
return new JCharView.RadarView<>(labelList, items);
}
/**
* 查询各项统计总数
*
* @return 图标渲染结果
* @throws Exception 异常
*/
public List selectMetadataTotal() throws Exception {
Future personTotalFuture = personTrunkApi.selectPersonTotal();
Future firmStaffTotalFuture = firmStaffTrunkApi.selectFirmStaffTotal();
Future firmTotalFuture = firmTrunkApi.selectFirmTotal();
Future recruitTotalFuture = recruitTrunkApi.selectRecruitTotal(YesOrNoEnum.NO);
List list = Lists.newArrayList();
list.add(new JCharView.GroupView<>("注册用户", personTotalFuture.get()));
list.add(new JCharView.GroupView<>("企业用户", firmStaffTotalFuture.get()));
list.add(new JCharView.GroupView<>("入驻企业", firmTotalFuture.get()));
list.add(new JCharView.GroupView<>("职位总数", recruitTotalFuture.get()));
return list;
}
/**
* 获取招聘企业排名统计数值
*
* @return 图标渲染结果
* @throws Exception 异常
*/
public JCharView.GroupView, List> selectFirmTopTotal() throws Exception {
Future> firmTotalFuture = recruitTrunkApi.selectWorkFirmIdGroupBy(40);
List> originList = groupViewWithGroupMap(firmTotalFuture.get());
if (CollectionUtils.isEmpty(originList)) {
return null;
}
List firmIds = originList.stream().map(x -> Long.valueOf(x.getName())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(firmIds)) {
return null;
}
List labelList = Lists.newArrayList();
List colorList = Lists.newArrayList();
List dataList = Lists.newArrayList();
Map firmMapping = firmTrunkApi.selectMapByIds(firmIds).get();
for (JCharView.GroupView groupView : originList) {
Firm firm = firmMapping.get(Long.valueOf(groupView.getName()));
if (null == firm) {
continue;
}
colorList.add(randomColor());
labelList.add(firm.getAlias());
dataList.add(groupView.getTotal());
}
return new JCharView.GroupView<>(labelList, dataList, colorList);
}
/**
* 获取城市排名统计数值
*
* @return 图标渲染结果
* @throws Exception 异常
*/
public JCharView.GroupView, List> selectWorkCityTopTotal() throws Exception {
Future> cityTotalFuture = recruitTrunkApi.selectWorkCityIdGroupBy(40);
List> originList = groupViewWithGroupMap(cityTotalFuture.get());
List cityIds = originList.stream().map(x -> Long.valueOf(x.getName())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(cityIds)) {
return null;
}
List labelList = Lists.newArrayList();
List colorList = Lists.newArrayList();
List dataList = Lists.newArrayList();
Map locationMapping = locationTrunkApi.selectMapByIds(cityIds).get();
for (JCharView.GroupView groupView : originList) {
Location location = locationMapping.get(Long.valueOf(groupView.getName()));
if (null == location) {
continue;
}
colorList.add(randomColor());
labelList.add(location.getName());
dataList.add(groupView.getTotal());
}
return new JCharView.GroupView<>(labelList, dataList, colorList);
}
/**
* 获取薪资要求统计数值
*
* @return 图标渲染结果
* @throws Exception 异常
*/
public JCharView.GroupView, List> selectWorkWageTotal() throws Exception {
Future> workWageFuture = recruitTrunkApi.selectWorkWageGroupBy();
return selectEachItemRateView(workWageFuture.get(), WorkWageEnum.Opt.INSTANCE());
}
/**
* 获取薪资要求统计数值
*
* @return 图标渲染结果
* @throws Exception 异常
*/
public JCharView.GroupView, List> selectWorkYearTotal() throws Exception {
Future> workYearFuture = recruitTrunkApi.selectWorkYearGroupBy();
return selectEachItemRateView(workYearFuture.get(), WorkYearEnum.Opt.INSTANCE());
}
/**
* 获取学历要求统计数值
*
* @return 图标渲染结果
* @throws Exception 异常
*/
public JCharView.GroupView, List> selectWorkEduTotal() throws Exception {
Future> workEduFuture = recruitTrunkApi.selectWorEduGroupBy();
return selectEachItemRateView(workEduFuture.get(), EducationEnum.Opt.INSTANCE());
}
/**
* 获取用户注册统计数值
*
* @return 图标渲染结果
* @throws Exception 异常
*/
public JCharView.GroupView, List> selectUserInjectTotal() throws Exception {
Future> personTotalFuture = personTrunkApi.selectUserInjectGroupBy();
return selectEachItemRateView(personTotalFuture.get(), InjectTypeEnum.Opt.INSTANCE());
}
/**
* 获取维度统计数据
*
* @param map 分组统计
* @param enumWrap 枚举
* @return 图标渲染结果
*/
private JCharView.GroupView, List> selectEachItemRateView(Map map,
EnumWrap enumWrap) {
List> originList = groupViewWithGroupMap(map);
List labelList = Lists.newArrayList();
List colorList = Lists.newArrayList();
List dataList = Lists.newArrayList();
for (JCharView.GroupView groupView : originList) {
String item = groupView.getName();
EnumType enumType = enumWrap.valueGet(Integer.valueOf(item));
if (null == enumType) {
continue;
}
colorList.add(randomColor());
labelList.add(enumType.getLabel());
dataList.add(groupView.getTotal());
}
return new JCharView.GroupView<>(labelList, dataList, colorList);
}
/**
* 抽取统计数据值
*
* @param map 集合
* @return 图标渲染结果
*/
private List> groupViewWithGroupMap(Map map) {
List> list = Lists.newArrayList();
Optional.ofNullable(map).orElse(Maps.newHashMap()).forEach((k, v) -> {
list.add(new JCharView.GroupView<>(k, v));
});
return list;
}
/**
* 获取当前年份的所有月份的第一天
*
* @return 日期集合
*/
public static List getNowYearFirstDayOfEachMonth() {
Calendar cal = Calendar.getInstance();
List list = Lists.newArrayList();
for (int i = 0; i < 12; i++) {
cal.set(Calendar.MONTH, i);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
list.add(cal.getTime());
}
return list;
}
/**
* 获取随机衍射
*
* @return 颜色码
*/
private String randomColor() {
//生成随机对象
Random random = new Random();
//生成红色颜色代码
String red = Integer.toHexString(random.nextInt(256)).toUpperCase();
//生成绿色颜色代码
String green = Integer.toHexString(random.nextInt(256)).toUpperCase();
//生成蓝色颜色代码
String blue = Integer.toHexString(random.nextInt(256)).toUpperCase();
//判断红色代码的位数
red = red.length() == 1 ? "0" + red : red;
//判断绿色代码的位数
green = green.length() == 1 ? "0" + green : green;
//判断蓝色代码的位数
blue = blue.length() == 1 ? "0" + blue : blue;
//生成十六进制颜色值
return "#" + red + green + blue;
}
}