| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- 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
- */
- public String inster(){
- 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(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);
- 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 update(){
- 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 (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);
- 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 queryPage(){
- JSONObject resultJson = new JSONObject();
- StringBuilder s1 = new StringBuilder("");
- 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;
- }
- /**
- * 描述:根据Id查询详细
- * @return
- */
- public String getById(){
- JSONObject resultJson = new JSONObject();
- 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;
- }
- /**
- * 描述:定时任务修改优惠卷状态
- */
- 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);
- }
- }
|