hotelAction.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. package com.happy.action;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.google.gson.Gson;
  4. import com.google.gson.reflect.TypeToken;
  5. import com.happy.Model.*;
  6. import com.happy.Until.GetHttpParam;
  7. import com.happy.Until.PwdDefind;
  8. import com.happy.Until.ResUtil;
  9. import com.happy.Until.UUIDUtil;
  10. import com.happy.dto.HotelEto;
  11. import com.happy.dto.IPage;
  12. import com.happy.service.*;
  13. import com.opensymphony.xwork2.ActionSupport;
  14. import net.sf.json.JSONObject;
  15. import org.apache.struts2.ServletActionContext;
  16. import org.apache.struts2.interceptor.ServletRequestAware;
  17. import org.springframework.beans.BeanUtils;
  18. import javax.annotation.Resource;
  19. import javax.servlet.http.HttpServletRequest;
  20. import javax.servlet.http.HttpServletResponse;
  21. import java.util.List;
  22. public class hotelAction extends ActionSupport implements ServletRequestAware {
  23. private HttpServletRequest request;
  24. public HttpServletResponse response;
  25. @Resource
  26. public AdminManagerService adminManagerService;
  27. @Resource
  28. public HotelService hotelService;
  29. @Resource
  30. public HotelDictService hotelDictService;
  31. @Resource
  32. public FileService fileService;
  33. public Integer id;
  34. public Integer managerId;//所属商家账号id
  35. public Integer code;//查询字典编码
  36. public int page; // 当前页
  37. public int rows;// 每页显示的行数rows
  38. public String fileListJson;
  39. public HttpServletRequest getRequest() {
  40. return request;
  41. }
  42. public void setRequest(HttpServletRequest request) {
  43. this.request = request;
  44. }
  45. public void setServletRequest(HttpServletRequest request) {
  46. this.request = request;
  47. }
  48. public HttpServletResponse getResponse() {
  49. return response;
  50. }
  51. public void setResponse(HttpServletResponse response) {
  52. this.response = response;
  53. }
  54. /**
  55. * 描述:维护民宿信息
  56. * @return
  57. */
  58. public String updateHotel(){
  59. JSONObject resultJson = new JSONObject();
  60. Gson gson = new Gson();
  61. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  62. if (json == null) {
  63. resultJson.put("message", "请传入参数");
  64. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  65. return null;
  66. }
  67. HotelEto hotelEto = new HotelEto();
  68. try{
  69. hotelEto = gson.fromJson(json.toString(), new TypeToken<HotelEto>() {}.getType());
  70. Hotel hotel = new Hotel();
  71. BeanUtils.copyProperties(hotelEto,hotel);
  72. int hotelId = hotel.getId()!=null ? hotel.getId():Math.toIntExact(UUIDUtil.generateID());
  73. if(hotelId==0){
  74. hotelId = Math.toIntExact(UUIDUtil.generateID());
  75. }
  76. int m = 0;
  77. //详细图附件
  78. List<FileInfo> fileList = JSONArray.parseArray(fileListJson, FileInfo.class);
  79. if(fileList==null){
  80. resultJson.put("message", "请上传详细图");
  81. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  82. return null;
  83. }
  84. //保存基本信息
  85. Hotel hotel1 = hotelService.getById(hotel.getId());
  86. if(hotel1!= null){
  87. m = hotelService.updateHotel(hotel);
  88. }else{
  89. hotel.setId(hotelId);
  90. m = hotelService.insertHotel(hotel);
  91. }
  92. if (m > 0) {
  93. if(hotel.getId()!= null){
  94. fileService.delLinkFile(hotel.getId());
  95. }
  96. for(FileInfo file : fileList){
  97. FileInfo fileInfo = fileService.getById(file.getId());
  98. if(fileInfo==null){
  99. fileService.insertFile(file);
  100. }else{
  101. file.setLinkId(hotelId);
  102. fileService.updateFile(file);
  103. }
  104. }
  105. resultJson.put("message", "维护成功");
  106. resultJson.put("code", 200);
  107. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  108. return null;
  109. } else {
  110. resultJson.put("message", "维护失败");
  111. resultJson.put("code", 502);
  112. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  113. return null;
  114. }
  115. } catch (Exception e){
  116. e.printStackTrace();
  117. }
  118. resultJson.put("message", "未知异常");
  119. resultJson.put("code", 205);
  120. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  121. return null;
  122. }
  123. /**
  124. * 描述:查看民宿详细
  125. * @return
  126. */
  127. public String getByHotelInfo(){
  128. JSONObject resultJson = new JSONObject();
  129. StringBuilder s1 = new StringBuilder("");
  130. if (managerId!=null){
  131. s1.append(" and manager_id = '").append(managerId).append("'");
  132. }else{
  133. resultJson.put("message", "请传入managerId");
  134. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  135. return null;
  136. }
  137. if(id!=null){
  138. s1.append(" and id = '").append(id).append("'");
  139. }
  140. //查询商户信息
  141. AdminManager adminManager = adminManagerService.getById(managerId);
  142. //查询民宿信息
  143. Hotel hotel = hotelService.getOen(s1.toString());
  144. HotelEto hotelEto = new HotelEto();
  145. if(adminManager!=null){
  146. hotelEto.setHotelName(adminManager.getHotelName());
  147. hotelEto.setHotelTownship(adminManager.getHotelTownship());
  148. hotelEto.setHotelTownshipName(adminManager.getHotelTownshipName());
  149. hotelEto.setCorpnName(adminManager.getCorpnName());
  150. hotelEto.setCorpnPhone(adminManager.getCorpnPhone());
  151. hotelEto.setManagerId(adminManager.getId());
  152. //hotelEto.setBankCard(adminManager.getBankCard());
  153. }
  154. if(hotel!=null){
  155. //获取有效民宿配置
  156. if(hotel.getHconfig() != null && !"".equals(hotel.getHconfig())){
  157. hotel.setHconfig(hotelDictService.setConfig(hotel.getHconfig()));
  158. }
  159. BeanUtils.copyProperties(hotel,hotelEto);
  160. hotelEto.setHotelTownshipName(adminManager.getHotelTownshipName());
  161. StringBuilder fileSqlx = new StringBuilder("");
  162. fileSqlx.append("and link_id = '").append(hotel.getId()).append("'");
  163. List<FileInfo> fileList = fileService.queryList(fileSqlx.toString());
  164. hotelEto.setFileInfoList(fileList);
  165. resultJson.put("message", "查询成功");
  166. resultJson.put("code", 200);
  167. resultJson.put("data", hotelEto);
  168. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  169. }
  170. if(adminManager == null && hotel == null){
  171. resultJson.put("message", "未查到数据请检查参数");
  172. resultJson.put("code", 500);
  173. resultJson.put("data", hotelEto);
  174. }
  175. resultJson.put("message", "查询成功");
  176. resultJson.put("code", 200);
  177. resultJson.put("data", hotelEto);
  178. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  179. return null;
  180. }
  181. /**
  182. * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
  183. * @return
  184. */
  185. public String insterHotelDict(){
  186. JSONObject resultJson = new JSONObject();
  187. Gson gson = new Gson();
  188. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  189. if (json == null) {
  190. resultJson.put("message", "请传入参数");
  191. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  192. return null;
  193. }
  194. HotelDict hotelDict = new HotelDict();
  195. try{
  196. hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
  197. if(hotelDict==null){
  198. resultJson.put("message", "数据为空");
  199. resultJson.put("code", 500);
  200. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  201. return null;
  202. }
  203. if(hotelDict.getName()==null || hotelDict.getCode()==null){
  204. resultJson.put("message", "各参数不能为空");
  205. resultJson.put("code", 500);
  206. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  207. return null;
  208. }
  209. if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
  210. resultJson.put("message", "服务图标不能为空");
  211. resultJson.put("code", 500);
  212. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  213. return null;
  214. }
  215. StringBuilder getOneSqlx = new StringBuilder("");
  216. getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
  217. .append(" and name = '").append(hotelDict.getName()).append("'");
  218. HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
  219. if(listc != null){
  220. resultJson.put("message", "已新增过相同名称的数据");
  221. resultJson.put("code", 500);
  222. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  223. return null;
  224. }
  225. int m = hotelDictService.insertHotelDict(hotelDict);
  226. if (m > 0) {
  227. resultJson.put("message", "添加成功");
  228. resultJson.put("code", 200);
  229. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  230. return null;
  231. } else {
  232. resultJson.put("message", "添加失败");
  233. resultJson.put("code", 502);
  234. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  235. return null;
  236. }
  237. }catch (Exception e){
  238. e.printStackTrace();
  239. resultJson.put("message", "未知异常:"+ e);
  240. resultJson.put("code", 205);
  241. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  242. }
  243. resultJson.put("message", "未知异常");
  244. resultJson.put("code", 205);
  245. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  246. return null;
  247. }
  248. /**
  249. * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
  250. * @return
  251. */
  252. public String updateHotelDict(){
  253. JSONObject resultJson = new JSONObject();
  254. Gson gson = new Gson();
  255. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  256. if (json == null) {
  257. resultJson.put("message", "请传入参数");
  258. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  259. return null;
  260. }
  261. HotelDict hotelDict = new HotelDict();
  262. try{
  263. hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
  264. if(hotelDict==null){
  265. resultJson.put("message", "数据为空");
  266. resultJson.put("code", 500);
  267. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  268. return null;
  269. }
  270. if(hotelDict.getId()==null){
  271. resultJson.put("message", "修改Id不能为空");
  272. resultJson.put("code", 500);
  273. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  274. return null;
  275. }
  276. if(hotelDict.getName()==null){
  277. resultJson.put("message", "各参数不能为空");
  278. resultJson.put("code", 500);
  279. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  280. return null;
  281. }
  282. if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
  283. resultJson.put("message", "服务图标不能为空");
  284. resultJson.put("code", 500);
  285. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  286. return null;
  287. }
  288. StringBuilder getOneSqlx = new StringBuilder("");
  289. getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
  290. .append(" and name = '").append(hotelDict.getName()).append("'")
  291. .append(" and id != '").append(hotelDict.getId()).append("'");
  292. HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
  293. if(listc != null){
  294. resultJson.put("message", "已新增过相同名称的数据");
  295. resultJson.put("code", 500);
  296. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  297. return null;
  298. }
  299. int m = hotelDictService.updateHotelDict(hotelDict);
  300. if (m > 0) {
  301. resultJson.put("message", "修改成功");
  302. resultJson.put("code", 200);
  303. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  304. return null;
  305. } else {
  306. resultJson.put("message", "修改失败");
  307. resultJson.put("code", 502);
  308. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  309. return null;
  310. }
  311. }catch (Exception e){
  312. e.printStackTrace();
  313. resultJson.put("message", "未知异常:"+ e);
  314. resultJson.put("code", 205);
  315. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  316. }
  317. resultJson.put("message", "未知异常");
  318. resultJson.put("code", 205);
  319. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  320. return null;
  321. }
  322. /**
  323. * 描述:删除民宿配置字典
  324. * @return
  325. */
  326. public String delHotelDict(){
  327. JSONObject resultJson = new JSONObject();
  328. if (id == null) {
  329. resultJson.put("message", "请传入id");
  330. resultJson.put("code", 500);
  331. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  332. return null;
  333. }
  334. int m = hotelDictService.delHotelDict(id);
  335. if (m > 0) {
  336. resultJson.put("message", "删除成功");
  337. resultJson.put("code", 200);
  338. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  339. return null;
  340. }
  341. resultJson.put("message", "未知异常");
  342. resultJson.put("code", 205);
  343. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  344. return null;
  345. }
  346. /**
  347. * 描述:查询民宿配置列表
  348. * @return
  349. */
  350. public String queryList(){
  351. JSONObject resultJson = new JSONObject();
  352. StringBuilder s1 = new StringBuilder("");
  353. StringBuilder s2 = new StringBuilder("");
  354. StringBuilder s3 = new StringBuilder("");
  355. StringBuilder s4 = new StringBuilder("");
  356. if(code==null){//查询全部
  357. s1.append("and code = 1");
  358. List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
  359. s2.append("and code = 2");
  360. List<HotelDict> list2 = hotelDictService.queryList(s2.toString());
  361. s3.append("and code = 3");
  362. List<HotelDict> list3 = hotelDictService.queryList(s3.toString());
  363. s4.append("and code = 4");
  364. List<HotelDict> list4 = hotelDictService.queryList(s4.toString());
  365. resultJson.put("message", "查询成功");
  366. resultJson.put("code", 200);
  367. resultJson.put("date1", list1);
  368. resultJson.put("date2", list2);
  369. resultJson.put("date3", list3);
  370. resultJson.put("date4", list4);
  371. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  372. return null;
  373. }else{
  374. s1.append("and code = ").append(code);
  375. List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
  376. resultJson.put("message", "查询成功");
  377. resultJson.put("code", 200);
  378. resultJson.put("data", list1);
  379. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  380. return null;
  381. }
  382. }
  383. }