LineController.groovy
上传用户:steveyhw
上传日期:2019-05-13
资源大小:307k
文件大小:5k
- import java.text.SimpleDateFormat
- class LineController {
-
- def index = { redirect(action:list,params:params) }
- // the delete, save and update actions only accept POST requests
- def allowedMethods = [delete:'POST', save:'POST', update:'POST']
- def list = {
- //if(!params.max) params.max = 10
- //[ lineInstanceList: Line.list( params ) ]
- /*
- println 'to line.list '
- println '_lineType_id:'+params._staType_id
- def df = new SimpleDateFormat('yyyy-MM-dd')
- if(!params.max) params.max = '2'
- if(!params.sort)params.sort = 'staId'
- if(!params.offset)params.offset = '0'
- if(!params.order)params.order = 'asc'
- if(!params._staId)params._staId = ''
- if(!params._staName)params._staName = ''
- java.util.Date _staLastchangefrom =null
- java.util.Date _staLastchangeto =null
- String staTypeSql =''
- if(!params._staLastchangefrom){
- _staLastchangefrom = df.parse('1970-01-01')
- }else{_staLastchangefrom = df.parse(params._staLastchangefrom)}
- if(!params._staLastchangeto){
- _staLastchangeto = new Date()
- }else{_staLastchangeto = df.parse(params._staLastchangeto)}
- if(params._staType_id&¶ms._staType_id!='')staTypeSql = " and str(s.staType.id) = '${params._staType_id}' "
- if(!params._staDel)params._staDel = null
- println '_staDel :'+params._staDel
- def _staDelState = '0'
- if(params._staDel == 'on'){
- _staDelState = ''
- } else if(params._staDel == null){ _staDelState = '0' }
- println '_staDelState :'+_staDelState
- println params
- def results=null
- println 'between '+_staLastchangefrom+' and '+_staLastchangeto
- results = Staff.findAll("from Staff s where s.staId like :_staId and s.staName like :_staName and s.staLastchange between :_staLastchangefrom and :_staLastchangeto $staTypeSql and s.staDel like :_staDelState order by ${params.sort} ${params.order} ",
- [_staId:'%'+params._staId+'%',_staName:'%'+params._staName+'%',_staLastchangefrom:_staLastchangefrom,_staLastchangeto:_staLastchangeto,_staDelState:'%'+_staDelState+'%'],[max:Integer.parseInt(params.max),offset:Integer.parseInt(params.offset)])
- params.count=Staff.findAll("from Staff s where s.staId like :_staId and s.staName like :_staName and s.staLastchange between :_staLastchangefrom and :_staLastchangeto $staTypeSql and s.staDel like :_staDelState order by ${params.sort} ${params.order} ",
- [_staId:'%'+params._staId+'%',_staName:'%'+params._staName+'%',_staLastchangefrom:_staLastchangefrom,_staLastchangeto:_staLastchangeto,_staDelState:'%'+_staDelState+'%']).size()
- render(view:'list',model:[staffList:results]) */
- }
- def show = {
- def lineInstance = Line.get( params.id )
- if(!lineInstance) {
- flash.message = "lineInstance.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Line not found with id ${params.id}"
- redirect(action:list)
- }
- else { return [ lineInstance : lineInstance ] }
- }
- def delete = {
- def lineInstance = Line.get( params.id )
- if(lineInstance) {
- lineInstance.delete()
- flash.message = "lineInstance.deleted"
- flash.args = [params.id]
- flash.defaultMessage = "Line ${params.id} deleted"
- redirect(action:list)
- }
- else {
- flash.message = "lineInstance.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Line not found with id ${params.id}"
- redirect(action:list)
- }
- }
- def edit = {
- def lineInstance = Line.get( params.id )
- if(!lineInstance) {
- flash.message = "lineInstance.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Line not found with id ${params.id}"
- redirect(action:list)
- }
- else {
- return [ line : lineInstance ]
- }
- }
- def update = {
- def lineInstance = Line.get( params.id )
- if(lineInstance) {
- lineInstance.properties = params
- if(!lineInstance.hasErrors() && lineInstance.save()) {
- flash.message = "lineInstance.updated"
- flash.args = [params.id]
- flash.defaultMessage = "Line ${params.id} updated"
- redirect(action:show,id:lineInstance.id)
- }
- else {
- render(view:'edit',model:[lineInstance:lineInstance])
- }
- }
- else {
- flash.message = "lineInstance.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Line not found with id ${params.id}"
- redirect(action:edit,id:params.id)
- }
- }
- def create = {
- def lineInstance = new Line()
- lineInstance.properties = params
- return ['lineInstance':lineInstance]
- }
- def save = {
- def lineInstance = new Line(params)
- if(!lineInstance.hasErrors() && lineInstance.save()) {
- flash.message = "lineInstance.created"
- flash.args = ["${lineInstance.id}"]
- flash.defaultMessage = "Line ${lineInstance.id} created"
- redirect(action:show,id:lineInstance.id)
- }
- else {
- render(view:'create',model:[lineInstance:lineInstance])
- }
- }
- }