QuotationController.groovy
上传用户:steveyhw
上传日期:2019-05-13
资源大小:307k
文件大小:8k
- import java.text.SimpleDateFormat
- class QuotationController {
-
- 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._quoBase)params._quoBase = '0.0'
- if(!params._quoName)params._quoName = ''
- if(!params._quoFactory)params._quoFactory = ''
- String quoTypeSql = ""
- if(params._quoType_id)quoTypeSql = " and str(q.quoType) = '${params._quoType_id}' "
- java.util.Date _quoLastchangefrom =null
- java.util.Date _quoLastchangeto =null
- if(!params._quoLastchangefrom){
- _quoLastchangefrom = df.parse('1970-01-01')
- }else{_quoLastchangefrom = df.parse(params._quoLastchangefrom)}
- if(!params._quoLastchangeto){
- _quoLastchangeto = new Date()
- }else{_quoLastchangeto = df.parse(params._quoLastchangeto)}
- if(!params._quoDel)params._quoDel = null
- println '_quoDel :'+params._quoDel
- def _quoDelState = '0'
- if(params._quoDel == 'on'){
- _quoDelState = ''
- } else if(params._quoDel == null){ _quoDelState = '0' }
- println '_quoDelState :'+_quoDelState
- println params
- def results=null
- println 'between '+_quoLastchangefrom+' and '+_quoLastchangeto
- //
- println 'sql:'+quoTypeSql
- results = Quotation.findAll("from Quotation q where str(q.quoName) like :_quoName and q.quoFactory like :_quoFactory ${quoTypeSql} and q.quoLastchange between :_quoLastchangefrom and :_quoLastchangeto and q.quoDel like :_quoDelState order by ${params.sort} ${params.order} ",
- [_quoName:'%'+params._quoName+'%',_quoFactory:'%'+params._quoFactory+'%',_quoLastchangefrom:_quoLastchangefrom,_quoLastchangeto:_quoLastchangeto,_quoDelState:'%'+_quoDelState+'%'],[max:Integer.parseInt(params.max),offset:Integer.parseInt(params.offset)])
- params.count=Quotation.findAll("from Quotation q where str(q.quoName) like :_quoName and q.quoFactory like :_quoFactory ${quoTypeSql} and q.quoLastchange between :_quoLastchangefrom and :_quoLastchangeto and q.quoDel like :_quoDelState order by ${params.sort} ${params.order} ",
- [_quoName:'%'+params._quoName+'%',_quoFactory:'%'+params._quoFactory+'%',_quoLastchangefrom:_quoLastchangefrom,_quoLastchangeto:_quoLastchangeto,_quoDelState:'%'+_quoDelState+'%']).size()
- println 'params._quoDel '+params._quoDel
- render(view:'list',model:[quotationList:results])
- }
- def show = {
- def quotation = Quotation.get( params.id )
- if(!quotation) {
- flash.message = "quotation.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Quotation not found with id ${params.id}"
- redirect(action:list,params:[_quoName:params._quoName,_quoFactory:params._quoFactory,_quoType_id:params._quoType_id,_quoLastchangefrom:params._quoLastchangefrom,_quoLastchangeto:params._quoLastchangeto,_quoDel:params._quoDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else { return [ quotation : quotation ] }
- }
- def delete = {
- def quotation = Quotation.get( params.id )
- if(quotation) {
- //quotation.delete()
- //设定删除状态 创建/更新时间 或人
- quotation.quoDel = '1'
- quotation.quoLastchange = new Date()
- quotation.quoLastchanger = 'session'
- quotation.save()
- flash.message = "quotation.deleted"
- flash.args = [params.id]
- flash.defaultMessage = "Quotation ${params.id} deleted"
- redirect(action:list,params:[_quoName:params._quoName,_quoFactory:params._quoFactory,_quoType_id:params._quoType_id,_quoLastchangefrom:params._quoLastchangefrom,_quoLastchangeto:params._quoLastchangeto,_quoDel:params._quoDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- flash.message = "quotation.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Quotation not found with id ${params.id}"
- redirect(action:list,params:[_quoName:params._quoName,_quoFactory:params._quoFactory,_quoType_id:params._quoType_id,_quoLastchangefrom:params._quoLastchangefrom,_quoLastchangeto:params._quoLastchangeto,_quoDel:params._quoDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- }
- def edit = {
- def quotation = Quotation.get( params.id )
- if(!quotation) {
- flash.message = "quotation.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Quotation not found with id ${params.id}"
- redirect(action:list,params:[_quoName:params._quoName,_quoFactory:params._quoFactory,_quoType_id:params._quoType_id,_quoLastchangefrom:params._quoLastchangefrom,_quoLastchangeto:params._quoLastchangeto,_quoDel:params._quoDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- println ''+params
- return [ quotation : quotation ]
- }
- }
- def update = {
- def quotation = Quotation.get( params.id )
- if(quotation) {
- quotation.properties = params
- //设定删除状态 更新人更新时间
- quotation.quoDel = '0'
- quotation.quoLastchanger = 'session'
- quotation.quoLastchange = new Date()
-
- if(!quotation.hasErrors() && quotation.save()) {
- flash.message = "quotation.updated"
- flash.args = [params.id]
- flash.defaultMessage = "Quotation ${params.id} updated"
- redirect(action:show,id:quotation.id,params:[_quoName:params._quoName,_quoFactory:params._quoFactory,_quoType_id:params._quoType_id,_quoLastchangefrom:params._quoLastchangefrom,_quoLastchangeto:params._quoLastchangeto,_quoDel:params._quoDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'edit',model:[quotation:quotation])
- }
- }
- else {
- flash.message = "quotation.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Quotation not found with id ${params.id}"
- redirect(action:edit,id:params.id,params:[_quoName:params._quoName,_quoFactory:params._quoFactory,_quoType_id:params._quoType_id,_quoLastchangefrom:params._quoLastchangefrom,_quoLastchangeto:params._quoLastchangeto,_quoDel:params._quoDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- }
- def create = {
- def quotation = new Quotation()
- quotation.properties = params
- return ['quotation':quotation]
- }
- def save = {
- String quoid=Quotation.executeQuery("select max(q.quoId) from Quotation q ")[0]
- println quoid
- if(quoid=="null"||quoid==null){
- quoid = 'QUO100000000'
- }else { quoid='QUO'+(Integer.parseInt(quoid.substring(3,12))+1)}
-
- def quotation = new Quotation(params)
- quotation.quoId = quoid //设置编号
- //设定删除状态 创建人创建时间 更新人更新时间
- quotation.quoDel = '0'
- quotation.quoCreater = 'session'
- quotation.quoCreatetime = new Date()
- quotation.quoLastchanger = 'session'
- quotation.quoLastchange = new Date()
- if(!quotation.hasErrors() && quotation.save()) {
- flash.message = "quotation.created"
- flash.args = ["${quotation.id}"]
- flash.defaultMessage = "Quotation ${quotation.id} created"
- redirect(action:show,id:quotation.id,params:[_quoName:params._quoName,_quoFactory:params._quoFactory,_quoType_id:params._quoType_id,_quoLastchangefrom:params._quoLastchangefrom,_quoLastchangeto:params._quoLastchangeto,_quoDel:params._quoDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'create',model:[quotation:quotation])
- }
- }
- }