ContractController.groovy
上传用户:steveyhw
上传日期:2019-05-13
资源大小:307k
文件大小:10k
- import java.text.SimpleDateFormat
- class ContractController {
-
- def index = { redirect(action:list,params:params) }
- // the delete, save and update actions only accept POST requests
- def allowedMethods = [list:['GET','POST'],delete:'POST', save:'POST', update:['POST','GET']]
- 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._conId)params._conId = ''
- if(!params._conMan)params._conMan = ''
- java.util.Date _conLastchangefrom =null
- java.util.Date _conLastchangeto =null
- if(!params._conLastchangefrom){
- _conLastchangefrom = df.parse('1970-01-01')
- }else{_conLastchangefrom = df.parse(params._conLastchangefrom)}
- if(!params._conLastchangeto){
- _conLastchangeto = new Date()
- }else{_conLastchangeto = df.parse(params._conLastchangeto)}
- if(!params._conDel)params._conDel = null
- println '_conDel :'+params._conDel
- def _conDelState = '0'
- if(params._conDel == 'on'){
- _conDelState = ''
- } else if(params._conDel == null){ _conDelState = '0' }
- println '_conDelState :'+_conDelState
- println 'in list'+params
- def results=null
- println 'between '+_conLastchangefrom+' and '+_conLastchangeto
- println 'params._staType_id '+ params._staType_id
- if(!params._staType_id){
- results = Contract.findAll("from Contract c where c.conId like :_conId and c.conMan.staName like :_conMan and c.conLastchange between :_conLastchangefrom and :_conLastchangeto and c.conDel like :_conDelState order by ${params.sort} ${params.order} ",
- [_conId:'%'+params._conId+'%',_conMan:'%'+params._conMan+'%',_conLastchangefrom:_conLastchangefrom,_conLastchangeto:_conLastchangeto,_conDelState:'%'+_conDelState+'%'],[max:Integer.parseInt(params.max),offset:Integer.parseInt(params.offset)])
- params.count=Contract.findAll("from Contract c where c.conId like :_conId and c.conMan.staName like :_conMan and c.conLastchange between :_conLastchangefrom and :_conLastchangeto and c.conDel like :_conDelState order by ${params.sort} ${params.order} ",
- [_conId:'%'+params._conId+'%',_conMan:'%'+params._conMan+'%',_conLastchangefrom:_conLastchangefrom,_conLastchangeto:_conLastchangeto,_conDelState:'%'+_conDelState+'%']).size()
- }else {
- println 'have type ' + params._staType_id instanceof String
- results = Contract.findAll("from Contract c where c.conId like :_conId and c.conMan.staName like :_conMan and str(c.conMan.staType.id)=:_staType_id and c.conLastchange between :_conLastchangefrom and :_conLastchangeto and c.conDel like :_conDelState order by ${params.sort} ${params.order} ",
- [_conId:'%'+params._conId+'%',_conMan:'%'+params._conMan+'%',_staType_id:params._staType_id,_conLastchangefrom:_conLastchangefrom,_conLastchangeto:_conLastchangeto,_conDelState:'%'+_conDelState+'%'],[max:Integer.parseInt(params.max),offset:Integer.parseInt(params.offset)])
- params.count=Contract.findAll("from Contract c where c.conId like :_conId and c.conMan.staName like :_conMan and str(c.conMan.staType.id)=:_staType_id and c.conLastchange between :_conLastchangefrom and :_conLastchangeto and c.conDel like :_conDelState order by ${params.sort} ${params.order} ",
- [_conId:'%'+params._conId+'%',_conMan:'%'+params._conMan+'%',_staType_id:params._staType_id,_conLastchangefrom:_conLastchangefrom,_conLastchangeto:_conLastchangeto,_conDelState:'%'+_conDelState+'%']).size()
- }
- println 'params._conDel '+params._conDel
- render(view:'list',model:[contractList:results])
- //[ contractList: Contract.list( params ) ]
- }
- def show = {
- def contract = Contract.get( params.id )
- if(!contract) {
- flash.message = "contract.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Contract not found with id ${params.id}"
- redirect(action:list,params:[_conId:params._conId,_conMan:params._conMan,_staType_id:params._staType_id,_conLastchangefrom:params._conLastchangefrom,_conLastchangeto:params._conLastchangeto,_conDel:params._conDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else { return [ contract : contract ] }
- }
- def delete = {
- def contract = Contract.get( params.id )
- if(contract) {
- // contract.delete()
- //设定删除状态 更新人更新时间
- contract.conDel = '1'
- contract.conLastchanger = 'session'
- contract.conLastchange = new Date()
- contract.save()
- flash.message = "contract.deleted"
- flash.args = [params.id]
- flash.defaultMessage = "Contract ${params.id} deleted"
- redirect(action:list,params:[_conId:params._conId,_conMan:params._conMan,_staType_id:params._staType_id,_conLastchangefrom:params._conLastchangefrom,_conLastchangeto:params._conLastchangeto,_conDel:params._conDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- flash.message = "contract.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Contract not found with id ${params.id}"
- redirect(action:list,params:[_conId:params._conId,_conMan:params._conMan,_staType_id:params._staType_id,_conLastchangefrom:params._conLastchangefrom,_conLastchangeto:params._conLastchangeto,_conDel:params._conDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- }
- def edit = {
- def contract = Contract.get( params.id )
- if(!contract) {
- flash.message = "contract.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Contract not found with id ${params.id}"
- redirect(action:list,params:[_conId:params._conId,_conMan:params._conMan,_staType_id:params._staType_id,_conLastchangefrom:params._conLastchangefrom,_conLastchangeto:params._conLastchangeto,_conDel:params._conDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- return [ contract : contract ]
- }
- }
- def update = {
- println "to contract.update"
- def contract = Contract.get( params.id )
- if(contract) {
- contract.properties = params
- contract.conMan = Staff.findById(params.conMan.id)
- //设定删除状态 创建人创建时间 更新人更新时间
- contract.conDel = '0'
- contract.conLastchanger = 'session'
- contract.conLastchange = new Date()
- if(!contract.hasErrors() && contract.save()) {
- println "contract.updated"
- flash.message = "contract.updated"
- flash.args = [params.id]
- flash.defaultMessage = "Contract ${params.id} updated"
- redirect(action:show,id:contract.id,params:[_conId:params._conId,_conMan:params._conMan,_staType_id:params._staType_id,_conLastchangefrom:params._conLastchangefrom,_conLastchangeto:params._conLastchangeto,_conDel:params._conDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'edit',model:[contract:contract])
- }
- }
- else {
- flash.message = "contract.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Contract not found with id ${params.id}"
- redirect(action:edit,id:params.id,params:[_conId:params._conId,_conMan:params._conMan,_staType_id:params._staType_id,_conLastchangefrom:params._conLastchangefrom,_conLastchangeto:params._conLastchangeto,_conDel:params._conDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- }
- def create = {
- def contract = new Contract()
- contract.properties = params
- return ['contract':contract]
- }
- def save = {
- String conid=Contract.executeQuery("select max(c.conId) from Contract c ")[0]
- println conid
- if(conid=="null"||conid==null){
- conid = 'CON100000000'
- }else { conid='CON'+(Integer.parseInt(conid.substring(3,12))+1)}
- def contract = new Contract()
- contract.properties = params
- contract.conMan = Staff.findById(params.conMan.id)
- contract.conId = conid //设置编号
- //设定删除状态 创建人创建时间 更新人更新时间
- contract.conDel = '0'
- contract.conCreater = 'session'
- contract.conCreatetime = new Date()
- contract.conLastchanger = 'session'
- contract.conLastchange = new Date()
-
- if(!contract.hasErrors() && contract.save()) {
- flash.message = "contract.created"
- flash.args = ["${contract.id}"]
- flash.defaultMessage = "Contract ${contract.id} created"
- redirect(action:show,id:contract.id,params:[_conId:params._conId,_conMan:params._conMan,_staType_id:params._staType_id,_conLastchangefrom:params._conLastchangefrom,_conLastchangeto:params._conLastchangeto,_conDel:params._conDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'create',model:[contract:contract])
- }
- }
- def showFile = {
- println 'contract id '+params.id
- def contract = Contract.findById(params.id )
- response.setContentType("application/msword");
- OutputStream out = response.getOutputStream();
- if(contract.conContrat==null){
- println('没有contract文件')
- //out.write('没有图片'.getBytes())
- out.close();
- } else {
- def file= contract.conContrat
- println 'send contract '
- byte[] bytes= file
- out.write(bytes)
- //javax.imageio.ImageIO.write(bytes, "PNG", out);
- out.close();
- }
- }
- }