Commit 585a838a authored by 廖旭伟's avatar 廖旭伟

确保每个员工只能有一条假期余额记录

parent dc5a897c
package com.mortals.xhx.module.attendance.service.impl;
import com.mortals.xhx.module.attendance.model.AttendanceVacationBalanceQuery;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
......@@ -15,5 +19,42 @@ import com.mortals.xhx.module.attendance.service.AttendanceVacationBalanceServic
*/
@Service("attendanceVacationBalanceService")
public class AttendanceVacationBalanceServiceImpl extends AbstractCRUDServiceImpl<AttendanceVacationBalanceDao, AttendanceVacationBalanceEntity, Long> implements AttendanceVacationBalanceService {
@Autowired
private StaffService staffService;
@Override
protected void saveBefore(AttendanceVacationBalanceEntity entity, Context context) throws AppException {
super.saveBefore(entity,context);
if(entity.getStaffId()==null){
throw new AppException("员工ID不能为空");
}
StaffEntity staff = staffService.get(entity.getStaffId());
if(staff==null){
throw new AppException("员工ID不正确");
}
entity.setStaffName(staff.getName());
entity.setDeptId(staff.getDeptId());
entity.setDeptName(staff.getDeptName());
}
@Override
public AttendanceVacationBalanceEntity save(AttendanceVacationBalanceEntity entity, Context context) throws AppException {
this.saveBefore(entity, context);
AttendanceVacationBalanceEntity temp = this.selectOne(new AttendanceVacationBalanceQuery().staffId(entity.getStaffId()));
int iRet = 0;
if(temp!=null){
entity.setId(temp.getId());
iRet = this.dao.update(entity);
}else {
iRet = this.dao.insert(entity);
}
if (iRet == 0) {
throw new AppException(-1001, "写入数据库失败!");
} else {
this.saveAfter(entity, context);
return entity;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment