@源码地址来源: https://minglisoft.cn/honghu/business.html
package com.honghu.cloud.controller;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.google.common.collect.Maps;
import com.honghu.cloud.bean.Activity;
import com.honghu.cloud.bean.ActivityGoods;
import com.honghu.cloud.code.ActivityResponseCode;
import com.honghu.cloud.code.ResponseCode;
import com.honghu.cloud.code.ResponseVO;
import com.honghu.cloud.common.page.Page;
import com.honghu.cloud.dto.GoodsDto;
import com.honghu.cloud.dto.UserDto;
import com.honghu.cloud.feign.AccessoryFeignClient;
import com.honghu.cloud.feign.GoodsFeignClient;
import com.honghu.cloud.service.IActivityGoodsService;
import com.honghu.cloud.service.IActivityService;
import com.honghu.cloud.tools.ActivityTools;
import com.honghu.cloud.tools.QueryUtils;
import com.honghu.cloud.tools.SecurityUserHolder;
import com.honghu.cloud.utils.CommUtil;
import net.sf.json.JSONObject;
/**
* 活动controller
* @author Administrator
*
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@RestController
@RequestMapping(value = "/activity")
public class ActivityController{
@Autowired
protected IActivityService activityService;
@Autowired
protected IActivityGoodsService activityGoodsService;
@Autowired
protected GoodsFeignClient goodsFeignClient;
@Autowired
protected AccessoryFeignClient accessoryFeignClient;
@Autowired
private ActivityTools activityTools;
@Autowired
private QueryUtils queryUtils;
/**
* 根据活动id查询活动,feign调用
* @param id
* @return
*/
@RequestMapping(value = "/apiForFeign/selectByPrimaryKey", method = RequestMethod.GET)
public Activity selectByPrimaryKey(@RequestParam("id") Long id) {
return activityService.selectByPrimaryKey(id);
}
/**
* 活动列表
* @param request
* @param response
* @return
*/
@RequestMapping({ "/activitys" })
public ResponseVO activitys(HttpServletRequest request, HttpServletResponse response) {
Map params = Maps.newHashMap();
params.put("ac_begin_time_less_than_equal", new Date());
params.put("ac_end_time_more_than_equal", new Date());
params.put("ac_status", Integer.valueOf(1));
List<Activity> activitys = this.activityService.queryPageList(params, 0, 12);
Map<String, Object> result = new HashMap<String, Object>();
for(Activity activity : activitys){
activity.setAc_acc(accessoryFeignClient.selectByPrimaryKey(activity.getAc_acc_id()));
activity.setAc_acc3(accessoryFeignClient.selectByPrimaryKey(activity.getAc_acc3_id()));
}
result.put("activitys", activitys);
return ActivityResponseCode.buildEnumResponseVO(ActivityResponseCode.RESPONSE_RETURN_CODE_SUCCESS, result);
}
/**
* 活动列表(限时购)
* @param request
* @param response
* @return
*/
@RequestMapping({ "/timeLimitBuy" })
public ResponseVO timeLimitBuy(HttpServletRequest request, HttpServletResponse response) {
Map params = Maps.newHashMap();
params.put("ac_begin_time_less_than_equal", new Date());
params.put("ac_end_time_more_than_equal", new Date());
params.put("ac_status", Integer.valueOf(1));
params.put("ac_type", Integer.valueOf(1)); //限时购
List<Activity> activitys = this.activityService.queryPageList(params);
Map<String, Object> result = new HashMap<String, Object>();
for(Activity activity : activitys){
activity.setAc_acc(accessoryFeignClient.selectByPrimaryKey(activity.getAc_acc_id()));
}
result.put("activitys", activitys);
//即将开始
params.clear();
params.put("ac_begin_time_more_than_equal", new Date());
params.put("ac_status", Integer.valueOf(1));
params.put("ac_type", Integer.valueOf(1)); //限时购
List<Activity> begain_activitys = this.activityService.queryPageList(params);
for(Activity activity : begain_activitys){
activity.setAc_acc(accessoryFeignClient.selectByPrimaryKey(activity.getAc_acc_id()));
}
result.put("begain_activitys", begain_activitys);
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, result);
}
/**
* 根据活动id查询活动,feign调用
* @param id
* @return
*/
/*
@RequestMapping(value = "/selectByPrimaryKey2", method = RequestMethod.GET)
public Activity selectByPrimaryKey2(@RequestParam("id") Long id) {
return activityService.selectByPrimaryKey2(id);
}*/
/**
* 活动商品(查询参加该活动的商品列表信息)
* @param request
* @param response
* @param act_id
* @return
*/
@RequestMapping({ "/activitys_items" })
public ResponseVO activitys_items(HttpServletRequest request,
HttpServletResponse response, @RequestBody JSONObject json) {
String act_id = json.optString("act_id");
UserDto currentUser = SecurityUserHolder.getCurrentUser(request);
if (null == currentUser || null == currentUser.getId()) {
return ActivityResponseCode.buildEnumResponseVO(ActivityResponseCode.RESPONSE_CODE_USER_DOES_NOT_EXIST,
null);
}
Map params = Maps.newHashMap();
params.clear();
params.put("ag_status", Integer.valueOf(1));
params.put("ag_goods_goods_status", Integer.valueOf(0));
params.put("act_id", CommUtil.null2Long(act_id));
List<ActivityGoods> activitygoods = activityGoodsService.queryPageList(params, 0, 12);
Map<String, Object> result = new HashMap<String, Object>();
result.put("activitygoods", activitygoods);
result.put("act_id", act_id);
if (activitygoods != null) {
for (ActivityGoods ag : activitygoods) {
// 根据商品的id查询对应的商品
GoodsDto good = goodsFeignClient.selectByPrimaryKey(CommUtil.null2Long(ag.getAg_goods_id()));
if (null != good) {
ag.setAg_goods(good);
// 根据用户等级查询团购价格
/*if (good.getActivity_status() == 2 && currentUser != null) {
Map activityGoodsInfo = activityTools.getActivityGoodsInfo(good.getId() + "",
currentUser.getId() + "");
Object price = activityGoodsInfo.get("rate_price");
ag.setAg_goods_price(activityTools.getBigDecimal(price));
}*/
}
}
}
return ActivityResponseCode.buildEnumResponseVO(ActivityResponseCode.RESPONSE_RETURN_CODE_SUCCESS, result);
}
/**
* 活动商品(查询参加该活动的商品列表信息)
* @param request
* @param response
* @param act_id
* @return
*/
@RequestMapping({ "/timeLimitBuyItems" })
public ResponseVO timeLimitBuyItems(HttpServletRequest request,
HttpServletResponse response, @RequestBody JSONObject json) {
String act_id = json.optString("act_id");
String currentPage = json.optString("currentPage");
UserDto currentUser = SecurityUserHolder.getCurrentUser(request);
if (null == currentUser || null == currentUser.getId()) {
return ResponseCode.buildEnumResponseVO(ResponseCode.FAILURE,
null);
}
Map params = Maps.newHashMap();
params.clear();
params = this.queryUtils.getParams(currentPage, 8,null, "desc");
params.put("ag_status", Integer.valueOf(1));
params.put("ag_goods_goods_status", Integer.valueOf(0));
params.put("act_id", CommUtil.null2Long(act_id));
Page<ActivityGoods> list = activityGoodsService.list(params);
//List<ActivityGoods> activitygoods = activityGoodsService.queryPageList(params);
Map<String, Object> result = new HashMap<String, Object>();
Activity activity = activityService.selectByPrimaryKey(CommUtil.null2Long(act_id));
activity.setAc_acc(accessoryFeignClient.selectByPrimaryKey(activity.getAc_acc_id()));
result.put("activity", activity);
result.put("act_id", act_id);
for (ActivityGoods ag : list.getResult()) {
// 根据商品的id查询对应的商品
GoodsDto good = goodsFeignClient.selectByPrimaryKey(CommUtil.null2Long(ag.getAg_goods_id()));
if (null != good) {
ag.setAg_goods(good);
// 根据用户等级查询团购价格
if (good.getActivity_status() == 2 && currentUser != null) {
Map activityGoodsInfo = activityTools.getActivityGoodsInfo(good.getId() + "",
currentUser.getId() + "");
Object price = activityGoodsInfo.get("rate_price");
ag.setAg_goods_price(activityTools.getBigDecimal(price));
}
}
}
result.put("currentPage", list.getCurrentPage());
result.put("pages", list.getPages());
result.put("pageSize", list.getPageSize());
result.put("result", list.getResult());
result.put("rowCount", list.getRowCount());
return ResponseCode.buildEnumResponseVO(ResponseCode.SUCCESS, result);
}
}
@源码地址来源: https://minglisoft.cn/honghu/business.html