| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- package com.happy.action;
- import com.alibaba.fastjson.JSONArray;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.happy.Model.*;
- import com.happy.Until.GetHttpParam;
- import com.happy.Until.PwdDefind;
- import com.happy.Until.ResUtil;
- import com.happy.Until.UUIDUtil;
- import com.happy.dto.HotelEto;
- import com.happy.dto.IPage;
- 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 org.springframework.beans.BeanUtils;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.util.List;
- public class hotelAction extends ActionSupport implements ServletRequestAware {
- private HttpServletRequest request;
- public HttpServletResponse response;
- @Resource
- public AdminManagerService adminManagerService;
- @Resource
- public HotelService hotelService;
- @Resource
- public HotelDictService hotelDictService;
- @Resource
- public FileService fileService;
- public Integer id;
- public Integer managerId;//所属商家账号id
- public Integer code;//查询字典编码
- public int page; // 当前页
- public int rows;// 每页显示的行数rows
- public String fileListJson;
- 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;
- }
- /**
- * 描述:维护民宿信息
- * @return
- */
- public String updateHotel(){
- JSONObject resultJson = new JSONObject();
- Gson gson = new Gson();
- com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
- if (json == null) {
- resultJson.put("message", "请传入参数");
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- HotelEto hotelEto = new HotelEto();
- try{
- hotelEto = gson.fromJson(json.toString(), new TypeToken<HotelEto>() {}.getType());
- Hotel hotel = new Hotel();
- BeanUtils.copyProperties(hotelEto,hotel);
- int hotelId = hotel.getId()!= null ? hotel.getId():Math.toIntExact(UUIDUtil.generateID());
- int m = 0;
- //详细图附件
- List<FileInfo> fileList = JSONArray.parseArray(fileListJson, FileInfo.class);
- if(fileList==null){
- resultJson.put("message", "请上传详细图");
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- //保存基本信息
- if(hotel.getId()!= null){
- m = hotelService.updateHotel(hotel);
- }else{
- hotel.setId(hotelId);
- m = hotelService.insertHotel(hotel);
- }
- if (m > 0) {
- if(hotel.getId()!= null){
- fileService.delLinkFile(hotel.getId());
- }
- for(FileInfo file : fileList){
- file.setLinkId(hotelId);
- fileService.updateFile(file);
- }
- resultJson.put("message", "维护成功");
- resultJson.put("code", 200);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- } else {
- resultJson.put("message", "维护失败");
- resultJson.put("code", 502);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- } catch (Exception e){
- e.printStackTrace();
- }
- resultJson.put("message", "未知异常");
- resultJson.put("code", 205);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- /**
- * 描述:查看民宿详细
- * @return
- */
- public String getByHotelInfo(){
- JSONObject resultJson = new JSONObject();
- StringBuilder s1 = new StringBuilder("");
- if (managerId!=null){
- s1.append(" and manager_id = '").append(managerId).append("'");
- }else{
- resultJson.put("message", "请传入登陆人账号Id");
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- //查询商户信息
- AdminManager adminManager = adminManagerService.getById(managerId);
- //查询民宿信息
- Hotel hotel = hotelService.getOen(s1.toString());
- HotelEto hotelEto = new HotelEto();
- if(adminManager!=null){
- BeanUtils.copyProperties(adminManager,hotelEto);
- }
- if(hotel!=null){
- BeanUtils.copyProperties(hotel,hotelEto);
- }
- StringBuilder fileSqlx = new StringBuilder("");
- fileSqlx.append("and link_id = '").append(id).append("'");
- List<FileInfo> fileList = fileService.queryList(fileSqlx.toString());
- hotelEto.setFileInfoList(fileList);
- resultJson.put("message", "查询成功");
- resultJson.put("code", 200);
- resultJson.put("data", hotelEto);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- /**
- * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
- * @return
- */
- public String insterHotelDict(){
- JSONObject resultJson = new JSONObject();
- Gson gson = new Gson();
- com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
- if (json == null) {
- resultJson.put("message", "请传入参数");
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- HotelDict hotelDict = new HotelDict();
- try{
- hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
- if(hotelDict==null){
- resultJson.put("message", "数据为空");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- if(hotelDict.getName()==null || hotelDict.getCode()==null){
- resultJson.put("message", "各参数不能为空");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
- resultJson.put("message", "服务图标不能为空");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- StringBuilder getOneSqlx = new StringBuilder("");
- getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
- .append(" and name = '").append(hotelDict.getName()).append("'");
- HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
- if(listc != null){
- resultJson.put("message", "已新增过相同名称的数据");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- int m = hotelDictService.insertHotelDict(hotelDict);
- if (m > 0) {
- resultJson.put("message", "添加成功");
- resultJson.put("code", 200);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- } else {
- resultJson.put("message", "添加失败");
- resultJson.put("code", 502);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- }catch (Exception e){
- e.printStackTrace();
- resultJson.put("message", "未知异常:"+ e);
- resultJson.put("code", 205);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- }
- resultJson.put("message", "未知异常");
- resultJson.put("code", 205);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- /**
- * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
- * @return
- */
- public String updateHotelDict(){
- JSONObject resultJson = new JSONObject();
- Gson gson = new Gson();
- com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
- if (json == null) {
- resultJson.put("message", "请传入参数");
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- HotelDict hotelDict = new HotelDict();
- try{
- hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
- if(hotelDict==null){
- resultJson.put("message", "数据为空");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- if(hotelDict.getId()==null){
- resultJson.put("message", "修改Id不能为空");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- if(hotelDict.getName()==null){
- resultJson.put("message", "各参数不能为空");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
- resultJson.put("message", "服务图标不能为空");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- StringBuilder getOneSqlx = new StringBuilder("");
- getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
- .append(" and name = '").append(hotelDict.getName()).append("'")
- .append(" and id != '").append(hotelDict.getId()).append("'");
- HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
- if(listc != null){
- resultJson.put("message", "已新增过相同名称的数据");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- int m = hotelDictService.updateHotelDict(hotelDict);
- if (m > 0) {
- resultJson.put("message", "修改成功");
- resultJson.put("code", 200);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- } else {
- resultJson.put("message", "修改失败");
- resultJson.put("code", 502);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- }catch (Exception e){
- e.printStackTrace();
- resultJson.put("message", "未知异常:"+ e);
- resultJson.put("code", 205);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- }
- resultJson.put("message", "未知异常");
- resultJson.put("code", 205);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- /**
- * 描述:删除民宿配置字典
- * @return
- */
- public String delHotelDict(){
- JSONObject resultJson = new JSONObject();
- if (id == null) {
- resultJson.put("message", "请传入id");
- resultJson.put("code", 500);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- int m = hotelDictService.delHotelDict(id);
- if (m > 0) {
- resultJson.put("message", "删除成功");
- resultJson.put("code", 200);
- 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 queryList(){
- JSONObject resultJson = new JSONObject();
- StringBuilder s1 = new StringBuilder("");
- StringBuilder s2 = new StringBuilder("");
- StringBuilder s3 = new StringBuilder("");
- StringBuilder s4 = new StringBuilder("");
- if(code==null){//查询全部
- s1.append("and code = 1");
- List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
- s2.append("and code = 2");
- List<HotelDict> list2 = hotelDictService.queryList(s2.toString());
- s3.append("and code = 3");
- List<HotelDict> list3 = hotelDictService.queryList(s3.toString());
- s4.append("and code = 4");
- List<HotelDict> list4 = hotelDictService.queryList(s4.toString());
- resultJson.put("message", "查询成功");
- resultJson.put("code", 200);
- resultJson.put("date1", list1);
- resultJson.put("date2", list2);
- resultJson.put("date3", list3);
- resultJson.put("date4", list4);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }else{
- s1.append("and code = ").append(code);
- List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
- resultJson.put("message", "查询成功");
- resultJson.put("code", 200);
- resultJson.put("data", list1);
- ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
- return null;
- }
- }
- }
|