提交 2198e12b 作者: 张小凤 提交者: 余乾开

Price(update)

上级 1e3600fb
......@@ -404,7 +404,8 @@ public enum ResultEnum implements BaseErrorInfoInterface {
NO_PERMISSION_TEMPORARILY("2016", "当前账号没有权限,只有后台账号拥有权限"),
THERE_IS_NO_SUCH_ORDER("2017", "没有当前订单,请输入正确的订单编号"),
THE_TOKEN_CANNOT_BE_NULL("2018", "token不能为null"),
THE_CURRENT_ACCOUNT_CANNOT_PLACE_ORDERS("2019", "后台管理账号不能下单");
THE_CURRENT_ACCOUNT_CANNOT_PLACE_ORDERS("2019", "后台管理账号不能下单"),
THIRD_PARTY_ERRORS("2020","第三方接口错误或者第三接口正在更新");
/**
* 错误码
......
......@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @Author small
* @Date 2023/5/26 14:10
......@@ -24,6 +26,6 @@ public class PriceAcquisition {
private Integer day;
@ApiModelProperty(value = "渠道等级id")
private Integer channelLevelId;
private List<Integer> channelLevelId;
}
......@@ -18,6 +18,7 @@ import com.mmc.oms.entity.order.OrderReceiptDO;
import com.mmc.oms.entity.order.OrderRefundDO;
import com.mmc.oms.entity.order.OrderVcuDO;
import com.mmc.oms.entity.ware.WareInfoDO;
import com.mmc.oms.model.dto.mall.CooperationTagVO;
import com.mmc.oms.model.dto.order.*;
import com.mmc.oms.model.dto.repo.RepoAccountDTO;
import com.mmc.oms.model.dto.transtatus.TranStatusDicDTO;
......@@ -28,6 +29,7 @@ import com.mmc.oms.model.vo.coupon.AppletMsgVO;
import com.mmc.oms.model.vo.order.*;
import com.mmc.oms.service.RentalOrdersService;
import com.mmc.oms.wx.WxMsgTemplete;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -40,9 +42,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -51,6 +55,7 @@ import java.util.stream.Collectors;
* @Author small @Date 2023/5/26 10:53 @Version 1.0
*/
@Service
@Slf4j
public class RentalOrdersServiceImpl implements RentalOrdersService {
@Autowired
......@@ -79,13 +84,20 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
return ResultBody.error(ResultEnum.THE_CURRENT_ACCOUNT_CANNOT_PLACE_ORDERS);
}
//用户信息的远程调用
ResponseEntity<String> responseEntity = UserId(user.getUserAccountId(), user.getToken());
ResultBody<ResponseEntity<String>> responseEntityResultBody = UserId(user.getUserAccountId(), user.getToken());
if (ResultEnum.THIRD_PARTY_ERRORS.getResultCode().equals(responseEntityResultBody.getCode())){
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
ResponseEntity<String> responseEntity = responseEntityResultBody.getResult();
UserAccountSimpleDTO account = JSON.parseObject(responseEntity.getBody(), UserAccountSimpleDTO.class);
//优惠券id获取优惠券面值
OrderInfoDO orderInfo = new OrderInfoDO(param);
PriceAcquisition priceAcquisition = getPriceAcquisition(param, account);
BigDecimal unitPrice = getUnitPrice(priceAcquisition);
ResultBody<BigDecimal> bigDecimalResultBody = getUnitPrice(priceAcquisition);
if (ResultEnum.THIRD_PARTY_ERRORS.getResultCode().equals(bigDecimalResultBody.getCode())){
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
BigDecimal unitPrice = bigDecimalResultBody.getResult();
//每天单价
orderInfo.setUnitPrice(unitPrice);
// 天数
......@@ -96,6 +108,11 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
orderInfo.setBuyerName(user.getUserName());
orderInfo.setBuyerPhone(user.getPhoneNum());
orderInfo.setNickName(user.getNickName());
//获取剩余的余额
ResultBody<BigDecimal> remainingBalance = getRemainingBalance(user.getToken(), user.getUserAccountId());
if (ResultEnum.THIRD_PARTY_ERRORS.getResultCode().equals(remainingBalance.getCode())) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
rentalOrdersDao.insertOrderInfo(orderInfo);
// 添加收货地址
Date cdate = new Date();
......@@ -104,8 +121,7 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
receipt.setOrderInfoId(orderInfo.getId());
receipt.setCreateTime(cdate);
rentalOrdersDao.insertOrderReceipt(receipt);
//获取剩余的余额
orderInfo.setBalance(getRemainingBalance(user.getToken(), user.getUserAccountId()));
orderInfo.setBalance(remainingBalance.getResult());
// 将当前的用户id及订单编号存入redis
OrderInfoDTO dto = orderInfo.buildOrderInfoDTO();
stringRedisTemplate.opsForValue().set(orderInfo.getOrderNo(), JsonUtil.parseObjToJson(dto));
......@@ -132,25 +148,36 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
//远程设置
private PriceAcquisition getPriceAcquisition(LeaseOrderVO param, UserAccountSimpleDTO account) {
List<CooperationTagVO> cooperationTagVOS = account.getCooperationTagVOS();
List<Integer> list = new ArrayList<>();
if (cooperationTagVOS!=null && !cooperationTagVOS.isEmpty()){
for (CooperationTagVO cooperationTagVO : cooperationTagVOS) {
list.add(cooperationTagVO.getId());
}
}
PriceAcquisition priceAcquisition = new PriceAcquisition();
priceAcquisition.setUserId(account.getId());
priceAcquisition.setDay(day(param));
priceAcquisition.setSpecsId(param.getSpecsId());
priceAcquisition.setChannelLevelId(account.getCooperationTagId());
priceAcquisition.setChannelLevelId(list);
return priceAcquisition;
}
private ResponseEntity<String> UserId(Integer repoAccountId, String token) {
HttpHeaders headers = new HttpHeaders();
//封装请求头
headers.add("token", token);
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
ResponseEntity<String> response = restTemplate.exchange(userAppUrl + "user-account/feignGetUserSimpleInfo?userAccountId=" + repoAccountId,
HttpMethod.GET, formEntity, String.class);
private ResultBody<ResponseEntity<String>> UserId(Integer repoAccountId, String token) {
ResponseEntity<String> response = null;
try {
HttpHeaders headers = new HttpHeaders();
//封装请求头
headers.add("token", token);
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
response = restTemplate.exchange(userAppUrl + "user-account/feignGetUserSimpleInfo?userAccountId=" + repoAccountId,
HttpMethod.GET, formEntity, String.class);
log.info(String.valueOf(formEntity));
} catch (RestClientException e) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
// 用户信息
/* ResponseEntity<String> response =
restTemplate.getForEntity(
......@@ -158,7 +185,7 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
+ "user-account/feignGetUserSimpleInfo?userAccountId="
+ repoAccountId,
String.class);*/
return response;
return ResultBody.success(response);
}
......@@ -168,19 +195,24 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
* @param repoAccountId
* @return
*/
public BigDecimal getRemainingBalance(String token, Integer repoAccountId) {
HttpHeaders headers = new HttpHeaders();
//封装请求头
headers.add("token", token);
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
ResponseEntity<String> result4 = restTemplate.exchange(paymentUrl + "repocash/RemainingBalance?repoAccountId=" + repoAccountId,
HttpMethod.GET, formEntity, String.class);
String body = result4.getBody();
if (body == null) {
body = "0";
public ResultBody<BigDecimal> getRemainingBalance(String token, Integer repoAccountId) {
BigDecimal bigDecimal = null;
try {
HttpHeaders headers = new HttpHeaders();
//封装请求头
headers.add("token", token);
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
ResponseEntity<String> result4 = restTemplate.exchange(paymentUrl + "repocash/RemainingBalance?repoAccountId=" + repoAccountId,
HttpMethod.GET, formEntity, String.class);
String body = result4.getBody();
if (body == null) {
body = "0";
}
bigDecimal = new BigDecimal(body);
} catch (RestClientException e) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
BigDecimal bigDecimal = new BigDecimal(body);
return bigDecimal;
return ResultBody.success(bigDecimal);
}
/**
......@@ -207,19 +239,24 @@ public class RentalOrdersServiceImpl implements RentalOrdersService {
* @param param
* @return
*/
private BigDecimal getUnitPrice(PriceAcquisition param) {
private ResultBody<BigDecimal> getUnitPrice(PriceAcquisition param) {
// 需要支付的价格
ResponseEntity<String> responseEntity = restTemplate.postForEntity(pmsUrl + "/product/spec/feignGetSpecLeaseUnitPrice"
, param, String.class);
String body = responseEntity.getBody();
if (null == body) {
body = "0";
BigDecimal bigDecimal = null;
try {
ResponseEntity<String> responseEntity = restTemplate.postForEntity(pmsUrl + "product/spec/feignGetSpecLeaseUnitPrice"
, param, String.class);
String body = responseEntity.getBody();
if (null == body) {
body = "0";
}
bigDecimal = new BigDecimal(body);
} catch (RestClientException e) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
BigDecimal bigDecimal = new BigDecimal(body);
// 模拟
// int i = 12;
// BigDecimal bigDecimal = BigDecimal.valueOf(i);
return bigDecimal;
return ResultBody.success(bigDecimal);
}
public Integer day(LeaseOrderVO param) {
......
......@@ -7,9 +7,8 @@ spring:
password: MMC@2022&MYSQL
redis:
database: 1
host: r-wz9ke310fs684hacn1pd.redis.rds.aliyuncs.com
host: 127.0.0.1
port: 6379
password: MMC@2022&REDIS
jedis:
pool:
max-active: 2
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论