-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
64 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 30 additions & 6 deletions
36
src/main/scala/poc/service/impl/TimetableServiceImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,61 @@ | ||
package poc.service.impl | ||
|
||
import java.sql.Timestamp | ||
import java.util.Calendar | ||
import java.util.Date | ||
|
||
import scala.collection.immutable.StringOps | ||
import scala.reflect.BeanProperty | ||
|
||
import org.squeryl.PrimitiveTypeMode._ | ||
import poc.model.Timetable | ||
import poc.model.Cashier | ||
import poc.resources.Snippets._ | ||
import poc.resources.TimetableView | ||
import poc.schema.TimetableDb._ | ||
import poc.service.TimetableService | ||
import poc.schema.BootStrap | ||
import poc.model.WorkingTimeRange | ||
|
||
class TimetableServiceImpl extends TimetableService { | ||
|
||
val BEGIN_HOUR = 8 | ||
val BEGIN_MINUTE = 30 | ||
|
||
def cashierTimetable(year: String, week: String, name: String): TimetableView = { | ||
|
||
implicit def string2Int(s: String): Int = new StringOps(s).toInt | ||
|
||
val cal = Calendar.getInstance | ||
cal.set(Calendar.YEAR, year) | ||
cal.set(Calendar.WEEK_OF_YEAR, week) | ||
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY) | ||
cal.set(Calendar.HOUR_OF_DAY, BEGIN_HOUR) | ||
cal.set(Calendar.MINUTE, BEGIN_MINUTE) | ||
|
||
val workingTime = (new Date(), new Date())::Nil | ||
TimetableView(name, (workingTime).toArray, cal.getTime, countTime(workingTime)) | ||
inTransaction { | ||
Timetable.findByWeekAndCashier(name, new Timestamp(cal.getTime.getTime)) | ||
} match { | ||
case Some(t) => TimetableView(name, workingTime.toArray, t.startWeek, countTime(workingTime)) | ||
case None => TimetableView(name, workingTime.toArray, cal.getTime, 0L) | ||
} | ||
} | ||
|
||
def saveSelection(name: String, selection: String, startWeekIdx: Long): TimetableView = { | ||
val workingTime = groupWorkingTimeList(string2Date(selection.split(',').toList)) | ||
TimetableView(name, (workingTime).toArray, new Date(startWeekIdx), countTime(workingTime)) | ||
val week = new Timestamp(startWeekIdx) | ||
transaction { | ||
val timetable = Timetable.findByWeekAndCashier(name, week).getOrElse( | ||
timetables.insert(new Timetable(week, Cashier.findByName(name).id))) | ||
timetable.workingTimeRanges.deleteAll | ||
for (timeRange <- workingTime) { | ||
val wtr = new WorkingTimeRange(new Timestamp(timeRange._1.getTime), | ||
new Timestamp(timeRange._2.getTime), timetable.id) | ||
timetable.workingTimeRanges.associate(wtr) | ||
} | ||
} | ||
|
||
TimetableView(name, workingTime.toArray, new Date(startWeekIdx), countTime(workingTime)) | ||
} | ||
|
||
} | ||
|