123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- package com.kingdee.eas.custom.server;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.security.SecureRandom;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Base64;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.crypto.Cipher;
- import javax.crypto.KeyGenerator;
- import javax.crypto.SecretKey;
- import javax.crypto.spec.SecretKeySpec;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.bsf.service.app.IHRMsfService;
- import com.kingdee.bos.dao.IObjectPK;
- import com.kingdee.bos.util.BOSUuid;
- import com.kingdee.eas.base.permission.UserInfo;
- import com.kingdee.eas.basedata.person.PersonCollection;
- import com.kingdee.eas.basedata.person.PersonFactory;
- import com.kingdee.eas.basedata.person.PersonInfo;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.framework.CoreBaseCollection;
- import com.kingdee.eas.framework.LineResult;
- import com.kingdee.eas.framework.Result;
- import com.kingdee.eas.hr.base.HRBillStateEnum;
- import com.kingdee.eas.hr.project.IWorkHoursConfirm;
- import com.kingdee.eas.hr.project.IWorkHoursReport;
- import com.kingdee.eas.hr.project.ProjectManagementInfo;
- import com.kingdee.eas.hr.project.WorkHoursConfirmCollection;
- import com.kingdee.eas.hr.project.WorkHoursConfirmFactory;
- import com.kingdee.eas.hr.project.WorkHoursConfirmInfo;
- import com.kingdee.eas.hr.project.WorkHoursReportEntryInfo;
- import com.kingdee.eas.hr.project.WorkHoursReportFactory;
- import com.kingdee.eas.hr.project.WorkHoursReportInfo;
- import com.kingdee.eas.hr.project.dataSource;
- import com.kingdee.eas.util.app.ContextUtil;
- import com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import com.kingdee.shr.empresume.util.ErrorCodeUtil;
- public class WorhHoursService implements IHRMsfService{
-
- private static final String ALGORITHM = "AES";
- private static final int KEY_SIZE = 128;
-
- public Object process(Context ctx, Map param) throws EASBizException, BOSException {
- _initWorkHoursConfirm(ctx, null, null, null, 100);
- return null;
- }
- /**
- * 生成打卡确认单
- */
- private void _initWorkHoursConfirm(Context ctx, String number, String star, String end, int day)
- throws BOSException, EASBizException {
- IRowSet rs = null;
- List<String> keyList = new ArrayList<String>();
- IWorkHoursConfirm biz = WorkHoursConfirmFactory.getLocalInstance(ctx);
-
- WorkHoursConfirmInfo wInfo = null;
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- List<WorkHoursConfirmInfo> listInfo = null;
- List<String> listproid = new ArrayList<String>();
- Map<String,String> mapdate = new HashMap<String,String>();
- Map<String,String> mapproid = new HashMap<String,String>();
- //存放打卡数据 map
- Map<String,List<WorkHoursConfirmInfo>> mapInfo = new HashMap<String,List<WorkHoursConfirmInfo>>();
- StringBuffer sb = new StringBuffer("/*dialect*/");
- if(day <= 0) {
- //默认3天
- day = 3;
- }
-
- sb = new StringBuffer("/*dialect*/");
- sb.append(" select distinct t1.fid pfid,t3.fid pid,TO_CHAR(t.FPUNCHCARDTIME, 'YYYY-MM-DD') CFCLOCKTIME1,t3en.fname_l2 CFCLOCKLOCATION from T_HR_ATS_PunchCardRecord t ").append(" \n");
- sb.append(" inner join T_BD_Person t1 on t1.fid = t.FPROPOSERID ").append(" \n");
- sb.append(" inner join CT_PRO_MemberManagement t2 on t2.CFEmployeeID = t1.fid ").append(" \n");
- sb.append(" inner join CT_PRO_ProjectManagement t3 on t3.fid = t2.CFProjectManagemenID ").append(" \n");
- sb.append(" inner join CT_PRO_ProjectClock t3en on t3en.CFPROJECTID = t3.fid and t3en.CFSTATE = '1' ").append(" \n");
- sb.append(" where t.FPUNCHCARDPLACE is not null ").append(" \n");
- // sb.append(" where t3.CFExpectedStartTime <FPUNCHCARDTIME and t3.CFExpectedEndTime >= FPUNCHCARDTIME ").append(" \n");
- //按照时间过滤
- if(star != null && star.length() > 0) {
- sb.append(" and t.FPUNCHCARDTIME >= TO_DATE('"+star+"', 'YYYY-MM-DD HH24:MI:SS')").append(" \n");
- }else if(end != null && end.length() > 0) {
- sb.append(" and t.FPUNCHCARDTIME <= TO_DATE('"+end+"', 'YYYY-MM-DD HH24:MI:SS')").append(" \n");
- }else {
- sb.append(" and t.FPUNCHCARDTIME >= sysdate -"+day).append(" \n");
- }
- if(number !=null && number.length() > 0) {
- sb.append(" and t1.fnumber in (").append(number).append(") \n");
- }
- //获取打卡数据
- rs = DbUtil.executeQuery(ctx, sb.toString());
- //项目对应的所有位置
- Map<String,List<String>> proCFCLOCKLOCATION = new HashMap<String,List<String>>();
- //人员+年月日 有几个项目
- Map<String,List<String>> keypro = new HashMap<String,List<String>>();
-
- List<String> CFCLOCKLOCATIONList = new ArrayList<String>();
- List<String> proList = new ArrayList<String>();
- try {
- if(rs != null && rs.size() > 0) {
- while (rs.next()) {
- String pfid = rs.getString("pfid");
- String CFCLOCKTIME1 = rs.getString("CFCLOCKTIME1");
- String proid = rs.getString("pid");
- String CFCLOCKLOCATION = rs.getString("CFCLOCKLOCATION");
- String key = pfid+CFCLOCKTIME1; //人员+年月日
- if(keypro.containsKey(key)) {
- proList = keypro.get(key);
- }else {
- proList = new ArrayList<String>();
- }
- if(!proList.contains(proid)) {
- proList.add(proid);
- }
- keypro.put(key, proList);
-
- if(CFCLOCKLOCATION != null && CFCLOCKLOCATION.length() > 0) {
- if(proCFCLOCKLOCATION.containsKey(proid)) {
- CFCLOCKLOCATIONList = proCFCLOCKLOCATION.get(proid);
- }else {
- CFCLOCKLOCATIONList = new ArrayList<String>();
- }
- if(!CFCLOCKLOCATIONList.contains(CFCLOCKLOCATION)) {
- CFCLOCKLOCATIONList.add(CFCLOCKLOCATION);
- }
- proCFCLOCKLOCATION.put(proid, CFCLOCKLOCATIONList);
- }
- }
- }
- System.out.println("keypro"+keypro.toString());
- System.out.println("proCFCLOCKLOCATION"+proCFCLOCKLOCATION.toString());
- sb = new StringBuffer("/*dialect*/");
- sb.append(" select t.fid tfid,t1.fid pid,t1.fnumber,t1.fname_l2,t3.fid proid,t3.fnumber,t3.CFProjectName ,TO_CHAR(t.FPUNCHCARDTIME, 'YYYY-MM-DD') CFCLOCKTIME1 "
- + ",TO_CHAR(t.FPUNCHCARDTIME, 'YYYY-MM-DD HH24:MI:SS') CFCLOCKTIME,t.FPUNCHCARDPLACE FPUNCHCARDPLACE from T_HR_ATS_PunchCardRecord t ").append(" \n");
- sb.append(" inner join T_BD_Person t1 on t1.fid = t.FPROPOSERID ").append(" \n");
- sb.append(" inner join CT_PRO_MemberManagement t2 on t2.CFEmployeeID = t1.fid ").append(" \n");
- sb.append(" inner join CT_PRO_ProjectManagement t3 on t3.fid = t2.CFProjectManagemenID ").append(" \n");
- // sb.append(" where t3.CFExpectedStartTime <FPUNCHCARDTIME and t3.CFExpectedEndTime >= FPUNCHCARDTIME ").append(" \n");
- sb.append(" where t.FPUNCHCARDPLACE is not null and t.fid not in (select FSOURCEBILLID from CT_PRO_WorkHoursConfirm where FSOURCEBILLID is not null ) ").append(" \n");
- //按照时间过滤
- if(star != null && star.length() > 0) {
- sb.append(" and t.FPUNCHCARDTIME >= TO_DATE('"+star+"', 'YYYY-MM-DD HH24:MI:SS')").append(" \n");
- }else if(end != null && end.length() > 0) {
- sb.append(" and t.FPUNCHCARDTIME <= TO_DATE('"+end+"', 'YYYY-MM-DD HH24:MI:SS')").append(" \n");
- }else {
- sb.append(" and t.FPUNCHCARDTIME >= sysdate -"+day).append(" \n");
- }
- if(number !=null && number.length() > 0) {
- sb.append(" and t1.fnumber in (").append(number).append(") \n");
- }
- sb.append(" order by t1.fid, t.FPUNCHCARDTIME desc ").append(" \n");//排序
- rs = DbUtil.executeQuery(ctx, sb.toString());
- while (rs.next()) {
- String pid = rs.getString("pid");
- String tfid = rs.getString("tfid");
- String proid = rs.getString("proid");
- String FPUNCHCARDPLACE = rs.getString("FPUNCHCARDPLACE"); //考勤位置打卡
- String CFCLOCKTIME = rs.getString("CFCLOCKTIME"); //年月日时分秒 打卡时间
- String CFCLOCKTIME1 = rs.getString("CFCLOCKTIME1"); //年月日--------当前
- String key = pid+CFCLOCKTIME1;//员工id+年月日为 一个 唯一组合
- //同一天不在多个项目情况下进行标记
- if(!listproid.contains(key)) {
- listproid.add(key);
- }
- //去重-年月日时分秒匹配-跳过
- if(mapdate.containsKey(key) && mapproid.get(key).equals(CFCLOCKTIME)) {
- continue;
- }
- if(mapInfo.containsKey(key)) {
- listInfo = mapInfo.get(key);
- }else {
- listInfo = new ArrayList<WorkHoursConfirmInfo>();
- keyList.add(key);
- mapproid.put(key, proid);
- mapdate.put(key, CFCLOCKTIME);
- }
- wInfo = getWConfirmInfo(ctx,pid, proid,proCFCLOCKLOCATION,FPUNCHCARDPLACE,simpleDateFormat.parse(CFCLOCKTIME),tfid);
- listInfo.add(wInfo);
- mapInfo.put(key, listInfo);
- }
- } catch (SQLException | ParseException e) {
- e.printStackTrace();
- }
- //写入打卡数据
- WorkHoursConfirmCollection addSubColl = new WorkHoursConfirmCollection();
- WorkHoursConfirmCollection addAudColl = new WorkHoursConfirmCollection();
-
- //多个项目且不在同一个项目情况下
- List<String> notList = new ArrayList<String>();
- if(listproid.size() > 0) {
- for (int i = 0; i < listproid.size(); i++) {
- String key = listproid.get(i);
- if(keypro.containsKey(key)) {
- proList = keypro.get(key);
- //当天有多个项目
- if(proList.size() > 1) {
- listInfo = mapInfo.get(key);
- List<String> addList = new ArrayList<String>();
- List<String> locaProList = new ArrayList<String>();
- List<String> idProList = new ArrayList<String>();
- boolean boolismu = false;
- //同一个打卡位置关联了多个项目
- for (int j = 0; j < listInfo.size(); j++) {
- wInfo = listInfo.get(j);
- if(wInfo.getProject() != null && wInfo.getClockLocation() != null) {
- String proid = wInfo.getProject().getId().toString();
- List<String> getclock = proCFCLOCKLOCATION.get(proid);
- if(getclock != null) {
- for (int k = 0; k < getclock.size(); k++) {
- if(getclock.get(k).contains(wInfo.getClockLocation())){
- if(locaProList.contains(wInfo.getClockLocation())) {
- if(!idProList.contains(proid)) {
- boolismu = true;
- }
- }else {
- if(!idProList.contains(proid)){
- idProList.add(proid);
- }
- locaProList.add(wInfo.getClockLocation());
- }
- }
- }
- }
- }
- }
- if(boolismu) {
- for (int j = 0; j < listInfo.size(); j++) {
- wInfo = listInfo.get(j);
- if(locaProList.contains(wInfo.getClockLocation())) {
- wInfo.setProject(null); //所属项目
- wInfo.setBillState(HRBillStateEnum.SAVED);//暂存
- addSubColl.add(wInfo);
- }
- }
- }
-
- for (int j = 0; j < listInfo.size(); j++) {
- wInfo = listInfo.get(j);
- if(wInfo.getClockLocation() != null && wInfo.getProject() != null && !addList.contains(wInfo.getSourceBillId())) {
- addList.add(wInfo.getSourceBillId());
- if(wInfo.getBillState().compareTo(HRBillStateEnum.AUDITED) == 0) {
- addAudColl.add(wInfo);
- }else {
- //匹配不上的
- addSubColl.add(wInfo);
- }
- }
- }
-
- for (int j = 0; j < listInfo.size(); j++) {
- wInfo = listInfo.get(j);
- if(wInfo.getClockLocation() != null && !addList.contains(wInfo.getSourceBillId())) {
- addList.add(wInfo.getSourceBillId());
- if(wInfo.getBillState().compareTo(HRBillStateEnum.AUDITED) == 0) {
- addAudColl.add(wInfo);
- }else {
- //匹配不上的
- addSubColl.add(wInfo);
- }
- }
- }
-
- notList.add(key);
- }
- }
- }
- }
- //剩余数据处理
- if (keyList.size() > 0){
- for (int i = 0; i < keyList.size(); i++) {
- String key = keyList.get(i);
- if(notList.contains(key)) {
- continue;
- }
- listInfo = mapInfo.get(key);
- for (int j = 0; j < listInfo.size(); j++) {
- wInfo = listInfo.get(j);
- //直接生效
- if(wInfo.getBillState().compareTo(HRBillStateEnum.AUDITED) == 0) {
- addAudColl.add(wInfo);
- }else {
- //匹配不上的
- addSubColl.add(wInfo);
- }
- }
- }
- }
- //提交工作流
- if(addSubColl.size() > 0) {
- CoreBaseCollection addSubCollnew = new CoreBaseCollection();
- List<String> addList = new ArrayList<String>();
- for (int i = 0; i < addSubColl.size(); i++) {
- WorkHoursConfirmInfo getinfo = addSubColl.get(i);
- if(getinfo.getClockLocation() != null && !addList.contains(getinfo.getSourceBillId())) {
- addList.add(getinfo.getSourceBillId());
- addSubCollnew.add(getinfo);
- }
- }
- if(addSubCollnew.size() > 0) {
- biz.submit(addSubCollnew);
- }
- }
- if(addAudColl.size() > 0) {
- CoreBaseCollection addAudCollNew = new CoreBaseCollection();
- List<String> addList = new ArrayList<String>();
- for (int i = 0; i < addAudColl.size(); i++) {
- WorkHoursConfirmInfo getinfo = addAudColl.get(i);
- if(getinfo.getClockLocation() != null && !addList.contains(getinfo.getSourceBillId())) {
- addList.add(getinfo.getSourceBillId());
- addAudCollNew.add(getinfo);
- }
- }
- if(addAudCollNew.size() > 0) {
- //保存处理-审核通过
- Result re = biz.addnew(addAudCollNew);
- LineResult lr = null;
- if(re != null && re.size() > 0){
- for (int i = 0; i < re.size(); i++) {
- lr = re.getLineResult(i);
- biz.setAudited(BOSUuid.read(lr.getPk().toString())); //-审核通过
- }
- }
- }
- }
- }
-
- /**
- * 解析为工时确认单
- * @param pid
- * @param proid
- * @param p1
- * @param p2
- * @param clockTime
- * @return
- */
- private WorkHoursConfirmInfo getWConfirmInfo(Context ctx,String pid,String proid,Map<String,List<String>> map,String p2,Date clockTime,String FSOURCEBILLID) {
- WorkHoursConfirmInfo wInfo = new WorkHoursConfirmInfo();
- PersonInfo pinfo = new PersonInfo();pinfo.setId(BOSUuid.read(pid)); //人员
-
- PersonCollection personCollection = null;
- try {
- personCollection = PersonFactory.getLocalInstance(ctx).getPersonCollection(" select * where id = '"+pid+"'");
- } catch (BOSException e) {
- e.printStackTrace();
- }
- if(personCollection != null && personCollection.size()>0){
- pinfo = personCollection.get(0);
- }
-
- ProjectManagementInfo proinfo = new ProjectManagementInfo();proinfo.setId(BOSUuid.read(proid)); //所属项目
- wInfo.setEmployee(pinfo);
- wInfo.setProject(proinfo); //所属项目
- wInfo.setClockDate(clockTime); //打卡日期
- wInfo.setSourceBillId(FSOURCEBILLID);//来源id
- wInfo.setHrOrgUnit(pinfo.getHrOrgUnit());
- wInfo.setCU(pinfo.getCU());
- Timestamp t = new Timestamp(clockTime.getTime());
- wInfo.setClockTime(t); //打卡--------------------------------------------------------------------------------------------------------------
- //打卡位置 clockLocation
- if(map != null) {
- List<String> plist = map.get(proid);
- if(plist != null && plist.contains(p2)) {
- wInfo.setClockLocation(p2);
- wInfo.setBillState(HRBillStateEnum.AUDITED);//审核通过
- }else {
- if(p2 != null && p2.length() > 0){
- wInfo.setClockLocation(p2);
- }
- wInfo.setProject(null); //所属项目
- wInfo.setBillState(HRBillStateEnum.SAVED);//暂存
- }
- }else {
- wInfo.setProject(null); //所属项目
- wInfo.setBillState(HRBillStateEnum.SAVED);//暂存
- }
- return wInfo;
- }
-
- }
|