提交 a159cbe4 authored 作者: gongwenjie's avatar gongwenjie

合并分支 'gwj' 到 'master'

Gwj 查看合并请求 !80
流水线 #121 已取消 于阶段
package com.zjty.tynotes.attendance.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.zjty.tynotes.attendance.dao.AttendanceDepartmentDao;
import com.zjty.tynotes.attendance.entity.ApprovalInformation;
import com.zjty.tynotes.attendance.entity.exl.DepartmentExl;
import com.zjty.tynotes.attendance.entity.vo.request.AttenRequest;
import com.zjty.tynotes.attendance.service.AttendanceDetailsService;
import com.zjty.tynotes.misc.config.AutoDocument;
import com.zjty.tynotes.misc.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.springframework.http.ResponseEntity.ok;
/**
......@@ -35,18 +17,14 @@ import static org.springframework.http.ResponseEntity.ok;
* @create 2020/3/25 9:12
* @des 考勤信息统计
*/
@Api(tags = "考勤模块")
@Api(tags = "考勤模块", protocols = "http")
@RestController
@AutoDocument
@Slf4j
@RequestMapping("/attendance/info")
public class AttendanceController {
@Autowired
private AttendanceDetailsService attendanceDetailsService;
@Autowired
AttendanceDepartmentDao attendanceDepartmentDao;
@ApiOperation(value = "查询个人考勤信息", response = ApprovalInformation.class)
@PostMapping("/personnel")
public ResponseEntity personnel(@RequestBody AttenRequest request){
......@@ -59,28 +37,4 @@ public class AttendanceController {
return ok(attendanceDetailsService.findDepartment(request));
}
@PostMapping("/excel")
@ApiOperation(value = "导出元数据excel表格")
public void exportCurrentPage(HttpServletRequest request, HttpServletResponse response) {
log.info("元数据 正在执行单页excel导出任务...");
//把要导出的信息放在map里面
List<Map<String, Object>> excelList = new ArrayList<>();
//构建创建导出excel表格所需要的Workbook对象的map
// VoMetadataTableInfo voTableInfo= metaDataService.getVoTableInfo(dbName, name);
List<DepartmentExl> list=new ArrayList<>();
list.add(new DepartmentExl("占金明",22,22f,0f,0,0,0f,0f));
Map<String, Object> map = new HashMap<>(8);
map.put("subFpName", "3月");
map.put("title", new ExportParams("3月", "3月"));
map.put("entity", DepartmentExl.class);
map.put("data",list);
excelList.add(map);
Workbook workbook = ExcelExportUtil.exportExcel(excelList, ExcelType.HSSF);
ExcelUtil.downloadExcel(request, response, workbook, "3月");
}
}
package com.zjty.tynotes.attendance.controller;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiUserGetRequest;
import com.dingtalk.api.response.OapiDepartmentListResponse;
import com.dingtalk.api.response.OapiUserGetResponse;
import com.taobao.api.ApiException;
import com.zjty.tynotes.attendance.entity.CardResult;
import com.zjty.tynotes.attendance.task.CardTask;
import com.zjty.tynotes.attendance.task.MyInit;
import com.zjty.tynotes.misc.config.AutoDocument;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
* @Author gwj
* @create 2020/4/3 9:37
*/
@Api(tags = "考勤模块", protocols = "http")
@RestController
@RequestMapping("/ding/test")
@AutoDocument
public class DingTestController {
@Autowired
private MyInit myInit;
@Autowired
private CardTask cardTask;
@GetMapping("/token")
public Object token(){
List<String> responses = new ArrayList<>();
myInit.getToken();
myInit.getDepartmentList();
myInit.getUserList();
List<String> userIds = myInit.userIds;
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get");
OapiUserGetRequest request = new OapiUserGetRequest();
request.setHttpMethod("GET");
userIds.forEach(str->{
request.setUserid(str);
try {
OapiUserGetResponse response = client.execute(request, myInit.token);
responses.add(response.getName());
} catch (ApiException e) {
e.printStackTrace();
}
});
System.out.println(responses.size());
return responses;
}
@GetMapping("/card")
public Object card(){
List<CardResult> cardDetails = cardTask.getCardDetails();
return cardDetails;
}
}
......@@ -25,7 +25,7 @@ import static org.springframework.http.ResponseEntity.ok;
/**
* @author mcj
*/
@Api(tags = "钉钉", protocols = "http")
@Api(tags = "考勤模块", protocols = "http")
@RestController
@RequestMapping("/attendance/user")
@AutoDocument
......
......@@ -3,6 +3,7 @@ package com.zjty.tynotes.attendance.dao;
import com.zjty.tynotes.attendance.entity.ApprovalInformation;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.Date;
import java.util.List;
/**
......@@ -16,4 +17,10 @@ public interface ApprovalInformationDao extends MongoRepository<ApprovalInformat
List<ApprovalInformation> findAllByApprovalUserIdOneOrApprovalUserIdTwo(String userId);
List<ApprovalInformation> findAllByStatusIn(List<String> statusList);
ApprovalInformation findAllByUserIdAndLeaveStartTimeBeforeAndLeaveEndTimeAfterAndApprovalTypeIn(String userId, Date startTime,Date endTime,List<String> type);
ApprovalInformation findAllByUserIdAndLeaveStartTimeBeforeAndLeaveEndTimeBetweenAndApprovalTypeIn(String userId, Date startTime,Date startTime1,Date endTime,List<String> type);
ApprovalInformation findAllByUserIdAndLeaveStartTimeBetweenAndLeaveEndTimeAfterAndApprovalTypeIn(String userId, Date startTime,Date endTime,Date endTime1,List<String> type);
}
package com.zjty.tynotes.attendance.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -31,13 +32,16 @@ public class ApprovalInformation {
@ApiModelProperty(value = "提交审批用户id",example = "1")
private String userId;
@ApiModelProperty(value = "提交审批用户姓名",example = "1")
private String name;
@ApiModelProperty(value = "审核审批用户id",example = "1")
private String approvalUserIdOne;
@ApiModelProperty(value = "审核审批用户id",example = "1")
private String approvalUserIdTwo;
@ApiModelProperty(value = "审批类型,事假/调休/病假/加班/公出",example = "事假/调休/病假/加班/公出")
@ApiModelProperty(value = "审批类型,事假/调休/病假/加班/公出/出差",example = "事假/调休/病假/加班/公出/出差")
private String approvalType;
@ApiModelProperty(value = "审批状态,0代表待审批,1代表已通过,2代表已拒绝",example = "0/1/2")
......@@ -53,9 +57,11 @@ public class ApprovalInformation {
private String approvalLevel;
@ApiModelProperty(value = "请假开始时间",example = "2020-03-20 09:00:00")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date leaveStartTime;
@ApiModelProperty(value = "请假结束时间",example = "2020-03-21 09:00:00")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date leaveEndTime;
@ApiModelProperty(value = "一级审批是否通过",example = "0/1")
......
......@@ -14,7 +14,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "个人考勤信息", description = "个人考勤信息")
@ApiModel(value = "部门考勤信息", description = "部门考勤信息")
@Document(collection = "ding_attendepart")
public class AttendanceDepartment {
private String id;
......@@ -41,8 +41,11 @@ public class AttendanceDepartment {
private Integer earlyDay;
@ApiModelProperty(value = "出差天数",example = "1")
private Float OutWorkDay;
private Float outWorkDay;
@ApiModelProperty(value = "请假天数",example = "1")
private Float offFromWorkDay;
@ApiModelProperty(value = "加班时长",example = "1")
private Float overWorkHours;
}
......@@ -51,18 +51,39 @@ public class AttendanceDetails {
@ApiModelProperty(value = "是否旷工0为旷工/1为未旷工",example = "2")
Integer isAbsenteeismDay;
@ApiModelProperty(value = "旷工天数",example = "2")
Float absenteeismDay;
@ApiModelProperty(value = "是否加班0为加班/1为未加班",example = "10")
Integer isWorkOverHours;
@ApiModelProperty(value = "是否调休0为调休/1为未调休",example = "1")
Float isPaidLeaveDay;
@ApiModelProperty(value = "加班时长",example = "4")
Integer workOverHours;
// @ApiModelProperty(value = "是否调休0为调休/1为未调休",example = "1")
// Integer isPaidLeaveDay;
//
// @ApiModelProperty(value = "调休时长",example = "1")
// Float paidLeaveDay;
@ApiModelProperty(value = "是否请假0为请假/1为未请假",example = "1")
Integer isSickLeaveDay;
@ApiModelProperty(value = "请假时长",example = "1")
Float sickLeaveDay;
@ApiModelProperty(value = "是否公出",example = "1")
Integer isOutSideBusinessDay;
@ApiModelProperty(value = "公出天数",example = "1")
Float outSideBusinessDay;
@ApiModelProperty(value = "是否病假0为病假/1为未病假",example = "1")
Float isSickLeaveDay;
@ApiModelProperty(value = "出差",example = "1")
Integer isOutWorkDay;
@ApiModelProperty(value = "是否公出0为公出/1为未公出",example = "1")
Float isOutSideBusinessDay;
@ApiModelProperty(value = "出差时长",example = "1")
Float outWorkDay;
@ApiModelProperty(value = "时间",example = "2020-03-22")
@ApiModelProperty(value = "时间",example = "2020-03-22 09:00:00")
Date date;
}
......@@ -2,6 +2,7 @@ package com.zjty.tynotes.attendance.entity.vo;
import com.zjty.tynotes.attendance.entity.AttendanceDetails;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -12,11 +13,56 @@ import lombok.NoArgsConstructor;
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "返回前台的个人考勤统计信息", description = "返回前台的个人考勤统计信息")
public class UserAttenVo extends AttendanceDetails {
public class UserAttenVo {
@ApiModelProperty(value = "用户编号",example = "1")
private String userId;
@ApiModelProperty(value = "用户姓名",example = "1")
private String name;
@ApiModelProperty(value = "应出勤天数",example = "1")
private Integer attendanceDay;
@ApiModelProperty(value = "实际出勤天数",example = "1")
private Float realAttendanceDay;
@ApiModelProperty(value = "公出天数",example = "1")
private Float outSideBusinessDay;
@ApiModelProperty(value = "迟到天数",example = "1")
private Integer lateDay;
@ApiModelProperty(value = "早退天数",example = "1")
private Integer leaveEarlyDay;
@ApiModelProperty(value = "出差天数",example = "1")
private Float outWorkDay;
@ApiModelProperty(value = "请假天数",example = "1")
private Float sickLeaveDay;
@ApiModelProperty(value = "加班时长",example = "1")
private Integer overWorkHours;
@ApiModelProperty(value = "旷工天数",example = "1")
private Float absenteeismDay;
public UserAttenVo() {
this.attendanceDay = 0;
this.realAttendanceDay = 0f;
this.outSideBusinessDay = 0f;
this.lateDay = 0;
this.leaveEarlyDay = 0;
this.outWorkDay = 0f;
this.sickLeaveDay = 0f;
this.overWorkHours = 0;
this.absenteeismDay = 0f;
}
public void computerRealAttendanceDay(){
realAttendanceDay = attendanceDay - outSideBusinessDay - outWorkDay - sickLeaveDay - absenteeismDay;
}
}
......@@ -2,6 +2,9 @@ package com.zjty.tynotes.attendance.service;
import com.zjty.tynotes.attendance.entity.vo.UserAttenVo;
import com.zjty.tynotes.attendance.entity.vo.request.AttenRequest;
import com.zjty.tynotes.pas.entity.Department;
import java.util.List;
/**
* @Author gwj
......@@ -9,7 +12,24 @@ import com.zjty.tynotes.attendance.entity.vo.request.AttenRequest;
*/
public interface AttendanceDetailsService {
/**
* 查询个人考勤
* @param id
* @return
*/
UserAttenVo findPersonnel(AttenRequest id);
/**
* 查询部门考勤
* @param request
* @return
*/
Object findDepartment(AttenRequest request);
/**
* 查询可查看的部门列表
* @param id
* @return
*/
List<Department> findDepartmentList(String id);
}
......@@ -54,8 +54,7 @@ public class ApprovalInformationServiceImpl implements ApprovalInformationServic
if(approvalInformation.getApprovalType().equals("调休")){
String userId = approvalInformation.getUserId();
AttendanceDetails attendanceDetails = attendanceDetailsDao.findByUserId(userId);
UserOverWork userOverWork = userOverWorkDao.findByUserId(approvalInformation.getUserId());
UserOverWork userOverWork = userOverWorkDao.findByUserId(userId);
Long workOverHours = userOverWork.getOverWorkHour();
Date leaveEndTime = approvalInformation.getLeaveEndTime();
Date leaveStartTime = approvalInformation.getLeaveStartTime();
......@@ -82,7 +81,7 @@ public class ApprovalInformationServiceImpl implements ApprovalInformationServic
}
}
approvalInformation.setStatus("待审批");
approvalInformation.setStatus("0");
return approvalInformationDao.save(approvalInformation);
}
......@@ -105,6 +104,7 @@ public class ApprovalInformationServiceImpl implements ApprovalInformationServic
public ApprovalInformation auditApproval(String userId,String approvalStatus,ApprovalInformation approvalInformation) {
String departmentId = approvalInformation.getDepartmentId();
String departmentLevel = iUserService.getDepartmentLevel(departmentId);
System.out.println(departmentLevel);
if(("1").equals(departmentLevel)||("2").equals(departmentLevel)){
approvalInformation.setApprovalUserIdOne(userId);
if(approvalInformation.getApprovalStatus()!=null && approvalInformation.getApprovalStatus().equals("0")){
......
......@@ -5,15 +5,17 @@ import com.zjty.tynotes.attendance.entity.AttendanceDetails;
import com.zjty.tynotes.attendance.entity.vo.UserAttenVo;
import com.zjty.tynotes.attendance.entity.vo.request.AttenRequest;
import com.zjty.tynotes.attendance.service.AttendanceDetailsService;
import com.zjty.tynotes.pas.dao.*;
import com.zjty.tynotes.pas.entity.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.Array;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
* @Author gwj
......@@ -25,6 +27,20 @@ public class AttendanceDetailsServiceImpl implements AttendanceDetailsService {
@Autowired
private AttendanceDetailsDao attendanceDetailsDao;
@Autowired
private DayDao dayDao;
@Autowired
private PasUserDao pasUserDao;
@Autowired
private UserRoleDao userRoleDao;
@Autowired
private RoleDao roleDao;
@Autowired
private RoleAuthorityDao roleAuthorityDao;
@Autowired
private AuthorityDao authorityDao;
@Autowired
private DepartmentDao departmentDao;
@Override
public UserAttenVo findPersonnel(AttenRequest request) {
......@@ -33,72 +49,191 @@ public class AttendanceDetailsServiceImpl implements AttendanceDetailsService {
String searchType = request.getSearchType();
if(("0").equals(searchType)){
sdf = new SimpleDateFormat("yyyy-MM");
String format = sdf.format(request.getDate());
Calendar calendar = Calendar.getInstance();
String date = request.getDate();
try {
Date parse = sdf.parse(format);
AttendanceDetails attendanceDetails = attendanceDetailsDao.findByUserIdAndDate(request.getId(), parse);
userAttenVo = (UserAttenVo) attendanceDetails;
userAttenVo.setName("");
Date parse = sdf.parse(date);
calendar.setTime(parse);
calendar.set(Calendar.DAY_OF_MONTH,1);
Date startTime = calendar.getTime();
calendar.add(Calendar.MONTH,1);
calendar.set(Calendar.DAY_OF_MONTH,0);
Date endTime = calendar.getTime();
List<Day> days = dayDao.findAllByStatusAndDateBetween("0", startTime, endTime);
List<AttendanceDetails> attendanceDetailsList = attendanceDetailsDao.findAllByUserIdAndDateBetween(request.getId(), startTime, endTime);
userAttenVo = new UserAttenVo();
userAttenVo.setUserId(request.getId());
Optional<User> optional = pasUserDao.findById(request.getId());
if(optional.isPresent()){
User user = optional.get();
userAttenVo.setName(user.getUsername());
}
if(attendanceDetailsList!=null){
if(days!=null){
userAttenVo.setAttendanceDay(days.size());
}
for (AttendanceDetails attendanceDetails : attendanceDetailsList) {
if(attendanceDetails.getOutSideBusinessDay()!=null){
userAttenVo.setOutSideBusinessDay(attendanceDetails.getOutSideBusinessDay()+userAttenVo.getOutSideBusinessDay());
}
if(attendanceDetails.getOutWorkDay()!=null){
userAttenVo.setOutWorkDay(userAttenVo.getOutWorkDay()+attendanceDetails.getOutWorkDay());
}
if(attendanceDetails.getSickLeaveDay()!=null){
userAttenVo.setSickLeaveDay(userAttenVo.getSickLeaveDay()+attendanceDetails.getSickLeaveDay());
}
if(("0").equals(attendanceDetails.getIsLateDay())){
userAttenVo.setLateDay(userAttenVo.getLateDay()+1);
}
if("0".equals(attendanceDetails.getIsLeaveEarlyDay())){
userAttenVo.setLeaveEarlyDay(userAttenVo.getLeaveEarlyDay()+1);
}
if(attendanceDetails.getWorkOverHours()!=null){
userAttenVo.setOverWorkHours(userAttenVo.getOverWorkHours()+attendanceDetails.getWorkOverHours());
}
if(attendanceDetails.getAbsenteeismDay()!=null){
userAttenVo.setAbsenteeismDay(attendanceDetails.getAbsenteeismDay()+userAttenVo.getAbsenteeismDay());
}
}
userAttenVo.computerRealAttendanceDay();
}
return userAttenVo;
} catch (ParseException e) {
e.printStackTrace();
logger.error("时间转换格式错误");
}
}else{
sdf = new SimpleDateFormat("yyyy");
String format = sdf.format(request.getDate());
Date endDate = null;
Calendar calendar = Calendar.getInstance();
String date = request.getDate();
try {
Date startDate = sdf.parse(format + "-01");
endDate = sdf.parse(format + "-12");
List<AttendanceDetails> attendanceDetails = attendanceDetailsDao.findAllByUserIdAndDateBetween(request.getId(), startDate, endDate);
Date parse = sdf.parse(date);
calendar.setTime(parse);
calendar.set(Calendar.DAY_OF_YEAR,1);
Date startTime = calendar.getTime();
calendar.add(Calendar.YEAR,1);
calendar.set(Calendar.DAY_OF_YEAR,0);
Date endTime = calendar.getTime();
List<Day> days = dayDao.findAllByStatusAndDateBetween("0", startTime, endTime);
List<AttendanceDetails> attendanceDetailsList = attendanceDetailsDao.findAllByUserIdAndDateBetween(request.getId(), startTime, endTime);
userAttenVo = new UserAttenVo();
userAttenVo.setUserId(request.getId());
int averageWorkHours = 0;
int attendanceDay = 0;
int realAttendanceDay = 0;
int lateDay = 0;
int leaveEarlyDay = 0;
int lessCard = 0;
int absenteeismDay = 0;
int workOverHours = 0;
float paidLeaveDay = 0;
float sickLeaveDay = 0;
float outSideBusinessDay = 0;
for (AttendanceDetails attendanceDetails1 : attendanceDetails) {
// averageWorkHours += attendanceDetails1.getAverageWorkHours();
// attendanceDay += attendanceDetails1.getAttendanceDay();
// realAttendanceDay += attendanceDetails1.getRealAttendanceDay();
// lateDay += attendanceDetails1.getLateDay();
// leaveEarlyDay += attendanceDetails1.getLeaveEarlyDay();
// lessCard += attendanceDetails1.getLessCard();
// absenteeismDay += attendanceDetails1.getAbsenteeismDay();
// workOverHours += attendanceDetails1.getWorkOverHours();
// paidLeaveDay += attendanceDetails1.getPaidLeaveDay();
// sickLeaveDay += attendanceDetails1.getSickLeaveDay();
// outSideBusinessDay += attendanceDetails1.getOutSideBusinessDay();
}
// userAttenVo.setAverageWorkHours(averageWorkHours);
// userAttenVo.setAttendanceDay(attendanceDay);
// userAttenVo.setRealAttendanceDay(realAttendanceDay);
// userAttenVo.setLateDay(lateDay);
// userAttenVo.setLeaveEarlyDay(leaveEarlyDay);
// userAttenVo.setLessCard(lessCard);
// userAttenVo.setAbsenteeismDay(absenteeismDay);
// userAttenVo.setWorkOverHours(workOverHours);
// userAttenVo.setPaidLeaveDay(paidLeaveDay);
// userAttenVo.setSickLeaveDay(sickLeaveDay);
// userAttenVo.setOutSideBusinessDay(outSideBusinessDay);
userAttenVo.setName("");
Optional<User> optional = pasUserDao.findById(request.getId());
if(optional.isPresent()){
User user = optional.get();
userAttenVo.setName(user.getUsername());
}
if(attendanceDetailsList!=null){
if(days!=null){
userAttenVo.setAttendanceDay(days.size());
}
for (AttendanceDetails attendanceDetails : attendanceDetailsList) {
if(attendanceDetails.getOutSideBusinessDay()!=null){
userAttenVo.setOutSideBusinessDay(attendanceDetails.getOutSideBusinessDay()+userAttenVo.getOutSideBusinessDay());
}
if(attendanceDetails.getOutWorkDay()!=null){
userAttenVo.setOutWorkDay(userAttenVo.getOutWorkDay()+attendanceDetails.getOutWorkDay());
}
if(attendanceDetails.getSickLeaveDay()!=null){
userAttenVo.setSickLeaveDay(userAttenVo.getSickLeaveDay()+attendanceDetails.getSickLeaveDay());
}
if(("0").equals(attendanceDetails.getIsLateDay())){
userAttenVo.setLateDay(userAttenVo.getLateDay()+1);
}
if("0".equals(attendanceDetails.getIsLeaveEarlyDay())){
userAttenVo.setLeaveEarlyDay(userAttenVo.getLeaveEarlyDay()+1);
}
if(attendanceDetails.getWorkOverHours()!=null){
userAttenVo.setOverWorkHours(userAttenVo.getOverWorkHours()+attendanceDetails.getWorkOverHours());
}
if(attendanceDetails.getAbsenteeismDay()!=null){
userAttenVo.setAbsenteeismDay(attendanceDetails.getAbsenteeismDay()+userAttenVo.getAbsenteeismDay());
}
}
userAttenVo.computerRealAttendanceDay();
}
return userAttenVo;
} catch (ParseException e) {
e.printStackTrace();
logger.error("时间转换格式错误");
}
}
return userAttenVo;
}
@Override
public List<UserAttenVo> findDepartment(AttenRequest request) {
List<UserAttenVo> userAttenVos = new ArrayList<>();
String id = request.getId();//部门id
List<User> users = pasUserDao.findAll();
List<User> userList = new ArrayList<>();
if(users!=null){
users.forEach(user -> {
List<String> departmentIds = user.getDepartmentIds();
if(departmentIds!=null){
departmentIds.contains(id);
userList.add(user);
}
});
}
return null;
List<AttenRequest> attenRequests = new ArrayList<>();
userList.forEach(user -> {
attenRequests.add(new AttenRequest(user.getId(),request.getDate(),request.getSearchType()));
});
if(attenRequests!=null){
attenRequests.forEach(attenRequest1->{
UserAttenVo userAttenVo = findPersonnel(attenRequest1);
userAttenVos.add(userAttenVo);
});
}
return userAttenVos;
}
/**
* 查询可查看的部门列表
* @param id
* @return
*/
@Override
public Object findDepartment(AttenRequest request) {
return null;
public List<Department> findDepartmentList(String id) {
List<UserRole> userRoles = userRoleDao.findAllByUserId(id);
List<String> roleIds = new ArrayList<>();
List<String> departmentIds = new ArrayList<>();
for (UserRole userRole : userRoles) {
roleIds.add(userRole.getRoleId());
}
List<Role> roles = roleDao.findAllByIdIn(roleIds);
for (Role role : roles) {
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleId(role.getId());
List<String> authorityIds = new ArrayList<>();
for (RoleAuthority roleAuthority : roleAuthorities) {
authorityIds.add(roleAuthority.getAuthorityId());
}
Authority authority = authorityDao.findByIdInAndName(authorityIds, "部门考勤");
if(authority!=null){
String departmentId = role.getDepartmentId();
departmentIds.add(departmentId);
}
}
List<Department> departmentList = departmentDao.findAllByIdIn(departmentIds);
getDepartments(departmentList);
// getDepartments(departmentIdList,departmentIds);
// List<Department> departments = departmentDao.findAllByIdIn(departmentIdList);
return departmentList;
}
/**
* 递归获得部门树
* @param departments
*/
public void getDepartments(List<Department> departments) {
for (Department department : departments) {
List<Department> departmentList = departmentDao.findAllByParentId(department.getId());
getDepartments(departmentList);
department.setDepartments(departmentList);
}
}
}
......@@ -5,14 +5,19 @@ import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiAttendanceListRequest;
import com.dingtalk.api.response.OapiAttendanceListResponse;
import com.taobao.api.ApiException;
import com.zjty.tynotes.attendance.dao.ApprovalInformationDao;
import com.zjty.tynotes.attendance.dao.AttendanceDetailsDao;
import com.zjty.tynotes.attendance.dao.CardResultDao;
import com.zjty.tynotes.attendance.dao.DingUserDao;
import com.zjty.tynotes.attendance.entity.ApprovalInformation;
import com.zjty.tynotes.attendance.entity.AttendanceDetails;
import com.zjty.tynotes.attendance.entity.CardResult;
import com.zjty.tynotes.attendance.entity.DingUser;
import com.zjty.tynotes.attendance.service.ApprovalInformationService;
import com.zjty.tynotes.pas.dao.ConfigDao;
import com.zjty.tynotes.pas.dao.DayDao;
import com.zjty.tynotes.pas.dao.PasUserDao;
import com.zjty.tynotes.pas.entity.Config;
import com.zjty.tynotes.pas.entity.Day;
import com.zjty.tynotes.pas.entity.User;
import org.slf4j.Logger;
......@@ -22,6 +27,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.validation.constraints.NotEmpty;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -47,11 +54,17 @@ public class CardTask {
private DayDao dayDao;
@Autowired
private PasUserDao pasUserDao;
@Autowired
private ApprovalInformationDao approvalInformationDao;
@Autowired
private ConfigDao configDao;
@Autowired
private AttendanceDetailsDao attendanceDetailsDao;
/**
* 定时任务,定时获取打卡信息.计算前天的个人考勤信息情况
*/
@Scheduled(cron = "0 59 23 * * ? ")
// @Scheduled(cron = "0 59 23 * * ? ")
public List<CardResult> getCardDetails(){
List<User> users = pasUserDao.findAll();
List<User> userList = new ArrayList<>();
......@@ -65,14 +78,25 @@ public class CardTask {
List<CardResult> cardResults = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE,-1);
// LocalDateTime.now().minusDays(1).atOffset(ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00"));
Date time = calendar.getTime();
String startTime = sdf.format(time);
String endTime = sdf.format(new Date());
String endTime = sdf3.format(time);
// String time1 = null;
// String time2 = null;
// try {
// long l1 = sdf2.parse(startTime).getTime() - 8*60*60*1000;
// time1 = sdf2.format(new Date(l1));
// long l2 = sdf2.parse(endTime).getTime() - 8*60*60*1000;
// time2 = sdf2.format(new Date(l2));
// } catch (ParseException e) {
// e.printStackTrace();
// }
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/attendance/list");
OapiAttendanceListRequest request = new OapiAttendanceListRequest();
......@@ -83,6 +107,7 @@ public class CardTask {
dingUserIds.add(dingUser.getDingUserId());
});
}
request.setWorkDateFrom(startTime);
request.setWorkDateTo(endTime);
......@@ -113,12 +138,62 @@ public class CardTask {
return null;
}
private void computerPersonAttenDanceDay(String startTime, String endTime, List<User> userList, List<CardResult> cardResults1) {
/**
* 计算个人每天的考勤情况
* @param startTime
* @param endTime
* @param userList
* @param cardResults1
*/
private void computerPersonAttenDanceDay(String startTime
, String endTime, List<User> userList, List<CardResult> cardResults1) {
List<AttendanceDetails> attendanceDetailsList = new ArrayList<>();
Config config = configDao.findAll().get(0);
String workTime = config.getWorkTime();//上班时间
String afterWorkTime = config.getAfterWorkTime();//下班时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
workTime = "yyyy-MM-dd "+workTime;
afterWorkTime = "yyyy-MM-dd "+afterWorkTime;
SimpleDateFormat sdf1 = new SimpleDateFormat(workTime);
SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf2 = new SimpleDateFormat(afterWorkTime);
List<String> type1 = new ArrayList<>();
type1.add("公出");
List<String> type2 = new ArrayList<>();
type2.add("出差");
List<String> type3 = new ArrayList<>();
type3.add("事假");
type3.add("病假");
type3.add("调休");
if(userList!=null){
userList.forEach(user -> {
// List<String> checkType = new ArrayList<>();
AttendanceDetails attendanceDetails = new AttendanceDetails();
Date parse = null;
try {
parse = sdf.parse(startTime);
} catch (ParseException e) {
e.printStackTrace();
}
if(parse!=null){
attendanceDetails.setDate(parse);
}
try {
String format = sdf1.format(parse);
Date date = sdf4.parse(format);
String format1 = sdf2.format(parse);
Date date1 = sdf4.parse(format1);
ApprovalInformation approvalInformation = approvalInformationDao.findAllByUserIdAndLeaveStartTimeBeforeAndLeaveEndTimeAfterAndApprovalTypeIn(user.getId(), date, date1,type1);
compute(approvalInformation,attendanceDetails,user.getId(),date,date1,type1);
ApprovalInformation approvalInformation1 = approvalInformationDao.findAllByUserIdAndLeaveStartTimeBeforeAndLeaveEndTimeAfterAndApprovalTypeIn(user.getId(), date, date1,type2);
compute(approvalInformation1,attendanceDetails,user.getId(),date,date1,type2);
ApprovalInformation approvalInformation2 = approvalInformationDao.findAllByUserIdAndLeaveStartTimeBeforeAndLeaveEndTimeAfterAndApprovalTypeIn(user.getId(), date, date1,type3);
compute(approvalInformation2,attendanceDetails,user.getId(),date,date1,type3);
attendanceDetails.setUserId(user.getId());
System.out.println(approvalInformation);
System.out.println(approvalInformation1);
System.out.println(approvalInformation2);
if(cardResults1!=null){
List<CardResult> cardResults = new ArrayList<>();
cardResults1.forEach(cardResult -> {
......@@ -132,16 +207,72 @@ public class CardTask {
// }
}
});
if(cardResults.size()>=2){
attendanceDetails.setLessCard(0);
}else if(cardResults.size()==1){
attendanceDetails.setLessCard(1);
if(approvalInformation == null && approvalInformation1==null&&approvalInformation2==null){
attendanceDetails.setIsAbsenteeismDay(0);
attendanceDetails.setAbsenteeismDay(0.5f);
}
}else{
attendanceDetails.setLessCard(2);
if(approvalInformation == null && approvalInformation1==null&&approvalInformation2==null){
attendanceDetails.setIsAbsenteeismDay(0);
attendanceDetails.setAbsenteeismDay(1f);
}
}
cardResults.forEach(cardResult -> {
String checkType = cardResult.getCheckType();
String timeResult = cardResult.getTimeResult();
if(("OnDuty").equals(checkType)){
// cardResult.get
if("Late".equals(timeResult)||"SeriousLate".equals(timeResult)){
attendanceDetails.setIsLateDay(0);
}
}else if("OffDuty".equals(checkType)){
if("Early".equals(timeResult)||"Absenteeism".equals(timeResult)){
attendanceDetails.setIsLeaveEarlyDay(0);
}
}
});
}
} catch (ParseException e) {
logger.error(e.getMessage());
}
// List<String> checkType = new ArrayList<>();
attendanceDetailsList.add(attendanceDetails);
});
attendanceDetailsDao.saveAll(attendanceDetailsList);
}
}
/**
* 计算当天公出,出差,请假时间
* @param approvalInformation
* @param attendanceDetails
* @param userId
* @param date1
* @param date2
* @param types
*/
private void compute(ApprovalInformation approvalInformation,AttendanceDetails attendanceDetails,String userId,Date date1,Date date2,List<String> types){
if(approvalInformation!=null){
attendanceDetails.setIsOutSideBusinessDay(0);
attendanceDetails.setOutSideBusinessDay(1f);
}else{
ApprovalInformation approvalInformation1 = approvalInformationDao.findAllByUserIdAndLeaveStartTimeBeforeAndLeaveEndTimeBetweenAndApprovalTypeIn(userId, date1, date1,date2,types);
ApprovalInformation approvalInformation2 = approvalInformationDao.findAllByUserIdAndLeaveStartTimeBetweenAndLeaveEndTimeAfterAndApprovalTypeIn(userId, date1, date2,date2,types);
if(approvalInformation1!=null){
attendanceDetails.setIsOutSideBusinessDay(0);
attendanceDetails.setOutSideBusinessDay(0.5f);
}
if(approvalInformation2!=null){
attendanceDetails.setIsOutSideBusinessDay(0);
if(attendanceDetails.getOutSideBusinessDay()!=null){
attendanceDetails.setOutSideBusinessDay(attendanceDetails.getOutSideBusinessDay()+0.5f);
}
}
}
}
......
......@@ -42,6 +42,10 @@ public class MyInit implements CommandLineRunner {
private String departmentMenberUrl;
@Value("${ding.userDetailsUrl}")
private String userDetailsUrl;
@Value("${ding.appKey}")
private String appKey;
@Value("${ding.appSecret}")
private String appSecret;
@Autowired
private PasUserDao pasUserDao;
......@@ -55,7 +59,7 @@ public class MyInit implements CommandLineRunner {
//从钉钉获取的所有人员的id
public List<String> userIds = new ArrayList<>();
//根据丁丁的人员名单与本地的人员名单作对比后需要绑定的人员
//根据钉钉的人员名单与本地的人员名单作对比后需要绑定的人员
public List<DingUser> dingUserList = new ArrayList<>();
@Override
......@@ -78,8 +82,8 @@ public class MyInit implements CommandLineRunner {
public void getToken(){
DefaultDingTalkClient client = new DefaultDingTalkClient(tokenUrl);
OapiGettokenRequest request = new OapiGettokenRequest();
request.setAppkey("dingpzurwgv19x9uzpgd");
request.setAppsecret("PgRC88Q8ML4S_tabbg5Oxne2fE43eemrHE4mFutcFcnPur4jbs3HshN-cpJAkF7-");
request.setAppkey(appKey);
request.setAppsecret(appSecret);
request.setHttpMethod("GET");
try {
OapiGettokenResponse response = client.execute(request);
......
......@@ -10,5 +10,5 @@ ding:
# 获取打卡结果地址
userCardUrl: https://oapi.dingtalk.com/attendance/list
# 钉钉的appkey
appKey: dingpzurwgv19x9uzpgd
appSecret: PgRC88Q8ML4S_tabbg5Oxne2fE43eemrHE4mFutcFcnPur4jbs3HshN-cpJAkF7-
appKey: dingfule26yutybtr2yg
appSecret: 2VpbeeoFMae3dn_eVK5KIBau4ZO0Mh_Z4B-1CwQo1Gs-vh-WtULjBQVqhX6CBF-a
......@@ -56,6 +56,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
httpSecurity
.cors().and()
.authorizeRequests()
.antMatchers("/ding/test/**").permitAll()
.antMatchers("/pas/user/judgeParent/**").permitAll()
.antMatchers("/pas/user/test").permitAll()
.antMatchers("/pas/user/addGuanLian").permitAll()
......
......@@ -9,12 +9,12 @@ import com.zjty.tynotes.pas.entity.Authority;
import com.zjty.tynotes.pas.entity.Day;
import com.zjty.tynotes.pas.entity.Role;
import com.zjty.tynotes.pas.entity.RoleAuthority;
import com.zjty.tynotes.pas.entity.vo.JobLeads;
import com.zjty.tynotes.pas.service.IUserService;
import com.zjty.tynotes.pas.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -36,6 +36,8 @@ public class TestController {
private RoleDao roleDao;
@Autowired
private RoleAuthorityDao roleAuthorityDao;
@Autowired
private UserServiceImpl userService;
// @GetMapping("/test")
// public void calculate() throws Exception{
......@@ -80,4 +82,11 @@ public class TestController {
}
}
@GetMapping("/test2/{id}")
public JobLeads addAuthority(@PathVariable String id) throws Exception{
JobLeads jobLeads = userService.findJobLeads(id);
return jobLeads;
}
}
......@@ -15,6 +15,8 @@ public interface RoleDao extends MongoRepository<Role, String> {
List<Role> findAllByDepartmentIdAndIsLeader(String departmentIds,String isLeader);
List<Role> findAllByDepartmentIdAndIsLeaderAndIsPlus(String departmentIds,String isLeader,String plus);
List<Role> findAllByDepartmentId(String departmentId);
Role findAllByName(String name);
......
......@@ -42,6 +42,9 @@ public class Role {
@ApiModelProperty(value = "是否领导",example = "1")
private String isLeader;//0代表是该部门领导,1代表为该部门普通员工
@ApiModelProperty(value = "正副经理0为正,1为副",example = "1")
private String isPlus;//0代表是总经理,1代表为该副经理
@Transient
@ApiModelProperty(value = "权限列表")
List<Authority> authorities;
......
package com.zjty.tynotes.pas.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
* @Author gwj
* @create 2020/4/7 10:25
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "领导", description = "返回给任务模块的总监、总经理,副总经理集合")
public class JobLeads {
@ApiModelProperty(value = "总监id集合",example = "[1,2,3]")
private List<String> majordomos;
@ApiModelProperty(value = "总经理id集合",example = "[1,2,3]")
private List<String> generalManagers;
@ApiModelProperty(value = "副经理id集合",example = "[1,2,3]")
private List<String> assistantManagers;
}
......@@ -2,6 +2,7 @@ package com.zjty.tynotes.pas.service;
import com.zjty.tynotes.pas.entity.Department;
import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.entity.vo.JobLeads;
import com.zjty.tynotes.pas.entity.vo.PageRequest;
import com.zjty.tynotes.pas.entity.vo.PageResponse;
import io.swagger.annotations.ApiModel;
......@@ -161,4 +162,12 @@ public interface IUserService {
* @return
*/
boolean judgeParent(String id, String userId);
/**
* 根据人员id返回总监,总经理、副经理id集合
* @param executorId
* @return
*/
JobLeads findJobLeads(String executorId);
}
......@@ -2,6 +2,7 @@ package com.zjty.tynotes.pas.service.impl;
import com.zjty.tynotes.pas.dao.*;
import com.zjty.tynotes.pas.entity.*;
import com.zjty.tynotes.pas.entity.vo.JobLeads;
import com.zjty.tynotes.pas.entity.vo.PageRequest;
import com.zjty.tynotes.pas.entity.vo.PageResponse;
import com.zjty.tynotes.pas.service.IDepartmentService;
......@@ -688,5 +689,86 @@ public class UserServiceImpl implements IUserService {
}
@Override
public JobLeads findJobLeads(String executorId){
JobLeads jobLeads = new JobLeads();
List<String> majordomos = new ArrayList<>();
List<String> generalManagers = new ArrayList<>();
List<String> assistantManagers = new ArrayList<>();
Optional<User> optional = pasUserDao.findById(executorId);
User user = null;
List<String> departs = new ArrayList<>();
if(optional.isPresent()){
user = optional.get();
List<String> departmentIds = user.getDepartmentIds();
List<String> deIds = new ArrayList<>();//自身或者上级部门
if(departmentIds!=null){
departmentIds.forEach(departmentId -> {
List<String> parentDepartIds = findParentDepartIds(departmentId, new ArrayList<>());
if(parentDepartIds!=null){
parentDepartIds.forEach(str->{
if(!deIds.contains(str)){
deIds.add(str);
}
});
}
});
List<Department> departments = departmentDao.findAllByIdIn(deIds);
if(departments!=null){
departments.forEach(department -> {
if(!department.getLevel().equals("1")&&!department.getLevel().equals("2")){
List<Role> roles = roleDao.findAllByDepartmentIdAndIsLeader(department.getId(), "0");
List<String> roleIds = new ArrayList<>();
if(roles!=null){
roles.forEach(role -> roleIds.add(role.getId()));
}
List<UserRole> userRoles = userRoleDao.findAllByRoleIdIn(roleIds);
if(userRoles!=null){
for (UserRole userRole : userRoles) {
if(!majordomos.contains(userRole.getUserId())){
majordomos.add(userRole.getUserId());
}
}
}
}else if(department.getLevel().equals("1")||department.getLevel().equals("2")){
List<Role> roles2 = roleDao.findAllByDepartmentIdAndIsLeaderAndIsPlus(department.getId(), "0","1");
List<Role> roles = roleDao.findAllByDepartmentIdAndIsLeaderAndIsPlus(department.getId(), "0","0");
List<String> roleIds = new ArrayList<>();
List<String> roleIds2 = new ArrayList<>();
if(roles!=null){
roles.forEach(role -> roleIds.add(role.getId()));
}
if(roles2!=null){
roles2.forEach(role -> roleIds2.add(role.getId()));
}
List<UserRole> userRoles = userRoleDao.findAllByRoleIdIn(roleIds);
List<UserRole> userRoles2 = userRoleDao.findAllByRoleIdIn(roleIds2);
if(userRoles!=null){
for (UserRole userRole : userRoles) {
if(!generalManagers.contains(userRole.getUserId())){
generalManagers.add(userRole.getUserId());
}
}
}
if(userRoles2!=null){
for (UserRole userRole : userRoles2) {
if(!assistantManagers.contains(userRole.getUserId())){
assistantManagers.add(userRole.getUserId());
}
}
}
}
});
}
}
}
jobLeads.setMajordomos(majordomos);
jobLeads.setAssistantManagers(assistantManagers);
jobLeads.setGeneralManagers(generalManagers);
return jobLeads;
}
}
......@@ -99,7 +99,7 @@ public class Init implements CommandLineRunner {
} else {
System.out.println("77777777777777777");
this.root = new User();
Role role = new Role(null, "管理员", "管理系统的人员", null, null, null);
Role role = new Role(null, "管理员", "管理系统的人员",null, null, null, null);
List<Authority> authorities = new ArrayList<>();
Authority authority2 = new Authority(null, "用户管理", "无");
Authority authority1 = new Authority(null, "权限管理", "无");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论