写了一个定时器,每天0晨执行返现操作
public void execute(JobExecutionContext arg0) throws JobExecutionException {
List<Jifenlog> log=Jifenlog.dao.find("select * from t_jifenlog where tianshu>=1");
for (Jifenlog jifen : log) {
//SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//获取用户信息
User umodel=User.dao.findFirst("select * from t_user where openid=?",jifen.getOpenid());
try {
if(jifen.getTianshu()>=1)
{
//验证当天是否已经返现
int fxnum= Db.queryNumber(" select count(id) from t_fanxianlog where to_days(time) = to_days(now()) and openid=?", jifen.getOpenid()).intValue();
//添加返现记录
if(fxnum==0)
{
//问题:在当天0点满足条件进行插入时 save()同时执行了几次
Fanxianlog fanxianlog=new Fanxianlog();
fanxianlog.setFanxiannum(Double.parseDouble(jifen.getFanxiannum().toString()));
fanxianlog.setJifenlogid(jifen.getId());
fanxianlog.setOpenid(jifen.getOpenid());
fanxianlog.setState("已完成");
fanxianlog.setTime(common.getNowtime());
boolean b= fanxianlog.save();
Thread.sleep(1000);
if(b)
{
System.out.print("提现返现日志:用户openid:"+jifen.getOpenid());
logger.debug("提现返现日志:用户openid"+jifen.getOpenid()+"执行时间");
if(umodel!=null)
{
umodel.setAutojifenlan(umodel.getAutojifenlan()+jifen.getFanxiannum());
umodel.update();
if(jifen.getTianshu()-1>=0)
{
jifen.setTianshu(jifen.getTianshu()-1);
jifen.update();
}
}
}
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
System.out.println("wancheng");
}本人已做测试 把服务器数据库拷贝到本地,然后程序在本地跑,写入正常,服务器版就会出现代码中描述问题
数据库数据
现在也不知道哪里出得问题,路过的大神给看看是不是哪里逻辑出了问题
解决方案
<Host name="xxx" appBase=""
unpackWARs="false" autoDeploy="false" xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="D:\tomcat7\tomcat\webapps\PJZM" workDir="D:\tomcat7\tomcat\webapps\PJZM" reloadable="false"/>
<Context docBase= "D:\tomcat7\tomcat\webapps\upload" path= "/upload"/> </Host>
host 节点中的appBase设置为空 增加workDir="工程路径"即可
感谢大波总提示
这里分享一下
项目:JFinal
https://my.oschina.net/jfinal/blog/353062