package com.product.administration.service; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.product.administration.config.CmnConst; import com.product.administration.config.SystemCode; import com.product.common.lang.StringUtils; import com.product.core.dao.BaseDao; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.exception.BaseException; import com.product.core.service.support.AbstractBaseService; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.module.sys.entity.SystemUser; /** * 打卡记录 * Copyright PRODUCT-BASE * @Title: PRODUCT-BASE- * @Project: PunchRecordService * @Date: 2021年8月9日 上午11:30:38 * @Author: 杜洪波 * @Description: */ @Component public class PunchRecordService extends AbstractBaseService{ @Autowired BaseDao baseDao; /** * 考勤打卡列表 * @param fse * @return */ public DataTableEntity listRecordInfo(FieldSetEntity fse) { DataTableEntity dt=baseDao.listTable(CmnConst.PRODUCT_OA_PUNCH_RECORD, "created_by=?", new Object[] {SpringMVCContextHolder.getCurrentUser().getUser_id()}, null, null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE)); dt.setFieldFormat("punch_time_one", "yyyy-MM-dd HH:mm:ss"); dt.setFieldFormat("punch_time_three", "yyyy-MM-dd HH:mm:ss"); baseDao.loadPromptData(dt); return dt; } /** * 考勤打卡详情 * @param uuid * @return */ public FieldSetEntity findRecordInfo(String uuid) { return baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_PUNCH_RECORD, uuid, true); } /** * 考勤打卡新增 * @param fse * @return */ public String addRecordInfo(FieldSetEntity fse) { SimpleDateFormat df = new SimpleDateFormat(CmnConst.YYYYMMDDHHMMSS); SystemUser currentUser=SpringMVCContextHolder.getCurrentUser(); //获取打卡人 Date created_datetime=fse.getDate("created_datetime"); //获取打卡时间 // Date created_datetime=new Date(); //获取打卡时间 String string_created_datetime=df.format(created_datetime); //时间转string //获取公司打卡时间配置信息 FieldSetEntity fseCompanyPunch=baseDao.getFieldSetEntityByFilter("product_oa_punch_time", "org_level_uuid=?", new Object[] {currentUser.getOrg_level_uuid()}, false); if (fseCompanyPunch==null) { throw new BaseException(SystemCode.SYSTEM_CONMAPNY_PUNCH_NO_EXIST.getValue(), SystemCode.SYSTEM_CONMAPNY_PUNCH_NO_EXIST.getText(), this.getClass(), "addRecordInfo"); } //获取当天打卡信息 FieldSetEntity fsePunchInfo=baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_OA_PUNCH_RECORD, "created_by=? and DATE_FORMAT(created_utc_datetime,'%Y-%m-%d')like ?", new Object[] {currentUser.getUser_id(),string_created_datetime.substring(0, 10)+"%"}, false); if (fsePunchInfo==null) { FieldSetEntity fseNewPunchInfo = new FieldSetEntity(); fseNewPunchInfo.setTableName(CmnConst.PRODUCT_OA_PUNCH_RECORD); fseNewPunchInfo.setValue(CmnConst.ORG_LEVEL_UUID, currentUser.getOrg_level_uuid()); fseNewPunchInfo.setValue(CmnConst.DEPT_UUID, currentUser.getDept_uuid()); fseNewPunchInfo.setValue(CmnConst.CREATED_BY, currentUser.getUser_id()); fseNewPunchInfo.setValue(CmnConst.CREATED_UTC_DATETIME, created_datetime); fseNewPunchInfo.setValue("punch_time_one", created_datetime); //新增打卡信息 return baseDao.add(fseNewPunchInfo); }else { //打卡模式(0:双卡 1:四卡) int punchMode=0; if (StringUtils.isEmpty(fseCompanyPunch.getString("work_time_two"))) { punchMode=1; } String punch_time_one=fsePunchInfo.getDate("punch_time_one", CmnConst.YYYYMMDDHHMMSS); String punch_time_two=fsePunchInfo.getDate("punch_time_two", CmnConst.YYYYMMDDHHMMSS); String punch_time_three=fsePunchInfo.getDate("punch_time_three", CmnConst.YYYYMMDDHHMMSS); String punch_time_four=fsePunchInfo.getDate("punch_time_four", CmnConst.YYYYMMDDHHMMSS); List list=new ArrayList<>(); if (punch_time_one!=null) { list.add(punch_time_one); } if (punch_time_two!=null) { list.add(punch_time_two); } if (punch_time_three!=null) { list.add(punch_time_three); } if (punch_time_four!=null) { list.add(punch_time_four); } list.add(string_created_datetime); Collections.sort(list); for (int i = 0; i < list.size(); i++) { if (punchMode==1) { if (i==0) { fsePunchInfo.setValue("punch_time_one", list.get(i)); }else if (i==1) { fsePunchInfo.setValue("punch_time_four", list.get(i)); } }else { if (i==0) { fsePunchInfo.setValue("punch_time_one", list.get(i)); }else if (i==1) { fsePunchInfo.setValue("punch_time_two", list.get(i)); }else if (i==2) { fsePunchInfo.setValue("punch_time_three", list.get(i)); }else if (i==3) { fsePunchInfo.setValue("punch_time_four", list.get(i)); } } } //修改打卡信息 baseDao.update(fsePunchInfo); return fsePunchInfo.getUUID(); } } }