HouseNumberStatusAction.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.happy.action;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.happy.Model.Holiday;
  4. import com.happy.Until.GetHttpParam;
  5. import com.happy.Until.ResUtil;
  6. import com.happy.common.controller.BaseController;
  7. import com.happy.dto.HouseNumberStatusDto;
  8. import com.happy.service.HouseNumberStatusService;
  9. import com.opensymphony.xwork2.ModelDriven;
  10. import lombok.SneakyThrows;
  11. import org.apache.struts2.ServletActionContext;
  12. import javax.annotation.Resource;
  13. import java.util.List;
  14. import static com.happy.Until.HolidayUtil.getYearHoliday;
  15. public class HouseNumberStatusAction extends BaseController implements ModelDriven<HouseNumberStatusDto> {
  16. private final HouseNumberStatusDto houseNumberStatusDto = new HouseNumberStatusDto();
  17. @Override
  18. public HouseNumberStatusDto getModel() {
  19. return houseNumberStatusDto;
  20. }
  21. @Resource(name = "HouseNumberStatusService")
  22. private HouseNumberStatusService houseNumberStatusService;
  23. /**
  24. * 根据年份获取节假日数据
  25. */
  26. public String queryHoliday() {
  27. String year = houseNumberStatusDto.getYear();
  28. if (year.length() > 4) {
  29. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  30. put("message", "请输入年份");
  31. put("code", 500);
  32. }}.toString());
  33. return null;
  34. }
  35. if (year == null) {
  36. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  37. put("message", "请传入参数");
  38. put("code", 500);
  39. }}.toString());
  40. return null;
  41. }
  42. List<Holiday> days = getYearHoliday("2023");
  43. if (days == null) {
  44. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  45. put("message", "第三方接口调用失败");
  46. put("code", 500);
  47. }}.toString());
  48. return null;
  49. }
  50. if (days.size() <= 0) {
  51. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  52. put("message", "第三方接口调用失败");
  53. put("code", 500);
  54. }}.toString());
  55. return null;
  56. }
  57. houseNumberStatusService.deleteHolidayByYear(year);
  58. int lenegth = houseNumberStatusService.saveHolidayBatch(days);
  59. if (lenegth <= 0) {
  60. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  61. put("message", "节假日数据存储失败");
  62. put("code", 500);
  63. }}.toString());
  64. return null;
  65. }
  66. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  67. put("message", "节假日数据存储成功");
  68. put("code", 200);
  69. }}.toString());
  70. return null;
  71. }
  72. /**
  73. * 表格数据 房态管理-房态管理
  74. */
  75. public void queryData() {
  76. JSONObject objects = houseNumberStatusService.queryData(houseNumberStatusDto,page,rows);
  77. if (objects != null) {
  78. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  79. put("message", "请求成功");
  80. put("code", 200);
  81. put("data", objects);
  82. }}.toString());
  83. } else {
  84. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  85. put("message", "该房型未新增房间号");
  86. put("code", 200);
  87. }}.toString());
  88. }
  89. }
  90. /**
  91. * 查询可置脏/净、可开/关的房型及房间号 房态管理-房态管理
  92. */
  93. public void queryListWithHouse() {
  94. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  95. put("message", "请求成功");
  96. put("code", 200);
  97. put("data", houseNumberStatusService.queryListWithHouse(houseNumberStatusDto));
  98. }}.toString());
  99. }
  100. /**
  101. * 批量开/关房 房态管理-房态管理
  102. */
  103. @SneakyThrows
  104. public void modifyStatusBatch() {
  105. String postDataStr = GetHttpParam.getRequestPostData(request);
  106. HouseNumberStatusDto postDataObj = JSONObject.parseObject(postDataStr, HouseNumberStatusDto.class);
  107. //2023-09-20 A-jax 参数判断
  108. if(postDataObj.getHouseNumberIds() == null){
  109. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  110. put("message", "房间不能为空");
  111. put("code", 500);
  112. }}.toString());
  113. }
  114. if(postDataObj.getStatus() == 2 && postDataObj.getCreateId() == null){
  115. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  116. put("message", "关房类型不能为空");
  117. put("code", 500);
  118. }}.toString());
  119. }
  120. if(postDataObj.getSetDate() == null){
  121. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  122. put("message", "日期不能为空");
  123. put("code", 500);
  124. }}.toString());
  125. }
  126. houseNumberStatusService.modifyStatusBatch(postDataObj);
  127. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  128. put("message", "请求成功");
  129. put("code", 200);
  130. }}.toString());
  131. }
  132. /**
  133. * 开/关房 房态管理-房态管理
  134. */
  135. @SneakyThrows
  136. public void modifyStatus() {
  137. if(houseNumberStatusDto.getCloseType() == null){
  138. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  139. put("message", "关房类型不能为空");
  140. put("code", 500);
  141. }}.toString());
  142. }
  143. houseNumberStatusService.modifyStatus(houseNumberStatusDto);
  144. ResUtil.writeJson(ServletActionContext.getResponse(), new JSONObject() {{
  145. put("message", "请求成功");
  146. put("code", 200);
  147. }}.toString());
  148. }
  149. }