首页>代码>基于ssh框架开发ktv预定管理系统(加毕业论文)>/1069基于ssh-ktv预定管理系统 - 副本/code/ktvManage/src/com/my/pro/action/BjAction.java
package com.my.pro.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.my.pro.utils.Pager;
import com.my.pro.utils.UUIDUtils;
import com.my.pro.utils.UserUtils;
import com.opensymphony.xwork2.ModelDriven;
import java.util.*;

import com.my.pro.model.*;
import com.my.pro.dao.*;
import com.my.pro.service.*;

/**
 * @ClassName:  
 * @Description: 
 * @author administrator
 * 
 */

@Controller("bjAction")
@Scope("prototype")
public class BjAction extends BaseAction implements ModelDriven<Bj>{
	
	private static final long serialVersionUID = 1L;
	@Autowired
	private BjGqService bjGqService;
	@Autowired
	private GqService gqService;
	//==========model==============
	  private Bj bj;
		@Override
		public Bj getModel() {
			if(bj==null) bj = new Bj();
			return bj;	
		}
		//==========model==============
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private BjService bjService;
	
	private String gqFind;
	@Autowired
	private OrderGqService orderGqService;
	
	//依赖注入 end  dao/service/===
	
	//-------------------------华丽分割线---------------------------------------------
	
	//============自定义参数start=============
	
	//============自定义参数end=============

	
	//-------------------------华丽分割线---------------------------------------------
	
	//============文件上传start=======================================================
	@Autowired
	private RoomOrderService roomOrderService;
	
	public String getGqFind() {
		return gqFind;
	}
	public void setGqFind(String gqFind) {
		this.gqFind = gqFind;
	}
	private File file;
	//提交过来的file的名字
    private String fileFileName;
    //提交过来的file的MIME类型
    private String fileContentType;
    public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	public String getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	public String getFileContentType() {
		return fileContentType;
	}
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}
	 //============文件上传end=========================================================
	public String jsonAction() {
		  // dataMap中的数据将会被Struts2转换成JSON字符串,所以这里要先清空其中的数据
		  jsonMap.clear();
		  jsonMap.put("success", true);
		  return JSON_TYPE;
	}
	 //-------------------------华丽分割线---------------------------------------------//
	
	 //=============公=======共=======方=======法==========区=========start============//
	/**
	 * 列表分页查询 and isDelete = 0 
	 * 
	 */
	public String bj(){
	    Map<String,Object> alias = new HashMap<String,Object>();
		StringBuffer sb = new StringBuffer();
		sb = sb.append("from Bj where 1=1 and isDelete = 0 ");
		sb = sb.append("order by id desc");
		Pager<Bj> pagers = bjService.findByAlias(sb.toString(),alias);
		ActionContext.getContext().put("pagers", pagers);
		ActionContext.getContext().put("Obj", bj);
		return SUCCESS;
    }
	
	/**
	 * 跳转到添加页面
	 * @return
	 */
	public String add(){
		return SUCCESS;
	}
	
	/**
	 * 执行添加
	 * @return
	 * @throws IOException 
	 */
	public String exAdd() throws IOException{
		    String root  = "D:/my/upload";
	        InputStream is = new FileInputStream(file);
	        fileFileName = UUIDUtils.create()+fileFileName;
	        OutputStream os = new FileOutputStream(new File(root, fileFileName));
	        System.out.println("fileFileName: " + fileFileName);
	        System.out.println("file: " + file.getName());
	        System.out.println("file: " + file.getPath());
	        byte[] buffer = new byte[500];
	        int length = 0;
	        
	        while(-1 != (length = is.read(buffer, 0, buffer.length)))
	        {
	            os.write(buffer);
	        }
	        os.close();
	        is.close();
	        bj.setUrls("\\upload\\"+fileFileName);
	        bj.setIsDelete(0);
	        bj.setStatus(0);
		    bjService.save(bj);
		ActionContext.getContext().put("url", "/bj_bj.do");
		return "redirect";
	}
	
	/**
	 * 查看详情页面
	 * @return
	 */
	public String view(){
		Bj n = bjService.getById(bj.getId());
		ActionContext.getContext().put("Obj", n);
		return SUCCESS;
	}
	
	/**
	 * 跳转修改页面
	 * @return
	 */
	public String update(){
		Bj n = bjService.getById(bj.getId());
		ActionContext.getContext().put("Obj", n);
		return SUCCESS;
	}
    
	/**
	 * 执行修改
	 * @return
	 * @throws IOException 
	 */
	public String exUpdate() throws IOException{
		String root  = "D:/my/upload";
		Bj n = bjService.getById(bj.getId());
		 InputStream is = new FileInputStream(file);
	        fileFileName = UUIDUtils.create()+fileFileName;
	        OutputStream os = new FileOutputStream(new File(root, fileFileName));
	        System.out.println("fileFileName: " + fileFileName);
	        System.out.println("file: " + file.getName());
	        System.out.println("file: " + file.getPath());
	        byte[] buffer = new byte[500];
	        int length = 0; 
	        
	        while(-1 != (length = is.read(buffer, 0, buffer.length)))
	        {
	            os.write(buffer);
	        }
	        os.close();
	        is.close();
	        n.setUrls("\\upload\\"+fileFileName);
	        BeanUtils.copyProperties(bj, n, getNullPropertyNames(bj));
		bjService.update(n);
		ActionContext.getContext().put("url", "/bj_bj.do");
		return "redirect";
	}
	
	
	/**
	 * 删除
	 * @return
	 */
	public String delete(){
		//bjService.delete(bj.getId());
		Bj n = bjService.getById(bj.getId());
		n.setIsDelete(1);
		bjService.update(n);
		ActionContext.getContext().put("url", "/bj_bj.do");
		return "redirect";
	}
	
	/**
	 * 预定
	 */
	public String yd(){
		
		if(UserUtils.getLoginId() == null){
			ActionContext.getContext().put("url", "/login_ulogin.do");
			return "redirect";
		}
		ActionContext.getContext().put("bjId", bj.getId());
		//热门歌曲:
		List<Gq> rmlist = gqService.listByAlias("from Gq  where isDelete=0 order by num desc", null);
		ActionContext.getContext().put("zx", rmlist.size());
		List<Gq> subList = rmlist.subList(0, 10);
		System.out.println("========================");
		 Map<String,Object> alias = new HashMap<String,Object>();
			StringBuffer sb = new StringBuffer();
			sb = sb.append("from Gq where 1=1 and isDelete =0 ");
			if(gqFind!=null && gqFind!=null && !"".equals(gqFind)){
				sb.append("  and( gs like :gs or name like :name )");
				alias.put("gs", "%" +gqFind+ "%" );
				alias.put("name", "%" +gqFind+ "%" );
			}
			sb = sb.append("order by id desc");
			Pager<Gq> pagers = gqService.findByAlias(sb.toString(),alias);
			ActionContext.getContext().put("pagers", pagers);
			ActionContext.getContext().put("gqFind", gqFind);
			ActionContext.getContext().put("subList", subList);
			return SUCCESS;
			
		//查询歌曲
	}
	
	/**
	 * 提交预定订单
	 * 
	 * @return
	 * @throws Exception 
	 */
	public String tj() throws Exception{
		Integer loginId = UserUtils.getLoginId();
		User user = new User();user.setId(loginId);
		RoomOrder ro = new RoomOrder();
		ro.setBj(bj);
		ro.setCode(getObject());
		ro.setCreateTime(new Date());
		ro.setStatus(0);
		ro.setUser(user);
		roomOrderService.save(ro);
		//修改房间被使用
		Bj byId2 = bjService.getById(bj.getId());
		byId2.setStatus(1);
		bjService.update(byId2);
		//插入歌曲
		List<BjGq> byHQL = bjGqService.getByHQL("from BjGq where user.id="+UserUtils.getLoginId()+" and bj.id="+bj.getId(), null);
		if(!isEmpty(byHQL)){
			
			for(BjGq b : byHQL){
				OrderGq og = new OrderGq();
				og.setGq(b.getGq());
				og.setRoomOrder(ro);
				orderGqService.save(og);
				bjGqService.delete(b.getId());
				//修改歌曲被点击的次数
				Gq byId = gqService.getById(b.getGq().getId());
				byId.setNum(byId.getNum()+1);
				gqService.update(byId);
				
			}
		}
		
		ActionContext.getContext().put("url", "/roomOrder_my.do");
		return "redirect";
	}
	//=============公=======共=======方=======法==========区=========end============//
	
	 //-------------------------华丽分割线---------------------------------------------//
	
	 //=============自=======定=======义=========方=======法==========区=========start============//
	
	
	private static long counter = 0;
	
	//=============自=======定=======义=========方=======法==========区=========end============//
	public synchronized String getObject() throws Exception {

        String date = new SimpleDateFormat("yyyyMMddHHMMSS").format(new Date()) + "";

        String sequ = new DecimalFormat("00").format(counter ++);

        return date + sequ;

    }
	
	
}
最近下载更多
pannifeng  LV2 2022年11月21日
五折也挺好的  LV13 2022年10月23日
yang future  LV4 2022年10月14日
591231555  LV20 2022年4月18日
MyPary  LV6 2022年4月3日
qlpqlp  LV7 2022年3月13日
karthurly  LV3 2022年3月8日
muzijijian  LV5 2022年2月17日
1983448992  LV8 2022年1月26日
北巷枫  LV9 2022年1月15日
最近浏览更多
wenpeng182013  LV7 2024年12月14日
shunlun8855  LV1 2024年10月29日
chutianyu  LV4 2024年9月29日
诗洛荨  LV3 2024年8月10日
cyd yyds  LV2 2024年8月5日
quye12 2024年6月20日
暂无贡献等级
hfffff  LV1 2024年6月3日
玖零定制问题修复  LV34 2024年4月4日
GJQ123  LV4 2024年4月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友