|
|
@@ -1,25 +1,44 @@
|
|
|
package com.happy.action;
|
|
|
|
|
|
import com.baidubce.services.media.model.Job;
|
|
|
+import com.google.common.base.Joiner;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
+import com.happy.Model.Admin;
|
|
|
import com.happy.Model.AdminManager;
|
|
|
import com.happy.Model.HotelCoupon;
|
|
|
import com.happy.Model.HotelDict;
|
|
|
+import com.happy.Until.Func;
|
|
|
import com.happy.Until.GetHttpParam;
|
|
|
import com.happy.Until.ResUtil;
|
|
|
+import com.happy.Until.UUIDUtil;
|
|
|
import com.happy.common.controller.BaseController;
|
|
|
import com.happy.dao.HotelCouponDao;
|
|
|
import com.happy.dto.IPage;
|
|
|
import com.happy.service.HotelCoupomService;
|
|
|
+import com.happy.service.HotelCoupomStatusService;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.struts2.ServletActionContext;
|
|
|
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
public class hotelCoupomAction extends BaseController implements ServletRequestAware {
|
|
|
|
|
|
+
|
|
|
+ public List<String> ids; //优惠卷id
|
|
|
+ public String name; //优惠卷名称
|
|
|
+ public String type; //类型
|
|
|
+ public String grantStartDate;//发放时间
|
|
|
+ public String grantEndDate;//发放时间
|
|
|
+
|
|
|
+ @Resource(name = "hotelCoupomService")
|
|
|
private HotelCoupomService hotelCoupomService;
|
|
|
|
|
|
+ @Resource(name = "hotelCoupomStatusService")
|
|
|
+ private HotelCoupomStatusService hotelCoupomStatusService;
|
|
|
/**
|
|
|
* 描述:新增优惠卷
|
|
|
* @return
|
|
|
@@ -35,13 +54,26 @@ public class hotelCoupomAction extends BaseController implements ServletRequestA
|
|
|
}
|
|
|
HotelCoupon hotelCoupon = null;
|
|
|
try{
|
|
|
- hotelCoupon = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
|
|
|
+ hotelCoupon = gson.fromJson(json.toString(), new TypeToken<HotelCoupon>() {}.getType());
|
|
|
if(hotelCoupon==null){
|
|
|
resultJson.put("message", "数据为空");
|
|
|
resultJson.put("code", 500);
|
|
|
ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
return null;
|
|
|
}
|
|
|
+ //格式化
|
|
|
+ hotelCoupon.setRemainderNumber(hotelCoupon.getGrantNumber());
|
|
|
+ hotelCoupon.setReversedNumber(0);
|
|
|
+ int m = hotelCoupomService.insert(hotelCoupon);
|
|
|
+ if (m > 0) {
|
|
|
+ resultJson.put("message", "添加成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ } 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);
|
|
|
@@ -69,7 +101,28 @@ public class hotelCoupomAction extends BaseController implements ServletRequestA
|
|
|
}
|
|
|
HotelCoupon hotelCoupon = null;
|
|
|
try{
|
|
|
- hotelCoupon = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
|
|
|
+ hotelCoupon = gson.fromJson(json.toString(), new TypeToken<HotelCoupon>() {}.getType());
|
|
|
+ if (hotelCoupon.getId()==null || "".equals(hotelCoupon.getId())){
|
|
|
+ resultJson.put("message", "请传入优惠卷id");
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ HotelCoupon h1 = hotelCoupomService.getById(hotelCoupon.getId());
|
|
|
+ if (h1==null){
|
|
|
+ resultJson.put("message", "修改失败,未查询到优惠卷");
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ int m = hotelCoupomService.update(hotelCoupon);
|
|
|
+ if (m > 0) {
|
|
|
+ resultJson.put("message", "修改成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ } 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);
|
|
|
@@ -89,7 +142,27 @@ public class hotelCoupomAction extends BaseController implements ServletRequestA
|
|
|
public String queryPage(){
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
StringBuilder s1 = new StringBuilder("");
|
|
|
- IPage<HotelCoupon> adminIPage = hotelCoupomService.queryPage(s1.toString(),page,rows);
|
|
|
+ if (name != null){
|
|
|
+ s1.append(" and name like '%").append(name).append("%' ");
|
|
|
+ }
|
|
|
+ if (status != null){
|
|
|
+ s1.append(" and status = ").append(status).append(" ");
|
|
|
+ }
|
|
|
+ if (grantStartDate != null && grantEndDate != null){
|
|
|
+ s1.append(" and DATE_FORMAT(grant_start_date,'%Y-%m-%d') >= '").append(grantStartDate).append("' ");
|
|
|
+ s1.append(" and DATE_FORMAT(grant_end_date,'%Y-%m-%d') <= '").append(grantEndDate).append("' ");
|
|
|
+ }
|
|
|
+ IPage<HotelCoupon> hotelCouponIPage = hotelCoupomService.queryPage(s1.toString(),page,rows);
|
|
|
+ if(hotelCouponIPage!=null && !"".equals(hotelCouponIPage)){
|
|
|
+ resultJson.put("message", "查询分页成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", hotelCouponIPage);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ }else{
|
|
|
+ resultJson.put("message", "查询分页失败");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -99,13 +172,63 @@ public class hotelCoupomAction extends BaseController implements ServletRequestA
|
|
|
*/
|
|
|
public String getById(){
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
- if (id==null && id == 0) {
|
|
|
+ if (id==null || "".equals(id)) {
|
|
|
resultJson.put("message", "请传入id");
|
|
|
resultJson.put("code", 500);
|
|
|
ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
return null;
|
|
|
}
|
|
|
HotelCoupon hotelCoupon = hotelCoupomService.getById(id);
|
|
|
+ if (hotelCoupon != null) {
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", hotelCoupon);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }else{
|
|
|
+ resultJson.put("message", "未查询到优惠卷信息");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述:优惠卷批量失效
|
|
|
+ */
|
|
|
+ public String saveBatchLapse(){
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ HotelCoupon hotelCoupon = null;
|
|
|
+ try {
|
|
|
+ hotelCoupon = gson.fromJson(json.toString(), new TypeToken<HotelCoupon>() {}.getType());
|
|
|
+ if (ids == null){
|
|
|
+ resultJson.put("message", "请传入优惠卷id");
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ int m = hotelCoupomService.updateLapse(ids);
|
|
|
+ //TODO 修改用户领取的优惠卷
|
|
|
+ int n = hotelCoupomStatusService.updateLapse(ids);
|
|
|
+ resultJson.put("message", "修改成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
@@ -113,6 +236,20 @@ public class hotelCoupomAction extends BaseController implements ServletRequestA
|
|
|
* 描述:定时任务修改优惠卷状态
|
|
|
*/
|
|
|
public void setCoupomStatus(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ try {
|
|
|
+ int n = hotelCoupomService.updateExpire();
|
|
|
+ int m = hotelCoupomStatusService.updateExpir();
|
|
|
+ resultJson.put("message", "修改成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ resultJson.put("message", "未知异常:"+ e);
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ }
|
|
|
System.out.println(1111);
|
|
|
}
|
|
|
|