JAVA版商城 B2B2C商城 多用户入驻商城 直播带货商城 新零售商城 o2o商城 拼团商城 分销商城 直播商城 短视频商城 VR商城 社交电商 分销商城 saas商城spring cloud商城

这是一个关于Spring Cloud微服务架构的示例代码,主要展示了如何通过Feign客户端进行服务间的接口调用,实现活动管理和商品信息的查询。包括活动列表、限时购商品列表的获取,以及根据活动ID查询详细信息。代码中还涉及到用户权限验证、数据分页和商品价格处理等功能。
摘要由CSDN通过智能技术生成
@源码地址来源: 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

企业软件定制

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值