超市仓库管理系统(过期提醒)

超市仓库管理系统(过期提醒)

   在超市系统的超市库存系统中,会有一个 对物品即将过期或已过期但未处理的物品的提醒。下面是仓库管理系统主页的一个显示情况:



 图1.仓库系统主页

 

从中截取出要实现的提醒部分如下:(布局有点Low,先将就一下)



 图2.商品过期提醒

 

实现步骤:

一、在dao层写出具体实现的方法,思路:设根据商品保质期的五分之一的天数作为快过期天数,然后用sql语句查询出将过期和已过期商品批次编号和天数,将数据放入map集合。

select   批次编号、((有效期-生产日期)/5 - abs(有效期-当前时间) ) 天数   from   商品批次表

where   (有效期-生产日期)/5 >= (有效期-当前时间)

 

 

/**
* 商品过期提醒(设根据商品保质期的五分之一的天数作为快过期天数,再作出判断)
* @return
*/
public Map<Integer, Integer> proDate(){
//定义map集合,用来存放商品批次编号和天数
Map<Integer,Integer> maps = new HashMap<Integer, Integer>() ;
//查询出将过期和已过期商品批次编号和天数 (过期提醒时间=保质期内时间/5)
//(有效期-生产日期)/5 - abs(有效期-当前时间) = 天数
//where条件:(有效期-生产日期)/5 >= (有效期-当前时间)
String sql = "select baid,(trunc(effdate,'dd')-trunc(prodate,'dd'))/5 - "
+ "(abs(trunc(effdate,'dd')-trunc(sysdate,'dd'))) time"
+ " from batch where ((trunc(effdate,'dd')-trunc(prodate,'dd'))/5 >= "
+ "(trunc(effdate,'dd')-trunc(sysdate,'dd')))";
conn = DBUtil.getConn();
try {
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();

while(rs.next()){
int baid = rs.getInt(1);
int time = rs.getInt(2);

maps.put(baid, time);
//判断:如果天数小于零表示该商品已过期,因为天数小于零是负数所有要加绝对值
if(time<0){
System.out.println("第 "+baid+ " 批次商品已过期"+Math.abs(time)+"天!");
}
//判断:如果天数刚好等于0则表示该批次商品于当前日期过期
else if(time==0){
System.out.println("第 "+baid+ " 批次商品今天过期!");
}
//判断:如果天数大于0,则表示该批次商品在保质期的五分之一时间内,也就是说即将过期
else if(time>0){
System.out.println("第 "+baid+ " 批次商品还有"+time+"天过期!");
}

}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBUtil.close(rs, ps, conn);
}
return maps;
}

 

二、在index.jsp主页的页面布局中将提醒位置放在页面右边

 

<div data-options="region:'east',split:false" style="width:190px;">
        <div id="p" class="easyui-panel" title="备注" data-options="fit:true" >
             <p style="font-size:20px;text-align:center">商品过期提醒!</p>
            <div data-options="fit:true" id="panel" class="easyui-panel"
            style="color:red ;font-size:15px;" >
           </div>
      </div>
</div>

    然后在该页面的script中调用servlet,获取数据到页面。

//将后台数据加载到面板中来
$("#panel").panel({
href:"WarehouseServlet?type=date"
});

 

三、servelet响应,从map中取出数据。

//商品过期提醒
if("date".equals(type)){
Map<Integer,Integer> maps = service.proDate();
for(Map.Entry<Integer, Integer> entry :maps.entrySet()){
int key = entry.getKey();
int value = entry.getValue();
if(value<0){
out.println("第 "+key+ " 批次商品已过期 "+Math.abs(value)+" 天!"+"\t\n");
}
else if(value==0){
out.println("第 "+key+ " 批次商品今天过期!"+"\t\n");
}
else if(value>0){
out.println("第 "+key+ " 批次商品还有 "+value+" 天过期!"+"\t\n");
}
out.println();
}
}

 大致实现过程就这样,不过还有很多地方不贴合实际情况。。。

 

最后还有一个监听器,每隔一段时间就来监听商品是否即将过期。

/**
* 监听器:1.每隔一段时间监听看是否有商品即将过期
* @author sunflower
*
*/
public class MyListener extends Thread implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {

}
@Override
public void contextInitialized(ServletContextEvent arg0) {
this.start();
}
@Override
public void run() {
WarehouseDao dao = new WarehouseDao();
while(true){
dao.proDate();//商品过期提醒
try {
Thread.sleep(1000*60*60);//时间可以自己任意设置
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

 

 

 

猜你喜欢

转载自sunflower-13.iteye.com/blog/2375549
今日推荐