ApplicatController.groovy
上传用户:steveyhw
上传日期:2019-05-13
资源大小:307k
文件大小:8k
- import java.text.SimpleDateFormat
- class ApplicatController {
-
- 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 = {
- def df = new SimpleDateFormat('yyyy-MM-dd')
- if(!params.max) params.max = '2'
- if(!params.sort)params.sort = 'id'
- if(!params.offset)params.offset = '0'
- if(!params.order)params.order = 'asc'
- if(!params._Requestman)params._Requestman = ''
- String appTypeSql = ""
- String appStateSql = ""
- if(params._appType_id)appTypeSql = " and str(a.appType.id) = '${params._appType_id}' "
- if(params._appState_id)appStateSql = " and str(a.appState.id) = '${params._appState_id}' "
- java.util.Date _appLastchangefrom =null
- java.util.Date _appLastchangeto =null
- if(!params._appLastchangefrom){
- _appLastchangefrom = df.parse('1970-01-01')
- }else{_appLastchangefrom = df.parse(params._appLastchangefrom)}
- if(!params._appLastchangeto){
- _appLastchangeto = new Date()
- }else{_appLastchangeto = df.parse(params._appLastchangeto)}
- if(!params._appDel)params._appDel = null
- println '_appDel :'+params._appDel
- def _appDelState = '0'
- if(params._appDel == 'on'){
- _appDelState = ''
- } else if(params._appDel == null || params._appDel == ""){ _appDelState = '0' }
- println '_appDelState :'+_appDelState
- println 'in list'+params
- def results=null
- println 'between '+_appLastchangefrom+' and '+_appLastchangeto
- println 'sql:'+appTypeSql+appStateSql
- results = Applicat.findAll("from Applicat a where str(a.appRequestman.staName) like :_Requestman ${appTypeSql+appStateSql} and a.appLastchange between :_appLastchangefrom and :_appLastchangeto and a.appDel like :_appDelState order by ${params.sort} ${params.order} ",
- [_Requestman:'%'+params._Requestman+'%',_appLastchangefrom:_appLastchangefrom,_appLastchangeto:_appLastchangeto,_appDelState:'%'+_appDelState+'%'],[max:Integer.parseInt(params.max),offset:Integer.parseInt(params.offset)])
- params.count=Applicat.findAll("from Applicat a where str(a.appRequestman.staName) like :_Requestman ${appTypeSql+appStateSql} and a.appLastchange between :_appLastchangefrom and :_appLastchangeto and a.appDel like :_appDelState order by ${params.sort} ${params.order} ",
- [_Requestman:'%'+params._Requestman+'%',_appLastchangefrom:_appLastchangefrom,_appLastchangeto:_appLastchangeto,_appDelState:'%'+_appDelState+'%']).size()
- println 'params._appDel '+params._appDel
- render(view:'list',model:[applicatList:results])
- }
- def show = {
- def applicat = Applicat.get( params.id )
- if(!applicat) {
- flash.message = "applicat.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Applicat not found with id ${params.id}"
- redirect(action:list,params:[_Requestman:params._Requestman,_appType_id:params._appType_id,_appState_id:params._appState_id,_appLastchangefrom:params._appLastchangefrom,_appLastchangeto:params._appLastchangeto,_appDel:params._appDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else { return [ applicat : applicat ] }
- }
- def delete = {
- def applicat = Applicat.get( params.id )
- if(applicat) {
- //设定删除状态 更新人更新时间
- applicat.appDel = '1'
- applicat.appLastchanger = 'session'
- applicat.appLastchange = new Date()
- applicat.save()
- flash.message = "applicat.deleted"
- flash.args = [params.id]
- flash.defaultMessage = "Applicat ${params.id} deleted"
- redirect(action:list,params:[_Requestman:params._Requestman,_appType_id:params._appType_id,_appState_id:params._appState_id,_appLastchangefrom:params._appLastchangefrom,_appLastchangeto:params._appLastchangeto,_appDel:params._appDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- flash.message = "applicat.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Applicat not found with id ${params.id}"
- redirect(action:list,params:[_Requestman:params._Requestman,_appType_id:params._appType_id,_appState_id:params._appState_id,_appLastchangefrom:params._appLastchangefrom,_appLastchangeto:params._appLastchangeto,_appDel:params._appDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- }
- def edit = {
- def applicat = Applicat.get( params.id )
- if(!applicat) {
- flash.message = "applicat.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Applicat not found with id ${params.id}"
- redirect(action:list,params:[_Requestman:params._Requestman,_appType_id:params._appType_id,_appState_id:params._appState_id,_appLastchangefrom:params._appLastchangefrom,_appLastchangeto:params._appLastchangeto,_appDel:params._appDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- return [ applicat : applicat ]
- }
- }
- def update = {
- def applicat = Applicat.get( params.id )
- if(applicat) {
- applicat.properties = params
- //设定删除状态 创建人创建时间 更新人更新时间
- applicat.appDel = '0'
- applicat.appLastchanger = 'session'
- applicat.appLastchange = new Date()
- if(!applicat.hasErrors() && applicat.save()) {
- flash.message = "applicat.updated"
- flash.args = [params.id]
- flash.defaultMessage = "Applicat ${params.id} updated"
- redirect(action:show,id:applicat.id,params:[_Requestman:params._Requestman,_appType_id:params._appType_id,_appState_id:params._appState_id,_appLastchangefrom:params._appLastchangefrom,_appLastchangeto:params._appLastchangeto,_appDel:params._appDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'edit',model:[applicat:applicat])
- }
- }
- else {
- flash.message = "applicat.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Applicat not found with id ${params.id}"
- redirect(action:edit,id:params.id,params:[_Requestman:params._Requestman,_appType_id:params._appType_id,_appState_id:params._appState_id,_appLastchangefrom:params._appLastchangefrom,_appLastchangeto:params._appLastchangeto,_appDel:params._appDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- }
- def create = {
- def applicat = new Applicat()
- applicat.properties = params
- return ['applicat':applicat]
- }
- def save = {
- def applicat = new Applicat(params)
- //设定删除状态 创建人创建时间 更新人更新时间
- applicat.appDel = '0'
- applicat.appCreater = 'session'
- applicat.appCreatetime = new Date()
- applicat.appLastchanger = 'session'
- applicat.appLastchange = new Date()
- applicat.appState = Code.findByCkindAndCodValue1(Ckind.findByCkiFlag('PermitState'),'waitCheck')
- if(!applicat.hasErrors() && applicat.save()) {
- flash.message = "applicat.created"
- flash.args = ["${applicat.id}"]
- flash.defaultMessage = "Applicat ${applicat.id} created"
- redirect(action:show,id:applicat.id,params:[_Requestman:params._Requestman,_appType_id:params._appType_id,_appState_id:params._appState_id,_appLastchangefrom:params._appLastchangefrom,_appLastchangeto:params._appLastchangeto,_appDel:params._appDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'create',model:[applicat:applicat])
- }
- }
- }