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

添加同步部门信息

parent 5fae4ad6
......@@ -43,25 +43,16 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
private DeptService deptService;
@Autowired
private UserService userService;
@Autowired
private AttendanceStatService attendanceStatService;
@Autowired
private AttendanceVacationBalanceService balanceService;
@Autowired
private IHikPersonService hikPersonService;
@Autowired
private StaffLeaveService staffLeaveService;
@Autowired
private IDingPersonService dingPersonService;
@Override
public void excuteTask(ITask task) throws AppException {
try {
log.info("同步部门");
syncDepts();
deptService.syncDept(null);
log.info("同步用户");
staffService.syncPersons(null);
log.info("同步钉钉usreId");
......@@ -73,11 +64,11 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
UserEntity userEntity = new UserEntity();
userEntity.setId(item.getId());
String mobile="";
String mobile = "";
StaffEntity staffCache = staffService.getCache(item.getCustomerId().toString());
if (!ObjectUtils.isEmpty(staffCache) && !ObjectUtils.isEmpty(staffCache.getPhoneNumber())) {
mobile = staffCache.getPhoneNumber();
if(ObjectUtils.isEmpty(item.getMobile())){
if (ObjectUtils.isEmpty(item.getMobile())) {
userEntity.setMobile(mobile);
}
}
......@@ -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
public void stopTask(ITask task) throws AppException {
......
......@@ -123,14 +123,14 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
query.setAttendanceDateEnd(DateUtil.today());
}
try {
if (DateUtils.getBetween(query.getAttendanceDateStart(), query.getAttendanceDateEnd(), DateUtils.P_yyyy_MM_dd, 2) != 0) {
throw new AppException("选择的日期跨度不能超过一天");
if (DateUtils.getBetween(query.getAttendanceDateStart(), query.getAttendanceDateEnd(), DateUtils.P_yyyy_MM_dd, 2) > 10) {
throw new AppException("选择的日期跨度不能超过十天!");
}
}catch (Exception e){
} catch (Exception e) {
throw new AppException(e.getMessage());
}
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 {
query.getOrderColList().add(new OrderCol("salaId"));
query.getOrderColList().add(new OrderCol("attendanceDate", OrderCol.DESCENDING));
......@@ -216,31 +216,31 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
AttendanceRecordDetailEntity detailEntity = attendanceRecordDetailList.get(i);
AttendanceClassDetailEntity cacheDetail = classDetailService.getCache(detailEntity.getShiftsId().toString());
StringBuilder preStr=new StringBuilder();
if(!ObjectUtils.isEmpty(cacheDetail)&&!ObjectUtils.isEmpty(cacheDetail.getRemark())){
StringBuilder preStr = new StringBuilder();
if (!ObjectUtils.isEmpty(cacheDetail) && !ObjectUtils.isEmpty(cacheDetail.getRemark())) {
preStr.append(cacheDetail.getRemark());
preStr.append("/");
}
//生成上班 结果 下班 结果 4个map
Map<String, Object> map = new HashMap<>();
map.put("name", String.format( preStr+"上班打卡时间", i + 1));
map.put("value", detailEntity.getGoWorkDate()==null?"--":preStr.toString()+DateUtil.formatDateTime(detailEntity.getGoWorkDate()));
map.put("name", String.format(preStr + "上班打卡时间", i + 1));
map.put("value", detailEntity.getGoWorkDate() == null ? "--" : preStr.toString() + DateUtil.formatDateTime(detailEntity.getGoWorkDate()));
mapList.add(map);
map = new HashMap<>();
map.put("name", String.format( preStr+"上班打卡结果", i + 1));
map.put("value", detailEntity.getGoWorkResult()==null?"--":preStr.toString()+GoWorkResultEnum.getByValue(detailEntity.getGoWorkResult()).getDesc());
map.put("name", String.format(preStr + "上班打卡结果", i + 1));
map.put("value", detailEntity.getGoWorkResult() == null ? "--" : preStr.toString() + GoWorkResultEnum.getByValue(detailEntity.getGoWorkResult()).getDesc());
mapList.add(map);
map = new HashMap<>();
map.put("name", String.format( preStr+"下班打卡时间", i + 1));
map.put("value", detailEntity.getOffWorkDate()==null?"--":preStr.toString()+DateUtil.formatDateTime(detailEntity.getOffWorkDate()));
map.put("name", String.format(preStr + "下班打卡时间", i + 1));
map.put("value", detailEntity.getOffWorkDate() == null ? "--" : preStr.toString() + DateUtil.formatDateTime(detailEntity.getOffWorkDate()));
mapList.add(map);
map = new HashMap<>();
map.put("name", String.format( preStr+"下班打卡结果", i + 1));
map.put("value",detailEntity.getOffWorkResult()==null?"--":preStr.toString()+OffWorkResultEnum.getByValue(detailEntity.getOffWorkResult()).getDesc());
map.put("name", String.format(preStr + "下班打卡结果", i + 1));
map.put("value", detailEntity.getOffWorkResult() == null ? "--" : preStr.toString() + OffWorkResultEnum.getByValue(detailEntity.getOffWorkResult()).getDesc());
mapList.add(map);
} else {
Map<String, Object> map = new HashMap<>();
......@@ -280,7 +280,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
ret.put("msg", e.getMessage());
try {
IOUtils.write(ret.toJSONString(), response.getOutputStream());
}catch (IOException e1){
} catch (IOException e1) {
}
......@@ -355,7 +355,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
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,如果已经存在对应的值,则依旧为原来的值。
//如果返回null表示添加数据成功(不重复),不重复(null==null :TRUE)
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
......@@ -368,7 +368,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
//求出列表中最多detail 的 添加动态列
List<AttendanceRecordDetailEntity> collect = list.parallelStream()
.flatMap(item -> item.getAttendanceRecordDetailList().stream())
.filter(distinctByKey(f->f.getOrderNum()))
.filter(distinctByKey(f -> f.getOrderNum()))
.sorted(Comparator.comparingInt(AttendanceRecordDetailEntity::getOrderNum))
.collect(Collectors.toList());
......@@ -494,7 +494,7 @@ public class AttendanceRecordController extends BaseCRUDJsonBodyMappingControlle
try {
HomeStatInfo homeStatInfo = cacheService.get(RedisKey.KEY_HOME_STAT_CACHE, HomeStatInfo.class);
recordSysLog(request, busiDesc + " 【成功】");
jsonObject.put(KEY_RESULT_DATA,homeStatInfo);
jsonObject.put(KEY_RESULT_DATA, homeStatInfo);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
} catch (Exception e) {
log.error("申诉审核", e);
......
......@@ -83,4 +83,12 @@ public interface DeptService extends ICRUDService<DeptEntity, Long> {
* @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;
import com.mortals.xhx.common.code.EnableEnum;
import com.mortals.xhx.common.code.EnabledEnum;
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.StaffQuery;
import com.mortals.xhx.module.staff.service.StaffService;
......@@ -38,6 +43,9 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
@Autowired
private StaffService staffService;
@Autowired
private IHikPersonService hikPersonService;
@Override
protected void saveBefore(DeptEntity entity, Context context) throws AppException {
if (ObjectUtils.isEmpty(entity.getParentId())) {
......@@ -291,4 +299,46 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
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();
}
}
......@@ -178,7 +178,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
vo.setWorkFormalDay(entity.getRegularDate());
vo.setAttendanceCount(attendDays);
vo.setLeaveCount(levealPersonNum);
vo.setLateCount(beLate+leaveEarly);
vo.setLateCount(beLate + leaveEarly);
vo.setMinerCount(0L);
vo.setLackCardCount(lackOfCards);
vo.setWorkOverDay(0L);
......@@ -205,6 +205,8 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
JSONObject jsonObject = new JSONObject();
String busiDesc = this.getModuleDesc() + "同步";
try {
//同步部门
deptService.syncDept(getContext());
Rest<Void> rest = this.service.syncPersons(getContext());
if (rest.getCode() == YesNoEnum.NO.getValue()) {
throw new AppException("同步异常!");
......@@ -236,7 +238,7 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
Context context = this.getContext();
try {
this.service.checkAuthorize(pdu,context);
this.service.checkAuthorize(pdu, context);
if (!ObjectUtils.isEmpty(context) && !ObjectUtils.isEmpty(context.getUser())) {
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