parent
3c3dd9f292
commit
f3ffcf32be
@ -0,0 +1,281 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.security.SessionObject; |
||||
import com.hai.common.security.UserCenter; |
||||
import com.hai.common.utils.*; |
||||
import com.hai.entity.ApiMerchants; |
||||
import com.hai.entity.ApiProduct; |
||||
import com.hai.enum_type.ApiAmountRecordTypeEnum; |
||||
import com.hai.enum_type.CompanyAmountSourceTypeEnum; |
||||
import com.hai.model.HighMerchantModel; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.model.UserInfoModel; |
||||
import com.hai.service.ApiMerchantsService; |
||||
import com.hai.service.ApiProductService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.dao.DeadlockLoserDataAccessException; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/apiMerchants") |
||||
@Api(value = "api商户") |
||||
public class ApiMerchantsController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(ApiProductController.class); |
||||
|
||||
@Resource |
||||
private ApiMerchantsService apiMerchantsService; |
||||
|
||||
@Autowired |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private RedisUtil redisUtil; |
||||
|
||||
@RequestMapping(value = "/getListApiMerchant", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询产品列表") |
||||
public ResponseData getListApiMerchant( |
||||
@RequestParam(value = "merchantName", required = false) String merchantName, |
||||
@RequestParam(value = "mchId", required = false) String mchId, |
||||
@RequestParam(value = "phone", required = false) String phone, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request |
||||
) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
|
||||
map.put("merchantName", merchantName); |
||||
map.put("phone", phone); |
||||
map.put("mchId", mchId); |
||||
map.put("status", status); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
|
||||
List<ApiMerchants> list = apiMerchantsService.getListApiMerchants(map); |
||||
return ResponseMsgUtil.success(new PageInfo<>(list)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiMerchantsController --> getListUser() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getListApiMerchantByAll", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询所以可用商户列表") |
||||
public ResponseData getListApiMerchantByAll(HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
|
||||
map.put("status", 100); |
||||
|
||||
List<ApiMerchants> list = apiMerchantsService.getListApiMerchants(map); |
||||
return ResponseMsgUtil.success(list); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiMerchantsController --> getListUser() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/insertMerchant",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "增加商户") |
||||
public ResponseData insertMerchant(@RequestBody ApiMerchants apiMerchants, HttpServletRequest request) { |
||||
try { |
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
if (userInfoModel.getBsCompany() == null) { |
||||
log.error("HighMerchantController -> updateMerchant() error!","该主角色没有权限"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(apiMerchants.getMerchantName()) |
||||
|| StringUtils.isBlank(apiMerchants.getPhone()) |
||||
|| StringUtils.isBlank(apiMerchants.getUserName()) |
||||
) { |
||||
log.error("ApiMerchantsController -> insertMerchant() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
apiMerchants.setCreateTime(new Date()); |
||||
apiMerchants.setOperatorId(userInfoModel.getSecUser().getId()); |
||||
apiMerchants.setOperatorName(userInfoModel.getSecUser().getUserName()); |
||||
apiMerchants.setStatus(100); |
||||
apiMerchants.setAmounts(new BigDecimal(0)); |
||||
apiMerchants.setUpdateTime(new Date()); |
||||
apiMerchants.setMchId(DateUtil.date2String(new Date(), "yyyyMM") + IDGenerator.nextId(5)); |
||||
apiMerchants.setApiKey(WxUtils.MD5(apiMerchants.getMchId() , true)); |
||||
apiMerchantsService.insertApiMerchants(apiMerchants); |
||||
|
||||
return ResponseMsgUtil.success("新增成功"); |
||||
} catch (Exception e) { |
||||
log.error("ApiMerchantsController -> insertMerchant() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/updateMerchant",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "修改商户") |
||||
public ResponseData updateMerchant(@RequestBody ApiMerchants apiMerchants, HttpServletRequest request) { |
||||
try { |
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
if (userInfoModel.getBsCompany() == null) { |
||||
log.error("ApiMerchantsController -> updateMerchant() error!","该主角色没有权限"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); |
||||
} |
||||
|
||||
ApiMerchants merchants = apiMerchantsService.findById(apiMerchants.getId()); |
||||
|
||||
if (StringUtils.isBlank(apiMerchants.getMerchantName()) |
||||
|| StringUtils.isBlank(apiMerchants.getPhone()) |
||||
|| StringUtils.isBlank(apiMerchants.getUserName()) |
||||
|| apiMerchants.getId() == null |
||||
) { |
||||
log.error("ApiMerchantsController -> insertMerchant() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
merchants.setOperatorId(userInfoModel.getSecUser().getId()); |
||||
merchants.setOperatorName(userInfoModel.getSecUser().getUserName()); |
||||
merchants.setUpdateTime(new Date()); |
||||
merchants.setMerchantName(apiMerchants.getMerchantName()); |
||||
merchants.setPhone(apiMerchants.getPhone()); |
||||
merchants.setUserName(apiMerchants.getUserName()); |
||||
apiMerchantsService.updateApiMerchants(merchants); |
||||
|
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} catch (Exception e) { |
||||
log.error("HighMerchantController -> insertMerchant() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/findById", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "根据id查询详情") |
||||
public ResponseData findById(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(apiMerchantsService.findById(id)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiMerchantsController --> findById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/editMerchantsStatus", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "修改商户状态") |
||||
public ResponseData editMerchantsStatus(@RequestBody JSONObject object, HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
ApiMerchants merchants = apiMerchantsService.findById(object.getLong("id")); |
||||
|
||||
merchants.setStatus(object.getInteger("status")); |
||||
merchants.setOperatorName(userInfoModel.getSecUser().getUserName()); |
||||
merchants.setOperatorId(userInfoModel.getSecUser().getId()); |
||||
apiMerchantsService.updateApiMerchants(merchants); |
||||
|
||||
return ResponseMsgUtil.success("修改成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiMerchantsController --> editPriceStatus() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/recharge", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "余额充值") |
||||
public synchronized ResponseData recharge(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
if (body.getLong("merchantId") == null |
||||
|| body.getBigDecimal("amount") == null |
||||
|| StringUtils.isBlank(body.getString("smsCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
if (body.getBigDecimal("amount").compareTo(new BigDecimal("0")) < 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "充值金额不能小于0"); |
||||
} |
||||
|
||||
if (redisUtil.get("COMPANY_AMOUNT_RECHARGE_SMS_CODE") == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误"); |
||||
} |
||||
if (!redisUtil.get("COMPANY_AMOUNT_RECHARGE_SMS_CODE").toString().equals(body.getString("smsCode"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误"); |
||||
} |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("sourceType", ApiAmountRecordTypeEnum.type1.getType()); |
||||
map.put("sourceContent", "充值金额:" + body.getBigDecimal("amount") + " 元"); |
||||
apiMerchantsService.recharge(body.getLong("merchantId"), body.getBigDecimal("amount"), map); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (DeadlockLoserDataAccessException deadlockLoserDataAccessException) { |
||||
log.error("ApiMerchantsController -> userLottery() error!", "服务器繁忙"); |
||||
return ResponseMsgUtil.builderResponse(ErrorCode.SERVER_BUSY_ERROR.getCode(),ErrorCode.SERVER_BUSY_ERROR.getMsg(),null); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiMerchantsController --> recharge() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getMerchRechargeData", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询商户充值记录") |
||||
public ResponseData getMerchRechargeData(@RequestParam(value = "merchantId", required = true) Long merchantId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(apiMerchantsService.getMerchRechargeData(merchantId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiMerchantsController --> findById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,256 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.security.SessionObject; |
||||
import com.hai.common.security.UserCenter; |
||||
import com.hai.common.utils.PageUtil; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.entity.ApiProduct; |
||||
import com.hai.entity.BsOperationLog; |
||||
import com.hai.entity.HighAgent; |
||||
import com.hai.entity.OutRechargePrice; |
||||
import com.hai.model.OutRechargePriceModel; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.model.UserInfoModel; |
||||
import com.hai.service.ApiProductService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.math.BigDecimal; |
||||
import java.util.*; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/apiProduct") |
||||
@Api(value = "api产品") |
||||
public class ApiProductController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(ApiProductController.class); |
||||
|
||||
@Resource |
||||
private ApiProductService apiProductService; |
||||
|
||||
@Autowired |
||||
private UserCenter userCenter; |
||||
|
||||
@RequestMapping(value = "/getListApiProduct", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询产品列表") |
||||
public ResponseData getListApiProduct( |
||||
@RequestParam(value = "operatorType", required = false) Integer operatorType, |
||||
@RequestParam(value = "rechargePlatform", required = false) Integer rechargePlatform, |
||||
@RequestParam(value = "phoneRechargeType", required = false) Integer phoneRechargeType, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request |
||||
) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
|
||||
map.put("operatorType", operatorType); |
||||
map.put("rechargePlatform", "-" + rechargePlatform + "-"); |
||||
map.put("phoneRechargeType", phoneRechargeType); |
||||
map.put("status", status); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
PageHelper.startPage(pageNum, pageSize); |
||||
|
||||
List<ApiProduct> list = apiProductService.getListApiProduct(map); |
||||
return ResponseMsgUtil.success(new PageInfo<>(list)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> getListUser() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/insertProduct", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "新增产品") |
||||
public ResponseData insertProduct(@RequestBody JSONObject object, HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
if (object == null || |
||||
object.getJSONArray("prices") == null || |
||||
object.getInteger("operatorType") == null || |
||||
object.getJSONArray("rechargePlatform") == null || |
||||
object.getInteger("phoneRechargeType") == null |
||||
) { |
||||
log.error("ApiProductController -> insertProduct() error!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
|
||||
object.put("operatorId", userInfoModel.getSecUser().getId()); |
||||
object.put("operatorName", userInfoModel.getSecUser().getLoginName()); |
||||
|
||||
apiProductService.insertApiProduct(object); |
||||
|
||||
return ResponseMsgUtil.success("新增成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiProductController --> insertPrice() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateProduct", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "修改产品") |
||||
public ResponseData updateProduct(@RequestBody JSONObject object, HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
if (object == null || |
||||
object.getLong("id") == null || |
||||
object.getInteger("operatorType") == null || |
||||
object.getJSONArray("rechargePlatform") == null || |
||||
object.getInteger("phoneRechargeType") == null |
||||
) { |
||||
log.error("ApiProductController -> updateProduct() error!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
ApiProduct apiProduct = apiProductService.findById(object.getLong("id")); |
||||
|
||||
if (apiProduct.getStatus() != 102) { |
||||
log.error("ApiProductController -> updateProduct() error!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态错误"); |
||||
} |
||||
|
||||
apiProduct.setOperatorId(userInfoModel.getSecUser().getId()); |
||||
apiProduct.setOperatorName(userInfoModel.getSecUser().getLoginName()); |
||||
apiProduct.setRechargeType(object.getInteger("rechargeType")); |
||||
apiProduct.setPhoneRechargeType(object.getInteger("phoneRechargeType")); |
||||
apiProduct.setOperatorType(object.getInteger("operatorType")); |
||||
apiProduct.setRechargePlatform("-" + StringUtils.join(object.getJSONArray("rechargePlatform"), "-") + "-"); |
||||
apiProduct.setUpdateTime(new Date()); |
||||
apiProduct.setSort(object.getInteger("sort")); |
||||
apiProduct.setProductId(object.getLong("productId")); |
||||
apiProduct.setOperatorName(object.getString("operatorName")); |
||||
apiProduct.setOperatorId(object.getLong("operatorId")); |
||||
|
||||
apiProductService.updateApiProduct(apiProduct); |
||||
|
||||
return ResponseMsgUtil.success("新增成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiProductController --> insertPrice() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/editProductStatus", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "修改产品状态") |
||||
public ResponseData editProductStatus(@RequestBody JSONObject object, HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
ApiProduct apiProduct = apiProductService.findById(object.getLong("id")); |
||||
|
||||
if (object.getInteger("status") == 101 && apiProduct.getRechargePlatform().contains("-2-") && apiProduct.getProductId() == null) { |
||||
log.error("ApiProductController -> editProductStatus() error!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "龙阅平台需要输入商品编码!"); |
||||
} |
||||
|
||||
apiProduct.setStatus(object.getInteger("status")); |
||||
apiProduct.setOperatorName(userInfoModel.getSecUser().getUserName()); |
||||
apiProduct.setOperatorId(userInfoModel.getSecUser().getId()); |
||||
apiProductService.updateApiProduct(apiProduct); |
||||
|
||||
|
||||
return ResponseMsgUtil.success("修改成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiProductController --> editPriceStatus() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/findById", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "根据id查询详情") |
||||
public ResponseData findById(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(apiProductService.findById(id)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> findById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getAvailableApiProductByList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询可用产品列表") |
||||
public ResponseData getAvailableApiProductByList( |
||||
HttpServletRequest request |
||||
) { |
||||
try { |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("rechargeType", 1); |
||||
map.put("status", 101); |
||||
|
||||
List<ApiProduct> list = apiProductService.getListApiProduct(map); |
||||
return ResponseMsgUtil.success(list); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("OutRechargePriceController --> getListUser() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/configApiProduct", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "配置产品") |
||||
public ResponseData configApiProduct(@RequestBody JSONObject object) { |
||||
try { |
||||
|
||||
if (object == null || |
||||
object.getJSONArray("productIds") == null || |
||||
object.getInteger("discount") == null || |
||||
object.getLong("merchantsId") == null |
||||
) { |
||||
log.error("ApiProductController -> configApiProduct() error!"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
apiProductService.configApiProduct(object); |
||||
|
||||
return ResponseMsgUtil.success("新增成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("ApiProductController --> insertPrice() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,42 @@ |
||||
package com.hai.enum_type; |
||||
|
||||
/** |
||||
* @serviceName ApiAmountRecordTypeEnum.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // api金额记录类型
|
||||
* @createTime 10:28 2022/6/8 |
||||
**/ |
||||
public enum ApiAmountRecordTypeEnum { |
||||
|
||||
type1(1, "金额充值"), |
||||
type2(2, "订单退款"), |
||||
type3(3, "话费消费") |
||||
; |
||||
|
||||
private Integer type; |
||||
|
||||
private String name; |
||||
|
||||
ApiAmountRecordTypeEnum(int type, String name) { |
||||
this.type = type; |
||||
this.name = name; |
||||
} |
||||
|
||||
public Integer getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(Integer type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,81 @@ |
||||
package com.hai.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.entity.ApiAmountRecord; |
||||
import com.hai.entity.ApiMerchants; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @serviceName ApiMerchantsService.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // api商户接口
|
||||
* @createTime 17:31 2022/6/7 |
||||
**/ |
||||
public interface ApiMerchantsService { |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name insertApiMerchants.java |
||||
* @Description // 新增api商户
|
||||
* @Date 14:55 2022/6/7 |
||||
* @Param [com.alibaba.fastjson.JSONObject] |
||||
* @return void |
||||
*/ |
||||
void insertApiMerchants(ApiMerchants apiMerchants); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name updateApiMerchants.java |
||||
* @Description // 修改api商户
|
||||
* @Date 14:56 2022/6/7 |
||||
* @Param [com.alibaba.fastjson.JSONObject] |
||||
* @return void |
||||
*/ |
||||
void updateApiMerchants(ApiMerchants apiMerchants); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name getListApiMerchants.java |
||||
* @Description // 查询api商户列表
|
||||
* @Date 14:57 2022/6/7 |
||||
* @Param [java.util.Map<java.lang.String,java.lang.Object>] |
||||
* @return java.util.List<com.hai.entity.ApiMerchants> |
||||
*/ |
||||
List<ApiMerchants> getListApiMerchants(Map<String, Object> map); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name findById.java |
||||
* @Description // 根据id 查询api商户
|
||||
* @Date 15:24 2022/6/7 |
||||
* @Param [java.lang.Long] |
||||
* @return com.hai.entity.ApiMerchants |
||||
*/ |
||||
ApiMerchants findById(Long id); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name recharge.java |
||||
* @Description // 进账
|
||||
* @Date 10:33 2022/6/8 |
||||
* @Param [java.lang.Long, java.math.BigDecimal, java.util.Map<java.lang.String,java.lang.Object>] |
||||
* @return void |
||||
*/ |
||||
void recharge(Long merchantId, BigDecimal amount, Map<String, Object> otherParam); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name getMerchRechargeData.java |
||||
* @Description // 查询商户充值记录
|
||||
* @Date 15:14 2022/6/8 |
||||
* @Param [java.lang.Long] |
||||
* @return java.util.List<com.hai.entity.ApiAmountRecord> |
||||
*/ |
||||
List<ApiAmountRecord> getMerchRechargeData(Long merchantId); |
||||
|
||||
|
||||
} |
@ -0,0 +1,68 @@ |
||||
package com.hai.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.entity.ApiProduct; |
||||
import io.swagger.annotations.Api; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @serviceName ApiProductService.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // Api产品配置
|
||||
* @createTime 14:54 2022/6/7 |
||||
**/ |
||||
public interface ApiProductService { |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name insertApiProduct.java |
||||
* @Description // 新增api产品
|
||||
* @Date 14:55 2022/6/7 |
||||
* @Param [com.alibaba.fastjson.JSONObject] |
||||
* @return void |
||||
*/ |
||||
void insertApiProduct(JSONObject object); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name updateApiProduct.java |
||||
* @Description // 修改api产品
|
||||
* @Date 14:56 2022/6/7 |
||||
* @Param [com.alibaba.fastjson.JSONObject] |
||||
* @return void |
||||
*/ |
||||
void updateApiProduct(ApiProduct apiProduct); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name getListApiProduct.java |
||||
* @Description // 查询api产品列表
|
||||
* @Date 14:57 2022/6/7 |
||||
* @Param [java.util.Map<java.lang.String,java.lang.Object>] |
||||
* @return java.util.List<com.hai.entity.ApiProduct> |
||||
*/ |
||||
List<ApiProduct> getListApiProduct(Map<String, Object> map); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name findById.java |
||||
* @Description // 根据id 查询api产品
|
||||
* @Date 15:24 2022/6/7 |
||||
* @Param [java.lang.Long] |
||||
* @return com.hai.entity.ApiProduct |
||||
*/ |
||||
ApiProduct findById(Long id); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name insertApiProduct.java |
||||
* @Description // 配置产品api产品
|
||||
* @Date 14:55 2022/6/7 |
||||
* @Param [com.alibaba.fastjson.JSONObject] |
||||
* @return void |
||||
*/ |
||||
void configApiProduct(JSONObject object); |
||||
} |
@ -0,0 +1,137 @@ |
||||
package com.hai.service.impl; |
||||
|
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.security.UserCenter; |
||||
import com.hai.common.utils.RedisUtil; |
||||
import com.hai.dao.ApiAmountRecordMapper; |
||||
import com.hai.dao.ApiMerchantsMapper; |
||||
import com.hai.entity.*; |
||||
import com.hai.model.UserInfoModel; |
||||
import com.hai.service.ApiMerchantsService; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Isolation; |
||||
import org.springframework.transaction.annotation.Propagation; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Service("apiMerchantsService") |
||||
public class ApiMerchantsServiceImpl implements ApiMerchantsService { |
||||
|
||||
@Resource |
||||
private ApiMerchantsMapper apiMerchantsMapper; |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private RedisUtil redisUtil; |
||||
|
||||
@Resource |
||||
private ApiAmountRecordMapper apiAmountRecordMapper; |
||||
|
||||
@Override |
||||
public void insertApiMerchants(ApiMerchants apiMerchants) { |
||||
apiMerchantsMapper.insert(apiMerchants); |
||||
} |
||||
|
||||
@Override |
||||
public void updateApiMerchants(ApiMerchants apiMerchants) { |
||||
apiMerchantsMapper.updateByPrimaryKey(apiMerchants); |
||||
} |
||||
|
||||
@Override |
||||
public List<ApiMerchants> getListApiMerchants(Map<String, Object> map) { |
||||
ApiMerchantsExample example = new ApiMerchantsExample(); |
||||
ApiMerchantsExample.Criteria criteria = example.createCriteria(); |
||||
|
||||
if (MapUtils.getString(map, "merchantName") != null) { |
||||
criteria.andMerchantNameLike("%" + MapUtils.getString(map, "merchantName") + "%"); |
||||
} |
||||
if (MapUtils.getString(map, "phone") != null) { |
||||
criteria.andPhoneEqualTo(MapUtils.getString(map, "phone")); |
||||
} |
||||
if (MapUtils.getString(map, "mchId") != null) { |
||||
criteria.andMchIdEqualTo(MapUtils.getString(map, "mchId")); |
||||
} |
||||
|
||||
if (MapUtils.getLong(map, "status") != null) { |
||||
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); |
||||
} |
||||
return apiMerchantsMapper.selectByExample(example); |
||||
} |
||||
|
||||
@Override |
||||
public ApiMerchants findById(Long id) { |
||||
return apiMerchantsMapper.selectByPrimaryKey(id); |
||||
} |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) |
||||
public void recharge(Long merchantId, BigDecimal amount, Map<String, Object> otherParam) { |
||||
|
||||
// 查询商户
|
||||
ApiMerchants apiMerchants = apiMerchantsMapper.selectByPrimaryKey(merchantId); |
||||
if (apiMerchants == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); |
||||
} |
||||
// 操作人
|
||||
UserInfoModel sessionModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
if (sessionModel == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知用户"); |
||||
} |
||||
if ( sessionModel.getSecRole().getRoleType() != 1) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "权限不足"); |
||||
} |
||||
if (apiMerchants.getStatus() != 100) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户被禁用"); |
||||
} |
||||
|
||||
// 变更前金额
|
||||
BigDecimal beforeAmount = apiMerchants.getAmounts(); |
||||
// 计算金额
|
||||
apiMerchants.setAmounts(apiMerchants.getAmounts().add(amount)); |
||||
// 变更后金额
|
||||
BigDecimal afterAmount = apiMerchants.getAmounts(); |
||||
|
||||
updateApiMerchants(apiMerchants); |
||||
|
||||
ApiAmountRecord apiAmountRecord = new ApiAmountRecord(); |
||||
|
||||
apiAmountRecord.setCreateTime(new Date()); |
||||
apiAmountRecord.setUpdateTime(new Date()); |
||||
apiAmountRecord.setMchId(apiMerchants.getMchId()); |
||||
apiAmountRecord.setOperatorId(sessionModel.getSecUser().getId()); |
||||
apiAmountRecord.setOperatorName(sessionModel.getSecUser().getUserName()); |
||||
apiAmountRecord.setStatus(100); |
||||
apiAmountRecord.setAmount(amount); |
||||
apiAmountRecord.setAfterAmount(afterAmount); |
||||
apiAmountRecord.setBeforeAmount(beforeAmount); |
||||
apiAmountRecord.setAmountType(1); |
||||
apiAmountRecord.setSourceType(MapUtils.getInteger(otherParam, "sourceType")); |
||||
apiAmountRecord.setSourceId(MapUtils.getLong(otherParam, "sourceId")); |
||||
apiAmountRecord.setSourceContent(apiMerchants.getMerchantName() + MapUtils.getString(otherParam, "sourceContent")); |
||||
|
||||
apiAmountRecordMapper.insert(apiAmountRecord); |
||||
|
||||
redisUtil.del("COMPANY_AMOUNT_RECHARGE_SMS_CODE"); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public List<ApiAmountRecord> getMerchRechargeData(Long merchantId) { |
||||
|
||||
ApiMerchants apiMerchants = apiMerchantsMapper.selectByPrimaryKey(merchantId); |
||||
|
||||
ApiAmountRecordExample example = new ApiAmountRecordExample(); |
||||
example.createCriteria().andMchIdEqualTo(apiMerchants.getMchId()); |
||||
return apiAmountRecordMapper.selectByExample(example); |
||||
} |
||||
} |
@ -0,0 +1,128 @@ |
||||
package com.hai.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.common.security.UserCenter; |
||||
import com.hai.dao.ApiProductConfigMapper; |
||||
import com.hai.dao.ApiProductMapper; |
||||
import com.hai.entity.*; |
||||
import com.hai.model.UserInfoModel; |
||||
import com.hai.service.ApiProductService; |
||||
import com.hai.service.CommonService; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Propagation; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Service("apiProductService") |
||||
public class ApiProductServiceImpl implements ApiProductService { |
||||
|
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
@Resource |
||||
private ApiProductMapper apiProductMapper; |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private ApiProductConfigMapper apiProductConfigMapper; |
||||
|
||||
@Override |
||||
public void insertApiProduct(JSONObject object) { |
||||
// 转换金额数组
|
||||
JSONArray priceArray = object.getJSONArray("prices"); |
||||
|
||||
// api产品
|
||||
ApiProduct apiProduct; |
||||
|
||||
for (Object price : priceArray) { |
||||
SecDictionary dictionary = commonService.mappingSysCode("RECHARGE_AMOUNT", String.valueOf(price)); |
||||
BigDecimal priceBd = new BigDecimal(dictionary.getCodeName()); |
||||
apiProduct = new ApiProduct(); |
||||
apiProduct.setRechargePrice(priceBd); |
||||
apiProduct.setRechargeType(object.getInteger("rechargeType")); |
||||
apiProduct.setPhoneRechargeType(object.getInteger("phoneRechargeType")); |
||||
apiProduct.setOperatorType(object.getInteger("operatorType")); |
||||
apiProduct.setRechargePlatform("-" + StringUtils.join(object.getJSONArray("rechargePlatform"), "-") + "-"); |
||||
apiProduct.setCreateTime(new Date()); |
||||
apiProduct.setUpdateTime(new Date()); |
||||
apiProduct.setStatus(102); |
||||
apiProduct.setSort(1); |
||||
apiProduct.setRechargeType(1); |
||||
apiProduct.setOperatorName(object.getString("operatorName")); |
||||
apiProduct.setOperatorId(object.getLong("operatorId")); |
||||
apiProductMapper.insert(apiProduct); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void updateApiProduct(ApiProduct apiProduct) { |
||||
apiProductMapper.updateByPrimaryKeySelective(apiProduct); |
||||
} |
||||
|
||||
@Override |
||||
public List<ApiProduct> getListApiProduct(Map<String, Object> map) { |
||||
ApiProductExample example = new ApiProductExample(); |
||||
ApiProductExample.Criteria criteria = example.createCriteria(); |
||||
|
||||
|
||||
if (MapUtils.getLong(map, "rechargePlatform") != null) { |
||||
criteria.andRechargePlatformLike("%" + MapUtils.getLong(map, "rechargePlatform") + "%"); |
||||
} |
||||
if (MapUtils.getLong(map, "rechargeType") != null) { |
||||
criteria.andRechargeTypeEqualTo(MapUtils.getInteger(map, "rechargeType")); |
||||
} |
||||
if (MapUtils.getLong(map, "operatorType") != null) { |
||||
criteria.andOperatorTypeEqualTo(MapUtils.getInteger(map, "operatorType")); |
||||
} |
||||
if (MapUtils.getLong(map, "phoneRechargeType") != null) { |
||||
criteria.andPhoneRechargeTypeEqualTo(MapUtils.getInteger(map, "phoneRechargeType")); |
||||
} |
||||
if (MapUtils.getLong(map, "status") != null) { |
||||
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); |
||||
} else { |
||||
criteria.andStatusNotEqualTo(100); |
||||
} |
||||
|
||||
example.setOrderByClause("sort asc"); |
||||
return apiProductMapper.selectByExample(example); |
||||
} |
||||
|
||||
@Override |
||||
public ApiProduct findById(Long id) { |
||||
return apiProductMapper.selectByPrimaryKey(id); |
||||
} |
||||
|
||||
@Override |
||||
public void configApiProduct(JSONObject object) { |
||||
|
||||
// 操作人
|
||||
UserInfoModel sessionModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
|
||||
// 转换产品数组
|
||||
JSONArray productsArray = object.getJSONArray("productIds"); |
||||
ApiProductConfig apiProductConfig; |
||||
for (Object productId : productsArray) { |
||||
apiProductConfig = new ApiProductConfig(); |
||||
apiProductConfig.setProductId(Long.valueOf(productId.toString())); |
||||
apiProductConfig.setCreateTime(new Date()); |
||||
apiProductConfig.setOperatorId(sessionModel.getSecUser().getId()); |
||||
apiProductConfig.setOperatorName(sessionModel.getSecUser().getUserName()); |
||||
apiProductConfig.setStatus(101); |
||||
apiProductConfig.setDiscount(object.getBigDecimal("discount")); |
||||
apiProductConfig.setMerchantsId(object.getLong("merchantsId")); |
||||
apiProductConfig.setUpdateTime(new Date()); |
||||
apiProductConfigMapper.insert(apiProductConfig); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue