SalaryController.groovy
上传用户:steveyhw
上传日期:2019-05-13
资源大小:307k
文件大小:9k
- import java.text.SimpleDateFormat
- class SalaryController {
-
- 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',create:'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._salBase)params._salBase = '0.0'
- if(!params._salMan)params._salMan = ''
- java.util.Date _salLastchangefrom =null
- java.util.Date _salLastchangeto =null
- if(!params._salLastchangefrom){
- _salLastchangefrom = df.parse('1970-01-01')
- }else{_salLastchangefrom = df.parse(params._salLastchangefrom)}
- if(!params._salLastchangeto){
- _salLastchangeto = new Date()
- }else{_salLastchangeto = df.parse(params._salLastchangeto)}
- if(!params._salDel)params._salDel = null
- println '_salDel :'+params._salDel
- def _salDelState = '0'
- if(params._salDel == 'on'){
- _salDelState = ''
- } else if(params._salDel == null){ _salDelState = '0' }
- println '_salDelState :'+_salDelState
- println params
- def results=null
- println 'between '+_salLastchangefrom+' and '+_salLastchangeto
- //
- if(!params._salType_id){
- results = Salary.findAll("from Salary s where s.salMan.staName like :_salMan and s.salBase >= :_salBase and s.salLastchange between :_salLastchangefrom and :_salLastchangeto and s.salDel like :_salDelState order by ${params.sort} ${params.order} ",
- [_salMan:'%'+params._salMan+'%',_salBase:Double.parseDouble(params._salBase),_salLastchangefrom:_salLastchangefrom,_salLastchangeto:_salLastchangeto,_salDelState:'%'+_salDelState+'%'],[max:Integer.parseInt(params.max),offset:Integer.parseInt(params.offset)])
- params.count=Salary.findAll("from Salary s where s.salMan.staName like :_salMan and s.salBase >= :_salBase and s.salLastchange between :_salLastchangefrom and :_salLastchangeto and s.salDel like :_salDelState order by ${params.sort} ${params.order} ",
- [_salMan:'%'+params._salMan+'%',_salBase:Double.parseDouble(params._salBase),_salLastchangefrom:_salLastchangefrom,_salLastchangeto:_salLastchangeto,_salDelState:'%'+_salDelState+'%']).size()
- }else {
- println 'have type ' + params._salType_id instanceof String
- results = Staff.findAll("from Salary s where s.salMan.staName like :_salMan and s.salBase >= :_salBase and str(s.salMan.staType.id)=:_salType_id and s.salLastchange between :_salLastchangefrom and :_salLastchangeto and s.salDel like :_salDelState order by ${params.sort} ${params.order}",
- [_salMan:'%'+params._salMan+'%',_salBase:Double.parseDouble(params._salBase),_salType_id:params._salType_id,_salLastchangefrom:_salLastchangefrom,_salLastchangeto:_salLastchangeto,_salDelState:'%'+_salDelState+'%'],[max:Integer.parseInt(params.max),offset:Integer.parseInt(params.offset)])
- params.count=Staff.findAll("from Salary s where s.salMan.staName like :_salMan and s.salBase >= :_salBase and str(s.salMan.staType.id)=:_salType_id and s.salLastchange between :_salLastchangefrom and :_salLastchangeto and s.salDel like :_salDelState order by ${params.sort} ${params.order}",
- [_salMan:'%'+params._salMan+'%',_salBase:Double.parseDouble(params._salBase),_salType_id:params._salType_id,_salLastchangefrom:_salLastchangefrom,_salLastchangeto:_salLastchangeto,_salDelState:'%'+_salDelState+'%']).size()
- }
- println 'params._salDel '+params._salDel
- render(view:'list',model:[salaryList:results])
- //[ salaryList: Salary.list( params ) ]
- }
- def show = {
- def salary = Salary.get( params.id )
- if(!salary) {
- flash.message = "salary.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Salary not found with id ${params.id}"
- redirect(action:list,params:[_salMan:params._salMan,_salBase:params._salBase,_salType_id:params._salType_id,_salLastchangefrom:params._salLastchangefrom,_salLastchangeto:params._salLastchangeto,_salDel:params._salDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'show',model:[ salary : salary])
- //return [ salary : salary ]
- }
- }
- def delete = {
- def salary = Salary.get( params.id )
- if(salary) {
- //设定删除状态 创建/更新时间 或人
- salary.salDel = '1'
- salary.salLastchange = new Date()
- salary.salLastchanger = 'session'
- salary.save()//salary.delete()
- flash.message = "salary.deleted"
- flash.args = [params.id]
- flash.defaultMessage = "Salary ${params.id} deleted"
- println 'delete is ' + params
- redirect(action:list,params:[_salMan:params._salMan,_salBase:params._salBase,_salType_id:params._salType_id,_salLastchangefrom:params._salLastchangefrom,_salLastchangeto:params._salLastchangeto,_salDel:params._salDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- flash.message = "salary.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Salary not found with id ${params.id}"
- redirect(action:list,params:[_salMan:params._salMan,_salBase:params._salBase,_salType_id:params._salType_id,_salLastchangefrom:params._salLastchangefrom,_salLastchangeto:params._salLastchangeto,_salDel:params._salDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- }
- def edit = {
- def salary = Salary.get( params.id )
- if(!salary) {
- flash.message = "salary.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Salary not found with id ${params.id}"
- redirect(action:list,params:[_salMan:params._salMan,_salBase:params._salBase,_salType_id:params._salType_id,_salLastchangefrom:params._salLastchangefrom,_salLastchangeto:params._salLastchangeto,_salDel:params._salDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- println 'edit '+params._salDel
- render(view:'edit',model:[ salary : salary])
- //return [ salary : salary ]
- }
- }
- def update = {
- def salary = Salary.get( params.id )
- if(salary) {
- println 'salMan.id '+ params.salMan.id
- salary.properties = params
- salary.salMan = Staff.findById(params.salMan.id)
- //设定发薪时间
- salary.salTime = new Date()
- //设定删除状态 创建/更新时间 或人
- salary.salDel = '0'
- salary.salLastchange = new Date()
- salary.salLastchanger = 'session'
- if(!salary.hasErrors() && salary.save()) {
- flash.message = "salary.updated"
- flash.args = [params.id]
- flash.defaultMessage = "Salary ${params.id} updated"
- redirect(action:show,id:salary.id,params:[_salMan:params._salMan,_salBase:params._salBase,_salType_id:params._salType_id,_salLastchangefrom:params._salLastchangefrom,_salLastchangeto:params._salLastchangeto,_salDel:params._salDel,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'edit',model:[salary:salary])
- }
- }
- else {
- flash.message = "salary.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Salary not found with id ${params.id}"
- redirect(action:edit,id:params.id,params:[_salMan:params._salMan,_salBase:params._salBase,_salType_id:params._salType_id,_salLastchangefrom:params._salLastchangefrom,_salLastchangeto:params._salLastchangeto,_salDel:params._salDe,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- }
- def create = {
- def salary = new Salary()
- //salary.properties = params
- salary.salBase = 0.0
- render(view:'create',model:[salary:salary])
- //return ['salary':salary]
- }
- def save = {
- def salary = new Salary()
- salary.properties = params
- salary.salMan = Staff.findById(params.salMan.id)
- //设定发薪时间
- salary.salTime = new Date()
- //设定删除状态 创建/更新时间 或人
- salary.salDel = '0'
- salary.salCreatetime = new Date()
- salary.salCreater = 'session'
- salary.salLastchange = new Date()
- salary.salLastchanger = 'session'
- if(!salary.hasErrors() && salary.save()) {
- flash.message = "salary.created"
- flash.args = ["${salary.id}"]
- flash.defaultMessage = "Salary ${salary.id} created"
- redirect(action:show,id:salary.id,params:[_salMan:params._salMan,_salBase:params._salBase,_salType_id:params._salType_id,_salLastchangefrom:params._salLastchangefrom,_salLastchangeto:params._salLastchangeto,_salDel:params._salDe,max:params.max,sort:params.sort,offset:params.offset,order:params.order])
- }
- else {
- render(view:'create',model:[salary:salary])
- }
- }
- }