admin
2020-05-19 744594ef1a2f530fc3e86ea9dc48b62247f79420
fanli/src/main/java/com/yeshi/fanli/controller/admin/UserSystemCouponAdminController.java
@@ -2,7 +2,6 @@
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
@@ -12,17 +11,14 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.controller.admin.utils.AdminUtils;
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;
import com.yeshi.fanli.vo.user.SystemCouponVO;
import com.yeshi.fanli.vo.user.UserSystemCouponCountVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@@ -341,179 +337,6 @@
         e.printStackTrace();
      }
   }
   /**
    * 奖励券数量曲线图
    * @param callback
    * @param dateType
    * @param year
    * @param startTime
    * @param endTime
    * @param out
    */
   @RequestMapping(value = "getRebateCouponUsedNumCharts")
   public void getRebateCouponUsedNumCharts(String callback, Integer dateType, String year, String startTime,
         String endTime, PrintWriter out){
      try {
         String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
         if (validateMsg != null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
         }
         JSONObject data = getChartsData(dateType, year, startTime, endTime, 1, null);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
         e.printStackTrace();
      }
   }
   /**
    * 奖励券数量曲线图
    * @param callback
    * @param dateType
    * @param year
    * @param startTime
    * @param endTime
    * @param out
    */
   @RequestMapping(value = "getRebateCouponMoneyCharts")
   public void getRebateCouponMoneyCharts(String callback, Integer dateType, String year, String startTime,
         String endTime, PrintWriter out){
      try {
         String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
         if (validateMsg != null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
         }
         JSONObject data = getChartsData(dateType, year, startTime, endTime, 2, null);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
         e.printStackTrace();
      }
   }
   /**
    * 奖励券数量曲线图
    * @param callback
    * @param dateType
    * @param year
    * @param startTime
    * @param endTime
    * @param out
    */
   @RequestMapping(value = "getFreeCouponMoneyCharts")
   public void getFreeCouponMoneyCharts(String callback, Integer dateType, String year, String startTime,
         String endTime, Integer coupon, PrintWriter out){
      try {
         if (coupon == null || (coupon.intValue() < 0 && coupon.intValue() > 4)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("券类型不正确"));
            return;
         }
         String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
         if (validateMsg != null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
         }
         String couponType = null;
         if (coupon == 1) {
            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));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
         e.printStackTrace();
      }
   }
   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;
      }
      if (dateType == 1 && year != null) {
         year = null;
      } else if (dateType == 2) {
         if (startTime != null)
            startTime = null;
         if (endTime != null)
            endTime = null;
      } else if (dateType == 3) {
         if (year != null)
            year = null;
         if (startTime != null)
            startTime = null;
         if (endTime != null)
            endTime = null;
      }
      Gson gson = new Gson();
      List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
      JSONObject innerList = new JSONObject();
      List<Map<String, Object>> list = null;
      if (source == 1) {
         // 奖励券数量
         innerList.put("name", "数量");
         list = userSystemCouponCountService.getRebateCouponUsedNumToCharts(dateType, year,
               startTime, endTime);
      } else if (source == 2) {
         // 奖励券金额
         innerList.put("name", "金额");
         list = userSystemCouponCountService.getRebateCouponMoneyToCharts(dateType, year,
               startTime, endTime);
      } else if (source == 3) {
         // 奖励券金额
         innerList.put("name", "金额");
         list = userSystemCouponCountService.getFreeCouponMoneyToCharts(dateType, year,
               startTime, endTime, couponType);
      }
      Object objectDate = null;
      if (dateType != 3) {
         innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
      } else {
         // 年视图
         Map<String, Object> map = AdminUtils.yearsDataFactory(list);
         if (objectDate == null) {
            objectDate = map.get("date");
         }
         innerList.put("data", gson.toJson(map.get("value")));
      }
      JSONArray line_list = new JSONArray();
      line_list.add(innerList);
      JSONObject data = new JSONObject();
      if (objectDate != null) {
         data.put("xAxis_list", gson.toJson(objectDate));
      } else {
         data.put("xAxis_list", gson.toJson(dateList));
      }
      data.put("line_list", line_list);
      return data;
   }
}