| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- package cn.com.lzt.userattendancetotal.service.impl;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
- import org.jeecgframework.core.common.model.json.DataGrid;
- import org.jeecgframework.core.common.model.json.DataGridReturn;
- import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
- import org.jeecgframework.core.constant.Globals;
- import org.jeecgframework.core.util.ListUtils;
- import org.jeecgframework.core.util.ResourceUtil;
- import org.jeecgframework.core.util.StringUtil;
- import org.jeecgframework.core.util.oConvertUtils;
- import org.jeecgframework.minidao.pojo.MiniDaoPage;
- import org.jeecgframework.tag.vo.datatable.SortDirection;
- import org.jeecgframework.web.system.pojo.base.TSBaseUser;
- import org.jeecgframework.web.system.pojo.base.TSUser;
- import org.jeecgframework.web.system.service.DepartServiceI;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import cn.com.lzt.dialogDeal.service.UserDepartOrgDealServiceI;
- import cn.com.lzt.dingattendanceinfo.entity.DingAttendanceinfoEntity;
- import cn.com.lzt.personnelbasearchivesmanage.dao.PersonnelBaseArchivesManageDao;
- import cn.com.lzt.personnelbasearchivesmanage.dto.PersonnelBaseArchivesManageInDto;
- import cn.com.lzt.personnelbasearchivesmanage.dto.PersonnelBaseArchivesManageOutDto;
- import cn.com.lzt.personnelbasearchivesmanage.entity.PersonnelBaseArchivesManageEntity;
- import cn.com.lzt.personnelbasearchivesmanage.service.PersonnelBaseArchivesManageServiceI;
- import cn.com.lzt.projarrangedetail.entity.ProjarrangeDetailEntity;
- import cn.com.lzt.userattendancedetail.entity.UserAttendanceDetailEntity;
- import cn.com.lzt.userattendancedetail.service.UserAttendanceDetailServiceI;
- import cn.com.lzt.userattendancetotal.dao.UserAttendanceTotalDao;
- import cn.com.lzt.userattendancetotal.entity.UserAttendanceTotalEntity;
- import cn.com.lzt.userattendancetotal.service.UserAttendanceTotalServiceI;
- @Service("userAttendanceTotalService")
- @Transactional
- public class UserAttendanceTotalServiceImpl extends CommonServiceImpl implements
- UserAttendanceTotalServiceI {
- @Autowired
- private UserAttendanceTotalDao userAttendanceTotalDao;
- @Autowired
- private PersonnelBaseArchivesManageServiceI personnelBaseArchivesManageService;
- @Autowired
- private UserAttendanceDetailServiceI userAttendanceDetailService;
- @Autowired
- private DepartServiceI departService;
- // 用户和项目关系
- @Autowired
- private UserDepartOrgDealServiceI userDepartOrgDealServiceI;
- @Autowired
- PersonnelBaseArchivesManageDao personnelBaseArchivesManageDao;
- //如果同一个月份数据定时任务再次启动, 需要将 未上报且 未调整的 删除掉重新计算, 其他的不进行覆盖
- @Override
- public void insertUserAttendanceTotalByyearmonth(String userid, String yearmonth)throws Exception {
- if (oConvertUtils.isEmpty(yearmonth) || oConvertUtils.isEmpty(userid)) {
- return;
- }
- // userAttendanceTotalDao.updateExpiredUserAttendanceDetailByUserId(userid,yearmonth);
- // userAttendanceTotalDao.updateExpiredUserAttendanceTotalByUserId(userid,yearmonth);
- List<Object> Obj2Delete = new ArrayList<>();
- CriteriaQuery cq = new CriteriaQuery(UserAttendanceTotalEntity.class);
- cq.eq("userId", userid);
- cq.add();
- cq.eq("yearmonth", yearmonth);
- cq.add();
- List<UserAttendanceTotalEntity> userAttendanceTotalEntities = getListByCriteriaQuery(
- cq, false);
- //如果同一个月份数据定时任务再次启动, 需要将[del--> 未上报且 未调整的]【全部的库中已有的】 删除掉重新计算, del--->其他的不进行覆盖
- if (!ListUtils.isNullOrEmpty(userAttendanceTotalEntities)) {
- for (UserAttendanceTotalEntity entry:userAttendanceTotalEntities) {
- List<UserAttendanceDetailEntity> userAttendanceDetailEntities =
- findByProperty(UserAttendanceDetailEntity.class, "attendanceId", entry.getId());
- Obj2Delete.addAll(userAttendanceDetailEntities);
- Obj2Delete.add(entry);
- }
- }
- UserAttendanceTotalEntity userAttendanceTotalEntity = new UserAttendanceTotalEntity();
- userAttendanceTotalEntity.setYearmonth(yearmonth);
- userAttendanceTotalEntity.setUserId(userid);
- if (oConvertUtils.isNotEmpty(userid)) {
- TSUser user = findUniqueByProperty(TSUser.class, "id", userid);
- if (oConvertUtils.isNotEmpty(user)&&oConvertUtils.isNotEmpty(user.getUserNum())) {
- userAttendanceTotalEntity.setUserCode(user.getUserNum() );
- }
- }
- String departid = getUserDepaertId(userid);
- List<String> pidlist = null;
- String piddddd = null;
- if (oConvertUtils.isNotEmpty(departid)) {
- //FIXME 如果获取的是多个项目id 的时候 如何处理
- pidlist = userDepartOrgDealServiceI.getProjectDepartId(departid);
- if (!ListUtils.isNullOrEmpty(pidlist)) {
- for (String pidd: pidlist) {
- piddddd = pidd;
- }
- }
- }
- userAttendanceTotalEntity.setDepartid(departid);
- userAttendanceTotalEntity.setPid(piddddd);
- userAttendanceTotalEntity.setAdjustRecord(Globals.ATTENDANCE_ADJUST_STATUS_0);
- userAttendanceTotalEntity.setAttendanceStatus(Globals.ATTENDANCE_REPORT_STATUS_0);
-
- List<PersonnelBaseArchivesManageEntity> perEntities = findByProperty(PersonnelBaseArchivesManageEntity.class, "userid", userid);
- PersonnelBaseArchivesManageEntity perEntity = null;
- if (!ListUtils.isNullOrEmpty(perEntities)) {
- for (PersonnelBaseArchivesManageEntity entity:perEntities) {
- perEntity = entity;
- }
- }
- if (perEntity!=null) {
- userAttendanceTotalEntity.setInPostid(perEntity.getInPostid());
- }
- userAttendanceTotalEntity.setConfirmStatus(Globals.ARRANGESTATUS_0);
- save(userAttendanceTotalEntity);
- // 计算某个人的考勤
- userAttendanceDetailService.saveOrUpdateUserAttendanceDetailEntitis(userAttendanceTotalEntity);
- deleteAllEntitie(Obj2Delete);
- }
-
- @Override
- public void insertUserAttendanceTotalByyearmonth(String yearmonth) throws Exception {
- if (oConvertUtils.isEmpty(yearmonth)) {
- return;
- }
- long s = System.currentTimeMillis();
- List<Object> Obj2Delete = new ArrayList<>();
- CriteriaQuery cq1 = new CriteriaQuery(ProjarrangeDetailEntity.class);
- cq1.eq("yearmonth", yearmonth);
- cq1.add();
- List<ProjarrangeDetailEntity> projarrangeDetailEntities = getListByCriteriaQuery(cq1, false);
- List<UserAttendanceTotalEntity> savelist = new ArrayList<UserAttendanceTotalEntity>();
- HashMap<String, HashMap<String, Object>> hm_cache = new HashMap<>();
- if (!ListUtils.isNullOrEmpty(projarrangeDetailEntities)) {
- for (ProjarrangeDetailEntity person : projarrangeDetailEntities) {
- //当前员工在当前月份没有记录
- UserAttendanceTotalEntity userAttendanceTotalEntity = new UserAttendanceTotalEntity();
- userAttendanceTotalEntity.setYearmonth(yearmonth);
- userAttendanceTotalEntity.setUserId(person.getUserid());
- if (oConvertUtils.isNotEmpty(person.getUserid())) {
- PersonnelBaseArchivesManageOutDto personnelBaseArchives = getPersonnelBaseArchivesManageOutDtoWithCache(hm_cache,person.getUserid());
- if (oConvertUtils.isNotEmpty(personnelBaseArchives)) {
- userAttendanceTotalEntity.setUserCode(personnelBaseArchives.getUserNum() );
- String departid = personnelBaseArchives.getOrgId();
- String piddddd = personnelBaseArchives.getGlcId();
- userAttendanceTotalEntity.setDepartid(departid);
- userAttendanceTotalEntity.setPid(piddddd);
- userAttendanceTotalEntity.setAdjustRecord(Globals.ATTENDANCE_ADJUST_STATUS_0);
- userAttendanceTotalEntity.setAttendanceStatus(Globals.ATTENDANCE_REPORT_STATUS_0);
- userAttendanceTotalEntity.setInPostid(personnelBaseArchives.getInPostid());
- userAttendanceTotalEntity.setConfirmStatus(Globals.ARRANGESTATUS_0);
- savelist.add(userAttendanceTotalEntity);
- }
- }
-
- }
- }
- long e00 = System.currentTimeMillis();
- System.out.println("get projarrangeDetailEntities costs: " + (e00-s) + "ms");
- List<UserAttendanceTotalEntity> userAttendanceTotalEntities = getUserAttendanceTotalEntitiesWithCache(hm_cache,yearmonth);
- long e01 = System.currentTimeMillis();
- System.out.println("get userAttendanceTotalEntities costs: " + (e01-e00) + "ms");
- //如果同一个月份数据定时任务再次启动, 需要将[del--> 未上报且 未调整的]【全部的库中已有的】 删除掉重新计算, del--->其他的不进行覆盖
- List<UserAttendanceDetailEntity> userAttendanceDetailEntities = getUserAttendanceDetailEntitiesWithCache(hm_cache,yearmonth);
- long e02 = System.currentTimeMillis();
- System.out.println("get userAttendanceDetailEntities costs: " + (e02-e01) + "ms");
- Obj2Delete.addAll(userAttendanceDetailEntities);
- Obj2Delete.addAll(userAttendanceTotalEntities);
-
-
- long e1 = System.currentTimeMillis();
- //根据用户的员工考勤合计信息, 计算每一个员工在这个月内的每天的考勤信息
- batchSave(savelist);
- long e2 = System.currentTimeMillis();
- System.out.println("deal batchSave costs: " + (e2-e1) + "ms");
- userAttendanceDetailService.saveOrUpdateUserAttendanceDetailEntitis(savelist);
- long e3 = System.currentTimeMillis();
- System.out.println("deal saveOrUpdateUserAttendanceDetailEntitis costs: " + (e3-e2) + "ms");
-
- deleteAllEntitie(Obj2Delete);
- long e4 = System.currentTimeMillis();
- System.out.println("deal deleteAllEntitie costs: " + (e4-e3) + "ms");
- }
- /**
- * @param hm_cache
- * @param userid
- * @return
- */
- private PersonnelBaseArchivesManageOutDto getPersonnelBaseArchivesManageOutDtoWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
- HashMap<String, Object> hm_personCache = hm_cache.get("getPersonnelBaseArchivesManageOutDtoWithCache");
- if(hm_personCache == null ||hm_personCache.isEmpty()) {
- hm_personCache = new HashMap<String, Object>();
- List<PersonnelBaseArchivesManageOutDto> listDB = personnelBaseArchivesManageDao.getAllEntities().getResults();
- for(PersonnelBaseArchivesManageOutDto person : listDB) {
- hm_personCache.put(person.getUserId(), person);
- }
- hm_cache.put("getPersonnelBaseArchivesManageOutDtoWithCache", hm_personCache);
- }
- return (PersonnelBaseArchivesManageOutDto)hm_personCache.get(userid);
- }
- /**
- * @param hm_cache
- * @param yearmonth
- * @return
- */
- private List<UserAttendanceDetailEntity> getUserAttendanceDetailEntitiesWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String yearmonth) {
- // String hql = "from UserAttendanceDetailEntity where ymdDate like '" +yearmonth+"%'";
- List<UserAttendanceDetailEntity> entitiesFromDB = new ArrayList<UserAttendanceDetailEntity>();
- String hql = "select id from t_bus_user_attendance_detail "
- + "where ymd_date like '"+ yearmonth +"%'";
-
- List<Map<String, Object>> mapList=new ArrayList<Map<String, Object>>();
-
- mapList = findForJdbc(hql, null);
- for(Map<String, Object> map : mapList) {
- UserAttendanceDetailEntity entity = new UserAttendanceDetailEntity();
- entity.setId(map.get("id").toString());
- entitiesFromDB.add(entity);
- }
- // for(UserAttendanceDetailEntity entity : entitiesFromDB) {
- // String attendanceIdInEntity = entity.getAttendanceId();
- // if(hm.containsKey(attendanceIdInEntity)) {
- // List<UserAttendanceDetailEntity> entitylist = (List<UserAttendanceDetailEntity>)hm.get(attendanceIdInEntity);
- // entitylist.add(entity);
- // }else {
- // List<UserAttendanceDetailEntity> newlist = new ArrayList<>();
- // newlist.add(entity);
- // hm.put(attendanceIdInEntity, newlist);
- // }
- // }
-
- // List<UserAttendanceDetailEntity> allList = (List<UserAttendanceDetailEntity>)hm.get(atendanceId);
- return entitiesFromDB;
- }
- /**
- * @param hm_cache
- * @param yearmonth
- * @return
- */
- private List<UserAttendanceTotalEntity> getUserAttendanceTotalEntitiesWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String yearmonth) {
- // HashMap<String, Object> hm = hm_cache.get("getUserAttendanceTotalEntitiesWithCache");
- // if(hm == null) {
- // hm = new HashMap<>();
- // hm_cache.put("getUserAttendanceTotalEntitiesWithCache", hm);
- // CriteriaQuery cq = new CriteriaQuery(UserAttendanceTotalEntity.class);
- // cq.eq("yearmonth", yearmonth);
- // cq.add();
- // List<UserAttendanceTotalEntity> entitiesFromDB = getListByCriteriaQuery(cq, false);
- // for(UserAttendanceTotalEntity entity : entitiesFromDB) {
- // String userInEntity = entity.getUserId();
- // if(hm.containsKey(userInEntity)) {
- // List<UserAttendanceTotalEntity> entitylist = (List<UserAttendanceTotalEntity>)hm.get(userInEntity);
- // entitylist.add(entity);
- // }else {
- // List<UserAttendanceTotalEntity> newlist = new ArrayList<>();
- // newlist.add(entity);
- // hm.put(userInEntity, newlist);
- // }
- // }
- // }
- List<UserAttendanceTotalEntity> entitiesFromDB = new ArrayList<UserAttendanceTotalEntity>();
- String hql = "select id from t_bus_user_attendance_total "
- + "where yearmonth = '"+ yearmonth +"'";
-
- List<Map<String, Object>> mapList=new ArrayList<Map<String, Object>>();
-
- mapList = findForJdbc(hql, null);
- for(Map<String, Object> map : mapList) {
- UserAttendanceTotalEntity entity = new UserAttendanceTotalEntity();
- entity.setId(map.get("id").toString());
- entitiesFromDB.add(entity);
- }
- return entitiesFromDB;
- }
- /**
- * @param hm_personCache
- * @param userid
- * @return
- */
- private List<PersonnelBaseArchivesManageEntity> getPersonnelBaseArchivesManageEntitysWithCache(
- HashMap<String, List<PersonnelBaseArchivesManageEntity>> hm_personCache, String userid) {
- if(hm_personCache.isEmpty()) {
- String hql = "from PersonnelBaseArchivesManageEntity where 1=1";
- List<PersonnelBaseArchivesManageEntity> listDB = findHql(hql);
- for(PersonnelBaseArchivesManageEntity person : listDB) {
- if(hm_personCache.containsKey(person.getUserid())) {
- hm_personCache.get(person.getUserid()).add(person);
- }else {
- List<PersonnelBaseArchivesManageEntity> newlist = new ArrayList<>();
- newlist.add(person);
- hm_personCache.put(person.getUserid(), newlist);
- }
- }
- }
- return hm_personCache.get(userid);
- }
- /**
- * 获取当前员工所在项目
- * @author hualong.zhao
- * @date 2017-11-28
- * @param userid
- * @return
- */
- private String getUserDepaertId(String userid) {
- String depaertId = null;
- if (oConvertUtils.isNotEmpty(userid)) {
- TSBaseUser user = get(TSBaseUser.class, userid);
- if (oConvertUtils.isNotEmpty(user)&&oConvertUtils.isNotEmpty(user.getUserName())) {
- PersonnelBaseArchivesManageInDto inDto = new PersonnelBaseArchivesManageInDto();
- inDto.setId(user.getId());
- MiniDaoPage<PersonnelBaseArchivesManageOutDto> resultlist =
- personnelBaseArchivesManageService.getPersonnelBaseArchivesManageList(inDto,1,10
- ,null,null);
- List<PersonnelBaseArchivesManageOutDto> list = resultlist.getResults();
- if (!ListUtils.isNullOrEmpty(list)) {
- for (PersonnelBaseArchivesManageOutDto dto : list) {
- depaertId = dto.getOrgId();
- }
- }
- }
- }
- return depaertId;
- }
- @Override
- public void getAttendanceTotalDtos(UserAttendanceTotalEntity userAttendanceTotal, DataGrid dataGrid) {
- List<String> pids = new ArrayList<>();
- List<String> userid = new ArrayList<>();
- boolean confirmStatusnotZero = false;
-
- if (oConvertUtils.isNotEmpty(userAttendanceTotal.getConfirmor())) {
- confirmStatusnotZero = true ;
- userAttendanceTotal.setConfirmor(null);
- }
- if (oConvertUtils.isNotEmpty(userAttendanceTotal.getDepartid())) {
- // userAttendanceTotal.setPid(userAttendanceTotal.getDepartid());
- pids = departService.getDePartIdAndallSonDepartIds(userAttendanceTotal.getDepartid());
- // pids.remove(userAttendanceTotal.getDepartid());
- userAttendanceTotal.setDepartid(null);
- }else {
- dataGrid.setObj("nodepartid");
- }
-
- if (oConvertUtils.isNotEmpty(userAttendanceTotal.getUserId())) {
- CriteriaQuery usercq = new CriteriaQuery(TSBaseUser.class);
- usercq.like("realName", "%"+userAttendanceTotal.getUserId()+"%");
- usercq.add();
- List<TSBaseUser> userlist = getListByCriteriaQuery(usercq, false);
- if (!ListUtils.isNullOrEmpty(userlist)) {
- for (TSBaseUser user:userlist) {
- userid.add(user.getId());
- }
- userAttendanceTotal.setUserId(null);
- }else {
-
- }
- }
- if (!ListUtils.isNullOrEmpty(pids)) {
- userAttendanceTotal.setDepartid(null);
- CriteriaQuery cq = new CriteriaQuery(UserAttendanceTotalEntity.class, dataGrid);
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, userAttendanceTotal);
- cq.add();
- if (!ListUtils.isNullOrEmpty(pids)) {
- cq.in("departid", pids.toArray());
- cq.add();
- }
- if (!ListUtils.isNullOrEmpty(userid)) {
- cq.in("userId", userid.toArray());
- cq.add();
- }
- if (confirmStatusnotZero) {
- cq.notEq("confirmStatus", Globals.ATTENDANCE_REPORT_STATUS_0);
- cq.add();
- }
- boolean isOffset = true ;
- if ("exportXls".equals(oConvertUtils.getString(dataGrid.getObj()))) {
- isOffset = false;
- }
- String sort = dataGrid.getSort(); // 排序对象
- if (StringUtil.isEmpty(sort)) {
- Map<String, Object> orderMap = new HashMap<String, Object>();
- orderMap.put("userCode", SortDirection.asc);
- cq.setOrder(orderMap);
- }
- DataGridReturn dr =getDataGridReturn(cq, isOffset);
- List l = dr.getRows();
- }else {
- List<UserAttendanceTotalEntity> resultlist = new ArrayList<>();
- dataGrid.setResults(resultlist);
- }
- }
- @Override
- public void doBatchAudit(String ids,String confirmStatus) throws Exception {
- for(String id:ids.split(",")){
- if (oConvertUtils.isNotEmpty(id)) {
- UserAttendanceTotalEntity userAttendanceTotal = getEntity(UserAttendanceTotalEntity.class,id);
- if (oConvertUtils.isNotEmpty(userAttendanceTotal)) {
- userAttendanceTotal.setConfirmStatus(confirmStatus);
- userAttendanceTotal.setConfirmDate(new Date());
- String confirmor = ResourceUtil.getSessionUser().getId();
- userAttendanceTotal.setConfirmor(confirmor);
- saveOrUpdate(userAttendanceTotal);
- }
- }
- }
-
- }
- @Override
- public void doBatchReport(String ids) throws Exception {
- for(String id:ids.split(",")){
- if (oConvertUtils.isNotEmpty(id)) {
- UserAttendanceTotalEntity userAttendanceTotal = getEntity(UserAttendanceTotalEntity.class,id);
- if (oConvertUtils.isNotEmpty(userAttendanceTotal)) {
- userAttendanceTotal.setConfirmStatus(Globals.ARRANGESTATUS_1);
- saveOrUpdate(userAttendanceTotal);
- }
- }
- }
-
-
-
- }
- @Override
- public List<UserAttendanceTotalEntity> getByuserid(String userid, String monthly) {
- return userAttendanceTotalDao.getByuserid(userid, monthly);
- }
- }
|