Commit 7d2e1156 authored by 赵啸非's avatar 赵啸非

添加同步部门信息

parent 5fae4ad6
...@@ -43,25 +43,16 @@ public class SyncUserTaskImpl implements ITaskExcuteService { ...@@ -43,25 +43,16 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
private DeptService deptService; private DeptService deptService;
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private AttendanceStatService attendanceStatService;
@Autowired
private AttendanceVacationBalanceService balanceService;
@Autowired @Autowired
private IHikPersonService hikPersonService; private IHikPersonService hikPersonService;
@Autowired @Autowired
private StaffLeaveService staffLeaveService;
@Autowired
private IDingPersonService dingPersonService; private IDingPersonService dingPersonService;
@Override @Override
public void excuteTask(ITask task) throws AppException { public void excuteTask(ITask task) throws AppException {
try { try {
log.info("同步部门"); log.info("同步部门");
syncDepts(); deptService.syncDept(null);
log.info("同步用户"); log.info("同步用户");
staffService.syncPersons(null); staffService.syncPersons(null);
log.info("同步钉钉usreId"); log.info("同步钉钉usreId");
...@@ -73,11 +64,11 @@ public class SyncUserTaskImpl implements ITaskExcuteService { ...@@ -73,11 +64,11 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
UserEntity userEntity = new UserEntity(); UserEntity userEntity = new UserEntity();
userEntity.setId(item.getId()); userEntity.setId(item.getId());
String mobile=""; String mobile = "";
StaffEntity staffCache = staffService.getCache(item.getCustomerId().toString()); StaffEntity staffCache = staffService.getCache(item.getCustomerId().toString());
if (!ObjectUtils.isEmpty(staffCache) && !ObjectUtils.isEmpty(staffCache.getPhoneNumber())) { if (!ObjectUtils.isEmpty(staffCache) && !ObjectUtils.isEmpty(staffCache.getPhoneNumber())) {
mobile = staffCache.getPhoneNumber(); mobile = staffCache.getPhoneNumber();
if(ObjectUtils.isEmpty(item.getMobile())){ if (ObjectUtils.isEmpty(item.getMobile())) {
userEntity.setMobile(mobile); userEntity.setMobile(mobile);
} }
} }
...@@ -108,45 +99,6 @@ public class SyncUserTaskImpl implements ITaskExcuteService { ...@@ -108,45 +99,6 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
} }
} }
private void syncDepts() {
//部门同步
OrgListReq orgListReq = new OrgListReq();
orgListReq.setPageNo(1);
orgListReq.setPageSize(1000);
Rest<OrgDataInfo> orgRest = hikPersonService.getOrgList(orgListReq);
if (orgRest.getCode() == YesNoEnum.YES.getValue()) {
List<OrgInfo> orgInfoList = orgRest.getData().getList();
for (OrgInfo orgInfo : orgInfoList) {
//查询数据库信息
DeptEntity deptEntity = deptService.selectOne(new DeptQuery().deptCode(orgInfo.getOrgIndexCode()));
DeptEntity deptEntityParent = deptService.selectOne(new DeptQuery().deptCode(orgInfo.getParentOrgIndexCode()));
//新增
if (ObjectUtils.isEmpty(deptEntity)) {
deptEntity = new DeptEntity();
deptEntity.initAttrValue();
if (!ObjectUtils.isEmpty(deptEntityParent)) {
deptEntity.setParentId(deptEntityParent.getId());
}
deptEntity.setDeptName(orgInfo.getOrgName());
deptEntity.setDeptCode(orgInfo.getOrgIndexCode());
deptEntity.setAncestors(orgInfo.getOrgPath());
deptEntity.setRemark(orgInfo.getParentOrgIndexCode());
deptEntity.setCreateTime(new Date());
deptEntity.setCreateUserId(1L);
deptService.save(deptEntity);
} else {
//更新
deptEntity.setDeptName(orgInfo.getOrgName());
deptEntity.setDeptCode(orgInfo.getOrgIndexCode());
deptEntity.setAncestors(orgInfo.getOrgPath());
deptEntity.setUpdateTime(new Date());
deptEntity.setUpdateUserId(1L);
deptService.update(deptEntity);
}
}
}
}
@Override @Override
public void stopTask(ITask task) throws AppException { public void stopTask(ITask task) throws AppException {
......
...@@ -123,14 +123,14 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle ...@@ -123,14 +123,14 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
query.setAttendanceDateEnd(DateUtil.today()); query.setAttendanceDateEnd(DateUtil.today());
} }
try { try {
if (DateUtils.getBetween(query.getAttendanceDateStart(), query.getAttendanceDateEnd(), DateUtils.P_yyyy_MM_dd, 2) != 0) { if (DateUtils.getBetween(query.getAttendanceDateStart(), query.getAttendanceDateEnd(), DateUtils.P_yyyy_MM_dd, 2) > 10) {
throw new AppException("选择的日期跨度不能超过一天"); throw new AppException("选择的日期跨度不能超过十天!");
} }
}catch (Exception e){ } catch (Exception e) {
throw new AppException(e.getMessage()); throw new AppException(e.getMessage());
} }
if (ObjectUtils.isEmpty(query.getOrderColList())) { if (ObjectUtils.isEmpty(query.getOrderColList())) {
query.setOrderColList(Arrays.asList(new OrderCol("salaId"),new OrderCol("attendanceDate", OrderCol.DESCENDING), new OrderCol("staffName", OrderCol.DESCENDING))); query.setOrderColList(Arrays.asList(new OrderCol("salaId"), new OrderCol("attendanceDate", OrderCol.DESCENDING), new OrderCol("staffName", OrderCol.DESCENDING)));
} else { } else {
query.getOrderColList().add(new OrderCol("salaId")); query.getOrderColList().add(new OrderCol("salaId"));
query.getOrderColList().add(new OrderCol("attendanceDate", OrderCol.DESCENDING)); query.getOrderColList().add(new OrderCol("attendanceDate", OrderCol.DESCENDING));
...@@ -216,31 +216,31 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle ...@@ -216,31 +216,31 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
AttendanceRecordDetailEntity detailEntity = attendanceRecordDetailList.get(i); AttendanceRecordDetailEntity detailEntity = attendanceRecordDetailList.get(i);
AttendanceClassDetailEntity cacheDetail = classDetailService.getCache(detailEntity.getShiftsId().toString()); AttendanceClassDetailEntity cacheDetail = classDetailService.getCache(detailEntity.getShiftsId().toString());
StringBuilder preStr=new StringBuilder(); StringBuilder preStr = new StringBuilder();
if(!ObjectUtils.isEmpty(cacheDetail)&&!ObjectUtils.isEmpty(cacheDetail.getRemark())){ if (!ObjectUtils.isEmpty(cacheDetail) && !ObjectUtils.isEmpty(cacheDetail.getRemark())) {
preStr.append(cacheDetail.getRemark()); preStr.append(cacheDetail.getRemark());
preStr.append("/"); preStr.append("/");
} }
//生成上班 结果 下班 结果 4个map //生成上班 结果 下班 结果 4个map
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("name", String.format( preStr+"上班打卡时间", i + 1)); map.put("name", String.format(preStr + "上班打卡时间", i + 1));
map.put("value", detailEntity.getGoWorkDate()==null?"--":preStr.toString()+DateUtil.formatDateTime(detailEntity.getGoWorkDate())); map.put("value", detailEntity.getGoWorkDate() == null ? "--" : preStr.toString() + DateUtil.formatDateTime(detailEntity.getGoWorkDate()));
mapList.add(map); mapList.add(map);
map = new HashMap<>(); map = new HashMap<>();
map.put("name", String.format( preStr+"上班打卡结果", i + 1)); map.put("name", String.format(preStr + "上班打卡结果", i + 1));
map.put("value", detailEntity.getGoWorkResult()==null?"--":preStr.toString()+GoWorkResultEnum.getByValue(detailEntity.getGoWorkResult()).getDesc()); map.put("value", detailEntity.getGoWorkResult() == null ? "--" : preStr.toString() + GoWorkResultEnum.getByValue(detailEntity.getGoWorkResult()).getDesc());
mapList.add(map); mapList.add(map);
map = new HashMap<>(); map = new HashMap<>();
map.put("name", String.format( preStr+"下班打卡时间", i + 1)); map.put("name", String.format(preStr + "下班打卡时间", i + 1));
map.put("value", detailEntity.getOffWorkDate()==null?"--":preStr.toString()+DateUtil.formatDateTime(detailEntity.getOffWorkDate())); map.put("value", detailEntity.getOffWorkDate() == null ? "--" : preStr.toString() + DateUtil.formatDateTime(detailEntity.getOffWorkDate()));
mapList.add(map); mapList.add(map);
map = new HashMap<>(); map = new HashMap<>();
map.put("name", String.format( preStr+"下班打卡结果", i + 1)); map.put("name", String.format(preStr + "下班打卡结果", i + 1));
map.put("value",detailEntity.getOffWorkResult()==null?"--":preStr.toString()+OffWorkResultEnum.getByValue(detailEntity.getOffWorkResult()).getDesc()); map.put("value", detailEntity.getOffWorkResult() == null ? "--" : preStr.toString() + OffWorkResultEnum.getByValue(detailEntity.getOffWorkResult()).getDesc());
mapList.add(map); mapList.add(map);
} else { } else {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
...@@ -280,7 +280,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle ...@@ -280,7 +280,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
ret.put("msg", e.getMessage()); ret.put("msg", e.getMessage());
try { try {
IOUtils.write(ret.toJSONString(), response.getOutputStream()); IOUtils.write(ret.toJSONString(), response.getOutputStream());
}catch (IOException e1){ } catch (IOException e1) {
} }
...@@ -355,7 +355,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle ...@@ -355,7 +355,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object,Boolean> seen = new ConcurrentHashMap<>(); Map<Object, Boolean> seen = new ConcurrentHashMap<>();
//putIfAbsent方法添加键值对,如果map集合中没有该key对应的值,则直接添加,并返回null,如果已经存在对应的值,则依旧为原来的值。 //putIfAbsent方法添加键值对,如果map集合中没有该key对应的值,则直接添加,并返回null,如果已经存在对应的值,则依旧为原来的值。
//如果返回null表示添加数据成功(不重复),不重复(null==null :TRUE) //如果返回null表示添加数据成功(不重复),不重复(null==null :TRUE)
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
...@@ -368,7 +368,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle ...@@ -368,7 +368,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
//求出列表中最多detail 的 添加动态列 //求出列表中最多detail 的 添加动态列
List<AttendanceRecordDetailEntity> collect = list.parallelStream() List<AttendanceRecordDetailEntity> collect = list.parallelStream()
.flatMap(item -> item.getAttendanceRecordDetailList().stream()) .flatMap(item -> item.getAttendanceRecordDetailList().stream())
.filter(distinctByKey(f->f.getOrderNum())) .filter(distinctByKey(f -> f.getOrderNum()))
.sorted(Comparator.comparingInt(AttendanceRecordDetailEntity::getOrderNum)) .sorted(Comparator.comparingInt(AttendanceRecordDetailEntity::getOrderNum))
.collect(Collectors.toList()); .collect(Collectors.toList());
...@@ -494,7 +494,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle ...@@ -494,7 +494,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
try { try {
HomeStatInfo homeStatInfo = cacheService.get(RedisKey.KEY_HOME_STAT_CACHE, HomeStatInfo.class); HomeStatInfo homeStatInfo = cacheService.get(RedisKey.KEY_HOME_STAT_CACHE, HomeStatInfo.class);
recordSysLog(request, busiDesc + " 【成功】"); recordSysLog(request, busiDesc + " 【成功】");
jsonObject.put(KEY_RESULT_DATA,homeStatInfo); jsonObject.put(KEY_RESULT_DATA, homeStatInfo);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
} catch (Exception e) { } catch (Exception e) {
log.error("申诉审核", e); log.error("申诉审核", e);
......
...@@ -83,4 +83,12 @@ public interface DeptService extends ICRUDService<DeptEntity, Long> { ...@@ -83,4 +83,12 @@ public interface DeptService extends ICRUDService<DeptEntity, Long> {
* @throws AppException * @throws AppException
*/ */
List<DeptEntity> getDeptBySalaId(Long salaId) throws AppException; List<DeptEntity> getDeptBySalaId(Long salaId) throws AppException;
/**
* 同步部门信息
* @param context
* @return
*/
Rest<String> syncDept(Context context);
} }
\ No newline at end of file
...@@ -4,6 +4,11 @@ import com.mortals.framework.common.Rest; ...@@ -4,6 +4,11 @@ import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.code.EnableEnum; import com.mortals.xhx.common.code.EnableEnum;
import com.mortals.xhx.common.code.EnabledEnum; import com.mortals.xhx.common.code.EnabledEnum;
import com.mortals.xhx.common.code.StaffSatusEnum; import com.mortals.xhx.common.code.StaffSatusEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.hik.person.model.req.org.OrgListReq;
import com.mortals.xhx.module.hik.person.model.rsp.org.OrgDataInfo;
import com.mortals.xhx.module.hik.person.model.rsp.org.OrgInfo;
import com.mortals.xhx.module.hik.person.service.IHikPersonService;
import com.mortals.xhx.module.staff.model.StaffEntity; import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffQuery; import com.mortals.xhx.module.staff.model.StaffQuery;
import com.mortals.xhx.module.staff.service.StaffService; import com.mortals.xhx.module.staff.service.StaffService;
...@@ -38,6 +43,9 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity ...@@ -38,6 +43,9 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
@Autowired @Autowired
private StaffService staffService; private StaffService staffService;
@Autowired
private IHikPersonService hikPersonService;
@Override @Override
protected void saveBefore(DeptEntity entity, Context context) throws AppException { protected void saveBefore(DeptEntity entity, Context context) throws AppException {
if (ObjectUtils.isEmpty(entity.getParentId())) { if (ObjectUtils.isEmpty(entity.getParentId())) {
...@@ -291,4 +299,46 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity ...@@ -291,4 +299,46 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
return dao.getList(query); return dao.getList(query);
} }
@Override
public Rest<String> syncDept(Context context) {
//部门同步
OrgListReq orgListReq = new OrgListReq();
orgListReq.setPageNo(1);
orgListReq.setPageSize(1000);
Rest<OrgDataInfo> orgRest = hikPersonService.getOrgList(orgListReq);
if (orgRest.getCode() == YesNoEnum.YES.getValue()) {
List<OrgInfo> orgInfoList = orgRest.getData().getList();
for (OrgInfo orgInfo : orgInfoList) {
//查询数据库信息
DeptEntity deptEntity = this.selectOne(new DeptQuery().deptCode(orgInfo.getOrgIndexCode()));
DeptEntity deptEntityParent = this.selectOne(new DeptQuery().deptCode(orgInfo.getParentOrgIndexCode()));
//新增
if (ObjectUtils.isEmpty(deptEntity)) {
deptEntity = new DeptEntity();
deptEntity.initAttrValue();
if (!ObjectUtils.isEmpty(deptEntityParent)) {
deptEntity.setParentId(deptEntityParent.getId());
}
deptEntity.setDeptName(orgInfo.getOrgName());
deptEntity.setDeptCode(orgInfo.getOrgIndexCode());
deptEntity.setAncestors(orgInfo.getOrgPath());
deptEntity.setRemark(orgInfo.getParentOrgIndexCode());
deptEntity.setCreateTime(new Date());
deptEntity.setCreateUserId(1L);
this.save(deptEntity);
} else {
//更新
deptEntity.setDeptName(orgInfo.getOrgName());
deptEntity.setDeptCode(orgInfo.getOrgIndexCode());
deptEntity.setAncestors(orgInfo.getOrgPath());
deptEntity.setUpdateTime(new Date());
deptEntity.setUpdateUserId(1L);
this.update(deptEntity);
}
}
}
return Rest.ok();
}
} }
...@@ -129,7 +129,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ ...@@ -129,7 +129,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
AttendanceRecordQuery attendanceRecordQuery = new AttendanceRecordQuery(); AttendanceRecordQuery attendanceRecordQuery = new AttendanceRecordQuery();
attendanceRecordQuery.setAttendanceDateStart(DateUtil.beginOfMonth(new Date()).toDateStr()); attendanceRecordQuery.setAttendanceDateStart(DateUtil.beginOfMonth(new Date()).toDateStr());
attendanceRecordQuery.setAttendanceDateEnd(DateUtil.today()); attendanceRecordQuery.setAttendanceDateEnd(DateUtil.today());
attendanceRecordQuery.setWorkNum(entity.getWorkNum()); attendanceRecordQuery.setWorkNum(entity.getWorkNum());
List<AttendanceRecordEntity> attendanceRecordEntities = recordService.find(attendanceRecordQuery); List<AttendanceRecordEntity> attendanceRecordEntities = recordService.find(attendanceRecordQuery);
...@@ -178,7 +178,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ ...@@ -178,7 +178,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
vo.setWorkFormalDay(entity.getRegularDate()); vo.setWorkFormalDay(entity.getRegularDate());
vo.setAttendanceCount(attendDays); vo.setAttendanceCount(attendDays);
vo.setLeaveCount(levealPersonNum); vo.setLeaveCount(levealPersonNum);
vo.setLateCount(beLate+leaveEarly); vo.setLateCount(beLate + leaveEarly);
vo.setMinerCount(0L); vo.setMinerCount(0L);
vo.setLackCardCount(lackOfCards); vo.setLackCardCount(lackOfCards);
vo.setWorkOverDay(0L); vo.setWorkOverDay(0L);
...@@ -205,6 +205,8 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ ...@@ -205,6 +205,8 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
String busiDesc = this.getModuleDesc() + "同步"; String busiDesc = this.getModuleDesc() + "同步";
try { try {
//同步部门
deptService.syncDept(getContext());
Rest<Void> rest = this.service.syncPersons(getContext()); Rest<Void> rest = this.service.syncPersons(getContext());
if (rest.getCode() == YesNoEnum.NO.getValue()) { if (rest.getCode() == YesNoEnum.NO.getValue()) {
throw new AppException("同步异常!"); throw new AppException("同步异常!");
...@@ -236,7 +238,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ ...@@ -236,7 +238,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
Context context = this.getContext(); Context context = this.getContext();
try { try {
this.service.checkAuthorize(pdu,context); this.service.checkAuthorize(pdu, context);
if (!ObjectUtils.isEmpty(context) && !ObjectUtils.isEmpty(context.getUser())) { if (!ObjectUtils.isEmpty(context) && !ObjectUtils.isEmpty(context.getUser())) {
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment