yujian
2020-01-17 bf0a347104579e5f7a2ed6e660ebb9f17f76ffc0
fanli/src/main/java/com/yeshi/fanli/controller/admin/UserSystemCouponAdminController.java
@@ -13,7 +13,10 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.controller.admin.utils.AdminUtils;
import com.yeshi.fanli.dto.ChartTDO;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord;
import com.yeshi.fanli.service.inter.count.UserSystemCouponCountService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponGiveRecordService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -29,6 +32,9 @@
   @Resource
   private UserSystemCouponCountService userSystemCouponCountService;
   @Resource
   private UserSystemCouponGiveRecordService userSystemCouponGiveRecordService;
   /**
    * 用户奖励券列表
@@ -147,7 +153,7 @@
            return;
         }
         long count = userSystemCouponCountService.countSystemCouponFree(key);
         long count = list.size();
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
@@ -275,6 +281,68 @@
         e.printStackTrace();
      }
   }
   /**
    * 查询赠送免券
    * @param callback
    * @param pageIndex
    * @param pageSize
    * @param key
    * @param type 1赠送免单券 、2-奖励券
    * @param state
    * @param out
    */
   @RequestMapping(value = "listGiveCoupon")
   public void listGiveCoupon(String callback, Integer pageIndex, Integer pageSize, String key, Integer type,
         Integer state, PrintWriter out) {
      if (pageIndex == null || pageIndex < 1) {
         pageIndex = 1;
      }
      if (pageSize == null || pageSize < 1) {
         pageSize = Constant.PAGE_SIZE;
      }
      String couponType = null;
      if (type != null) {
         if (type == 1) {
            couponType = "freeCouponGive";
         } else if  (type == 2){
            couponType = "rebatePercentCoupon";
         }
      }
      try {
         List<UserSystemCouponGiveRecord> list = userSystemCouponGiveRecordService.listGiveRecord((pageIndex - 1) * pageSize,
               pageSize, couponType, state);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
            return;
         }
         long count = userSystemCouponGiveRecordService.countGiveRecord(couponType, state);
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
         GsonBuilder gsonBuilder = new GsonBuilder();
         gsonBuilder.serializeNulls();
         Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create();
         JSONObject data = new JSONObject();
         data.put("pe", pe);
         data.put("result_list", gson.toJson(list));
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   /**
    * 奖励券数量曲线图
@@ -342,8 +410,7 @@
   public void getFreeCouponMoneyCharts(String callback, Integer dateType, String year, String startTime,
         String endTime, Integer coupon, PrintWriter out){
      try {
         if (coupon == null || (coupon != 1 && coupon != 2)) {
         if (coupon == null || (coupon.intValue() < 0 && coupon.intValue() > 4)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("券类型不正确"));
            return;
         }
@@ -359,8 +426,9 @@
            couponType = "freeCoupon";
         } else if  (coupon == 2){
            couponType = "welfareFreeCoupon";
         } else if  (coupon == 3){
            couponType = "freeCouponBuy";
         }
         
         JSONObject data = getChartsData(dateType, year, startTime, endTime, 3, couponType);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
@@ -372,7 +440,6 @@
   
   public JSONObject getChartsData(Integer dateType, String year, String startTime,
         String endTime, int source, String couponType) throws Exception {
      if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
         startTime = null;
         endTime = null;
@@ -401,7 +468,7 @@
      List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
      JSONObject innerList = new JSONObject();
      List<Map<String, Object>> list = null;
      List<ChartTDO> list = null;
      if (source == 1) {
         // 奖励券数量
         innerList.put("name", "数量");
@@ -419,9 +486,7 @@
               startTime, endTime, couponType);
      }
      
      Object objectDate = null;
      if (dateType != 3) {
         innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
      } else {