顺胜组织架构图初始化

顺胜组织架构图
Chengliang 1 year ago
parent c0a44c5c5f
commit b1dd8815d7

@ -1,14 +0,0 @@
package com.api.matfron.web;
import javax.ws.rs.Path;
/**
* @Author liang.cheng
* @Date 2023/9/26 5:49 PM
* @Description:
* @Version 1.0
*/
@Path("/matfron/portal/element")
public class StatisticsPortalAction extends com.engine.matfron.web.StatisticsPortalAction {
}

@ -0,0 +1,10 @@
package com.api.sship.web;
import javax.ws.rs.Path;
/**
* @author liang.cheng
*/
@Path("/sship/organization/chart")
public class OrgChartController extends com.engine.sship.web.OrgChartController {
}

@ -1,26 +0,0 @@
package com.engine.matfron.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2023/9/28 10:06 AM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DepartmentParam {
private Integer departmentId;
private String name;
private Integer count;
}

@ -1,47 +0,0 @@
package com.engine.matfron.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.LinkedList;
/**
* @Author liang.cheng
* @Date 2023/9/27 5:30 PM
* @Description: echarts option
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OptionVO {
private String titleText;
private LinkedList<String> xData;
private Integer yMin;
private Integer yMax;
private Integer yInterval;
private LinkedList<Integer> yData;
private LinkedList<String> legendDataFirst;
private LinkedList<String> legendDataTwo;
private LinkedList<Integer> barSeriesData;
private LinkedList<Integer> barSeriesDataTwo;
private LinkedList<Integer> barSeriesDataThree;
private LinkedList<SeriesParam> seriesData;
}

@ -1,25 +0,0 @@
package com.engine.matfron.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2023/9/27 3:45 PM
* @Description:
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PortalTopVO<T> {
private String title;
private T count;
}

@ -1,28 +0,0 @@
package com.engine.matfron.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2023/9/28 2:02 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SeriesParam {
private Double value;
private String name;
private String color;
}

@ -1,25 +0,0 @@
package com.engine.matfron.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2023/10/9 1:11 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SurnameParam {
private Double companyworkyear;
private Integer count;
}

@ -1,118 +0,0 @@
package com.engine.matfron.service;
import com.engine.matfron.entity.OptionVO;
import com.engine.matfron.entity.PortalTopVO;
import java.util.LinkedList;
import java.util.Map;
/**
* @Author liang.cheng
* @Date 2023/9/26 5:51 PM
* @Description:
* @Version 1.0
*/
public interface StatisticsPortalService {
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/9/27 4:02 PM
* @param: []
* @return: com.engine.matfron.entity.PortalTopVO
*/
LinkedList<PortalTopVO> getPortalTop();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/9/27 5:40 PM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getPortalDepartment();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/9/28 11:23 AM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getPortalSubCompany();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 9:52 AM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getPortalEthnic();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/10 5:57 PM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getHomePlace();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 9:53 AM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getEducational();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 11:21 AM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getSurname();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 2:32 PM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getAgeAndSex();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 5:52 PM
* @param: []
* @return: com.engine.matfron.entity.OptionVO
*/
OptionVO getJobType();
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/9 7:00 PM
* @param: [departmentIds]
* @return: map
*/
Map<String,Object> getLeaveMonth(String departmentIds);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2023/10/10 9:37 AM
* @param: [departmentIds]
* @return: map
*/
Map<String,Object> getLeaveYear(String departmentIds);
}

@ -1,634 +0,0 @@
package com.engine.matfron.service.impl;
import com.engine.core.impl.Service;
import com.engine.matfron.entity.*;
import com.engine.matfron.exception.CustomizeRunTimeException;
import com.engine.matfron.service.StatisticsPortalService;
import com.engine.matfron.util.CommonDateUtil;
import com.engine.matfron.util.CommonUtils;
import lombok.SneakyThrows;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.YearMonth;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* @Author liang.cheng
* @Date 2023/9/26 5:52 PM
* @Description:
* @Version 1.0
*/
public class StatisticsPortalServiceImpl extends Service implements StatisticsPortalService {
private final DecimalFormat df = new DecimalFormat("#.00");
@Override
public LinkedList<PortalTopVO> getPortalTop() {
RecordSet rs = new RecordSet();
LinkedList<PortalTopVO> portalTopVOList = new LinkedList<>();
rs.executeQuery("select count(1) as count from hrmresource where status < 4");
rs.next();
Integer count = Util.getIntValue(rs.getString("count"), 0);
portalTopVOList.add(PortalTopVO.builder().title("在职人数总数").count(count).build());
portalTopVOList.add(PortalTopVO.builder().title("社保缴纳人数").count(0).build());
List<String> birthdayList = new ArrayList<>();
rs.executeQuery("select birthday from hrmresource where status < 4 and birthday is not null and birthday <> ''");
while (rs.next()) {
birthdayList.add(Util.null2String(rs.getString("birthday")));
}
double averageAge = birthdayList.stream()
.map(CommonUtils::parseLocalDate)
.mapToInt(CommonUtils::calculateAge)
.average()
.orElse(0);
String avgAge = df.format(averageAge);
portalTopVOList.add(PortalTopVO.builder().title("平均年龄").count(avgAge).build());
String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(YearMonth.now()));
String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(YearMonth.now()));
rs.executeQuery("select count(1) as sum from hrmresource where status < 4 and companystartdate >= ? and companystartdate <= ",startMonth,endMonth);
rs.next();
Integer sum = Util.getIntValue(rs.getString("sum"),0);
portalTopVOList.add(PortalTopVO.builder().title("本月新入职人员").count(sum).build());
return portalTopVOList;
}
@SneakyThrows
@Override
public OptionVO getPortalDepartment() {
RecordSet rs = new RecordSet();
LinkedList<String> xData = new LinkedList<>();
LinkedList<Integer> yData = new LinkedList<>();
DepartmentComInfo comInfo = new DepartmentComInfo();
List<Integer> ids = new ArrayList<>();
rs.executeQuery("select id,departmentname from hrmdepartment where supdepid = 0 and (canceled = 0 or canceled is null)");
while (rs.next()) {
xData.add(Util.null2String(rs.getString("departmentname")));
ids.add(Util.getIntValue(rs.getString("id")));
}
List<DepartmentParam> deptList = new ArrayList<>();
rs.executeQuery("SELECT d.id, CASE WHEN t.count IS NULL THEN 0 ELSE t.count END AS num \n" +
" FROM hrmdepartment d left join (SELECT departmentid, COUNT(1) AS count FROM hrmresource where status < 4 GROUP BY departmentid) t ON d.id = t.departmentid \n" +
" where d.id in ("+StringUtils.join(ids,",")+")");
while (rs.next()) {
int deptid = Util.getIntValue(rs.getString("id"));
int num = Util.getIntValue(rs.getString("num"));
String allSupDepartment;
allSupDepartment = comInfo.getAllSupDepartment(String.valueOf(deptid));
if (StringUtils.isNotEmpty(allSupDepartment)) {
int count = countBydeptIds(allSupDepartment);
num = num + count;
}
yData.add(num);
deptList.add(DepartmentParam.builder().departmentId(deptid).count(num).build());
}
int max = Collections.max(yData);
int ceil =(int) Math.ceil((double) max / 5);
ceil = CommonUtils.roundUpToNearestTen(ceil);
int roundedMax = CommonUtils.roundedMax(ceil, 5);
return OptionVO.builder()
.titleText("一级部门人数统计")
.xData(xData)
.yMin(0)
.yMax(roundedMax)
.yInterval(ceil)
.yData(yData)
.build();
}
@Override
public OptionVO getPortalSubCompany() {
RecordSet rs = new RecordSet();
LinkedList<Integer> yData = new LinkedList<>();
List<YearMonth> yearMonths = CommonDateUtil.getYearMonths(LocalDate.now());
yearMonths.forEach(yearMonth -> {
String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(yearMonth));
String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(yearMonth));
rs.executeQuery("select count(1) as sum from hrmresource where status < 4 and companystartdate <= ?",endMonth);
if (rs.next()) {
Integer sum = Util.getIntValue(rs.getString("sum"),0);
yData.add(sum);
}
});
int max = Collections.max(yData);
int ceil =(int) Math.ceil((double) max / 5);
ceil = CommonUtils.roundUpToNearestTen(ceil);
int roundedMax = CommonUtils.roundedMax(ceil, 5);
return OptionVO.builder()
.titleText("各月份分部总人数")
.yMin(0)
.yMax(roundedMax)
.yInterval(ceil)
.yData(yData)
.build();
}
@Override
public OptionVO getPortalEthnic() {
RecordSet rs = new RecordSet();
List<String> colorList = Arrays.asList("#6e94f3","#faf0e6","#7cfc00","#ao20f0","#00ced1","#83d8ae","#697695","#8ac9e9","#9933fa","#c0ff3e","#ffe4c4","#cd6090");
LinkedList<SeriesParam> seriesData = new LinkedList<>();
LinkedList<String> nameSet = new LinkedList<>();
rs.executeQuery("select distinct folk,count(1) as sums from hrmresource where status < 4 \n" +
" and folk is not null group by folk");
while (rs.next()) {
Random random = new Random();
String color = colorList.get(random.nextInt(colorList.size()));
String name = Util.null2String(rs.getString("folk"));
seriesData.add(SeriesParam.builder().value(Util.getDoubleValue(rs.getString("sums")))
.name(name).color(color).build());
nameSet.add(name);
}
double percentage = seriesData.stream().mapToDouble(SeriesParam::getValue).sum();
seriesData.forEach(item -> item.setValue(Double.valueOf(df.format((item.getValue() * 100) / percentage))));
// LinkedList<String> legendDataFirst = null;
// if (nameSet.size() > 2) {
// int splitSize = nameSet.size() / 2;
// legendDataFirst = nameSet.stream()
// .collect(Collectors.partitioningBy(e -> nameSet.indexOf(e) < splitSize,
// Collectors.toCollection(LinkedList::new)))
// .get(false);
// nameSet.removeAll(legendDataFirst);
// }
return OptionVO.builder()
.titleText("民族分析")
.legendDataTwo(nameSet)
.seriesData(seriesData)
.build();
}
@Override
public OptionVO getHomePlace() {
RecordSet rs = new RecordSet();
List<String> colorList = Arrays.asList("#ao20f0","#8ac9e9","#697695","#83d8ae","#faf0e6","#7cfc00","#6e94f3","#9933fa","#c0ff3e","#00ced1","#ffe4c4","#cd6090");
LinkedList<SeriesParam> seriesData = new LinkedList<>();
LinkedList<String> legendData = new LinkedList<>();
rs.executeQuery("select h.locationid,l.locationname,count(1) as num from hrmresource h\n" +
" left join hrmlocations l on h.locationid = l.id\n" +
" where h.status < 4 and h.locationid is not null group by h.locationid,l.locationname");
while (rs.next()) {
String locationname = Util.null2String(rs.getString("locationname"));
legendData.add(locationname);
Random random = new Random();
String color = colorList.get(random.nextInt(colorList.size()));
seriesData.add(SeriesParam.builder().value(Util.getDoubleValue(rs.getString("num"))).name(locationname).color(color).build());
}
List<Double> values = seriesData.stream().map(SeriesParam :: getValue).collect(Collectors.toList());
double percentage = values.stream().mapToDouble(Double::doubleValue).sum();
seriesData.forEach(item -> item.setValue(Double.valueOf(df.format((item.getValue() * 100) / percentage))));
return OptionVO.builder()
.titleText("归属地分析")
.legendDataFirst(legendData)
.seriesData(seriesData)
.build();
}
@Override
public OptionVO getEducational() {
RecordSet rs = new RecordSet();
List<String> colorList = Arrays.asList("#faf0e6","#7cfc00","#ee8164","#9933fa","#f19c45","#6fcecf","#507ef7","#ao20f0");
LinkedList<SeriesParam> seriesData = new LinkedList<>();
LinkedList<String> nameSet = new LinkedList<>();
rs.executeQuery("select distinct h.educationlevel,count(1) as sum,d.name from hrmresource h\n" +
"left join hrmeducationlevel d on h.educationlevel = d.id where status < 4 \n" +
"and h.educationlevel is not null and d.name is not null group by h.educationlevel,d.name ");
int index = 0;
while (rs.next()) {
if (index > colorList.size()){
index = 0;
}
index++;
String name = Util.formatMultiLang (Util.null2String(rs.getString("name")));
seriesData.add(SeriesParam.builder().value(Util.getDoubleValue(rs.getString("sum")))
.name(name).color(colorList.get(index)).build());
nameSet.add(name);
}
double percentage = seriesData.stream().mapToDouble(SeriesParam::getValue).sum();
seriesData.forEach(item -> item.setValue(Double.valueOf(df.format((item.getValue() * 100) / percentage))));
LinkedList<String> legendDataFirst = new LinkedList<>();
if (nameSet.size() > 2) {
legendDataFirst = treeSetSplitExample(nameSet);
}
return OptionVO.builder()
.titleText("学历分析")
.legendDataFirst(legendDataFirst)
.legendDataTwo(nameSet)
.seriesData(seriesData)
.build();
}
@Override
public OptionVO getSurname() {
RecordSet rs = new RecordSet();
LinkedList<SeriesParam> seriesData = new LinkedList<>();
List<SurnameParam> surnameList = new ArrayList<>();
rs.executeQuery("select companyworkyear,count(1) as sum from hrmresource where status < 4 " +
" and companyworkyear is not null group by companyworkyear ");
while (rs.next()) {
surnameList.add(SurnameParam.builder().companyworkyear(Util.getDoubleValue(rs.getString("companyworkyear"))).count(Util.getIntValue(rs.getString("sum"))).build());
}
List<Integer> statisticsArr = Arrays.asList(0,1,3,5,10,100);
List<Double> statisticsList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
double count = statisticsSurname(statisticsArr.get(i), statisticsArr.get(i+1), surnameList);
statisticsList.add(count);
}
double percentage = statisticsList.stream().mapToDouble(Double::doubleValue).sum();
List<Double> newList = statisticsList.stream()
.map(num -> Double.valueOf (df.format((num * 100 ) / percentage)))
.collect(Collectors.toList());
newList.forEach(count -> seriesData.add(SeriesParam.builder().value(count).build()));
return OptionVO.builder()
.titleText("司龄统计")
.seriesData(seriesData)
.build();
}
@Override
public OptionVO getAgeAndSex() {
RecordSet rs = new RecordSet();
LinkedList<Integer> barSeriesData = new LinkedList<>();
LinkedList<Integer> barSeriesDataTwo = new LinkedList<>();
List<String> ageArr = Arrays.asList("16~20","21~25","26~30","31~35","36~40","41~45","46~50","51~55","56~60","61~65","66~70");
List<String> birthdayListMen = new ArrayList<>();
rs.executeQuery("select birthday from hrmresource where status < 4 and sex is not null and birthday is not null and birthday <> '' and sex = 0");
while (rs.next()) {
birthdayListMen.add(Util.null2String(rs.getString("birthday")));
}
List<Integer> menAge = birthdayListMen.stream()
.map(birthday -> {
LocalDate birthdate = LocalDate.parse(birthday);
LocalDate now = LocalDate.now();
return Period.between(birthdate, now).getYears();
})
.collect(Collectors.toList());
for (int i = 0; i < ageArr.size(); i++) {
String[] split = ageArr.get(i).split("~");
List<Integer> collect = menAge.stream().filter(item -> item > Integer.parseInt(split[0]) && item <= Integer.parseInt(split[1])).collect(Collectors.toList());
barSeriesData.add(collect.size());
}
int yMax = barSeriesData.stream().max(Integer::compare).orElse(0);
List<String> birthdayListWomen = new ArrayList<>();
rs.executeQuery("select birthday from hrmresource where status < 4 and sex is not null and birthday is not null and sex = 1");
while (rs.next()) {
birthdayListWomen.add(Util.null2String(rs.getString("birthday")));
}
List<Integer> womenAge = birthdayListWomen.stream()
.map(birthday -> {
LocalDate birthdate = LocalDate.parse(birthday);
LocalDate now = LocalDate.now();
return Period.between(birthdate, now).getYears();
})
.collect(Collectors.toList());
LinkedList<Integer> list = new LinkedList<>();
for (int i = 0; i < ageArr.size(); i++) {
String[] split = ageArr.get(i).split("~");
List<Integer> collect = womenAge.stream().filter(item -> item > Integer.parseInt(split[0]) && item <= Integer.parseInt(split[1])).collect(Collectors.toList());
barSeriesDataTwo.add(-collect.size());
list.add(collect.size());
}
int yMin = -(list.stream().max(Integer::compare).orElse(0));
int sum = yMax > Math.abs(yMin) ? yMax : yMin ;
int divisor = sum % 6;
sum = sum + (6 - divisor) + 12;
int ceil =(int) Math.ceil((double) sum / 3);
int roundedMax = CommonUtils.roundedMax(ceil, 6);
return OptionVO.builder()
.titleText("年龄与性别分析")
.yMin(-roundedMax)
.yMax(roundedMax)
.yInterval(ceil)
.barSeriesData(barSeriesData)
.barSeriesDataTwo(barSeriesDataTwo)
.build();
}
@Override
public OptionVO getJobType() {
RecordSet rs = new RecordSet();
LinkedList<String> xData = new LinkedList<>();
LinkedList<Integer> barSeriesData = new LinkedList<>();
rs.executeQuery("select a.*,b.jobgroupname from (select g.id as jobgroupid,count(1) as sum from hrmresource h \n" +
" left join hrmjobtitles j on h.jobtitle = j.id\n" +
" left join hrmjobactivities c on j.jobactivityid = c.id\n" +
" left join hrmjobgroups g on c.jobgroupid = g.id\n" +
" where h.status < 4 and g.id is not null group by g.id) as a left join hrmjobgroups b on a.jobgroupid = b.id");
while (rs.next()) {
xData.add(Util.null2String(rs.getString("jobgroupname")));
barSeriesData.add(Util.getIntValue(rs.getString("sum")));
}
int max = Collections.max(barSeriesData);
int ceil =(int) Math.ceil((double) max / 4);
ceil = CommonUtils.roundUpToNearestTen(ceil);
int roundedMax = CommonUtils.roundedMax(ceil, 4);
return OptionVO.builder()
.titleText("职务类别统计")
.xData(xData)
.yMin(0)
.yMax(roundedMax)
.yInterval(ceil)
.barSeriesData(barSeriesData)
.build();
}
@Override
public Map<String,Object> getLeaveMonth(String departmentIds) {
Map<String,Object> data = new HashMap<>(4);
RecordSet rs = new RecordSet();
String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(YearMonth.now()));
String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(YearMonth.now()));
LinkedList<String> xData = new LinkedList<>();
LinkedList<Integer> barSeriesData = new LinkedList<>();
LinkedList<BrowserParam> browser = new LinkedList<>();
StringBuilder sql = new StringBuilder();
sql.append("select t.departmentname, t.id,CASE \n" +
" WHEN a.sum IS NULL THEN 0 \n" +
" ELSE a.sum \n" +
" END AS num from hrmdepartment t \n" +
" left join (select s.departmentid,count(1) as sum from hrmstatushistory h left join hrmresource s on h.resourceid = s.id " +
" where h.type_n = 5 and h.changedate >= ? and h.changedate <= ? group by s.departmentid ) a\n" +
" on t.id = a.departmentid ");
if(StringUtils.isNotEmpty(departmentIds)) {
sql.append(" where (t.canceled = 0 or t.canceled is null)");
sql.append(" and t.id in (").append(departmentIds).append(")");
}
rs.executeQuery(sql.toString(),startMonth,endMonth);
int i = 0;
while (rs.next() && i < 5) {
i++;
Integer id = Util.getIntValue(rs.getString("id"));
String name = Util.null2String(rs.getString("departmentname"));
int num = Util.getIntValue(rs.getString("num"));
xData.add(name);
int countBydeptId = countBydeptId(id, endMonth) + num;
barSeriesData.add( countBydeptId == 0 ? 0 : (num * 100) / countBydeptId);
browser.add(BrowserParam.builder().id(id).name(name).build());
}
int max = Collections.max(barSeriesData);
max = max < 80 ? max + 20 : 100;
int ceil =(int) Math.ceil((double) max / 4);
int roundedMax = CommonUtils.roundedMax(ceil, 4);
OptionVO optionVo = OptionVO.builder().titleText("当月多部门离职率统计")
.xData(xData)
.yMin(0)
.yMax(roundedMax)
.yInterval(ceil)
.barSeriesData(barSeriesData)
.build();
data.put("replaceDatas",browser);
data.put("optionVo",optionVo);
return data;
}
@Override
public Map<String,Object> getLeaveYear(String departmentIds) {
Map<String,Object> data = new HashMap<>(4);
RecordSet rs = new RecordSet();
LinkedList<String> legendDataFirst = new LinkedList<>();
LinkedList<Integer> barSeriesData = new LinkedList<>();
LinkedList<Integer> barSeriesDataTwo = new LinkedList<>();
LinkedList<Integer> barSeriesDataThree = new LinkedList<>();
DepartmentComInfo comInfo = new DepartmentComInfo();
LinkedList<BrowserParam> browser = new LinkedList<>();
List<Integer> deptList = new ArrayList<>();
if(StringUtils.isNotEmpty(departmentIds)) {
deptList = Arrays.stream(departmentIds.split(",")).map(Integer::parseInt)
.collect(Collectors.toList());
}else {
// rs.executeQuery("select distinct t.id from hrmdepartment t \n" +
// " left join hrmresource h on t.id = h.departmentid\n" +
// " left join hrmstatushistory s on h.id = s.resourceid where s.type_n = 5 ");
rs.executeQuery("select id from hrmdepartment where canceled = 0 or canceled is null");
while (rs.next()) {
deptList.add(Util.getIntValue(rs.getString("id")));
}
}
deptList = deptList.stream().limit(3).collect(Collectors.toList());
deptList.forEach(dept -> {
try {
String departmentName = comInfo.getDepartmentName(String.valueOf(dept));
legendDataFirst.add(departmentName);
browser.add(BrowserParam.builder().id(dept).name(departmentName).build());
} catch (Exception e) {
throw new CustomizeRunTimeException("所选部门不存在");
}
});
List<YearMonth> yearMonths = CommonDateUtil.getYearMonths(LocalDate.now());
List<Integer> finalDeptList = deptList;
yearMonths.forEach(yearMonth -> {
String startMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateStartOfMonth(yearMonth));
String endMonth = CommonDateUtil.getFormatYear(CommonDateUtil.toDateEndOfMonth(yearMonth));
for (int i = 0; i < 3; i++) {
Integer value = calculateLeave(finalDeptList.get(i), startMonth, endMonth);
switch (i) {
case 0:
barSeriesData.add(value);
break;
case 1:
barSeriesDataTwo.add(value);
break;
case 2:
barSeriesDataThree.add(value);
break;
default:
break;
}
}
});
LinkedList<Integer> sumData = new LinkedList<>();
sumData.addAll(barSeriesData);
sumData.addAll(barSeriesDataTwo);
sumData.addAll(barSeriesDataThree);
int max = Collections.max(sumData);
max = max < 80 ? max + 20 : 100;
int ceil =(int) Math.ceil((double) max / 4);
int roundedMax = CommonUtils.roundedMax(ceil, 4);
OptionVO optionVo = OptionVO.builder().titleText("年度离职率统计")
.legendDataFirst(legendDataFirst)
.yMin(0)
.yMax(roundedMax)
.yInterval(ceil)
.barSeriesData(barSeriesData)
.barSeriesDataTwo(barSeriesDataTwo)
.barSeriesDataThree(barSeriesDataThree)
.build();
data.put("replaceDatas",browser);
data.put("optionVo",optionVo);
return data;
}
private Integer calculateLeave(Integer id,String startMonth,String endMonth) {
RecordSet rs = new RecordSet();
String sql = ("select t.departmentname, t.id,CASE \n" +
" WHEN a.sum IS NULL THEN 0 \n" +
" ELSE a.sum \n" +
" END AS num from hrmdepartment t \n" +
" left join (select s.departmentid,count(1) as sum from hrmstatushistory h left join hrmresource s on h.resourceid = s.id " +
" where type_n = 5 and changedate >= ? and changedate <= ? group by s.departmentid ) a\n" +
" on t.id = a.departmentid where t.id = ? and (t.canceled = 0 or t.canceled is null)");
rs.executeQuery(sql,startMonth,endMonth,id);
rs.next();
int countBydeptId = countBydeptId(id, endMonth);
return countBydeptId == 0 ? 0 : ((Util.getIntValue(rs.getString("num")) * 100) / countBydeptId);
}
/**
*
* @param departmentId
* @return
*/
private int countBydeptId(Integer departmentId,String endMonth) {
RecordSet rs = new RecordSet();
rs.executeQuery("select count(1) as sum from hrmresource where departmentId = ? and status < 4 and companystartdate <= ? ",departmentId,endMonth);
rs.next();
return Util.getIntValue(rs.getString("sum"));
}
/**
*
* @param deptIds
* @return
*/
private int countBydeptIds(String deptIds) {
RecordSet rs = new RecordSet();
rs.executeQuery("select count(1) as sum from hrmresource where departmentId in ("+deptIds+")");
rs.next();
return Util.getIntValue(rs.getString("sum"));
}
/**
*
* @return
*/
private Double statisticsSurname(Integer min,Integer max,List<SurnameParam> surnameList) {
return surnameList.stream().filter(item -> item.getCompanyworkyear() > min && item.getCompanyworkyear() <= max)
.mapToDouble(SurnameParam::getCount).sum();
}
/**
* legendData
* @param nameSet
*/
private LinkedList<String> treeSetSplitExample(LinkedList<String> nameSet) {
int splitSize = nameSet.size() / 2;
LinkedList<String> legendDataFirst = nameSet.stream()
.collect(Collectors.partitioningBy(e -> nameSet.indexOf(e) < splitSize,
Collectors.toCollection(LinkedList::new)))
.get(false);
nameSet.removeAll(legendDataFirst);
return legendDataFirst;
}
/**
*
* @param input
* @return
*/
private String chineseSubstringExample(String input) {
String r = "7.*`~`8";
Pattern pattern1 = Pattern.compile(r);
Matcher matcher = pattern1.matcher(input);
while (matcher.find()) {
input = matcher.group(0);
}
// 使用正则表达式匹配中文
String pattern = "[\u4E00-\u9FA5\u8FBD-\u9FBB\uFA0E-\uFA29]+";
Pattern s = Pattern.compile(pattern);
Matcher m = s.matcher(input);
while (m.find()) {
input = m.group(0);
}
return input;
}
}

@ -1,94 +0,0 @@
package com.engine.matfron.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* @Author liang.cheng
* @Date 2023/9/27 4:44 PM
* @Description:
* @Version 1.0
*/
@Slf4j
public class CommonDateUtil {
public static final String DATE_FORMATTER_PATTERN = "yyyy-MM-dd";
/**
* YearMonthDate
* dayOfMonth13122928
* 使toDateEndOfMonth(YearMonth)
*
* @param yearMonth
* @param dayOfMonth
* @return
*/
public static Date toDate(YearMonth yearMonth, int dayOfMonth) {
Objects.requireNonNull(yearMonth, "yearMonth");
return localDateToDate(yearMonth.atDay(dayOfMonth));
}
/**
* YearMonthDate
*
* @param yearMonth
* @return
*/
public static Date toDateStartOfMonth(YearMonth yearMonth) {
return toDate(yearMonth, 1);
}
/**
* YearMonthDate
*
* @param yearMonth
* @return
*/
public static Date toDateEndOfMonth(YearMonth yearMonth) {
Objects.requireNonNull(yearMonth, "yearMonth");
return localDateToDate(yearMonth.atEndOfMonth());
}
public static Date localDateToDate(LocalDate localDate) {
if (null == localDate) {
return null;
}
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
return Date.from(zonedDateTime.toInstant());
}
public static String getFormatYear(Date localDate) {
if (localDate == null) {
return StringUtils.EMPTY;
}
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMATTER_PATTERN);
return simpleDateFormat.format(localDate);
} catch (Exception e) {
log.warn("格式化年份错误", e);
return StringUtils.EMPTY;
}
}
public static List<YearMonth> getYearMonths(LocalDate date) {
List<YearMonth> yearMonths = new ArrayList<>();
for (int month = 1; month <= 12; month++) {
LocalDate firstDayOfMonth = date.withMonth(month);
yearMonths.add(YearMonth.from(firstDayOfMonth));
}
return yearMonths;
}
}

@ -1,34 +0,0 @@
package com.engine.matfron.util;
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
/**
* @Author liang.cheng
* @Date 2023/9/27 4:52 PM
* @Description: TODO
* @Version 1.0
*/
public class CommonUtils {
public static LocalDate parseLocalDate(String dateString) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return LocalDate.parse(dateString, formatter);
}
public static int calculateAge(LocalDate birthday) {
LocalDate currentDate = LocalDate.now();
return Period.between(birthday, currentDate).getYears();
}
public static int roundUpToNearestTen(int num) {
return (num + 9) / 10 * 10;
}
public static int roundedMax(int ceil,int copies){
return ceil * copies;
}
}

@ -1,130 +0,0 @@
package com.engine.matfron.web;
import com.engine.common.util.ServiceUtil;
import com.engine.matfron.entity.OptionVO;
import com.engine.matfron.entity.PortalTopVO;
import com.engine.matfron.service.StatisticsPortalService;
import com.engine.matfron.service.impl.StatisticsPortalServiceImpl;
import com.engine.matfron.util.ResponseResult;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.LinkedList;
import java.util.Map;
/**
* @Author liang.cheng
* @Date 2023/9/26 5:51 PM
* @Description:
* @Version 1.0
*/
public class StatisticsPortalAction {
private StatisticsPortalService getCommonDutyService(User user) {
return ServiceUtil.getService(StatisticsPortalServiceImpl.class,user);
}
@GET
@Path("/statistics/top")
@Produces(MediaType.APPLICATION_JSON)
public String getPortalTop(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, LinkedList<PortalTopVO>>(user).run(getCommonDutyService(user) :: getPortalTop);
}
@GET
@Path("/statistics/department")
@Produces(MediaType.APPLICATION_JSON)
public String getPortalDepartment(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getPortalDepartment);
}
@GET
@Path("/statistics/subcompany")
@Produces(MediaType.APPLICATION_JSON)
public String getPortalSubCompany(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getPortalSubCompany);
}
@GET
@Path("/statistics/homePlace")
@Produces(MediaType.APPLICATION_JSON)
public String getHomePlace(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getHomePlace);
}
@GET
@Path("/statistics/ethnic")
@Produces(MediaType.APPLICATION_JSON)
public String getPortalEthnic(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getPortalEthnic);
}
@GET
@Path("/statistics/educational")
@Produces(MediaType.APPLICATION_JSON)
public String getEducational(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getEducational);
}
@GET
@Path("/statistics/surname")
@Produces(MediaType.APPLICATION_JSON)
public String getSurname(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getSurname);
}
@GET
@Path("/statistics/ageAndSex")
@Produces(MediaType.APPLICATION_JSON)
public String getAgeAndSex(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getAgeAndSex);
}
@GET
@Path("/statistics/jobType")
@Produces(MediaType.APPLICATION_JSON)
public String getJobType(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getJobType);
}
@GET
@Path("/statistics/leaveMonth")
@Produces(MediaType.APPLICATION_JSON)
public String getLeaveMonth(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("departmentIds") String departmentIds) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, Map<String,Object>>(user).run(getCommonDutyService(user) :: getLeaveMonth,departmentIds);
}
@GET
@Path("/statistics/leaveYear")
@Produces(MediaType.APPLICATION_JSON)
public String getLeaveYear(@Context HttpServletRequest request, @Context HttpServletResponse response,@QueryParam("departmentIds") String departmentIds) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, Map<String,Object>>(user).run(getCommonDutyService(user) :: getLeaveYear,departmentIds);
}
}

@ -0,0 +1,26 @@
package com.engine.sship.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author liang.cheng
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ChartChildrensVO {
private Integer id;
private Integer pid;
private String label;
private List<ChartChildrensVO> childrens;
}

@ -1,24 +1,24 @@
package com.engine.matfron.entity; package com.engine.sship.entity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** import java.util.List;
* @Author liang.cheng
* @Date 2023/10/10 1:41 PM
* @Description: TODO
* @Version 1.0
*/
@Data @Data
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class BrowserParam { public class TreeDataVO {
private Integer id; private Integer id;
private String name; private String label;
private List<ChartChildrensVO> childrens;
} }

@ -1,4 +1,4 @@
package com.engine.matfron.exception; package com.engine.sship.exception;
/** /**
* @Author weaver_cl * @Author weaver_cl

@ -0,0 +1,20 @@
package com.engine.sship.service;
import com.engine.sship.entity.ChartChildrensVO;
/**
* @author apple
*/
public interface OrgChartService {
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/1/3 10:07 AM
* @param: []
* @return: com.engine.sship.entity.ChartChildrensVO
*/
ChartChildrensVO selectResourceChart();
}

@ -0,0 +1,21 @@
package com.engine.sship.service.impl;
import com.engine.core.impl.Service;
import com.engine.sship.entity.ChartChildrensVO;
import com.engine.sship.service.OrgChartService;
/**
* @Author liang.cheng
* @Date 2023/9/26 5:52 PM
* @Description:
* @Version 1.0
*/
public class OrgChartServiceImpl extends Service implements OrgChartService {
@Override
public ChartChildrensVO selectResourceChart() {
return null;
}
}

@ -1,6 +1,6 @@
package com.engine.matfron.util; package com.engine.sship.util;
import com.engine.matfron.exception.CustomizeRunTimeException; import com.engine.sship.exception.CustomizeRunTimeException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;

@ -1,4 +1,4 @@
package com.engine.matfron.util; package com.engine.sship.util;
/** /**
* @Author weaver_cl * @Author weaver_cl

@ -1,11 +1,11 @@
package com.engine.matfron.util; package com.engine.sship.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.core.exception.ECException; import com.engine.core.exception.ECException;
import com.engine.matfron.exception.CustomizeRunTimeException; import com.engine.sship.exception.CustomizeRunTimeException;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

@ -0,0 +1,43 @@
package com.engine.sship.web;
import com.engine.common.util.ServiceUtil;
import com.engine.sship.entity.ChartChildrensVO;
import com.engine.sship.service.OrgChartService;
import com.engine.sship.service.impl.OrgChartServiceImpl;
import com.engine.sship.util.ResponseResult;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
/**
* @Author liang.cheng
* @Date 2023/9/26 5:51 PM
* @Description:
* @Version 1.0
*/
public class OrgChartController {
private OrgChartService getOrgChartService(User user) {
return ServiceUtil.getService(OrgChartServiceImpl.class,user);
}
@GET
@Path("/resource")
@Produces(MediaType.APPLICATION_JSON)
public String selectResourceChart(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, ChartChildrensVO>(user).run(getOrgChartService(user) :: selectResourceChart);
}
}

@ -1,14 +1,7 @@
package test; package test;
import com.engine.matfron.entity.SurnameParam;
import com.engine.matfron.util.CommonDateUtil;
import emo.doors.b;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* @Author weaver_cl * @Author weaver_cl
* @Description: * @Description:

Loading…
Cancel
Save