|
|
|
@ -3,6 +3,7 @@ package com.ccsens.common.service; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.ccsens.common.bean.dto.CClockingInDto; |
|
|
|
import com.ccsens.common.bean.po.ProClockingIn; |
|
|
|
@ -10,12 +11,16 @@ import com.ccsens.common.bean.po.ProMember; |
|
|
|
import com.ccsens.common.bean.vo.CClockingInVo; |
|
|
|
import com.ccsens.common.persist.dao.ProClockingInDao; |
|
|
|
import com.ccsens.common.persist.dao.ProMemberDao; |
|
|
|
import com.ccsens.common.util.CommonCodeError; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.text.DateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
@ -29,6 +34,8 @@ public class ClockingInService implements IClockingInService { |
|
|
|
private ProMemberDao memberDao; |
|
|
|
@Resource |
|
|
|
private ProClockingInDao clockingInDao; |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<CClockingInVo.ClockingInInfo> queryClockingIn(CClockingInDto.QueryClockingIn params, Long userId) { |
|
|
|
@ -91,6 +98,46 @@ public class ClockingInService implements IClockingInService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void punchTheClock(CClockingInDto.PunchTheClock params, Long userId) { |
|
|
|
//判断选择打卡的成员和当前用户是否匹配
|
|
|
|
ProMember proMember = memberDao.selectByPrimaryKey(params.getMemberId()); |
|
|
|
if(ObjectUtil.isNull(proMember) || proMember.getUserId().equals(userId)){ |
|
|
|
throw new BaseException(CommonCodeError.MEMBER_NOT_MINE); |
|
|
|
} |
|
|
|
//验证打卡日期是否是今天
|
|
|
|
DateFormat df = new SimpleDateFormat("yy-MM-dd"); |
|
|
|
String format = df.format(new Date()); |
|
|
|
log.info("获取今天的日期:{}",format); |
|
|
|
if(!format.equalsIgnoreCase(params.getDateTime().toString())){ |
|
|
|
throw new BaseException(CommonCodeError.DATE_ERROR); |
|
|
|
} |
|
|
|
//判断是否有打卡记录
|
|
|
|
if(ObjectUtil.isNotNull(params.getId())){ |
|
|
|
//如果有记录则查找记录并修改
|
|
|
|
ProClockingIn proClockingIn = clockingInDao.selectByPrimaryKey(params.getId()); |
|
|
|
if(params.getClockType() == 0 && proClockingIn.getMorningStatus() == 0){ |
|
|
|
proClockingIn.setMorning(System.currentTimeMillis()); |
|
|
|
proClockingIn.setMorningStatus((byte) 1); |
|
|
|
}else if(params.getClockType() == 1 && proClockingIn.getNightStatus() == 0){ |
|
|
|
proClockingIn.setNight(System.currentTimeMillis()); |
|
|
|
proClockingIn.setNightStatus((byte) 1); |
|
|
|
} |
|
|
|
proClockingIn.setCheckerId(params.getCheckerId()); |
|
|
|
clockingInDao.updateByPrimaryKeySelective(proClockingIn); |
|
|
|
}else { |
|
|
|
//如果没有记录,则添加一条新的记录
|
|
|
|
ProClockingIn proClockingIn = new ProClockingIn(); |
|
|
|
proClockingIn.setId(snowflake.nextId()); |
|
|
|
proClockingIn.setMemberId(params.getMemberId()); |
|
|
|
proClockingIn.setCheckerId(params.getCheckerId()); |
|
|
|
if(params.getClockType() == 0){ |
|
|
|
proClockingIn.setMorning(System.currentTimeMillis()); |
|
|
|
proClockingIn.setMorningStatus((byte) 1); |
|
|
|
}else if(params.getClockType() == 1){ |
|
|
|
proClockingIn.setNight(System.currentTimeMillis()); |
|
|
|
proClockingIn.setNightStatus((byte) 1); |
|
|
|
} |
|
|
|
clockingInDao.insertSelective(proClockingIn); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|