public String checkWorkLog(String data,HttpServletRequest request){
 JSONObject result = new JSONObject() ;
 JSONObject dataJsonObject = JSONObject.fromObject(data);
 String date = dataJsonObject.getString("date") ;
 String userId = CommonUtils.getSessionUserId(request).toString() ;
 Calendar cal = Calendar.getInstance() ;
 String preDate = "" ,currentDate = "",isRepeate="0",flag = "0";
 currentDate = DateUtils.convertDateToString("yyyy-MM-dd",cal.getTime()) ;
 String currenttime = DateUtils.convertDateToString("HH:mm",cal.getTime()) ;
 cal.add(Calendar.HOUR,-24) ;
 preDate = DateUtils.convertDateToString("yyyy-MM-dd",cal.getTime()) ;
 DbOpt dbopt = new DbOpt() ;
 try{
 //判断日志是否重复填写
 String isRepeat = dbopt.executeQueryToStr("select count(whir$rz_id) from whir$rz where whir$rz_owner=? and whir$rz_rq=?"
 , new Object[]{userId,date}) ;
 if(!"0".equals(isRepeat)){//日志重复填写
 isRepeate = "1";
 }else{
 if(date.compareTo(currentDate)>0){//提交日期大于当前日期
 flag = "1" ;
 }else if(date.compareTo(preDate)<0){//提交日期小于前一天
 flag = "2" ;
 }else if(date.equals(preDate) && currenttime.compareTo("12:00")>0){
 flag = "3" ;
 }
 }
 }catch(Exception e){
 }finally{
if(dbopt != null){
try {
dbopt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
     }
 result.put("isRepeate",isRepeate) ;
 result.put("flag",flag) ;
 return result.toString() ;
 }

解决方案 »

  1.   

    假设你表中存的是用户id与日志时间,并且“今天”是周一,可以用下面语句进行判断
    (oracle/sql)
    with tab1 as (
    select 1 user_id, to_date('2019030813', 'yyyymmddhh24') dt from dual union all
    select 2 user_id, to_date('2019030713', 'yyyymmddhh24') dt from dual
    )
    select decode(count(1), 0, '不可补写', '可以') "flag"
      from tab1 t1
     where t1.user_id = 1
       and (trunc(t1.dt) = trunc(sysdate, 'd') - 2
       and to_char(sysdate, 'd') = 2
       and to_number(to_char(sysdate, 'hh24')) < 12)
    ;