bug fix 1018

This commit is contained in:
Cauchy
2023-10-18 16:37:58 +08:00
parent 5dee4b619e
commit c90ecfb7ce
33 changed files with 309 additions and 114 deletions

View File

@@ -3,9 +3,9 @@ package com.peanut.common.utils;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.peanut.modules.book.entity.CityEntity; import com.peanut.modules.book.entity.City;
import com.peanut.modules.book.entity.CountyEntity; import com.peanut.modules.book.entity.County;
import com.peanut.modules.book.entity.ProvinceEntity; import com.peanut.modules.book.entity.Province;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
@@ -14,7 +14,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
public class ReadProvinceUtil { public class ReadProvinceUtil {
public static List<ProvinceEntity> getFile(String filePath) { public static List<Province> getFile(String filePath) {
JSONArray proJsonArray = null; JSONArray proJsonArray = null;
JSONArray cityJsonArray = null; JSONArray cityJsonArray = null;
JSONArray countyJsonArray = null; JSONArray countyJsonArray = null;
@@ -23,9 +23,9 @@ public class ReadProvinceUtil {
JSONObject countyJson = null; JSONObject countyJson = null;
Date date = new Date(); Date date = new Date();
List<ProvinceEntity> provinceList = null; List<Province> provinceList = null;
List<CityEntity> cityList = null; List<City> cityList = null;
List<CountyEntity> countyList = null; List<County> countyList = null;
// String path = request.getSession().getServletContext().getRealPath("/"); // String path = request.getSession().getServletContext().getRealPath("/");
// path = path + filePath; // path = path + filePath;
@@ -39,29 +39,29 @@ public class ReadProvinceUtil {
if (proJson != null) { if (proJson != null) {
// 取出数据 // 取出数据
proJsonArray = proJson.getJSONArray("china"); proJsonArray = proJson.getJSONArray("china");
provinceList = new ArrayList<ProvinceEntity>(); provinceList = new ArrayList<Province>();
if (proJsonArray != null) { if (proJsonArray != null) {
for (int i = 0; i < proJsonArray.size(); i++) { for (int i = 0; i < proJsonArray.size(); i++) {
ProvinceEntity province = new ProvinceEntity(); Province province = new Province();
JSONObject temp = proJsonArray.getJSONObject(i); JSONObject temp = proJsonArray.getJSONObject(i);
province.setProvName(temp.getString("name")); province.setProvName(temp.getString("name"));
province.setCreateDate(date); province.setCreateDate(date);
province.setRegionCode(temp.getString("code")); province.setRegionCode(temp.getString("code"));
cityJsonArray = JSONArray.parseArray(temp.getString("cityList")); cityJsonArray = JSONArray.parseArray(temp.getString("cityList"));
cityList = new ArrayList<CityEntity>(); cityList = new ArrayList<City>();
if (cityJsonArray != null) { if (cityJsonArray != null) {
for (int j = 0; j < cityJsonArray.size(); j++) { for (int j = 0; j < cityJsonArray.size(); j++) {
CityEntity city = new CityEntity(); City city = new City();
cityJson = cityJsonArray.getJSONObject(j); cityJson = cityJsonArray.getJSONObject(j);
city.setCityName(cityJson.getString("name")); city.setCityName(cityJson.getString("name"));
city.setRegionCode(cityJson.getString("code")); city.setRegionCode(cityJson.getString("code"));
city.setCreateDate(date); city.setCreateDate(date);
countyJsonArray = JSONArray.parseArray(cityJson.getString("areaList")); countyJsonArray = JSONArray.parseArray(cityJson.getString("areaList"));
countyList = new ArrayList<CountyEntity>(); countyList = new ArrayList<County>();
if (countyJsonArray != null) { if (countyJsonArray != null) {
for (int k = 0; k < countyJsonArray.size(); k++) { for (int k = 0; k < countyJsonArray.size(); k++) {
CountyEntity county = new CountyEntity(); County county = new County();
countyJson = countyJsonArray.getJSONObject(k); countyJson = countyJsonArray.getJSONObject(k);
county.setCountyName(countyJson.getString("name")); county.setCountyName(countyJson.getString("name"));
county.setRegionCode(countyJson.getString("code")); county.setRegionCode(countyJson.getString("code"));

View File

@@ -745,18 +745,18 @@ public class BookController {
@RequestMapping("/file") @RequestMapping("/file")
public String getFile() { public String getFile() {
String filePath = "C:\\Users\\Administrator\\IdeaProjects\\peanut_book\\2020年8月中华人民共和国县以上行政区划代码.json"; String filePath = "C:\\Users\\Administrator\\IdeaProjects\\peanut_book\\2020年8月中华人民共和国县以上行政区划代码.json";
List<ProvinceEntity> provinceList = ReadProvinceUtil.getFile(filePath); List<Province> provinceList = ReadProvinceUtil.getFile(filePath);
// System.out.println(provinceList); // System.out.println(provinceList);
if (provinceList != null && provinceList.size() > 0) { if (provinceList != null && provinceList.size() > 0) {
for (ProvinceEntity province : provinceList) { for (Province province : provinceList) {
// ProvinceEntity provinceEntity = new ProvinceEntity(); // ProvinceEntity provinceEntity = new ProvinceEntity();
// provinceEntity.setProvName(province.getProvName()); // provinceEntity.setProvName(province.getProvName());
// provinceEntity.setCreateDate(province.getCreateDate()); // provinceEntity.setCreateDate(province.getCreateDate());
// provinceEntity.setRegionCode(province.getRegionCode()); // provinceEntity.setRegionCode(province.getRegionCode());
provinceService.save(province); provinceService.save(province);
List<CityEntity> cityList = province.getCityList(); List<City> cityList = province.getCityList();
if (cityList != null && cityList.size() > 0) { if (cityList != null && cityList.size() > 0) {
for (CityEntity city : cityList) { for (City city : cityList) {
// CityEntity cityEntity = new CityEntity(); // CityEntity cityEntity = new CityEntity();
// cityEntity.setCreateDate(city.getCreateDate()); // cityEntity.setCreateDate(city.getCreateDate());
// cityEntity.setCityName(city.getCityName()); // cityEntity.setCityName(city.getCityName());
@@ -764,9 +764,9 @@ public class BookController {
// city.setProvId(province.getProvId()); // city.setProvId(province.getProvId());
city.setProvId(province.getProvId()); city.setProvId(province.getProvId());
cityService.save(city); cityService.save(city);
List<CountyEntity> countyList = city.getCountyList(); List<County> countyList = city.getCountyList();
if (countyList != null && countyList.size() > 0) { if (countyList != null && countyList.size() > 0) {
for (CountyEntity county : countyList) { for (County county : countyList) {
// CountyEntity countyEntity = new CountyEntity(); // CountyEntity countyEntity = new CountyEntity();
county.setCityId(city.getCityId()); county.setCityId(city.getCityId());
// countyEntity.setCountyName(county.getCountyName()); // countyEntity.setCountyName(county.getCountyName());

View File

@@ -10,10 +10,15 @@ import com.peanut.config.Constants;
import com.peanut.config.DelayQueueConfig; import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.book.entity.*; import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*; import com.peanut.modules.book.service.*;
import com.peanut.modules.book.vo.ExpressQueryResponseVo; import com.peanut.modules.book.vo.request.ProductRequestVo;
import com.peanut.modules.book.vo.request.ProductTransportVo;
import com.peanut.modules.book.vo.response.ExpressQueryResponseVo;
import com.peanut.modules.book.vo.ShippingAddressRequestVo; import com.peanut.modules.book.vo.ShippingAddressRequestVo;
import com.peanut.modules.book.vo.UserAddressVo;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo; import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import com.peanut.modules.pay.weChatPay.service.WxpayService; import com.peanut.modules.pay.weChatPay.service.WxpayService;
import com.peanut.modules.sys.entity.SysConfigEntity;
import com.peanut.modules.sys.service.SysConfigService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessagePostProcessor; import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
@@ -24,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -61,12 +67,16 @@ public class BuyOrderController {
private WxpayService wxpayService; private WxpayService wxpayService;
@Autowired @Autowired
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
@Autowired @Autowired
private ShopProductBookService shopProductBookService; private ShopProductBookService shopProductBookService;
@Autowired @Autowired
private ExpressOrderService expressOrderService; private ExpressOrderService expressOrderService;
@Autowired
private UserAddressService userAddressService;
@Autowired
private ExpressFeeService expressFeeService;
@Autowired
private SysConfigService sysConfigService;
/** /**
* 列表 * 列表
@@ -91,11 +101,11 @@ public class BuyOrderController {
@Transactional @Transactional
public R buySave(@RequestBody BuyOrder buyOrder) throws IOException { public R buySave(@RequestBody BuyOrder buyOrder) throws IOException {
// 获取订单详情 // 获取订单详情
List<BuyOrderDetail> products = buyOrder.getProducts(); List<BuyOrderDetail> buyOrderDetails = buyOrder.getProducts();
// 订单总金额 // 订单总金额
BigDecimal totalPrice = new BigDecimal(0); BigDecimal totalPrice = new BigDecimal(0);
// 遍历商品总价计算 // 遍历商品总价计算
for (BuyOrderDetail buyOrderDetail : products) { for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
Integer productId = buyOrderDetail.getProductId(); Integer productId = buyOrderDetail.getProductId();
int quantity = buyOrderDetail.getQuantity(); int quantity = buyOrderDetail.getQuantity();
ShopProductEntity product = shopProductService.getById(productId); ShopProductEntity product = shopProductService.getById(productId);
@@ -120,16 +130,24 @@ public class BuyOrderController {
String orderSn = IdWorker.getTimeId().substring(0, 32); String orderSn = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(orderSn); buyOrder.setOrderSn(orderSn);
buyOrder.setPaymentDate(new Date()); buyOrder.setPaymentDate(new Date());
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", buyOrder.getAddressId());
UserAddress userAddress = userAddressService.getOne(queryWrapper);
UserAddressVo vo = new UserAddressVo();
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
buyOrder.setProvince(vo.getProvince());
buyOrder.setCity(vo.getCity());
buyOrder.setDistrict(vo.getCity());
buyOrderService.save(buyOrder); buyOrderService.save(buyOrder);
for (BuyOrderDetail buyOrderDetail : products) { for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
buyOrderDetail.setOrderId(buyOrder.getOrderId()); buyOrderDetail.setOrderId(buyOrder.getOrderId());
buyOrderDetail.setUserId(buyOrder.getUserId()); buyOrderDetail.setUserId(buyOrder.getUserId());
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) { if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
handleBuyCart(buyOrder, buyOrderDetail); handleBuyCart(buyOrder, buyOrderDetail);
} }
} }
buyOrderDetailService.saveBatch(products); buyOrderDetailService.saveBatch(buyOrderDetails);
// 1. 虚拟币支付 // 1. 虚拟币支付
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) { if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED); buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED);
@@ -138,7 +156,7 @@ public class BuyOrderController {
// 更新订单状态 // 更新订单状态
buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0"); buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0");
recordTransaction(buyOrder, user, totalPrice); recordTransaction(buyOrder, user, totalPrice);
addEbookToUser(products, buyOrder); addEbookToUser(buyOrderDetails, buyOrder);
} else { } else {
return R.error(500, "花生币余额不足!"); return R.error(500, "花生币余额不足!");
} }
@@ -163,6 +181,24 @@ public class BuyOrderController {
return R.ok(result); return R.ok(result);
} }
@RequestMapping(path = "/calculateTransportPrice", method = RequestMethod.POST)
public R getTransportPrice(@RequestBody ProductTransportVo vo) {
String regionCode = vo.getRegionCode();
List<ProductRequestVo> products = vo.getProducts();
BigDecimal totalWeight = new BigDecimal(0);
for (ProductRequestVo product : products) {
ShopProductEntity shopProduct = shopProductService.getById(product.getProductId());
BigDecimal weight = BigDecimal.valueOf(Double.valueOf(shopProduct.getWeight()) / 1000.0);
totalWeight = totalWeight.add(weight.multiply(new BigDecimal(product.getQuantity())));
}
totalWeight = totalWeight.setScale(0, RoundingMode.UP);
QueryWrapper<SysConfigEntity> configQueryWrapper = new QueryWrapper<>();
configQueryWrapper.eq("param_key", "DEFAULT_EXPRESS");
SysConfigEntity config = sysConfigService.getOne(configQueryWrapper);
BigDecimal expressFee = expressFeeService.calculateExpressFee(config.getParamValue(), totalWeight, regionCode);
return R.ok().put("result", expressFee);
}
/** /**
* 修改 * 修改

View File

@@ -4,9 +4,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.R; import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.CityEntity; import com.peanut.modules.book.entity.City;
import com.peanut.modules.book.entity.CountyEntity; import com.peanut.modules.book.entity.County;
import com.peanut.modules.book.entity.ProvinceEntity; import com.peanut.modules.book.entity.Province;
import com.peanut.modules.book.service.CityService; import com.peanut.modules.book.service.CityService;
import com.peanut.modules.book.service.CountyService; import com.peanut.modules.book.service.CountyService;
import com.peanut.modules.book.service.ProvinceService; import com.peanut.modules.book.service.ProvinceService;
@@ -50,15 +50,15 @@ public class ProvinceController {
} }
return R.ok().put("provinceEntity", listData); return R.ok().put("provinceEntity", listData);
} }
List<ProvinceEntity> provinceEntityList = provinceService.getCity(); List<Province> provinceList = provinceService.getCity();
redisTemplate.opsForValue().set("Province", JSON.toJSONString(provinceEntityList)); redisTemplate.opsForValue().set("Province", JSON.toJSONString(provinceList));
return R.ok().put("provinceEntity", provinceEntityList); return R.ok().put("provinceEntity", provinceList);
} }
//获取省列表 //获取省列表
@RequestMapping("/getProvinceList") @RequestMapping("/getProvinceList")
public R getProvinceList() { public R getProvinceList() {
List<ProvinceEntity> provinceList = provinceService.getBaseMapper().selectList(new QueryWrapper<ProvinceEntity>()); List<Province> provinceList = provinceService.getBaseMapper().selectList(new QueryWrapper<Province>());
return R.ok().put("provinceList", provinceList); return R.ok().put("provinceList", provinceList);
} }
@@ -66,7 +66,7 @@ public class ProvinceController {
//获取市列表 //获取市列表
@RequestMapping("/getCityList") @RequestMapping("/getCityList")
public R getCityList(@RequestParam("provId") Integer provId) { public R getCityList(@RequestParam("provId") Integer provId) {
List<CityEntity> prov = cityService.getBaseMapper().selectList(new QueryWrapper<CityEntity>() List<City> prov = cityService.getBaseMapper().selectList(new QueryWrapper<City>()
.eq("prov_id", provId)); .eq("prov_id", provId));
return R.ok().put("prov", prov); return R.ok().put("prov", prov);
} }
@@ -74,7 +74,7 @@ public class ProvinceController {
//获取区列表 //获取区列表
@RequestMapping("/getCountyList") @RequestMapping("/getCountyList")
public R getCountyList(@RequestParam("cityId") Integer cityId) { public R getCountyList(@RequestParam("cityId") Integer cityId) {
List<CountyEntity> countyList = countyService.getBaseMapper().selectList(new QueryWrapper<CountyEntity>().eq("city_id", cityId)); List<County> countyList = countyService.getBaseMapper().selectList(new QueryWrapper<County>().eq("city_id", cityId));
return R.ok().put("countyList", countyList); return R.ok().put("countyList", countyList);
} }
} }

View File

@@ -1,15 +1,16 @@
package com.peanut.modules.book.controller; package com.peanut.modules.book.controller;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R; import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.UserAddress; import com.peanut.modules.book.entity.UserAddress;
import com.peanut.modules.book.service.UserAddressService; import com.peanut.modules.book.service.UserAddressService;
import com.peanut.modules.book.vo.UserAddressVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@RestController @RestController
@@ -18,19 +19,6 @@ public class UserAddressController {
@Autowired @Autowired
private UserAddressService userAddressService; private UserAddressService userAddressService;
/**
* 用户地址列表
*
* @param params param
* @return R
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params) {
PageUtils page = userAddressService.queryPage(params);
return R.ok().put("page", page);
}
/** /**
* 获取地址信息 * 获取地址信息
* *
@@ -40,18 +28,34 @@ public class UserAddressController {
@RequestMapping("/info/{addressId}") @RequestMapping("/info/{addressId}")
public R info(@PathVariable("addressId") Integer addressId) { public R info(@PathVariable("addressId") Integer addressId) {
UserAddress userAddress = userAddressService.getById(addressId); UserAddress userAddress = userAddressService.getById(addressId);
return R.ok().put("userAddress", userAddress); UserAddressVo vo = new UserAddressVo();
BeanUtil.copyProperties(userAddress, vo);
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
return R.ok().put("result", vo);
} }
/** /**
* 保存、更新 * 保存
* *
* @param userAddress 用户地址 * @param userAddress 用户地址
* @return R * @return R
*/ */
@RequestMapping("/save") @RequestMapping("/save")
public R save(@RequestBody UserAddress userAddress) { public R save(@RequestBody UserAddress userAddress) {
userAddressService.saveOrUpdate(userAddress); // 判断是否已经有默认的地址了
if ((userAddressService.getUserDefaultAddressCount(userAddress.getUserId()) >= 1) && userAddress.getIsDefault() == 1) {
return R.error("已经存在默认地址");
}
userAddressService.save(userAddress);
return R.ok();
}
@RequestMapping("/update")
public R update(@RequestBody UserAddress userAddress) {
if ((userAddressService.getUserDefaultAddressCount(userAddress.getUserId()) >= 1) && userAddress.getIsDefault() == 1) {
return R.error("已经存在默认地址");
}
userAddressService.updateById(userAddress);
return R.ok(); return R.ok();
} }
@@ -79,6 +83,13 @@ public class UserAddressController {
queryWrapper.eq("user_id", userId); queryWrapper.eq("user_id", userId);
queryWrapper.orderByDesc("is_default"); queryWrapper.orderByDesc("is_default");
List<UserAddress> userAddressList = userAddressService.list(queryWrapper); List<UserAddress> userAddressList = userAddressService.list(queryWrapper);
return R.ok().put("list", userAddressList); List<UserAddressVo> result = new ArrayList<>();
for (UserAddress userAddress : userAddressList) {
UserAddressVo vo = new UserAddressVo();
BeanUtil.copyProperties(userAddress, vo);
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
result.add(vo);
}
return R.ok().put("list", result);
} }
} }

View File

@@ -1,7 +1,7 @@
package com.peanut.modules.book.dao; package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.CityEntity; import com.peanut.modules.book.entity.City;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2022-10-27 16:07:59 * @date 2022-10-27 16:07:59
*/ */
@Mapper @Mapper
public interface CityDao extends BaseMapper<CityEntity> { public interface CityDao extends BaseMapper<City> {
} }

View File

@@ -1,7 +1,7 @@
package com.peanut.modules.book.dao; package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.CountyEntity; import com.peanut.modules.book.entity.County;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2022-10-27 16:07:59 * @date 2022-10-27 16:07:59
*/ */
@Mapper @Mapper
public interface CountyDao extends BaseMapper<CountyEntity> { public interface CountyDao extends BaseMapper<County> {
} }

View File

@@ -1,7 +1,7 @@
package com.peanut.modules.book.dao; package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.ProvinceEntity; import com.peanut.modules.book.entity.Province;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2022-10-27 16:07:59 * @date 2022-10-27 16:07:59
*/ */
@Mapper @Mapper
public interface ProvinceDao extends BaseMapper<ProvinceEntity> { public interface ProvinceDao extends BaseMapper<Province> {
} }

View File

@@ -20,7 +20,7 @@ import lombok.Data;
*/ */
@Data @Data
@TableName("base_city") @TableName("base_city")
public class CityEntity implements Serializable { public class City implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
@@ -46,5 +46,5 @@ public class CityEntity implements Serializable {
private String regionCode; private String regionCode;
@TableField(exist = false) @TableField(exist = false)
private List<CountyEntity> countyList; private List<County> countyList;
} }

View File

@@ -1,13 +1,11 @@
package com.peanut.modules.book.entity; package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List;
import lombok.Data; import lombok.Data;
@@ -20,7 +18,7 @@ import lombok.Data;
*/ */
@Data @Data
@TableName("base_county") @TableName("base_county")
public class CountyEntity implements Serializable { public class County implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**

View File

@@ -20,7 +20,7 @@ import lombok.Data;
*/ */
@Data @Data
@TableName("base_province") @TableName("base_province")
public class ProvinceEntity implements Serializable { public class Province implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
@@ -42,5 +42,5 @@ public class ProvinceEntity implements Serializable {
private String regionCode; private String regionCode;
@TableField(exist = false) @TableField(exist = false)
private List<CityEntity> cityList; private List<City> cityList;
} }

View File

@@ -167,6 +167,4 @@ public class ShopProductEntity implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private List<String> shoproudLabels; private List<String> shoproudLabels;
private int expressOrderId;
} }

View File

@@ -2,7 +2,7 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.CityEntity; import com.peanut.modules.book.entity.City;
import java.util.Map; import java.util.Map;
@@ -13,7 +13,7 @@ import java.util.Map;
* @email yl328572838@163.com * @email yl328572838@163.com
* @date 2022-10-27 16:07:59 * @date 2022-10-27 16:07:59
*/ */
public interface CityService extends IService<CityEntity> { public interface CityService extends IService<City> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
} }

View File

@@ -2,7 +2,7 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.CountyEntity; import com.peanut.modules.book.entity.County;
import java.util.Map; import java.util.Map;
@@ -13,7 +13,7 @@ import java.util.Map;
* @email yl328572838@163.com * @email yl328572838@163.com
* @date 2022-10-27 16:07:59 * @date 2022-10-27 16:07:59
*/ */
public interface CountyService extends IService<CountyEntity> { public interface CountyService extends IService<County> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
} }

View File

@@ -2,7 +2,7 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.ProvinceEntity; import com.peanut.modules.book.entity.Province;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -14,10 +14,10 @@ import java.util.Map;
* @email yl328572838@163.com * @email yl328572838@163.com
* @date 2022-10-27 16:07:59 * @date 2022-10-27 16:07:59
*/ */
public interface ProvinceService extends IService<ProvinceEntity> { public interface ProvinceService extends IService<Province> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
List<ProvinceEntity> getCity(); List<Province> getCity();
} }

View File

@@ -3,12 +3,11 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.UserAddress; import com.peanut.modules.book.entity.UserAddress;
import com.peanut.modules.book.vo.UserAddressVo;
import java.util.Map; import java.util.Map;
/** /**
*
*
* @author yl * @author yl
* @email yl328572838@163.com * @email yl328572838@163.com
* @date 2022-10-31 11:20:32 * @date 2022-10-31 11:20:32
@@ -16,5 +15,9 @@ import java.util.Map;
public interface UserAddressService extends IService<UserAddress> { public interface UserAddressService extends IService<UserAddress> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
UserAddressVo getAddressName(UserAddressVo vo, String regionCode);
int getUserDefaultAddressCount(Integer userId);
} }

View File

@@ -265,9 +265,9 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
// 获取用户地址 // 获取用户地址
Integer orderId = buyOrderDetailList.get(0).getOrderId(); Integer orderId = buyOrderDetailList.get(0).getOrderId();
BuyOrder buyOrder = getById(orderId); BuyOrder buyOrder = getById(orderId);
QueryWrapper<CountyEntity> countyQueryWrapper = new QueryWrapper<>(); QueryWrapper<County> countyQueryWrapper = new QueryWrapper<>();
countyQueryWrapper.eq("county_name", buyOrder.getDistrict()); countyQueryWrapper.eq("county_name", buyOrder.getDistrict());
CountyEntity county = countyService.getOne(countyQueryWrapper); County county = countyService.getOne(countyQueryWrapper);
// 计算快递费用 // 计算快递费用
BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, county.getRegionCode()); BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, county.getRegionCode());
ExpressOrder expressOrder = new ExpressOrder(); ExpressOrder expressOrder = new ExpressOrder();

View File

@@ -1,6 +1,6 @@
package com.peanut.modules.book.service.impl; package com.peanut.modules.book.service.impl;
import com.peanut.modules.book.entity.CityEntity; import com.peanut.modules.book.entity.City;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -14,13 +14,13 @@ import com.peanut.modules.book.service.CityService;
@Service("cityService") @Service("cityService")
public class CityServiceImpl extends ServiceImpl<CityDao, CityEntity> implements CityService { public class CityServiceImpl extends ServiceImpl<CityDao, City> implements CityService {
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<CityEntity> page = this.page( IPage<City> page = this.page(
new Query<CityEntity>().getPage(params), new Query<City>().getPage(params),
new QueryWrapper<CityEntity>() new QueryWrapper<City>()
); );
return new PageUtils(page); return new PageUtils(page);

View File

@@ -1,6 +1,6 @@
package com.peanut.modules.book.service.impl; package com.peanut.modules.book.service.impl;
import com.peanut.modules.book.entity.CountyEntity; import com.peanut.modules.book.entity.County;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -14,13 +14,13 @@ import com.peanut.modules.book.service.CountyService;
@Service("countyService") @Service("countyService")
public class CountyServiceImpl extends ServiceImpl<CountyDao, CountyEntity> implements CountyService { public class CountyServiceImpl extends ServiceImpl<CountyDao, County> implements CountyService {
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<CountyEntity> page = this.page( IPage<County> page = this.page(
new Query<CountyEntity>().getPage(params), new Query<County>().getPage(params),
new QueryWrapper<CountyEntity>() new QueryWrapper<County>()
); );
return new PageUtils(page); return new PageUtils(page);

View File

@@ -40,7 +40,7 @@ public class ExpressFeeServiceImpl extends ServiceImpl<ExpressFeeDao, ExpressFee
private BigDecimal calculateSFExpressFee(BigDecimal weight, String regionCode) { private BigDecimal calculateSFExpressFee(BigDecimal weight, String regionCode) {
// 判断运费计算区间 // 判断运费计算区间
int weightInterval; int weightInterval;
BigDecimal additionalWeight = null; BigDecimal additionalWeight;
if (weight.compareTo(new BigDecimal(0)) >= 0 && weight.compareTo(new BigDecimal(3)) < 0) { if (weight.compareTo(new BigDecimal(0)) >= 0 && weight.compareTo(new BigDecimal(3)) < 0) {
weightInterval = 1; weightInterval = 1;
additionalWeight = weight.subtract(new BigDecimal(1)); additionalWeight = weight.subtract(new BigDecimal(1));
@@ -72,7 +72,7 @@ public class ExpressFeeServiceImpl extends ServiceImpl<ExpressFeeDao, ExpressFee
* @return 费用 * @return 费用
*/ */
private BigDecimal calculateYDExpressFee(BigDecimal weight, String regionCode) { private BigDecimal calculateYDExpressFee(BigDecimal weight, String regionCode) {
regionCode = regionCode.substring(0, 3).concat("00"); regionCode = regionCode.substring(0, 4).concat("00");
QueryWrapper<ExpressFee> queryWrapper = new QueryWrapper<>(); QueryWrapper<ExpressFee> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("dest_code", regionCode); queryWrapper.eq("dest_code", regionCode);
queryWrapper.eq("express_code", "YD"); queryWrapper.eq("express_code", "YD");

View File

@@ -10,6 +10,7 @@ import com.peanut.modules.book.entity.ExpressOrder;
import com.peanut.modules.book.entity.ExpressQueryResponse; import com.peanut.modules.book.entity.ExpressQueryResponse;
import com.peanut.modules.book.service.ExpressOrderService; import com.peanut.modules.book.service.ExpressOrderService;
import com.peanut.modules.book.vo.*; import com.peanut.modules.book.vo.*;
import com.peanut.modules.book.vo.request.ExpressOrderRequestVo;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

View File

@@ -1,8 +1,8 @@
package com.peanut.modules.book.service.impl; package com.peanut.modules.book.service.impl;
import com.peanut.modules.book.entity.CityEntity; import com.peanut.modules.book.entity.City;
import com.peanut.modules.book.entity.CountyEntity; import com.peanut.modules.book.entity.County;
import com.peanut.modules.book.entity.ProvinceEntity; import com.peanut.modules.book.entity.Province;
import com.peanut.modules.book.service.CityService; import com.peanut.modules.book.service.CityService;
import com.peanut.modules.book.service.CountyService; import com.peanut.modules.book.service.CountyService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +21,7 @@ import com.peanut.modules.book.service.ProvinceService;
@Service("provinceService") @Service("provinceService")
public class ProvinceServiceImpl extends ServiceImpl<ProvinceDao, ProvinceEntity> implements ProvinceService { public class ProvinceServiceImpl extends ServiceImpl<ProvinceDao, Province> implements ProvinceService {
@Autowired @Autowired
private CityService cityService; private CityService cityService;
@@ -30,26 +30,26 @@ public class ProvinceServiceImpl extends ServiceImpl<ProvinceDao, ProvinceEntity
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<ProvinceEntity> page = this.page( IPage<Province> page = this.page(
new Query<ProvinceEntity>().getPage(params), new Query<Province>().getPage(params),
new QueryWrapper<ProvinceEntity>() new QueryWrapper<Province>()
); );
return new PageUtils(page); return new PageUtils(page);
} }
@Override @Override
public List<ProvinceEntity> getCity() { public List<Province> getCity() {
List<ProvinceEntity> provinceList = this.baseMapper.selectList(new QueryWrapper<ProvinceEntity>()); List<Province> provinceList = this.baseMapper.selectList(new QueryWrapper<Province>());
for (ProvinceEntity province:provinceList){ for (Province province:provinceList){
List<CityEntity> prov = cityService.getBaseMapper().selectList(new QueryWrapper<CityEntity>() List<City> prov = cityService.getBaseMapper().selectList(new QueryWrapper<City>()
.eq("prov_id", province.getProvId())); .eq("prov_id", province.getProvId()));
if (prov.size() > 0) { if (prov.size() > 0) {
for (CityEntity cityEntity : prov) { for (City city : prov) {
List<CountyEntity> countyList = countyService.getBaseMapper().selectList(new QueryWrapper<CountyEntity>().eq("city_id", cityEntity.getCityId())); List<County> countyList = countyService.getBaseMapper().selectList(new QueryWrapper<County>().eq("city_id", city.getCityId()));
if (countyList != null) { if (countyList != null) {
cityEntity.setCountyList(countyList); city.setCountyList(countyList);
} }
} }
province.setCityList(prov); province.setCityList(prov);

View File

@@ -1,7 +1,17 @@
package com.peanut.modules.book.service.impl; package com.peanut.modules.book.service.impl;
import com.peanut.modules.book.entity.City;
import com.peanut.modules.book.entity.County;
import com.peanut.modules.book.entity.Province;
import com.peanut.modules.book.service.CityService;
import com.peanut.modules.book.service.CountyService;
import com.peanut.modules.book.service.ProvinceService;
import com.peanut.modules.book.vo.UserAddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -15,6 +25,14 @@ import com.peanut.modules.book.service.UserAddressService;
@Service("userAddressService") @Service("userAddressService")
public class UserAddressServiceImpl extends ServiceImpl<UserAddressDao, UserAddress> implements UserAddressService { public class UserAddressServiceImpl extends ServiceImpl<UserAddressDao, UserAddress> implements UserAddressService {
@Autowired
private CountyService countyService;
@Autowired
private CityService cityService;
@Autowired
private ProvinceService provinceService;
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
@@ -24,4 +42,34 @@ public class UserAddressServiceImpl extends ServiceImpl<UserAddressDao, UserAddr
); );
return new PageUtils(page); return new PageUtils(page);
} }
public UserAddressVo getAddressName(UserAddressVo vo, String regionCode) {
QueryWrapper<County> countyQueryWrapper = new QueryWrapper<>();
countyQueryWrapper.eq("region_code", regionCode);
County county = countyService.getOne(countyQueryWrapper);
vo.setCounty(county.getCountyName());
String cityRegionCode;
if (regionCode.startsWith("11") || regionCode.startsWith("12") || regionCode.startsWith("31") || regionCode.startsWith("50")) {
cityRegionCode = regionCode.substring(0, 2).concat("0000");
} else {
cityRegionCode = regionCode.substring(0, 4).concat("00");
}
QueryWrapper<City> cityQueryWrapper = new QueryWrapper<>();
cityQueryWrapper.eq("region_code", cityRegionCode);
City city = cityService.getOne(cityQueryWrapper);
vo.setCity(city.getCityName());
String provinceRegionCode = regionCode.substring(0, 2).concat("0000");
QueryWrapper<Province> provinceQueryWrapper = new QueryWrapper<>();
provinceQueryWrapper.eq("region_code", provinceRegionCode);
Province province = provinceService.getOne(provinceQueryWrapper);
vo.setProvince(province.getProvName());
return vo;
}
public int getUserDefaultAddressCount(Integer userId) {
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
queryWrapper.eq("is_default", 1);
return this.count(queryWrapper);
}
} }

View File

@@ -1,5 +1,6 @@
package com.peanut.modules.book.vo; package com.peanut.modules.book.vo;
import com.peanut.modules.book.vo.response.ExpressResponseOrderVo;
import lombok.Data; import lombok.Data;
/** /**

View File

@@ -0,0 +1,58 @@
package com.peanut.modules.book.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import java.util.Date;
/**
* @Description: 用户地址 Value Object
* @Author: Cauchy
* @CreateTime: 2023/10/18
*/
@Data
public class UserAddressVo {
/**
* id
*/
private int id;
/**
* 会员 ID
*/
private Integer userId;
/**
* 收货人
*/
private String consigneeName;
/**
* 收货人手机号码
*/
private String consigneePhone;
/**
* 区域代码
*/
private String regionCode;
/**
* 详细地址
*/
private String detailAddress;
/**
* 默认
*/
private Integer isDefault;
/**
* 省
*/
private String province;
/**
* 城市
*/
private String city;
/**
* 县
*/
private String county;
}

View File

@@ -1,6 +1,7 @@
package com.peanut.modules.book.vo; package com.peanut.modules.book.vo.request;
import com.peanut.modules.book.entity.ExpressCommodity; import com.peanut.modules.book.entity.ExpressCommodity;
import com.peanut.modules.book.vo.ExpressUserInfoVo;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;

View File

@@ -0,0 +1,20 @@
package com.peanut.modules.book.vo.request;
import lombok.Data;
/**
* @Description: 商品请求 Value Object
* @Author: Cauchy
* @CreateTime: 2023/10/18
*/
@Data
public class ProductRequestVo {
/**
* 商品 ID
*/
private String productId;
/**
* 商品数量
*/
private int quantity;
}

View File

@@ -0,0 +1,20 @@
package com.peanut.modules.book.vo.request;
import com.peanut.modules.book.entity.ShopProductEntity;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @Description: 计算运费
* @Author: Cauchy
* @CreateTime: 2023/10/18
*/
@Data
public class ProductTransportVo {
private String regionCode;
private List<ProductRequestVo> products;
}

View File

@@ -1,4 +1,4 @@
package com.peanut.modules.book.vo; package com.peanut.modules.book.vo.response;
import com.peanut.modules.book.entity.Trace; import com.peanut.modules.book.entity.Trace;
import lombok.Data; import lombok.Data;

View File

@@ -1,9 +1,9 @@
package com.peanut.modules.book.vo; package com.peanut.modules.book.vo.response;
import lombok.Data; import lombok.Data;
/** /**
* @Description: TODO * @Description: 快递查询相应 Order Value Object
* @Author: Cauchy * @Author: Cauchy
* @CreateTime: 2023/10/17 * @CreateTime: 2023/10/17
*/ */

View File

@@ -4,7 +4,7 @@
<mapper namespace="com.peanut.modules.book.dao.CityDao"> <mapper namespace="com.peanut.modules.book.dao.CityDao">
<!-- 可根据自己的需求,是否要使用 --> <!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.peanut.modules.book.entity.CityEntity" id="cityMap"> <resultMap type="com.peanut.modules.book.entity.City" id="cityMap">
<result property="cityId" column="city_id"/> <result property="cityId" column="city_id"/>
<result property="provId" column="prov_id"/> <result property="provId" column="prov_id"/>
<result property="cityName" column="city_name"/> <result property="cityName" column="city_name"/>

View File

@@ -4,7 +4,7 @@
<mapper namespace="com.peanut.modules.book.dao.CountyDao"> <mapper namespace="com.peanut.modules.book.dao.CountyDao">
<!-- 可根据自己的需求,是否要使用 --> <!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.peanut.modules.book.entity.CountyEntity" id="countyMap"> <resultMap type="com.peanut.modules.book.entity.County" id="countyMap">
<result property="countyId" column="county_id"/> <result property="countyId" column="county_id"/>
<result property="cityId" column="city_id"/> <result property="cityId" column="city_id"/>
<result property="countyName" column="county_name"/> <result property="countyName" column="county_name"/>

View File

@@ -4,7 +4,7 @@
<mapper namespace="com.peanut.modules.book.dao.ProvinceDao"> <mapper namespace="com.peanut.modules.book.dao.ProvinceDao">
<!-- 可根据自己的需求,是否要使用 --> <!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.peanut.modules.book.entity.ProvinceEntity" id="provinceMap"> <resultMap type="com.peanut.modules.book.entity.Province" id="provinceMap">
<result property="provId" column="prov_id"/> <result property="provId" column="prov_id"/>
<result property="provName" column="prov_name"/> <result property="provName" column="prov_name"/>
<result property="createDate" column="create_date"/> <result property="createDate" column="create_date"/>