Commit 0dc47a17 authored by zhangyong's avatar zhangyong

1

parent 8e7132c8
package com.egolm.shop.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.egolm.shop.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags={"公共数据接口"})
@RestController
@RequestMapping("common")
public class CommonController {
@Autowired
private CommonService commonService;
@ApiOperation("组织构购获取省市区")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "orgNO", dataType = "String", required = true, value = "组织机构", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/queryDistrictByOrgNO",method=RequestMethod.GET)
public String detail(HttpServletRequest request) {
String orgNO = request.getParameter("orgNO");
String langID = request.getParameter("langID");
return commonService.queryDistrictByOrgNO(orgNO, langID);
}
}
package com.egolm.shop.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.egolm.common.bean.Rjx;
import com.egolm.shop.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags={"优惠券相关接口"})
@RestController
@RequestMapping("coupon")
public class CouponController {
@Autowired
private CouponService couponService;
@ApiOperation("查询所有可领取券制券单列表")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "tradeDate", dataType = "String", required = false, value = "查询日期", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "orgNO", dataType = "String", required = true, value = "组织机构", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "shopNO", dataType = "String", required = false, value = "店铺编码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "userNO", dataType = "String", required = true, value = "用户编码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/allCoupon",method=RequestMethod.GET)
public String allCoupon(HttpServletRequest request) {
String shopNO = request.getParameter("shopNO");
String userNO = request.getParameter("userNO");
String orgNO = request.getParameter("orgNO");
String terminal = request.getParameter("terminal");
String tradeDate = request.getParameter("tradeDate");
String langID = request.getParameter("langID");
Map<String,Object> params = new HashMap<String,Object>();
params.put("shopNO", shopNO);
params.put("userNO", userNO);
params.put("orgNO", orgNO);
params.put("tradeDate", tradeDate);
params.put("terminal", terminal);
params.put("langID", langID);
List<Map<String,Object>> list = couponService.allCoupon(params);
return Rjx.jsonOk().set("list", list).toJson();
}
@ApiOperation("我的优惠券")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "tradeDate", dataType = "String", required = false, value = "查询日期", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "orgNO", dataType = "String", required = true, value = "组织机构", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "shopNO", dataType = "String", required = false, value = "店铺编码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "userNO", dataType = "String", required = true, value = "用户编码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "status", dataType = "String", required = true, value = "券状态(unused/used/expire)", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "beginDate", dataType = "String", required = false, value = "开始日期", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "endDate", dataType = "String", required = false, value = "结束日期", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/myCoupon",method=RequestMethod.GET)
public String myCoupon(HttpServletRequest request) {
String shopNO = request.getParameter("shopNO");
String userNO = request.getParameter("userNO");
String orgNO = request.getParameter("orgNO");
String terminal = request.getParameter("terminal");
String tradeDate = request.getParameter("tradeDate");
String status = request.getParameter("status");
String beginDate = request.getParameter("beginDate");
String endDate = request.getParameter("endDate");
String langID = request.getParameter("langID");
Map<String,Object> params = new HashMap<String,Object>();
params.put("shopNO", shopNO);
params.put("userNO", userNO);
params.put("orgNO", orgNO);
params.put("tradeDate", tradeDate);
params.put("status", status);
params.put("beginDate", beginDate);
params.put("endDate", endDate);
params.put("terminal", terminal);
params.put("langID", langID);
List<Map<String,Object>> list = couponService.myCoupon(params);
return Rjx.jsonOk().set("list", list).toJson();
}
@ApiOperation("领取优惠券")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "tradeDate", dataType = "String", required = false, value = "查询日期", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "orgNO", dataType = "String", required = true, value = "组织机构", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "shopNO", dataType = "String", required = false, value = "店铺编码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "userNO", dataType = "String", required = true, value = "用户编码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "makePaperNO", dataType = "String", required = true, value = "制券单号", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "point", dataType = "int", required = false, value = "抵扣金币", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/getCoupon",method=RequestMethod.GET)
public String getCoupon(HttpServletRequest request) {
String shopNO = request.getParameter("shopNO");
String userNO = request.getParameter("userNO");
String orgNO = request.getParameter("orgNO");
String terminal = request.getParameter("terminal");
String tradeDate = request.getParameter("tradeDate");
String status = request.getParameter("status");
String beginDate = request.getParameter("beginDate");
String endDate = request.getParameter("endDate");
String langID = request.getParameter("langID");
Map<String,Object> params = new HashMap<String,Object>();
params.put("shopNO", shopNO);
params.put("userNO", userNO);
params.put("orgNO", orgNO);
params.put("tradeDate", tradeDate);
params.put("status", status);
params.put("beginDate", beginDate);
params.put("endDate", endDate);
params.put("terminal", terminal);
params.put("langID", langID);
return couponService.getCoupon(params);
}
}
...@@ -16,4 +16,6 @@ public interface CommonService { ...@@ -16,4 +16,6 @@ public interface CommonService {
public void saveViewHistory(String zone,String terminalTypeID,String shopNO,String viewTypeID,String values); public void saveViewHistory(String zone,String terminalTypeID,String shopNO,String viewTypeID,String values);
public List<TCommon> getTCommon(String commonNO,String comID); public List<TCommon> getTCommon(String commonNO,String comID);
public String queryDistrictByOrgNO(String orgNO,String langID) ;
} }
package com.egolm.shop.service;
import java.util.List;
import java.util.Map;
import com.egolm.common.jdbc.Page;
import com.egolm.shop.pojo.TCustAddress;
public interface CouponService {
public List<Map<String,Object>> allCoupon(Map<String,Object> params );
public List<Map<String,Object>> myCoupon(Map<String,Object> params );
public String getCoupon(Map<String, Object> params);
}
package com.egolm.shop.service.impl; package com.egolm.shop.service.impl;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
...@@ -8,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -8,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil; import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.SqlServerDialect; import com.egolm.common.jdbc.dialect.SqlServerDialect;
import com.egolm.shop.pojo.TCommon; import com.egolm.shop.pojo.TCommon;
...@@ -64,7 +67,15 @@ public class CommonServiceImpl implements CommonService{ ...@@ -64,7 +67,15 @@ public class CommonServiceImpl implements CommonService{
} }
} }
/**
* 获取共通资料
* <p>Title: getTCommon</p>
* <p>Description: </p>
* @param commonNO
* @param comID
* @return
* @see com.egolm.shop.service.CommonService#getTCommon(java.lang.String, java.lang.String)
*/
public List<TCommon> getTCommon(String commonNO,String comID){ public List<TCommon> getTCommon(String commonNO,String comID){
List<TCommon> commList = null; List<TCommon> commList = null;
jdbcTemplate.setDialect(new SqlServerDialect()); jdbcTemplate.setDialect(new SqlServerDialect());
...@@ -77,4 +88,45 @@ public class CommonServiceImpl implements CommonService{ ...@@ -77,4 +88,45 @@ public class CommonServiceImpl implements CommonService{
} }
return commList; return commList;
} }
/**
* 根据组织机构获取对应的省市区
* @Title: queryDistrictByOrgNO
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param orgNO
* @param: @param langID
* @param: @return
* @return: String
* @throws
*/
public String queryDistrictByOrgNO(String orgNO,String langID) {
try {
String psql="select provinceID=sRegionNO,province=sRegionDesc from tRegion where sRegionNO=(select sUpRegionNO from tRegion where sRegionNO=(select sRegionNO from tOrg where sOrgNO='"+orgNO+"' and nTag&1=0) and nTag&1=0 ) and nTag&1=0 ";
String csql="select cityID=sRegionNO,city=sRegionDesc from tRegion r where sRegionNO=(select sRegionNO from tOrg where sOrgNO='"+orgNO+"' and nTag&1=0) and r.nTag&1=0 ";
String dsql="select districtID=sRegionNO,district=sRegionDesc from tRegion where sUpRegionNO=(select sRegionNO from tOrg where sOrgNO='"+orgNO+"' and nTag&1=0) AND nTag&1=0";
String ssql="select streetID=sRegionNO,street=sRegionDesc, upRegionNO=sUpRegionNO from tRegion where sUpRegionNO in (select districtID=sRegionNO from tRegion where sUpRegionNO = (select sRegionNO from tOrg where sOrgNO='"+orgNO+"' and nTag&1=0) and nTag&1=0) AND nTag&1=0";
Map<String, Object> pMap=jdbcTemplate.queryForMap(psql);
Map<String, Object> cMap=jdbcTemplate.queryForMap(csql);
List<Map<String, Object>> dList=jdbcTemplate.queryForList(dsql);
List<Map<String, Object>> sList=jdbcTemplate.queryForList(ssql);
for(Map<String,Object> dMap:dList){
List<Map<String, Object>> dsList=new ArrayList<Map<String, Object>>();
for(Map<String,Object> sMap:sList){
if(sMap.get("upRegionNO").equals(dMap.get("districtID"))){
dsList.add(sMap);
}
}
dMap.put("countyList", dsList);
}
cMap.put("districtList", dList);
pMap.put("city", cMap);
return Rjx.jsonOk().set("province", pMap).toJson();
} catch (Exception e) {
e.printStackTrace();
}
return Rjx.jsonErr().setCode(-100).setMessage("省市区数据获取失败").toJson();
}
} }
package com.egolm.shop.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.Util;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.shop.pojo.TCustomer;
import com.egolm.shop.service.CouponService;
import com.egolm.shop.service.UserService;
@Service
public class CouponServiceImpl implements CouponService {
private static final Log logger = LogFactory.getLog(CouponServiceImpl.class);
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private UserService userService;
/**
* 可领取券制券单列表
* <p>Title: query</p>
* <p>Description: </p>
* @param params
* @return
* @see com.egolm.shop.service.CouponService#query(java.util.Map)
*/
@Override
public List<Map<String, Object>> allCoupon(Map<String, Object> params) {
List<Map<String, Object>> returnMap = new ArrayList<Map<String, Object>>();
try {
String shopNO = params.get("shopNO")+"";
String userNO = params.get("userNO")+"";
String orgNO = params.get("orgNO")+"";
String terminal = params.get("terminal")+"";
String tradeDate = params.get("tradeDate")+"";
String sql = "exec up_EgolmCouponAvailList '"+orgNO+"' ,'"+shopNO+"' , '"+userNO+"' , '"+tradeDate+"' , '"+terminal+"'";
returnMap = jdbcTemplate.executeMutil(sql).getDatas().get(0);
return returnMap;
} catch (Exception e) {
e.printStackTrace();
}
return returnMap;
}
/**
* 我的优惠券列表
* <p>Title: myCoupon</p>
* <p>Description: </p>
* @param params
* @return
* @see com.egolm.shop.service.CouponService#myCoupon(java.util.Map)
*/
@Override
public List<Map<String, Object>> myCoupon(Map<String, Object> params) {
List<Map<String, Object>> returnMap = new ArrayList<Map<String, Object>>();
try {
String shopNO = params.get("shopNO")+"";
String userNO = params.get("userNO")+"";
String orgNO = params.get("orgNO")+"";
String terminal = params.get("terminal")+"";
String tradeDate = params.get("tradeDate")+"";
String status = params.get("status")+"";
String beginDate = params.get("beginDate")+"";
String endDate = params.get("endDate")+"";
String sql = "exec up_EgolmShopCoupon '"+orgNO+"' , '"+shopNO+"' , '"+userNO+"' , '"+terminal+"' , '"+tradeDate+"' , '"+status+"'," +beginDate+" , "+endDate+"";
returnMap = jdbcTemplate.executeMutil(sql).getDatas().get(0);
return returnMap;
} catch (Exception e) {
e.printStackTrace();
}
return returnMap;
}
/**
* 兑换优惠券
* @Title: getCoupon
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param params
* @param: @return
* @return: String
* @throws
*/
public String getCoupon(Map<String, Object> params) {
String shopNO = params.get("shopNO")+"";
String userNO = params.get("userNO")+"";
String orgNO = params.get("orgNO")+"";
String terminal = params.get("terminal")+"";
String tradeDate = params.get("tradeDate")+""; //领取日期
String makePaperNO = params.get("makePaperNO")+""; //制券单号
Integer point = Integer.valueOf(params.get("point")+""); //消耗的金币
boolean isGoldChange = false ; //是否积分换券
boolean canChange = true;
if(point > 0) { //金币兑换
TCustomer customer = userService.getCustomer(userNO, shopNO);
BigDecimal cPoint = customer.getnPoint();
if(cPoint.compareTo(new BigDecimal(point)) >=0) { //用户积分大于 券积分
try {
String pointSql = " DECLARE @EndPoint varchar(10) "
+" exec up_AddMemberPoint '"+shopNO+"','28','-"+point+"','积分换券',null,null,@EndPoint out "
+ " select EndPoint = @EndPoint ";
List<Map<String, Object>> returnPointMap = jdbcTemplate.executeMutil(pointSql).getDatas().get(0);
isGoldChange = true;
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setCode(-100).setMessage("操作异常,扣积分失败.").toJson();
}
}else {
canChange = false;
return Rjx.jsonErr().setCode(-100).setMessage("金币不足,兑换失败.").toJson();
}
}
boolean changeSuccess = true;
if(canChange) { //换券
String sql = "DECLARE @ResultCode varchar(10) "
+ "DECLARE @ResultMsg varchar(255) "
+ "DECLARE @ConponNO varchar(36) "
+ "exec up_EgolmGetCoupon '"+orgNO+"' ,'"+shopNO+"' , '"+userNO+"' , '"+terminal+"' ,'"+makePaperNO+"' ,'"+tradeDate+"', @ResultCode out ,@ResultMsg out,@ConponNO OUT "
+ "SELECT ResultCode=@ResultCode,ResultMsg=@ResultMsg,ConponNO=@ConponNO ";
List<Map<String, Object>> returnMap = jdbcTemplate.executeMutil(sql).getDatas().get(0);
if (Util.objTo(returnMap.get(0).get("ResultCode"), Integer.class) == 0 ) {
return Rjx.jsonOk().setMessage("优惠券兑换成功").toJson();
} else {
changeSuccess = false;
String errorMsg = "";
if(returnMap.size()>1){
errorMsg = (String)returnMap.get(0).get("ResultMsgResultMsg")+";"+(String)returnMap.get(1).get("ResultMsg");
}else{
errorMsg = (String)returnMap.get(0).get("ResultMsg");
}
return Rjx.jsonErr().setCode(-100).setMessage("优惠券兑换失败").set("errorMsg", errorMsg).toJson();
}
}
if(!changeSuccess && isGoldChange) {
try{
String pointSql = " DECLARE @EndPoint varchar(10) "
+" exec up_AddMemberPoint '"+shopNO+"','31','"+point+"','积分换券失败返还',null,null,@EndPoint out "
+ " select EndPoint = @EndPoint ";
jdbcTemplate.executeMutil(pointSql).getDatas().get(0);
}catch(Exception ex){
ex.printStackTrace();
return Rjx.jsonErr().setCode(-100).setMessage("金币返还失败").toJson();
}
}
return Rjx.json().toJson();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment