Commit eba3618f authored by daijunxiong's avatar daijunxiong

修改定时任务 修改人员统计

parent a11b1988
...@@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -48,12 +47,14 @@ public class SyncUserTaskImpl implements ITaskExcuteService { ...@@ -48,12 +47,14 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
for (ListItem list : personHikData.getList()) { for (ListItem list : personHikData.getList()) {
//根据id获取本地数据 //根据id获取本地数据
StaffEntity staffEntity1 = staffDao.queryHik(list.getPersonId()); StaffEntity staffEntity1 = staffDao.queryHik(list.getPersonId());
List<StaffEntity> staffEntities = staffDao.queryAllList(); DeptEntity deptEntity = deptDao.queryDept(list.getOrgIndexCode());
//判断本地数据是否为空 //判断本地数据是否为空
if (Objects.isNull(staffEntity1)) { if (Objects.isNull(staffEntity1)) {
//如果为空则将数据存入数据库 //如果为空则将数据存入数据库
StaffEntity staffEntity = new StaffEntity(); StaffEntity staffEntity = new StaffEntity();
System.out.println(list.getPersonName()); if (Objects.nonNull(deptEntity)) {
staffEntity.setDeptId(deptEntity.getId());
}
staffEntity.setName(list.getPersonName()); staffEntity.setName(list.getPersonName());
staffEntity.setRemarkId(list.getPersonId()); staffEntity.setRemarkId(list.getPersonId());
staffEntity.setPhotoPath(list.getPersonPhoto().getPicUri()); staffEntity.setPhotoPath(list.getPersonPhoto().getPicUri());
...@@ -74,83 +75,71 @@ public class SyncUserTaskImpl implements ITaskExcuteService { ...@@ -74,83 +75,71 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
} }
//本地数据不为空 //本地数据不为空
else { else {
//本地数据遍历数据 //执行修改
for (StaffEntity staffEntity : staffEntities) { if (Objects.nonNull(deptEntity)) {
//如果本地的id等于海康的id staffEntity1.setDeptId(deptEntity.getId());
if (staffEntity.getRemarkId().equals(list.getPersonId())) { }
//执行修改 staffEntity1.setName(list.getPersonName());
StaffEntity staffEntity2 = new StaffEntity(); staffEntity1.setRemarkId(list.getPersonId());
System.out.println(list.getPersonName()); staffEntity1.setPhotoPath(list.getPersonPhoto().getPicUri());
staffEntity2.setName(list.getPersonName()); staffEntity1.setDeptName(list.getOrgName());
staffEntity2.setRemarkId(list.getPersonId()); staffEntity1.setSource(1);
staffEntity2.setPhotoPath(list.getPersonPhoto().getPicUri()); staffEntity1.setStatus(1);
staffEntity2.setDeptName(list.getOrgName()); staffEntity1.setGender(list.getGender());
staffEntity2.setSource(1); staffEntity1.setWorkNum(list.getJobNo());
staffEntity2.setStatus(1); staffEntity1.setCreateUserId(Long.valueOf(1));
staffEntity2.setGender(list.getGender()); staffEntity1.setCreateTime(new Date());
staffEntity2.setWorkNum(list.getJobNo()); if (list.getBirthday() != null) {
staffEntity2.setCreateUserId(Long.valueOf(1)); staffEntity1.setBirthday((Date) list.getBirthday());
staffEntity2.setCreateTime(new Date()); }
if (list.getBirthday() != null) { if (list.getPhoneNo() != null) {
staffEntity2.setBirthday((Date) list.getBirthday()); staffEntity1.setPhoneNumber(String.valueOf(list.getPhoneNo()));
}
if (list.getPhoneNo() != null) {
staffEntity2.setPhoneNumber(String.valueOf(list.getPhoneNo()));
}
staffDao.update(staffEntity2);
}
for (ListItem item : personHikData.getList()) {
//如果本地id不等于海康id并且海康id不等于本地id
if (!item.getPersonId().equals(staffEntity.getRemarkId())) {
//否则执行删除
staffDao.delete(staffEntity.getId());
}
}
} }
staffDao.update(staffEntity1);
} }
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
try { try {
String resultDept = ArtemisPostTest.callPostApiGetDeptList(); String resultDept = ArtemisPostTest.callPostApiGetDeptList();
JSONObject jsonObjectDept = JSON.parseObject(resultDept); JSONObject jsonObjectDept = JSON.parseObject(resultDept);
JSONObject jsonObjectDept1 = jsonObjectDept.getJSONObject("data"); JSONObject jsonObjectDept1 = jsonObjectDept.getJSONObject("data");
DeptHikData deptHikData = JSONObject.parseObject(jsonObjectDept1.toJSONString(), DeptHikData.class); DeptHikData deptHikData = JSONObject.parseObject(jsonObjectDept1.toJSONString(), DeptHikData.class);
System.out.println(resultDept);
if (Objects.nonNull(deptHikData)) { if (Objects.nonNull(deptHikData)) {
for (ListDept listDept : deptHikData.getList()) { for (ListDept listDept : deptHikData.getList()) {
//查询数据库信息
DeptEntity deptEntity = deptDao.queryDept(listDept.getOrgIndexCode()); DeptEntity deptEntity = deptDao.queryDept(listDept.getOrgIndexCode());
List<DeptEntity> deptEntities = deptDao.queryAllList(); DeptEntity deptEntityParent = deptDao.queryDeptParient(listDept.getParentOrgIndexCode());
DeptEntity deptEntity1 = new DeptEntity();
if (Objects.isNull(deptEntity)) { if (Objects.isNull(deptEntity)) {
DeptEntity deptEntity1 = new DeptEntity(); if (Objects.nonNull(deptEntityParent)) {
deptEntity1.setParentId(deptEntityParent.getId());
}
deptEntity1.setDeptName(listDept.getOrgName()); deptEntity1.setDeptName(listDept.getOrgName());
deptEntity1.setDeptCode(listDept.getOrgIndexCode()); deptEntity1.setDeptCode(listDept.getOrgIndexCode());
deptEntity1.setAncestors(listDept.getOrgPath()); deptEntity1.setAncestors(listDept.getOrgPath());
deptEntity1.setDeptStatus(1); deptEntity1.setDeptStatus(1);
deptEntity1.setOrderNum(0); deptEntity1.setOrderNum(0);
deptEntity1.setPersonNum(0); deptEntity1.setRemark(listDept.getParentOrgIndexCode());
deptEntity1.setCreateTime(new Date()); deptEntity1.setCreateTime(new Date());
deptEntity1.setCreateUserId(Long.valueOf(1)); deptEntity1.setCreateUserId(Long.valueOf(1));
System.out.println(deptEntity1);
deptDao.insert(deptEntity1); deptDao.insert(deptEntity1);
} else { } else {
for (DeptEntity deptEntity2 : deptEntities) { if (Objects.nonNull(deptEntityParent)) {
if (!deptEntity2.getDeptCode().equals(listDept.getOrgIndexCode())) { deptEntity.setParentId(deptEntityParent.getId());
deptEntity2.setDeptName(listDept.getOrgName());
deptEntity2.setDeptCode(listDept.getOrgIndexCode());
deptEntity2.setAncestors(listDept.getOrgPath());
deptEntity2.setCreateTime(new Date());
deptEntity2.setCreateUserId(Long.valueOf(1));
deptDao.update(deptEntity2);
}
for (ListDept dept : deptHikData.getList()) {
if (!dept.getOrgIndexCode().equals(deptEntity2.getDeptCode())) {
deptDao.delete(deptEntity2.getId());
}
}
} }
deptEntity.setDeptName(listDept.getOrgName());
deptEntity.setDeptCode(listDept.getOrgIndexCode());
deptEntity.setAncestors(listDept.getOrgPath());
deptEntity.setCreateTime(new Date());
deptEntity.setCreateUserId(Long.valueOf(1));
deptDao.update(deptEntity);
} }
} }
} }
...@@ -159,6 +148,7 @@ public class SyncUserTaskImpl implements ITaskExcuteService { ...@@ -159,6 +148,7 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
e.printStackTrace(); e.printStackTrace();
} }
} }
......
...@@ -39,10 +39,11 @@ public class AttendanceVacationRecordController extends BaseCRUDJsonBodyMappingC ...@@ -39,10 +39,11 @@ public class AttendanceVacationRecordController extends BaseCRUDJsonBodyMappingC
super.init(model, context); super.init(model, context);
} }
@Override @Override
protected void saveBefore(AttendanceVacationRecordEntity entity, Map<String, Object> model, Context context) throws AppException { protected int saveAfter(AttendanceVacationRecordEntity entity, Map<String, Object> model, Context context) throws AppException {
AttendanceVacationBalanceEntity attendanceVacationBalanceEntity=attendanceVacationBalanceService.get(entity.getStaffId()); AttendanceVacationBalanceEntity attendanceVacationBalanceEntity=attendanceVacationBalanceService.get(entity.getStaffId());
model.put("allHoliday",attendanceVacationBalanceEntity); model.put("allHoliday",attendanceVacationBalanceEntity);
super.saveBefore(entity, model, context); return super.saveAfter(entity, model, context);
} }
} }
\ No newline at end of file
...@@ -27,9 +27,17 @@ public interface DeptDao extends ICRUDDao<DeptEntity,Long>{ ...@@ -27,9 +27,17 @@ public interface DeptDao extends ICRUDDao<DeptEntity,Long>{
List<DeptEntity> queryAllList(); List<DeptEntity> queryAllList();
/** /**
* 统计部门人数 * 查询部门信息
* */ * */
DeptEntity queryDept(String deptCode); DeptEntity queryDept(String deptCode);
/**
* 查询是否作为上级本门
* */
DeptEntity queryDeptParient(String parentCode);
/**
*
* */
int queryDeptParentId(Long deptId);
} }
...@@ -32,5 +32,15 @@ public class DeptDaoImpl extends BaseCRUDDaoMybatis<DeptEntity,Long> implements ...@@ -32,5 +32,15 @@ public class DeptDaoImpl extends BaseCRUDDaoMybatis<DeptEntity,Long> implements
return getSqlSession().selectOne(getSqlId("queryDept"),deptCode); return getSqlSession().selectOne(getSqlId("queryDept"),deptCode);
} }
@Override
public DeptEntity queryDeptParient(String parentCode) {
return getSqlSession().selectOne(getSqlId("queryDeptParient"),parentCode);
}
@Override
public int queryDeptParentId(Long deptId) {
return getSqlSession().selectOne(getSqlId("queryDeptParentId"),deptId);
}
} }
package com.mortals.xhx.module.dept.service; package com.mortals.xhx.module.dept.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.dept.model.DeptEntity; import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptTreeSelect; import com.mortals.xhx.module.dept.model.DeptTreeSelect;
import java.util.List; import java.util.List;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
/** /**
* DeptService * DeptService
* *
...@@ -48,4 +48,15 @@ public interface DeptService extends ICRUDService<DeptEntity,Long>{ ...@@ -48,4 +48,15 @@ public interface DeptService extends ICRUDService<DeptEntity,Long>{
* @return * @return
*/ */
List<DeptTreeSelect> getListByParentId(Long parentId,Context context); List<DeptTreeSelect> getListByParentId(Long parentId,Context context);
/**
* 查询部门人数
* */
DeptEntity queryDept(String deptCode);
DeptEntity queryParent(String parentCode);
int queryParentId(Long deptId);
} }
\ No newline at end of file
...@@ -191,4 +191,19 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity ...@@ -191,4 +191,19 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
return collect; return collect;
} }
@Override
public DeptEntity queryDept(String deptCode) {
return dao.queryDept(deptCode);
}
@Override
public DeptEntity queryParent(String parentCode) {
return dao.queryDeptParient(parentCode);
}
@Override
public int queryParentId(Long deptId) {
return dao.queryDeptParentId(deptId);
}
} }
\ No newline at end of file
...@@ -59,7 +59,7 @@ public interface StaffDao extends ICRUDDao<StaffEntity,Long>{ ...@@ -59,7 +59,7 @@ public interface StaffDao extends ICRUDDao<StaffEntity,Long>{
/** /**
* * 查询部门信息
* */ * */
StaffEntity queryHik(String remarkId); StaffEntity queryHik(String remarkId);
} }
...@@ -18,4 +18,6 @@ public interface StaffService extends ICRUDCacheService<StaffEntity,Long> { ...@@ -18,4 +18,6 @@ public interface StaffService extends ICRUDCacheService<StaffEntity,Long> {
int queryDeptNum(Long deptId); int queryDeptNum(Long deptId);
int queryAllPerson(); int queryAllPerson();
} }
\ No newline at end of file
...@@ -65,4 +65,5 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta ...@@ -65,4 +65,5 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
} }
} }
\ No newline at end of file
...@@ -104,10 +104,19 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ ...@@ -104,10 +104,19 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
@Override @Override
protected int saveAfter(StaffEntity entity, Map<String, Object> model, Context context) throws AppException { protected int saveAfter(StaffEntity entity, Map<String, Object> model, Context context) throws AppException {
int personNum = service.queryDeptNum(entity.getDeptId()); //统计当前部门
DeptEntity deptEntity = deptService.get(entity.getDeptId()); DeptEntity deptEntity = deptService.get(entity.getDeptId());
deptEntity.setPersonNum(personNum); int personNumcount = service.queryDeptNum(entity.getDeptId());
deptEntity.setPersonNum(personNumcount);
deptService.update(deptEntity); deptService.update(deptEntity);
//统计上级部门
int personNumId = deptService.queryParentId(entity.getDeptId());
if (personNumId!=0){
DeptEntity deptEntity1 = deptService.get(entity.getDeptId());
int personParentNumcount = service.queryDeptNum(deptEntity1.getParentId());
deptEntity1.setPersonNum(personParentNumcount);
deptService.update(deptEntity1);
}
return super.saveAfter(entity, model, context); return super.saveAfter(entity, model, context);
} }
......
...@@ -881,4 +881,10 @@ ...@@ -881,4 +881,10 @@
<select id="queryDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity"> <select id="queryDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
select * from mortals_xhx_dept where deptCode = #{deptCode} select * from mortals_xhx_dept where deptCode = #{deptCode}
</select> </select>
<select id="queryDeptParient" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
select * from mortals_xhx_dept where deptCode = #{parentCode}
</select>
<select id="queryDeptParentId" resultType="integer">
select parentId from mortals_xhx_dept where deptId = #{deptId}
</select>
</mapper> </mapper>
\ No newline at end of file
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