首页>代码>s2sh开发汽车租赁管理系统>/car/src/com/neusoft/action/OrderAction.java
001package com.neusoft.action;
002 
003import org.apache.struts2.ServletActionContext;
004import org.springframework.beans.factory.annotation.Autowired;
005import org.springframework.stereotype.Controller;
006import java.io.File;
007import java.text.SimpleDateFormat;
008import java.util.Date;
009import java.util.HashMap;
010import java.util.List;
011import java.util.Map;
012import org.springframework.context.annotation.Scope;
013import com.opensymphony.xwork2.ActionContext;
014import com.opensymphony.xwork2.ActionSupport;
015import com.neusoft.utils.Pager;
016import com.opensymphony.xwork2.ModelDriven;
017import com.neusoft.dto.RateDto;
018import com.neusoft.model.*;
019import com.neusoft.service.OrderService;
020import com.neusoft.service.RentService;
021 
022/**
023 * @ClassName: 
024 * @Description:
025 * @author administrator
026 * @date 2015年12月24日 下午1:46:33 - 2016年12月15日 21时47分54秒
027 */
028 
029@Controller("orderAction")
030@Scope("prototype")
031public class OrderAction extends ActionSupport implements ModelDriven<Order>{
032     
033    private static final long serialVersionUID = 1L;
034 
035    //==========model==============
036      private Order order;
037        @Override
038        public Order getModel() {
039            if(order==null) order = new Order();
040            return order;  
041        }
042        //==========model==============
043    /**
044     * 依赖注入 start dao/service/===
045     */
046    @Autowired
047    private OrderService orderService;
048     
049    @Autowired
050    private RentService rentService;
051     
052    //依赖注入 end  dao/service/===
053     
054    //-------------------------华丽分割线---------------------------------------------
055     
056    //============自定义参数start=============
057    private String startTime; //页面传入的开始时间
058    private String endTime; //页面传入的结束时间
059    private Integer flag;//标识位
060    private Date rentTime;
061    private Date returnTime;
062    public String getStartTime() {
063        return startTime;
064    }
065    public void setStartTime(String startTime) {
066        this.startTime = startTime;
067    }
068    public String getEndTime() {
069        return endTime;
070    }
071    public void setEndTime(String endTime) {
072        this.endTime = endTime;
073    }
074    public Integer getFlag() {
075        return flag;
076    }
077    public void setFlag(Integer flag) {
078        this.flag = flag;
079    }
080     
081    //============自定义参数end=============
082     
083    //-------------------------华丽分割线---------------------------------------------
084 
085    public Date getRentTime() {
086        return rentTime;
087    }
088    public void setRentTime(Date rentTime) {
089        this.rentTime = rentTime;
090    }
091    public Date getReturnTime() {
092        return returnTime;
093    }
094    public void setReturnTime(Date returnTime) {
095        this.returnTime = returnTime;
096    }
097    //============文件上传start=======================================================
098    private File file;
099    //提交过来的file的名字
100    private String fileFileName;
101    //提交过来的file的MIME类型
102    private String fileContentType;
103    public File getFile() {
104        return file;
105    }
106    public void setFile(File file) {
107        this.file = file;
108    }
109    public String getFileFileName() {
110        return fileFileName;
111    }
112    public void setFileFileName(String fileFileName) {
113        this.fileFileName = fileFileName;
114    }
115    public String getFileContentType() {
116        return fileContentType;
117    }
118    public void setFileContentType(String fileContentType) {
119        this.fileContentType = fileContentType;
120    }
121     //============文件上传end=========================================================
122             
123     //-------------------------华丽分割线---------------------------------------------//
124     
125     //=============公=======共=======方=======法==========区=========start============//
126     
127    /**
128     * 前台用户查看我的订单(我的订单)
129     * @return
130     */
131    public String findOrderByUserId() {
132        // 获得用户的id.
133        User existUser = (User) ServletActionContext.getRequest().getSession()
134                .getAttribute("user");
135        if(existUser==null){
136            return "userLogin";
137        }else{
138            Map<String,Object> alias = new HashMap<String,Object>();
139            StringBuffer sb = new StringBuffer();
140            sb = sb.append("from Order where 1=1 ");
141         
142            sb = sb.append(" and user.id = :userId ");
143            // 获得用户的id
144            Integer userId = existUser.getId();
145            alias.put("userId",userId);
146            //根据编号模糊查询
147            if(order.getCode()!=null){
148                sb = sb.append(" and code like :code ");
149                alias.put("code", "%"+order.getCode()+"%");
150            }
151            sb = sb.append("order by id desc");
152            // 根据用户的id查询订单:
153            Pager<Order> pagers =orderService.findByAlias(sb.toString(),alias);
154            // 将PageBean数据带到页面上.
155            ActionContext.getContext().put("pagers", pagers);
156                return "findOrderByUid";
157        }
158    }
159     
160    /**
161     * 前台订单详情
162     * @return
163     */
164    public String getByOrderId(){
165        Order currOrder = orderService.getById(order.getId());
166        ActionContext.getContext().put("order", currOrder);
167        if(flag==1){//当前台传入为1时表示查看详情 当为2的时就为跳入到订单修改页面
168            return SUCCESS;
169        }else{
170            return "updateOrderByOrderId";
171        }
172    }
173     
174    /**
175     * 前台修改订单
176     * @return
177     */
178    public String exUpdateOrderByOrderId(){
179        Order n = orderService.getById(order.getId());
180        Rent r=rentService.getById(n.getRent().getId());
181        r.setRentTime(rentTime);
182        r.setReturnTime(returnTime);
183        rentService.update(r);
184        ActionContext.getContext().put("url", "/order_findOrderByUserId.do");
185        return "redirect";
186    }
187     
188    /**
189     * 前台用户查看租车记录(租车记录)
190     * @return
191     */
192    public String rentInfoList() {
193        // 获得用户的id.
194        User existUser = (User) ServletActionContext.getRequest().getSession()
195                .getAttribute("user");
196        if(existUser==null){
197            return "userLogin";
198        }else{
199            Map<String,Object> alias = new HashMap<String,Object>();
200            StringBuffer sb = new StringBuffer();
201            sb = sb.append("from Order where 1=1 and isDeal=1");
202         
203            sb = sb.append(" and user.id = :userId ");
204            // 获得用户的id
205            Integer userId = existUser.getId();
206            alias.put("userId",userId);
207            //根据编号模糊查询
208            if(order.getCode()!=null){
209                sb = sb.append(" and code like :code ");
210                alias.put("code", "%"+order.getCode()+"%");
211            }
212            sb = sb.append("order by id desc");
213            // 根据用户的id查询订单:
214            Pager<Order> pagers =orderService.findByAlias(sb.toString(),alias);
215            // 将PageBean数据带到页面上.
216            ActionContext.getContext().put("pagers", pagers);
217        return SUCCESS;
218        }
219    }
220     
221    /**
222     * 前台租车记录中的已经完成租车详情
223     * @return
224     */
225    public String getDetailByOrderId(){
226        Map<String,Object> alias = new HashMap<String,Object>();
227        String hql ="from Order where 1=1  and id = :id  and isDeal=1";
228         alias.put("id", order.getId());
229        List<Order> orderList = orderService.getByHQL(hql, alias);
230         if(orderList.size()>0){
231            ActionContext.getContext().put("order", orderList.get(0));
232         }
233        return SUCCESS;
234    }
235     
236    /**
237     * 列表分页查询
238     * @throws Exception
239     */
240    public String order() throws Exception{
241        Map<String,Object> alias = new HashMap<String,Object>();
242        StringBuffer sb = new StringBuffer();
243        sb = sb.append("from Order where 1=1 ");
244        if(startTime != null && !"".equals(startTime)){
245            sb.append(" and createTime >= :startTime");
246        }
247        if(endTime != null && !"".equals(endTime)){
248            sb.append(" and createTime < :endTime");
249        }
250        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
251        if(startTime != null && !"".equals(startTime)){
252            alias.put("startTime", sdf.parse(startTime+" 00:00:00"));
253        }
254        if(endTime != null && !"".equals(endTime)){
255            alias.put("endTime", sdf.parse(endTime+" 23:59:59"));
256        }
257        sb = sb.append(" order by id desc");
258        Pager<Order> pagers =orderService.findByAlias(sb.toString(),alias);
259        ActionContext.getContext().put("pagers", pagers);
260        ActionContext.getContext().put("order", order);
261        return SUCCESS;
262    }
263     
264    /**
265     * 跳转到添加页面
266     * @return
267     */
268    public String add(){
269        return SUCCESS;
270    }
271     
272    /**
273     * 执行添加
274     * @return
275     */
276    public String exAdd(){
277        orderService.save(order);
278        ActionContext.getContext().put("url", "/order_order.do");
279        return "redirect";
280    }
281     
282    /**
283     * 查看详情页面
284     * @return
285     */
286    public String view(){
287        Order n = orderService.getById(order.getId());
288        ActionContext.getContext().put("order", n);
289        if(flag==1){//当传入1时显示的详情
290            return SUCCESS;
291        }else if(flag==2){//当传入2时已经审核通过的详情
292            return "agreeOrder";
293        }else{//当传入2时已经完成交易的的详情
294            return "finishOrder";
295        }
296    }
297     
298     
299    /**
300     * 跳转修改页面
301     * @return
302     */
303    public String update(){
304        Order n = orderService.getById(order.getId());
305        ActionContext.getContext().put("order", n);
306        return SUCCESS;
307    }
308     
309    /**
310     * 执行修改
311     * @return
312     */
313    public String exUpdate(){
314        Order n = orderService.getById(order.getId());
315        orderService.update(n);
316        ActionContext.getContext().put("url", "/order_order.do");
317        return "redirect";
318    }
319     
320     
321    /**
322     * 删除
323     * @return
324     */
325    public String delete(){
326        Order n = orderService.getById(order.getId());
327        orderService.update(n);
328        ActionContext.getContext().put("url", "/order_order.do");
329        return "redirect";
330    }
331     
332    /**
333     * 查询未审核订单列表分页查询
334     * @throws Exception
335     */
336    public String unAgreeOrder() throws Exception{
337        Map<String,Object> alias = new HashMap<String,Object>();
338        StringBuffer sb = new StringBuffer();
339        sb = sb.append("from Order where 1=1 and state=0 ");
340        if(startTime != null && !"".equals(startTime)){
341            sb.append(" and createTime >= :startTime");
342        }
343        if(endTime != null && !"".equals(endTime)){
344            sb.append(" and createTime < :endTime");
345        }
346        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
347        if(startTime != null && !"".equals(startTime)){
348            alias.put("startTime", sdf.parse(startTime+" 00:00:00"));
349        }
350        if(endTime != null && !"".equals(endTime)){
351            alias.put("endTime", sdf.parse(endTime+" 23:59:59"));
352        }
353        sb = sb.append(" order by id desc");
354        Pager<Order> pagers =orderService.findByAlias(sb.toString(),alias);
355        ActionContext.getContext().put("pagers", pagers);
356        ActionContext.getContext().put("order", order);
357        return SUCCESS;
358    }
359     
360    /**
361     * 查询未完成交易订单列表分页查询
362     * @throws Exception
363     */
364    public String unFinishOrder() throws Exception{
365        Map<String,Object> alias = new HashMap<String,Object>();
366        StringBuffer sb = new StringBuffer();
367        sb = sb.append("from Order where 1=1 and isDeal=0 ");
368        if(startTime != null && !"".equals(startTime)){
369            sb.append(" and createTime >= :startTime");
370        }
371        if(endTime != null && !"".equals(endTime)){
372            sb.append(" and createTime < :endTime");
373        }
374        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
375        if(startTime != null && !"".equals(startTime)){
376            alias.put("startTime", sdf.parse(startTime+" 00:00:00"));
377        }
378        if(endTime != null && !"".equals(endTime)){
379            alias.put("endTime", sdf.parse(endTime+" 23:59:59"));
380        }
381        sb = sb.append(" order by id desc");
382        Pager<Order> pagers =orderService.findByAlias(sb.toString(),alias);
383        ActionContext.getContext().put("pagers", pagers);
384        ActionContext.getContext().put("order", order);
385        return SUCCESS;
386    }
387     
388    /**
389     * 完成交易
390     * @return
391     */
392    public String finishOrder(){
393        Order n = orderService.getById(order.getId());
394        n.setIsDeal(1);
395        n.setFinishTime(new Date());
396        orderService.update(n);
397        ActionContext.getContext().put("url", "/order_order.do");
398        return "redirect";
399    }
400     
401    /**
402     * 审批通过
403     * @return
404     */
405    public String agreeOrder(){
406        Order n = orderService.getById(order.getId());
407        n.setState(1);
408        orderService.update(n);
409        ActionContext.getContext().put("url", "/order_order.do");
410        return "redirect";
411    }
412     
413    /**
414     * 查询完成交易订单列表分页查询
415     * @throws Exception
416     */
417    public String hasFinishedOrder() throws Exception{
418        Map<String,Object> alias = new HashMap<String,Object>();
419        StringBuffer sb = new StringBuffer();
420        sb = sb.append("from Order where 1=1 and isDeal=1 ");
421        if(startTime != null && !"".equals(startTime)){
422            sb.append(" and finishTime >= :startTime");
423        }
424        if(endTime != null && !"".equals(endTime)){
425            sb.append(" and finishTime < :endTime");
426        }
427        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
428        if(startTime != null && !"".equals(startTime)){
429            alias.put("startTime", sdf.parse(startTime+" 00:00:00"));
430        }
431        if(endTime != null && !"".equals(endTime)){
432            alias.put("endTime", sdf.parse(endTime+" 23:59:59"));
433        }
434        sb = sb.append(" order by id desc");
435        Pager<Order> pagers =orderService.findByAlias(sb.toString(),alias);
436        ActionContext.getContext().put("pagers", pagers);
437        ActionContext.getContext().put("order", order);
438        return SUCCESS;
439    }
440     
441     
442     /**
443     * 利润统计
444     * @Description (TODO这里用一句话描述这个方法的作用)
445     * @return
446     */
447    public String tongji(){
448        List<RateDto> list =orderService.listAll();
449        ActionContext.getContext().put("list", list);
450        return SUCCESS;
451    }
452 
453    //=============公=======共=======方=======法==========区=========end============//
454     
455     //-------------------------华丽分割线---------------------------------------------//
456     
457     //=============自=======定=======义=========方=======法==========区=========start============//
458     
459     
460     
461     
462    //=============自=======定=======义=========方=======法==========区=========end============//
463         
464     
465     
466}
最近下载更多
wuying8208  LV15 2024年10月23日
微信网友_6917967074955264  LV2 2024年3月30日
tx1121  LV14 2023年4月4日
朱朱啊哈  LV16 2023年1月31日
飞翔的面包片  LV13 2022年12月12日
jimodeai  LV15 2022年11月6日
liangge2115  LV27 2022年6月15日
121516  LV3 2022年5月3日
cjwcjwll  LV1 2022年3月15日
xiaore  LV4 2022年3月15日
最近浏览更多
1516299986  LV9 4月3日
Mhgfhjyrf  LV3 2024年12月9日
微笑刺客  LV21 2024年11月22日
微信网友_6927932988952576  LV12 2024年11月4日
wuying8208  LV15 2024年10月23日
3339790961 2024年9月14日
暂无贡献等级
微信网友_6745742881968128  LV3 2024年6月25日
cherrylxj  LV3 2024年6月13日
yyyyyyyj  LV1 2024年5月16日
fuyouou  LV5 2024年4月23日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友