UserStatsServiceImpl.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package cn.com.lzt.userstats.service.impl;
  2. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.transaction.annotation.Propagation;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.UUID;
  12. import java.io.Serializable;
  13. import java.math.BigDecimal;
  14. import org.jeecgframework.core.util.ApplicationContextUtil;
  15. import org.jeecgframework.core.util.JeecgDataAutorUtils;
  16. import org.jeecgframework.core.util.LogUtil;
  17. import org.jeecgframework.core.util.MyClassLoader;
  18. import org.jeecgframework.core.util.StringUtil;
  19. import org.jeecgframework.minidao.pojo.MiniDaoPage;
  20. import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter;
  21. import antlr.StringUtils;
  22. import cn.com.lzt.common.util.DataUtil;
  23. import cn.com.lzt.dialogDeal.service.UserDepartOrgDealServiceI;
  24. import cn.com.lzt.overtimestats.entity.ProjOvertimeStatsEntity;
  25. import cn.com.lzt.userstats.dao.UserStatsMinidaoDao;
  26. import cn.com.lzt.userstats.enitity.DeptUserEntity;
  27. import cn.com.lzt.userstats.enitity.ProjUserEntity;
  28. import cn.com.lzt.userstats.service.UserStatsServiceI;
  29. @Service("userStatsService")
  30. @Transactional(propagation = Propagation.REQUIRES_NEW)
  31. public class UserStatsServiceImpl extends CommonServiceImpl implements UserStatsServiceI {
  32. @Autowired
  33. private UserStatsMinidaoDao userStatsMinidaoDao;
  34. @Autowired
  35. private UserDepartOrgDealServiceI userDepartOrgDealServiceI;
  36. @Override
  37. public void userStatsTaskData() {
  38. userStatsTaskData(null);
  39. }
  40. @Override
  41. public void userStatsTaskData(String attmonth) {
  42. LogUtil.info("===============人员统计定时任务开始=================");
  43. //String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  44. String beforeMonth = DataUtil.getBeforeMonth();
  45. if(StringUtil.isNotEmpty(attmonth)){
  46. beforeMonth = attmonth;
  47. }
  48. Map<String,Object> params = new HashMap<String, Object>();
  49. params = DataUtil.getMonthInfo(beforeMonth);
  50. params.put("yearmonth", beforeMonth);
  51. //查询上个月的部门月度人员情况
  52. MiniDaoPage<DeptUserEntity> deptUserlist = new MiniDaoPage<DeptUserEntity>();
  53. deptUserlist = userStatsMinidaoDao.deptUserStatsData(params,null);
  54. List<DeptUserEntity> deptList = findByProperty(DeptUserEntity.class, "yearmonth", beforeMonth);
  55. List<DeptUserEntity> deptListRes = new ArrayList<DeptUserEntity>();
  56. List<DeptUserEntity> list = new ArrayList<DeptUserEntity>();
  57. //遍历通过部门id查询项目id
  58. for(DeptUserEntity due : deptUserlist.getResults()){
  59. if(StringUtil.isEmpty(due.getPjtId())){
  60. String pid = userDepartOrgDealServiceI.getProjectDepartParentId(due.getDeptId());
  61. if(StringUtil.isNotEmpty(pid)){
  62. String pmId = userStatsMinidaoDao.getPmIdByPid(pid);
  63. due.setPjtId(pid);
  64. due.setPmId(pmId);
  65. deptListRes.add(due);
  66. }
  67. }else{
  68. if(due.getPjtId() != null && due.getPjtId().equals(due.getDeptId())){
  69. list.add(due);
  70. }
  71. deptListRes.add(due);
  72. }
  73. }
  74. try {
  75. deleteAllEntitie(deptList);
  76. super.batchSave(deptListRes);
  77. LogUtil.info("===============部门人员统计表保存成功=================");
  78. } catch (Exception e) {
  79. LogUtil.info("===============部门人员统计表保存失败=================");
  80. }
  81. //查询上个月的项目月度人员情况
  82. MiniDaoPage<ProjUserEntity> projUserlist = new MiniDaoPage<ProjUserEntity>();
  83. projUserlist = userStatsMinidaoDao.projUserStatsData(params,null);
  84. List<ProjUserEntity> projList = findByProperty(ProjUserEntity.class, "yearmonth", beforeMonth);
  85. try {
  86. deleteAllEntitie(projList);
  87. /* for(ProjUserEntity pu : projUserlist.getResults()){
  88. for(DeptUserEntity de : list){
  89. if(pu.getPjtId().equals(de.getPjtId())){
  90. pu.setEarlymonthTotal(pu.getEarlymonthTotal() + de.getEarlymonthTotal());
  91. pu.setEntryTotal(pu.getEntryTotal() + de.getEntryTotal());
  92. pu.setLeaveTotal(pu.getLeaveTotal() + de.getLeaveTotal());
  93. pu.setEndmonthTotal(pu.getEarlymonthTotal() + pu.getEntryTotal() - pu.getLeaveTotal());
  94. float a = (float)pu.getLeaveTotal()/pu.getEarlymonthTotal() * 100;
  95. BigDecimal bd = new BigDecimal(a);
  96. pu.setFlowProportion(new BigDecimal(DataUtil.getFormatDecimailTwo(bd)));
  97. }
  98. }
  99. }*/
  100. super.batchSave(projUserlist.getResults());
  101. LogUtil.info("===============项目人员统计表保存成功=================");
  102. } catch (Exception e) {
  103. LogUtil.info("===============项目人员统计表保存失败=================");
  104. }
  105. LogUtil.info("===============人员统计定时任务开始=================");
  106. }
  107. }