class ArrangementManagementServiceImpl implements ArrangementManagementService {

    @Override
    public CommonResult modifyArrangements(ArrangementParam arrangementParam){
        int count = 0;
        List<Arrangement> arrangements = arrangementParam.getArrangements();
        Date startDate = Date.valueOf(arrangementParam.getStartDate());
        Date endDate = Date.valueOf(arrangementParam.getEndDate());
        Integer departmentId = arrangementParam.getDepartmentId();

        //参数检验
        if(startDate.compareTo(endDate) > 0)
            return CommonResult.fail(ResultCode.E_809);
        if(departmentId == null)
            return CommonResult.fail(ResultCode.E_801);

        //删除时间段内的排班结果
        arrangementMapper.deleteByDepartmentIdAndDatePeriod(startDate, endDate, departmentId);
        //新增修改后的排班结果
        for(Arrangement arrangement : arrangements){
            arrangement.setDepartmentId(departmentId);
            count += arrangementMapper.insertSelective(arrangement);
        }

        return CommonResult.success(count);

    }

}