| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- package com.happy.action;
- import com.baidubce.model.User;
- import com.happy.Model.Hotel;
- import com.happy.Model.weixin.Users;
- import com.happy.Until.*;
- import com.happy.Until.Enum.B;
- import com.happy.Until.Enum.TempEnum;
- import com.happy.constant.ResultStatusCode;
- import com.happy.dao.UserVisitsDao;
- import com.happy.dto.IPage;
- import com.happy.dto.townshipCountDTO;
- import com.happy.service.*;
- import com.opensymphony.xwork2.ActionSupport;
- import net.sf.json.JSONObject;
- import org.apache.struts2.ServletActionContext;
- import org.apache.struts2.interceptor.ServletRequestAware;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.util.List;
- /**
- * 首页进去Action请求交互
- */
- public class AppHomePageAction extends ActionSupport implements ServletRequestAware {
- private HttpServletRequest request;
- public HttpServletResponse response;
- @Resource
- public UserVisitsDao userVisitsDao;
- @Resource
- public UserService userService;
- @Resource
- public AppHomePageService appHomePageService;
- @Resource
- public HotelService hotelService;
- @Resource
- public FileService fileService;
- @Resource
- public AdminManagerService adminManagerService;
- public int page; // 当前页
- public int rows;// 每页显示的行数rows
- public Integer id = new Integer(0);
- public String status;
- public String hotelId; //选择的当前酒店的id
- public String queryStartTime; // 查询开始时间
- public String queryEndTime; // 查询结束时间
- public String userCode; // 第一次进来获取用户的code
- public String queryValue; // 首页查寻搜索关键词
- private String hotel_township; // 所属乡镇
- public String userId; // 用户id
- public int type;
- public HttpServletRequest getRequest() {
- return request;
- }
- public void setRequest(HttpServletRequest request) {
- this.request = request;
- }
- public void setServletRequest(HttpServletRequest request) {
- this.request = request;
- }
- public HttpServletResponse getResponse() {
- return response;
- }
- public void setResponse(HttpServletResponse response) {
- this.response = response;
- }
- public int getPage() {
- return page;
- }
- public void setPage(int page) {
- this.page = page;
- }
- public int getRows() {
- return rows;
- }
- public void setRows(int rows) {
- this.rows = rows;
- }
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getStatus() {
- return status;
- }
- public void setStatus(String status) {
- this.status = status;
- }
- /**
- * 进入首页,展示民宿数据列表
- * queryValue 查询字段
- * hotel_townshipId 所属乡镇
- * @return
- */
- public String homePage()
- {
- // 获取民宿列表
- IPage iPage = appHomePageService.getHotelList(queryValue, hotel_township,type,page,rows);
- // 用户访问量数据
- userVisitsDao.add(userId);
- ResponseUtil.writeJsonIPage(ServletActionContext.getResponse(),iPage);
- return null;
- }
- /**
- * 用户点击收藏民宿
- * userId
- * hotelId
- * @return
- */
- public String collectHotel()
- {
- if (Func.checkNull(userId) || Func.checkNull(hotelId))
- return null;
- Users users = userService.addhotelAndUsers(hotelId,userId, TempEnum.收藏);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put(B.code,ResultStatusCode.OK.getStatus());
- jsonObject.put(B.data,users);
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
- return null;
- }
- /**
- * 用户点击取消 收藏民宿
- * userId 用户id
- * hotelId 酒店id
- * @return
- */
- public String delCollectHotel()
- {
- if (Func.checkNull(userId) || Func.checkNull(hotelId))
- return null;
- Users users = userService.delhotelAndUsers(hotelId,userId, TempEnum.收藏);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put(B.code,ResultStatusCode.OK.getStatus());
- jsonObject.put(B.data,users);
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
- return null;
- }
- /**
- * hotelId 酒店id
- * queryStartTime
- * queryEndTime
- * userId
- * 通过酒店的id获取到房间信息
- * @return
- */
- public String getHouseByHotelId()
- {
- JSONObject jsonObject = new JSONObject();
- // 如果未赋值,则直接跳出
- if (Func.checkNull(hotelId) || Func.checkNull(queryStartTime) || Func.checkNull(queryEndTime))
- {
- jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
- jsonObject.put(B.message,ResultStatusCode.BAD_REQUEST.getMsg());
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
- return null;
- }
- // 使用天去查"yyyy/MM/dd"
- String startDate = DateUtil.parseDateToStr((Func.parseDate(queryStartTime)), DateUtil.Time_Formatter_Day);
- String endDate = DateUtil.parseDateToStr((Func.parseDate(queryEndTime)), DateUtil.Time_Formatter_Day);
- Hotel hotel = appHomePageService.getHotelAndHouseByHotelId(hotelId,startDate, endDate);
- hotel.setHotelFileInfoList(fileService.queryListByLinkId(hotelId));
- // 添加是否已收藏的酒店
- if (!Func.checkNull(userId))
- appHomePageService.assignCollect(userId, hotel);
- // 通过时间区间查询房间信息,并带好是否有房标识给前台
- jsonObject.put(B.code,ResultStatusCode.OK.getStatus());
- jsonObject.put(B.data,ResultUtil.ok(hotel));
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
- return null;
- }
- /**
- * 通过酒店的id获取到酒店详细信息
- * hotelId
- * userId
- * @return
- */
- public String getHotelInfoByHotelId()
- {
- JSONObject jsonObject = new JSONObject();
- // 如果未赋值,则直接跳出
- if (Func.checkNull(hotelId))
- {
- jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
- jsonObject.put(B.message,ResultStatusCode.BAD_REQUEST.getMsg());
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
- return null;
- }
- Hotel hotel = hotelService.getById(Func.parseInt(hotelId));
- if (hotel == null)
- {
- jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
- jsonObject.put(B.message,"无法查询到当前酒店信息");
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
- return null;
- }
- hotel.setHotelFileInfoList(fileService.queryListByLinkId(hotelId));
- // 添加是否已收藏的酒店
- if (!Func.checkNull(userId))
- appHomePageService.assignCollect(userId, hotel);
- jsonObject.put(B.code,ResultStatusCode.OK.getStatus());
- jsonObject.put(B.data,hotel);
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
- return null;
- }
- /**
- * 描述:获取各乡俗民宿级别数量
- * @return
- */
- public String getTownshipCount(){
- JSONObject resultjson = new JSONObject();
- List<townshipCountDTO> list = adminManagerService.getTownshipCount();
- if (list!=null){
- resultjson.put("message", "返回成功");
- resultjson.put("code", 200);
- resultjson.put("data",list);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
- return null;
- }
- resultjson.put("message", "数据为空");
- resultjson.put("code", 205);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
- return null;
- }
- /**
- * 描述:获取各乡镇剩余房数
- * @return
- */
- public String getResidueCount(){
- JSONObject resultjson = new JSONObject();
- List<townshipCountDTO> list = adminManagerService.getResidueCount();
- if (list!=null){
- resultjson.put("message", "返回成功");
- resultjson.put("code", 200);
- resultjson.put("data",list);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
- return null;
- }
- resultjson.put("message", "数据为空");
- resultjson.put("code", 205);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
- return null;
- }
- public String getUserCode() {
- return userCode;
- }
- public void setUserCode(String userCode) {
- this.userCode = userCode;
- }
- public String getQueryValue() {
- return queryValue;
- }
- public void setQueryValue(String queryValue) {
- this.queryValue = queryValue;
- }
- public String getHotelId() {
- return hotelId;
- }
- public void setHotelId(String hotelId) {
- this.hotelId = hotelId;
- }
- public void setHotel_township(String hotel_township) {
- this.hotel_township = hotel_township;
- }
- }
|