hotelCoupomAction.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. package com.happy.action;
  2. import com.baidubce.services.media.model.Job;
  3. import com.google.common.base.Joiner;
  4. import com.google.gson.Gson;
  5. import com.google.gson.reflect.TypeToken;
  6. import com.happy.Model.Admin;
  7. import com.happy.Model.AdminManager;
  8. import com.happy.Model.HotelCoupon;
  9. import com.happy.Model.HotelDict;
  10. import com.happy.Until.Func;
  11. import com.happy.Until.GetHttpParam;
  12. import com.happy.Until.ResUtil;
  13. import com.happy.Until.UUIDUtil;
  14. import com.happy.common.controller.BaseController;
  15. import com.happy.dao.HotelCouponDao;
  16. import com.happy.dto.IPage;
  17. import com.happy.service.HotelCoupomService;
  18. import com.happy.service.HotelCoupomStatusService;
  19. import net.sf.json.JSONObject;
  20. import org.apache.struts2.ServletActionContext;
  21. import org.apache.struts2.interceptor.ServletRequestAware;
  22. import javax.annotation.Resource;
  23. import java.util.Arrays;
  24. import java.util.List;
  25. public class hotelCoupomAction extends BaseController implements ServletRequestAware {
  26. public List<String> ids; //优惠卷id
  27. public String name; //优惠卷名称
  28. public String type; //类型
  29. public String grantStartDate;//发放时间
  30. public String grantEndDate;//发放时间
  31. @Resource(name = "hotelCoupomService")
  32. private HotelCoupomService hotelCoupomService;
  33. @Resource(name = "hotelCoupomStatusService")
  34. private HotelCoupomStatusService hotelCoupomStatusService;
  35. /**
  36. * 描述:新增优惠卷
  37. * @return
  38. */
  39. public String inster(){
  40. JSONObject resultJson = new JSONObject();
  41. Gson gson = new Gson();
  42. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  43. if (json == null) {
  44. resultJson.put("message", "请传入参数");
  45. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  46. return null;
  47. }
  48. HotelCoupon hotelCoupon = null;
  49. try{
  50. hotelCoupon = gson.fromJson(json.toString(), new TypeToken<HotelCoupon>() {}.getType());
  51. if(hotelCoupon==null){
  52. resultJson.put("message", "数据为空");
  53. resultJson.put("code", 500);
  54. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  55. return null;
  56. }
  57. //格式化
  58. hotelCoupon.setRemainderNumber(hotelCoupon.getGrantNumber());
  59. hotelCoupon.setReversedNumber(0);
  60. int m = hotelCoupomService.insert(hotelCoupon);
  61. if (m > 0) {
  62. resultJson.put("message", "添加成功");
  63. resultJson.put("code", 200);
  64. } else {
  65. resultJson.put("message", "添加失败");
  66. resultJson.put("code", 502);
  67. }
  68. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  69. return null;
  70. }catch (Exception e){
  71. e.printStackTrace();
  72. resultJson.put("message", "未知异常:"+ e);
  73. resultJson.put("code", 205);
  74. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  75. }
  76. resultJson.put("message", "未知异常");
  77. resultJson.put("code", 205);
  78. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  79. return null;
  80. }
  81. /**
  82. * 描述:修改优惠卷
  83. * @return
  84. */
  85. public String update(){
  86. JSONObject resultJson = new JSONObject();
  87. Gson gson = new Gson();
  88. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  89. if (json == null) {
  90. resultJson.put("message", "请传入参数");
  91. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  92. return null;
  93. }
  94. HotelCoupon hotelCoupon = null;
  95. try{
  96. hotelCoupon = gson.fromJson(json.toString(), new TypeToken<HotelCoupon>() {}.getType());
  97. if (hotelCoupon.getId()==null || "".equals(hotelCoupon.getId())){
  98. resultJson.put("message", "请传入优惠卷id");
  99. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  100. return null;
  101. }
  102. HotelCoupon h1 = hotelCoupomService.getById(hotelCoupon.getId());
  103. if (h1==null){
  104. resultJson.put("message", "修改失败,未查询到优惠卷");
  105. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  106. return null;
  107. }
  108. int m = hotelCoupomService.update(hotelCoupon);
  109. if (m > 0) {
  110. resultJson.put("message", "修改成功");
  111. resultJson.put("code", 200);
  112. } else {
  113. resultJson.put("message", "修改失败");
  114. resultJson.put("code", 502);
  115. }
  116. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  117. return null;
  118. }catch (Exception e){
  119. e.printStackTrace();
  120. resultJson.put("message", "未知异常:"+ e);
  121. resultJson.put("code", 205);
  122. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  123. }
  124. resultJson.put("message", "未知异常");
  125. resultJson.put("code", 205);
  126. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  127. return null;
  128. }
  129. /**
  130. * 描述:分页查询
  131. * @return
  132. */
  133. public String queryPage(){
  134. JSONObject resultJson = new JSONObject();
  135. StringBuilder s1 = new StringBuilder("");
  136. if (name != null){
  137. s1.append(" and name like '%").append(name).append("%' ");
  138. }
  139. if (status != null){
  140. s1.append(" and status = ").append(status).append(" ");
  141. }
  142. if (grantStartDate != null && grantEndDate != null){
  143. s1.append(" and DATE_FORMAT(grant_start_date,'%Y-%m-%d') >= '").append(grantStartDate).append("' ");
  144. s1.append(" and DATE_FORMAT(grant_end_date,'%Y-%m-%d') <= '").append(grantEndDate).append("' ");
  145. }
  146. IPage<HotelCoupon> hotelCouponIPage = hotelCoupomService.queryPage(s1.toString(),page,rows);
  147. if(hotelCouponIPage!=null && !"".equals(hotelCouponIPage)){
  148. resultJson.put("message", "查询分页成功");
  149. resultJson.put("code", 200);
  150. resultJson.put("data", hotelCouponIPage);
  151. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  152. }else{
  153. resultJson.put("message", "查询分页失败");
  154. resultJson.put("code", 500);
  155. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  156. }
  157. return null;
  158. }
  159. /**
  160. * 描述:根据Id查询详细
  161. * @return
  162. */
  163. public String getById(){
  164. JSONObject resultJson = new JSONObject();
  165. if (id==null || "".equals(id)) {
  166. resultJson.put("message", "请传入id");
  167. resultJson.put("code", 500);
  168. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  169. return null;
  170. }
  171. HotelCoupon hotelCoupon = hotelCoupomService.getById(id);
  172. if (hotelCoupon != null) {
  173. resultJson.put("message", "查询成功");
  174. resultJson.put("code", 200);
  175. resultJson.put("data", hotelCoupon);
  176. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  177. return null;
  178. }else{
  179. resultJson.put("message", "未查询到优惠卷信息");
  180. resultJson.put("code", 500);
  181. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  182. return null;
  183. }
  184. }
  185. /**
  186. * 描述:优惠卷批量失效
  187. */
  188. public String saveBatchLapse(){
  189. JSONObject resultJson = new JSONObject();
  190. Gson gson = new Gson();
  191. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  192. if (json == null) {
  193. resultJson.put("message", "请传入参数");
  194. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  195. return null;
  196. }
  197. HotelCoupon hotelCoupon = null;
  198. try {
  199. hotelCoupon = gson.fromJson(json.toString(), new TypeToken<HotelCoupon>() {}.getType());
  200. if (ids == null){
  201. resultJson.put("message", "请传入优惠卷id");
  202. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  203. return null;
  204. }
  205. int m = hotelCoupomService.updateLapse(ids);
  206. //TODO 修改用户领取的优惠卷
  207. int n = hotelCoupomStatusService.updateLapse(ids);
  208. resultJson.put("message", "修改成功");
  209. resultJson.put("code", 200);
  210. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  211. return null;
  212. }catch (Exception e){
  213. e.printStackTrace();
  214. resultJson.put("message", "未知异常:"+ e);
  215. resultJson.put("code", 205);
  216. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  217. }
  218. resultJson.put("message", "未知异常");
  219. resultJson.put("code", 205);
  220. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  221. return null;
  222. }
  223. /**
  224. * 描述:定时任务修改优惠卷状态
  225. */
  226. public void setCoupomStatus(){
  227. JSONObject resultJson = new JSONObject();
  228. try {
  229. int n = hotelCoupomService.updateExpire();
  230. int m = hotelCoupomStatusService.updateExpir();
  231. resultJson.put("message", "修改成功");
  232. resultJson.put("code", 200);
  233. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  234. }catch (Exception e){
  235. e.printStackTrace();
  236. resultJson.put("message", "未知异常:"+ e);
  237. resultJson.put("code", 205);
  238. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  239. }
  240. System.out.println(1111);
  241. }
  242. }