Commit 04fd5f60 authored by 赵啸非's avatar 赵啸非

修改用户等

parent d682e5d7
......@@ -10,6 +10,8 @@ import com.mortals.framework.service.IUser;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.feign.user.IUserFeign;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
......@@ -19,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
......@@ -74,6 +77,8 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
@Autowired
private ICacheService cacheService;
@Autowired
private UserService userService;
/**
* 获取信息
......@@ -96,6 +101,14 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
cacheService.select(db);
if (StringUtils.isNotEmpty(userStr)) {
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
//与本地转换
UserQuery userQuery = new UserQuery();
userQuery.setLoginName(userEntity.getLoginName());
UserEntity localuserEntity = userService.selectOne(userQuery);
if(ObjectUtils.isEmpty(localuserEntity)){
localuserEntity.setToken(token);
return localuserEntity;
}
userEntity.setToken(token);
return userEntity;
}else{
......
......@@ -36,12 +36,15 @@ public class IdgeneratorServiceImpl implements IdgeneratorService {
private ConcurrentHashMap<IdGeneratorKey, SequenceId> seqIdMap = new ConcurrentHashMap<>();
/** 默认步长,即一次取多少个ID */
/**
* 默认步长,即一次取多少个ID
*/
private static final Long DEFAULT_STEP = 50L;
/**
* <B>Description</B> 生成器key枚举 <br />
*
* @author
* @createTime 2016年3月16日 上午10:07:19
*/
......@@ -64,15 +67,25 @@ public class IdgeneratorServiceImpl implements IdgeneratorService {
EFFECT_KEY(1L, "effect", null),
OTHER_KEY(1L, "other", null),
/** 空,测试用 */
USER_KEY(10000L, "user", null),
/**
* 空,测试用
*/
DUMMY(DEFAULT_STEP, "", null),
;
/** 步长 */
/**
* 步长
*/
private final Long step;
/** 生成ID方法名 */
/**
* 生成ID方法名
*/
private final String methodName;
/** 生成ID所需参数因子类型 */
/**
* 生成ID所需参数因子类型
*/
private final Class[] factorsClazz;
private IdGeneratorKey(Long step, String methodName, Class[] factorsClazz) {
......@@ -169,6 +182,12 @@ public class IdgeneratorServiceImpl implements IdgeneratorService {
}
}
private Long user() {
synchronized (IdGeneratorKey.USER_KEY) {
return getNextSequenceId(IdGeneratorKey.USER_KEY, null);
}
}
// *******************************************************************************
/**
......@@ -326,13 +345,19 @@ public class IdgeneratorServiceImpl implements IdgeneratorService {
private class SequenceId {
/** 步长 */
/**
* 步长
*/
private Long step = 100L;
/** 开始ID */
/**
* 开始ID
*/
private volatile AtomicLong startSeq = new AtomicLong(1);
/** 结束ID */
/**
* 结束ID
*/
private volatile Long finishSeq = 0L;
public Long next() {
......
package com.mortals.xhx.daemon.task;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 同步门户用户
*/
@Slf4j
@Service("SyncPortalUserTask")
public class SyncPortalUserTaskImpl implements ITaskExcuteService {
@Autowired
private IUserFeign userFeign;
@Autowired
private UserService userService;
@Override
public void excuteTask(ITask task) throws AppException {
try {
log.info("同步门户用户");
syncPersons();
} catch (Exception e) {
log.error("同步门户异常", e);
}
}
private void syncPersons() {
UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu);
if (resp.getCode() == YesNoEnum.YES.getValue()) {
List<UserPdu> userPduList = resp.getData().getData();
log.info("用户总数量:{}", userPduList.size());
if (!ObjectUtils.isEmpty(userPduList)) {
List<UserEntity> newUserList = userPduList.stream().map(newUser -> {
UserEntity userEntity = new UserEntity();
userEntity.initAttrValue();
BeanUtils.copyProperties(newUser, userEntity, new String[]{"id", "lastLoginTime", "lastLoginAddress"});
return userEntity;
}).collect(Collectors.toList());
List<UserEntity> oldUserList = userService.find(new UserQuery());
log.info(" oldUserList size:{}", oldUserList.size());
//当前用户map
Map<String, UserEntity> oldUserMap = oldUserList.parallelStream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
//门户用户map
// Map<String, UserEntity> newUserMap = newUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
List<UserEntity> saveUserList = newUserList.stream().map(item -> {
if (!oldUserMap.containsKey(item.getLoginName())) {
item.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(saveUserList)) {
log.info("用户新增,size:{}", saveUserList.size());
saveUserList.stream().forEach(item -> {
userService.getUserDao().insert(item);
});
}
}
//查找新增 与更新
}
}
@Override
public void stopTask(ITask task) throws AppException {
}
}
......@@ -6,7 +6,7 @@ import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.code.*;
import com.mortals.xhx.module.attendance.model.AttendanceStatEntity;
import com.mortals.xhx.module.attendance.model.AttendanceVacationBalanceEntity;
import com.mortals.xhx.module.attendance.service.AttendanceStatService;
......@@ -22,18 +22,20 @@ import com.mortals.xhx.module.hik.person.model.rsp.person.PersonDataInfo;
import com.mortals.xhx.module.hik.person.model.rsp.person.PersonInfo;
import com.mortals.xhx.module.hik.person.service.IHikPersonService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffLeaveEntity;
import com.mortals.xhx.module.staff.model.StaffQuery;
import com.mortals.xhx.module.staff.service.StaffLeaveService;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
* 同步用户
* 同步海康用户
*/
@Slf4j
@Service("SyncUserTask")
......@@ -52,6 +54,8 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
@Autowired
private IHikPersonService hikPersonService;
@Autowired
private StaffLeaveService staffLeaveService;
@Override
public void excuteTask(ITask task) throws AppException {
......@@ -72,11 +76,21 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
Rest<PersonDataInfo> personRest = hikPersonService.getPersonList(personReq);
if (personRest.getCode() == YesNoEnum.YES.getValue()) {
List<PersonInfo> personInfoList = personRest.getData().getList();
//做差集 更新本地用户为离职员工
StaffQuery staffQuery = new StaffQuery();
staffQuery.setSource(1);
staffQuery.setStatusNotList(Arrays.asList(StaffSatusEnum.离职.getValue()));
Map<String, StaffEntity> staffCollect = staffService.find(staffQuery).stream().collect(Collectors.toMap(x -> x.getWorkNum(), y -> y, (o, n) -> n));
for (PersonInfo personInfo : personInfoList) {
if(ObjectUtils.isEmpty(personInfo.getJobNo())){
if (ObjectUtils.isEmpty(personInfo.getJobNo())) {
log.info("jobNo is null ==>{}", JSON.toJSONString(personInfo));
continue;
}
if (staffCollect.containsKey(personInfo.getJobNo())) {
staffCollect.remove(personInfo.getJobNo());
}
StaffEntity staffEntity = staffService.getExtCache(StrUtil.padPre(personInfo.getJobNo(), 8, "0"));
DeptEntity deptEntity = deptService.selectOne(new DeptQuery().deptCode(personInfo.getOrgIndexCode()));
......@@ -164,6 +178,44 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
}
}
if (staffCollect.size() > 0) {
//需要将此人员变更为离职
staffCollect.entrySet().stream().forEach(item -> {
StaffEntity staffEntity = item.getValue();
staffEntity.setStatus(StaffSatusEnum.离职.getValue());
staffEntity.setUpdateTime(new Date());
staffEntity.setUpdateUserId(1L);
staffService.update(staffEntity);
//新增离职人员
StaffLeaveEntity staffLeaveEntity = new StaffLeaveEntity();
staffLeaveEntity.initAttrValue();
staffLeaveEntity.setStaffId(staffEntity.getId());
staffLeaveEntity.setStaffName(staffEntity.getName());
staffLeaveEntity.setGender(staffEntity.getGender());
staffLeaveEntity.setBirthday(staffEntity.getBirthday());
staffLeaveEntity.setPhotoPath(staffEntity.getPhotoPath());
staffLeaveEntity.setPhoneNumber(staffEntity.getPhoneNumber());
staffLeaveEntity.setIdCard(staffEntity.getIdCard());
staffLeaveEntity.setWorkNum(staffEntity.getWorkNum());
staffLeaveEntity.setPoliticalstatus(staffEntity.getPoliticalstatus());
staffLeaveEntity.setDeptId(staffEntity.getDeptId());
staffLeaveEntity.setDeptName(staffEntity.getDeptName());
staffLeaveEntity.setJobId(staffEntity.getPositionId());
staffLeaveEntity.setJobName(staffEntity.getPositionName());
staffLeaveEntity.setStaffType(staffEntity.getStaffType());
staffLeaveEntity.setStatus(StaffSatusEnum.离职.getValue());
staffLeaveEntity.setLeaveDate(new Date());
staffLeaveEntity.setLeaveReason("");
staffLeaveEntity.setAuditStatus(AuditStatusEnum.通过.getValue());
staffLeaveEntity.setCreateUserId(1L);
staffLeaveEntity.setCreateTime(new Date());
staffLeaveService.save(staffLeaveEntity);
});
}
}
}
......
......@@ -227,6 +227,25 @@ public class FixWorkOtherAttendance extends AttendanceWorkAbstract {
}
}
if (!ObjectUtils.isEmpty(commonData.getDetailEntityList())) {
//判断当前计算的时间,如果小于缺卡打卡时间 则删除详细考勤记录
Iterator<AttendanceRecordDetailEntity> iterator = commonData.getDetailEntityList().iterator();
while (iterator.hasNext()) {
AttendanceRecordDetailEntity next = iterator.next();
if (next.getGoWorkResult() == GoWorkResultEnum.缺卡.getValue()) {
if (DateUtil.compare(new Date(), next.getGoWorkDate()) < 0) {
iterator.remove();
}
}
if (next.getOffWorkResult() == OffWorkResultEnum.缺卡.getValue()) {
if (DateUtil.compare(new Date(), next.getOffWorkDate()) < 0) {
next.setGoWorkDate(null);
next.setGoWorkResult(GoWorkResultEnum.正常.getValue());
}
}
}
AttendanceClassDetailEntity attendanceClassDetailEntity = attendanceClassDetailService.get(commonData.getDetailEntityList().get(0).getShiftsId());
commonData.getAttendanceRecordEntity().setClassId(attendanceClassDetailEntity == null ? 0L : attendanceClassDetailEntity.getClassId());
commonData.getAttendanceRecordEntity().setClassName(attendanceClassDetailEntity == null ? "" : attendanceClassDetailEntity.getClassName());
......@@ -318,8 +337,8 @@ public class FixWorkOtherAttendance extends AttendanceWorkAbstract {
Long[] errorIds = errorService.find(errorQuery).stream().map(i -> i.getId()).toArray(Long[]::new);
if(!ObjectUtils.isEmpty(errorIds)){
errorService.remove(errorIds,context);
if (!ObjectUtils.isEmpty(errorIds)) {
errorService.remove(errorIds, context);
}
for (AttendanceRecordErrorEntity errorEntity : errorEntityList) {
......
......@@ -8,6 +8,8 @@ import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.SecurityUtil;
import com.mortals.xhx.base.system.idgenerator.service.IdgeneratorService;
import com.mortals.xhx.base.system.idgenerator.service.impl.IdgeneratorServiceImpl;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.base.system.user.model.UserEntity;
......@@ -42,6 +44,8 @@ import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
import static com.mortals.xhx.base.system.idgenerator.service.impl.IdgeneratorServiceImpl.IdGeneratorKey.USER_KEY;
/**
* StaffService
* 员工基本信息 service实现
......@@ -69,6 +73,9 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
@Autowired
private AttendanceVacationBalanceService balanceService;
@Autowired
private IdgeneratorService idgeneratorService;
@Override
protected String getExtKey(StaffEntity data) {
......@@ -85,9 +92,6 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
}
}
@Override
public StaffInfoVo queryAll(Context context) {
StaffInfoVo staffInfoVo = new StaffInfoVo();
......@@ -226,6 +230,9 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
entity.setLoginPwd("123456");
}
//生成用户id,不与门户服务用户相同
// Long userId = idgeneratorService.getLongId(USER_KEY);
// entity.setId(userId);
userEntity.setLoginName(StrUtil.cleanBlank(entity.getLoginName()));
userEntity.setRealName(entity.getName());
userEntity.setUserType(UserType.WORK_PERSON.getValue());
......
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