|
@@ -1,5 +1,6 @@
|
|
|
package com.jpsoft.smart.modules.business.controller;
|
|
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
import com.jpsoft.smart.config.OSSConfig;
|
|
|
import com.jpsoft.smart.modules.base.entity.AlarmConfig;
|
|
|
import com.jpsoft.smart.modules.base.entity.CompanyInfo;
|
|
@@ -66,195 +67,196 @@ public class WorkAttendanceController {
|
|
|
@Autowired
|
|
|
private ValueOperations<String, Object> valueOperations;
|
|
|
|
|
|
- @ApiOperation(value="考勤统计列表")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name="companyId",value = "单位编号",required = true,paramType = "form"),
|
|
|
- @ApiImplicitParam(name="name",value = "用户姓名",required = true,paramType = "form"),
|
|
|
- @ApiImplicitParam(name="jobNumber",value = "工号",required = true,paramType = "form"),
|
|
|
- @ApiImplicitParam(name = "startDate",value = "开始时间", required = true,paramType="form"),
|
|
|
- @ApiImplicitParam(name = "endDate",value = "截止时间", required = true,paramType="form"),
|
|
|
- @ApiImplicitParam(name = "subject",value = "subject", required = false,paramType="form")
|
|
|
- })
|
|
|
- @RequestMapping(value = "statList",method = RequestMethod.POST)
|
|
|
- public MessageResult<Map> statList(
|
|
|
- String companyId,String name,String jobNumber,
|
|
|
- @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
|
|
|
- @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
|
|
|
- @RequestAttribute String subject){
|
|
|
- MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
-
|
|
|
+ private Map<String,Object> pageSearch(String companyId,String name,String jobNumber,
|
|
|
+ Date startDate,
|
|
|
+ Date endDate,
|
|
|
+ int pageIndex,
|
|
|
+ int pageSize) throws Exception{
|
|
|
Map<String,Object> dataMap = new HashMap<>();
|
|
|
|
|
|
- try {
|
|
|
- if (startDate==null){
|
|
|
- startDate = DateTime.now().dayOfMonth().withMinimumValue().toDate();
|
|
|
- }
|
|
|
+ if (startDate==null){
|
|
|
+ startDate = DateTime.now().dayOfMonth().withMinimumValue().toDate();
|
|
|
+ }
|
|
|
|
|
|
- if (endDate==null){
|
|
|
- endDate = DateTime.now().plusMonths(1).dayOfMonth().withMinimumValue().toDate();
|
|
|
- }
|
|
|
+ if (endDate==null){
|
|
|
+ endDate = DateTime.now().plusMonths(1).dayOfMonth().withMinimumValue().toDate();
|
|
|
+ }
|
|
|
|
|
|
- //todo 起始时间与结束时间间隔最大1个月
|
|
|
- DateTime startTime = new DateTime(startDate);
|
|
|
- DateTime endTime = new DateTime(endDate);
|
|
|
+ //todo 起始时间与结束时间间隔最大1个月
|
|
|
+ DateTime startTime = new DateTime(startDate);
|
|
|
+ DateTime endTime = new DateTime(endDate);
|
|
|
|
|
|
- int months = Months.monthsBetween(startTime,endTime).getMonths();
|
|
|
+ int months = Months.monthsBetween(startTime,endTime).getMonths();
|
|
|
|
|
|
- if(months>1){
|
|
|
- throw new Exception("最多只能查询一个月内的考勤记录!");
|
|
|
- }
|
|
|
+ if(months>1){
|
|
|
+ throw new Exception("最多只能查询一个月内的考勤记录!");
|
|
|
+ }
|
|
|
|
|
|
- CompanyInfo companyInfo = companyInfoService.get(companyId);
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(companyId);
|
|
|
|
|
|
- //todo 查询考勤设置
|
|
|
- List<AlarmConfig> alarmConfigList = alarmConfigService.findByCompanyId(companyId);
|
|
|
+ //todo 查询考勤设置
|
|
|
+ List<AlarmConfig> alarmConfigList = alarmConfigService.findByCompanyId(companyId);
|
|
|
|
|
|
- int dayOfWorkAttendanceNum = alarmConfigList.size();
|
|
|
+ int dayOfWorkAttendanceNum = alarmConfigList.size();
|
|
|
|
|
|
- //todo 查询单位人员
|
|
|
- List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("position1_","asc"));
|
|
|
- sortList.add(new Sort("position2_","asc"));
|
|
|
- sortList.add(new Sort("position3_","asc"));
|
|
|
+ //todo 查询单位人员
|
|
|
|
|
|
- Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(name)) {
|
|
|
- String[] names = name.split(",");
|
|
|
- List nameList = new ArrayList();
|
|
|
- for (String n : names) {
|
|
|
- nameList.add("%"+ n +"%");
|
|
|
- }
|
|
|
- searchParams.put("nameList", nameList);
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(jobNumber)) {
|
|
|
- searchParams.put("jobNumber", "%" + jobNumber + "%");
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ String[] names = name.split(",");
|
|
|
+ List nameList = new ArrayList();
|
|
|
+ for (String n : names) {
|
|
|
+ nameList.add("%"+ n +"%");
|
|
|
}
|
|
|
+ searchParams.put("nameList", nameList);
|
|
|
+ }
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(jobNumber)) {
|
|
|
+ searchParams.put("position3", "%" + jobNumber + "%");
|
|
|
+ }
|
|
|
|
|
|
- searchParams.put("code",companyInfo.getCode() + "%");
|
|
|
+ searchParams.put("companyCode",companyInfo.getCode() + "%");
|
|
|
|
|
|
- List<PersonInfo> personInfoList = personInfoService.findByCompanyCode(searchParams,sortList);
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("position1_","asc"));
|
|
|
+ sortList.add(new Sort("position2_","asc"));
|
|
|
+ sortList.add(new Sort("position3_","asc"));
|
|
|
|
|
|
- int days = Days.daysBetween(startTime,endTime).getDays();
|
|
|
+ Page<PersonInfo> personInfoPage = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ int days = Days.daysBetween(startTime,endTime).getDays();
|
|
|
|
|
|
- List<Map> personMapList = new ArrayList<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
- for (PersonInfo personInfo : personInfoList) {
|
|
|
- //todo 每个人在指定时间段(出勤天数,休息天数,迟到次数,早退次数,上班缺卡次数,下班缺卡次数,旷工天数)
|
|
|
- int workDays=0,restDays=0,lateNum=0,leaveNum=0,missCardOnWorkCount=0,missCardOffWorkCount=0,missCardAllDayCount=0;
|
|
|
+ List<Map> personMapList = new ArrayList<>();
|
|
|
|
|
|
- Map<String,Object> personMap = new HashMap<>();
|
|
|
- Map<String,List> workAttendanceMap = new HashMap<>();
|
|
|
+ for (PersonInfo personInfo : personInfoPage) {
|
|
|
+ //todo 每个人在指定时间段(出勤天数,休息天数,迟到次数,早退次数,上班缺卡次数,下班缺卡次数,旷工天数)
|
|
|
+ int workDays=0,restDays=0,lateNum=0,leaveNum=0,missCardOnWorkCount=0,missCardOffWorkCount=0,missCardAllDayCount=0;
|
|
|
|
|
|
- for (int i=0;i<days;i++){
|
|
|
- List<WorkAttendance> list = new ArrayList<>();
|
|
|
- DateTime dt = startTime.plusDays(i);
|
|
|
- workAttendanceMap.put(dt.toString("yyyy-MM-dd"),list);
|
|
|
- }
|
|
|
+ Map<String,Object> personMap = new HashMap<>();
|
|
|
+ Map<String,List> workAttendanceMap = new HashMap<>();
|
|
|
|
|
|
- //todo 每个人在指定时间段内每天的考勤情况
|
|
|
- List<WorkAttendance> workAttendanceList = workAttendanceService.findByPersonIdAndDate(personInfo.getId(),startDate,endDate);
|
|
|
-
|
|
|
- Map<String,Boolean> configMap = new HashMap<>();
|
|
|
- for (WorkAttendance workAttendance : workAttendanceList) {
|
|
|
- if(workAttendance.getRecordTime()!=null) {
|
|
|
- String key = sdf.format(workAttendance.getRecordTime());
|
|
|
-// String key2 = key + "-" + workAttendance.getAlarmConfigId();
|
|
|
-//
|
|
|
-// if (workAttendance.getClassifier().equals(1)){
|
|
|
-// //上班考勤,本轮考勤已打卡则不再记录后续打卡(以免算迟到)
|
|
|
-// if(configMap.containsKey(key2) && configMap.get(key2)){
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-//
|
|
|
-// configMap.put(key2,workAttendance.getResult().equalsIgnoreCase(WorkAttendance.SUCCESS));
|
|
|
-// }
|
|
|
-
|
|
|
- workAttendanceMap.get(key).add(workAttendance);
|
|
|
- }
|
|
|
+ for (int i=0;i<days;i++){
|
|
|
+ List<WorkAttendance> list = new ArrayList<>();
|
|
|
+ DateTime dt = startTime.plusDays(i);
|
|
|
+ workAttendanceMap.put(dt.toString("yyyy-MM-dd"),list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //todo 每个人在指定时间段内每天的考勤情况
|
|
|
+ List<WorkAttendance> workAttendanceList = workAttendanceService.findByPersonIdAndDate(personInfo.getId(),startDate,endDate);
|
|
|
+
|
|
|
+ Map<String,Boolean> configMap = new HashMap<>();
|
|
|
+ for (WorkAttendance workAttendance : workAttendanceList) {
|
|
|
+ if(workAttendance.getRecordTime()!=null) {
|
|
|
+ String key = sdf.format(workAttendance.getRecordTime());
|
|
|
+
|
|
|
+ workAttendanceMap.get(key).add(workAttendance);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- for (int i=0;i<days;i++){
|
|
|
- DateTime dt = startTime.plusDays(i);
|
|
|
- String key = dt.toString("yyyy-MM-dd");
|
|
|
+ for (int i=0;i<days;i++){
|
|
|
+ DateTime dt = startTime.plusDays(i);
|
|
|
+ String key = dt.toString("yyyy-MM-dd");
|
|
|
|
|
|
- List<WorkAttendance> workAttendances = workAttendanceMap.get(key);
|
|
|
+ List<WorkAttendance> workAttendances = workAttendanceMap.get(key);
|
|
|
|
|
|
- if (workAttendances.size()==0){
|
|
|
- //单天不需要考勤则不会有记录
|
|
|
- restDays++;
|
|
|
- }
|
|
|
- else{
|
|
|
- workDays++;
|
|
|
+ if (workAttendances.size()==0){
|
|
|
+ //单天不需要考勤则不会有记录
|
|
|
+ restDays++;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ workDays++;
|
|
|
|
|
|
- for (WorkAttendance workAttendance : workAttendances) {
|
|
|
- String result = workAttendance.getResult();
|
|
|
+ for (WorkAttendance workAttendance : workAttendances) {
|
|
|
+ String result = workAttendance.getResult();
|
|
|
|
|
|
- if (result.equals(WorkAttendance.LATE)){
|
|
|
- lateNum++; //迟到
|
|
|
- }
|
|
|
- else if(result.equals(WorkAttendance.LEAVE_EARLY)){
|
|
|
- leaveNum++; //早退
|
|
|
+ if (result.equals(WorkAttendance.LATE)){
|
|
|
+ lateNum++; //迟到
|
|
|
+ }
|
|
|
+ else if(result.equals(WorkAttendance.LEAVE_EARLY)){
|
|
|
+ leaveNum++; //早退
|
|
|
+ }
|
|
|
+ else if(result.equals(WorkAttendance.MISSING)){
|
|
|
+ if (workAttendance.getClassifier().equals("1")){
|
|
|
+ //上班缺卡
|
|
|
+ missCardOnWorkCount++;
|
|
|
}
|
|
|
- else if(result.equals(WorkAttendance.MISSING)){
|
|
|
- if (workAttendance.getClassifier().equals("1")){
|
|
|
- //上班缺卡
|
|
|
- missCardOnWorkCount++;
|
|
|
- }
|
|
|
- else{
|
|
|
- //下班缺卡
|
|
|
- missCardOffWorkCount++;
|
|
|
- }
|
|
|
+ else{
|
|
|
+ //下班缺卡
|
|
|
+ missCardOffWorkCount++;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (dayOfWorkAttendanceNum == missCardOnWorkCount + missCardOffWorkCount){
|
|
|
- //当天的考勤总数=上下班缺卡之和
|
|
|
- missCardAllDayCount++;
|
|
|
- }
|
|
|
+ if (dayOfWorkAttendanceNum == missCardOnWorkCount + missCardOffWorkCount){
|
|
|
+ //当天的考勤总数=上下班缺卡之和
|
|
|
+ missCardAllDayCount++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- personMap.put("name",personInfo.getName());
|
|
|
- personMap.put("company",personInfo.getPosition1());
|
|
|
- personMap.put("department",personInfo.getPosition2());
|
|
|
- personMap.put("jobNumber",personInfo.getPosition3());
|
|
|
- personMap.put("workDays",workDays);
|
|
|
- personMap.put("restDays",restDays);
|
|
|
- personMap.put("lateNum",lateNum);
|
|
|
- personMap.put("leaveNum",leaveNum);
|
|
|
- personMap.put("missCardOnWorkCount",missCardOnWorkCount);
|
|
|
- personMap.put("missCardOffWorkCount",missCardOffWorkCount);
|
|
|
- personMap.put("missCardAllDayCount",missCardAllDayCount);
|
|
|
- personMap.put("workAttendanceMap",workAttendanceMap);
|
|
|
-
|
|
|
- personMapList.add(personMap);
|
|
|
}
|
|
|
|
|
|
- //todo 保存到redis
|
|
|
- String tmplKey = "workAttendance_" + DateTime.now().toString("yyMMddHHmmssSSS");
|
|
|
- valueOperations.set(tmplKey,personMapList,30, TimeUnit.MINUTES);
|
|
|
+ personMap.put("name",personInfo.getName());
|
|
|
+ personMap.put("company",personInfo.getPosition1());
|
|
|
+ personMap.put("department",personInfo.getPosition2());
|
|
|
+ personMap.put("jobNumber",personInfo.getPosition3());
|
|
|
+ personMap.put("workDays",workDays);
|
|
|
+ personMap.put("restDays",restDays);
|
|
|
+ personMap.put("lateNum",lateNum);
|
|
|
+ personMap.put("leaveNum",leaveNum);
|
|
|
+ personMap.put("missCardOnWorkCount",missCardOnWorkCount);
|
|
|
+ personMap.put("missCardOffWorkCount",missCardOffWorkCount);
|
|
|
+ personMap.put("missCardAllDayCount",missCardAllDayCount);
|
|
|
+ personMap.put("workAttendanceMap",workAttendanceMap);
|
|
|
+
|
|
|
+ personMapList.add(personMap);
|
|
|
+ }
|
|
|
|
|
|
- dataMap.put("list",personMapList);
|
|
|
-// dataMap.put("url",downloadUrl);
|
|
|
+ dataMap.put("totalElements",personInfoPage.getTotal());
|
|
|
+ dataMap.put("totalPage",personInfoPage.getPages());
|
|
|
+ dataMap.put("pageNumber",personInfoPage.getPageNum());
|
|
|
+ dataMap.put("pageSize",personInfoPage.getPageSize());
|
|
|
+ dataMap.put("data", personMapList);
|
|
|
|
|
|
- List<Map> dayColumns = new ArrayList<>();
|
|
|
+ List<Map> dayColumns = new ArrayList<>();
|
|
|
|
|
|
- for (int i=0;i<days;i++){
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- DateTime dt = startTime.plusDays(i);
|
|
|
+ for (int i=0;i<days;i++){
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ DateTime dt = startTime.plusDays(i);
|
|
|
|
|
|
- map.put("name",dt.toString("yyyy-MM-dd"));
|
|
|
- map.put("label",dt.toString("MM-dd") + " " + dt.dayOfWeek().getAsShortText(Locale.CHINA));
|
|
|
+ map.put("name",dt.toString("yyyy-MM-dd"));
|
|
|
+ map.put("label",dt.toString("MM-dd") + " " + dt.dayOfWeek().getAsShortText(Locale.CHINA));
|
|
|
|
|
|
- dayColumns.add(map);
|
|
|
- }
|
|
|
+ dayColumns.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ dataMap.put("dayColumns", dayColumns);
|
|
|
+
|
|
|
+ return dataMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="考勤统计列表")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="companyId",value = "单位编号",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="name",value = "用户姓名",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="jobNumber",value = "工号",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "startDate",value = "开始时间", required = true,paramType="form"),
|
|
|
+ @ApiImplicitParam(name = "endDate",value = "截止时间", required = true,paramType="form"),
|
|
|
+ @ApiImplicitParam(name = "subject",value = "subject", required = false,paramType="form")
|
|
|
+ })
|
|
|
+ @RequestMapping(value = "statList",method = RequestMethod.POST)
|
|
|
+ public MessageResult<Map> statList(
|
|
|
+ String companyId,String name,String jobNumber,
|
|
|
+ @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
|
|
|
+ @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
|
|
- dataMap.put("dayColumns", dayColumns);
|
|
|
- dataMap.put("tmplKey",tmplKey);
|
|
|
+ try {
|
|
|
+ Map<String,Object> dataMap = pageSearch(companyId,name,jobNumber,startDate,endDate,pageIndex,pageSize);
|
|
|
|
|
|
msgResult.setData(dataMap);
|
|
|
msgResult.setResult(true);
|
|
@@ -284,13 +286,15 @@ public class WorkAttendanceController {
|
|
|
@ApiOperation(value="导出考勤报表")
|
|
|
@RequestMapping(value = "exportXls",method = RequestMethod.POST)
|
|
|
@ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name="tmplKey",value = "模板数据key",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="companyId",value = "单位编号",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="name",value = "用户姓名",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="jobNumber",value = "工号",required = true,paramType = "form"),
|
|
|
@ApiImplicitParam(name = "startDate",value = "开始时间", required = true,paramType="form"),
|
|
|
@ApiImplicitParam(name = "endDate",value = "截止时间", required = true,paramType="form"),
|
|
|
@ApiImplicitParam(name = "subject",value = "subject", required = false,paramType="form")
|
|
|
})
|
|
|
public MessageResult<String> exportXls(
|
|
|
- String tmplKey,
|
|
|
+ String companyId,String name,String jobNumber,
|
|
|
@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
|
|
|
@DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
|
|
|
@RequestAttribute String subject) throws Exception {
|
|
@@ -300,7 +304,9 @@ public class WorkAttendanceController {
|
|
|
DateTime startTime = new DateTime(startDate);
|
|
|
DateTime endTime = new DateTime(endDate);
|
|
|
|
|
|
- List<Map> personMapList = (List<Map>) valueOperations.get(tmplKey);
|
|
|
+ Map<String,Object> dataMap = pageSearch(companyId,name,jobNumber,startDate,endDate,1,10000);
|
|
|
+
|
|
|
+ List<Map> personMapList = (List<Map>)dataMap.get("data");
|
|
|
|
|
|
int days = Days.daysBetween(startTime, endTime).getDays();
|
|
|
ClassPathResource resource = new ClassPathResource("static/workAttendanceReport.xls");
|
|
@@ -336,8 +342,8 @@ public class WorkAttendanceController {
|
|
|
Row row = sheet.createRow(startRowIndex + i);
|
|
|
Map personMap = personMapList.get(i);
|
|
|
|
|
|
- String name = (String) personMap.get("name");
|
|
|
- row.createCell(0).setCellValue(name);
|
|
|
+ String personName = (String) personMap.get("name");
|
|
|
+ row.createCell(0).setCellValue(personName);
|
|
|
|
|
|
String companyName = (String) personMap.get("company");
|
|
|
row.createCell(1).setCellValue(companyName);
|
|
@@ -345,8 +351,8 @@ public class WorkAttendanceController {
|
|
|
String department = (String) personMap.get("department");
|
|
|
row.createCell(2).setCellValue(department);
|
|
|
|
|
|
- String jobNumber = (String) personMap.get("jobNumber");
|
|
|
- row.createCell(3).setCellValue(jobNumber);
|
|
|
+ String personJobNumber = (String) personMap.get("jobNumber");
|
|
|
+ row.createCell(3).setCellValue(personJobNumber);
|
|
|
|
|
|
Integer workDays = Integer.valueOf(personMap.get("workDays").toString());
|
|
|
row.createCell(4).setCellValue(workDays);
|