StaffController.groovy
上传用户:steveyhw
上传日期:2019-05-13
资源大小:307k
文件大小:8k
- import java.text.SimpleDateFormat
- class StaffController {
-
- 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 = { /*
- println 'to staff.list '
- println '_staType_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 staff = Staff.get( params.id )
- if(!staff) {
- flash.message = "staff.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Staff not found with id ${params.id}"
- redirect(action:list,params:[_staId:params._staId,_staName:params._staName,_staType_id:params._staType_id,_staLastchangefrom:params._staLastchangefrom,_staLastchangeto:params._staLastchangeto,_staDel:params._staDel,offset:params.offset,sort:params.sort,order:params.order])
- }
- else { return [ staff : staff ] }
- }
- def delete = {
- def staff = Staff.get( params.id )
- if(staff) {
- //�趨ɾ��״̬
- staff.staDel = '1'
- flash.message = "staff.deleted"
- flash.args = [params.id]
- flash.defaultMessage = "Staff ${params.id} deleted"
- redirect(action:list,params:[_staId:params._staId,_staName:params._staName,_staType_id:params._staType_id,_staLastchangefrom:params._staLastchangefrom,_staLastchangeto:params._staLastchangeto,_staDel:params._staDel,offset:params.offset,sort:params.sort,order:params.order])
- }
- else {
- flash.message = "staff.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Staff not found with id ${params.id}"
- redirect(action:list,params:[_staId:params._staId,_staName:params._staName,_staType_id:params._staType_id,_staLastchangefrom:params._staLastchangefrom,_staLastchangeto:params._staLastchangeto,_staDel:params._staDel,offset:params.offset,sort:params.sort,order:params.order])
- }
- }
- def edit = {
- def staff = Staff.get( params.id )
- if(!staff) {
- flash.message = "staff.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Staff not found with id ${params.id}"
- redirect(action:list,params:[_staId:params._staId,_staName:params._staName,_staType_id:params._staType_id,_staLastchangefrom:params._staLastchangefrom,_staLastchangeto:params._staLastchangeto,_staDel:params._staDel,offset:params.offset,sort:params.sort,order:params.order])
- }
- else {
- return [ staff : staff ]
- }
- }
- def update = {
- def staff = Staff.get( params.id )
- if(staff) {
- staff.properties = params
- //�趨ɾ��״̬ �����˸���ʱ��
- staff.staDel = '0'
- staff.staLastchanger = 'session'
- staff.staLastchange = new Date()
- if(!staff.hasErrors() && staff.save()) {
- flash.message = "staff.updated"
- flash.args = [params.id]
- flash.defaultMessage = "Staff ${params.id} updated"
- redirect(action:show,id:staff.id,params:[_staId:params._staId,_staName:params._staName,_staType_id:params._staType_id,_staLastchangefrom:params._staLastchangefrom,_staLastchangeto:params._staLastchangeto,_staDel:params._staDel,offset:params.offset,sort:params.sort,order:params.order])
- }
- else {
- render(view:'edit',model:[staff:staff])
- }
- }
- else {
- flash.message = "staff.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Staff not found with id ${params.id}"
- redirect(action:edit,id:params.id,params:[_staId:params._staId,_staName:params._staName,_staType_id:params._staType_id,_staLastchangefrom:params._staLastchangefrom,_staLastchangeto:params._staLastchangeto,_staDel:params._staDel,offset:params.offset,sort:params.sort,order:params.order])
- }
- }
- def create = {
- def staff = new Staff()
- staff.properties = params
- return ['staff':staff]
- }
- def save = {
- String staid=Staff.executeQuery("select max(s.staId) from Staff s ")[0]
- println staid
- if(staid=="null"||staid==null){
- staid = 'STA100000000'
- }else { staid='STA'+(Integer.parseInt(staid.substring(3,12))+1)}
- def staff = new Staff(params)
- staff.staId = staid //���ñ��
- //�趨ɾ��״̬ �����˴���ʱ�� �����˸���ʱ��
- staff.staDel = '0'
- staff.staCreater = 'session'
- staff.staCreatetime = new Date()
- staff.staLastchanger = 'session'
- staff.staLastchange = new Date()
- if(!staff.hasErrors() && staff.save()) {
- flash.message = "staff.created"
- flash.args = ["${staff.id}"]
- flash.defaultMessage = "Staff ${staff.id} created"
- redirect(action:show,id:staff.id,params:[_staId:params._staId,_staName:params._staName,_staType_id:params._staType_id,_staLastchangefrom:params._staLastchangefrom,_staLastchangeto:params._staLastchangeto,_staDel:params._staDel,offset:params.offset,sort:params.sort,order:params.order])
- }
- else {
- render(view:'create',model:[staff:staff])
- }
- }
- def showImage = {
- def staff = Staff.findById(params.id )
- response.setContentType("image/png");
- OutputStream out = response.getOutputStream();
- if(Staff.staImage==null){
- println('staff û��ͼƬ')
- out.close();
- } else {
- def image= staff.staImage
- //println image
- byte[] bytes= image
- out.write(bytes)
- //javax.imageio.ImageIO.write(bytes, "PNG", out);
- out.close();
- }
- }
- }