diff --git a/src/main/java/com/peanut/common/utils/ReadProvinceUtil.java b/src/main/java/com/peanut/common/utils/ReadProvinceUtil.java index c69bc00e..1d7295ec 100644 --- a/src/main/java/com/peanut/common/utils/ReadProvinceUtil.java +++ b/src/main/java/com/peanut/common/utils/ReadProvinceUtil.java @@ -3,9 +3,9 @@ package com.peanut.common.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.peanut.modules.book.entity.CityEntity; -import com.peanut.modules.book.entity.CountyEntity; -import com.peanut.modules.book.entity.ProvinceEntity; +import com.peanut.modules.book.entity.City; +import com.peanut.modules.book.entity.County; +import com.peanut.modules.book.entity.Province; import org.apache.commons.io.FileUtils; import java.io.File; @@ -14,7 +14,7 @@ import java.util.Date; import java.util.List; public class ReadProvinceUtil { - public static List getFile(String filePath) { + public static List getFile(String filePath) { JSONArray proJsonArray = null; JSONArray cityJsonArray = null; JSONArray countyJsonArray = null; @@ -23,9 +23,9 @@ public class ReadProvinceUtil { JSONObject countyJson = null; Date date = new Date(); - List provinceList = null; - List cityList = null; - List countyList = null; + List provinceList = null; + List cityList = null; + List countyList = null; // String path = request.getSession().getServletContext().getRealPath("/"); // path = path + filePath; @@ -39,29 +39,29 @@ public class ReadProvinceUtil { if (proJson != null) { // 取出数据 proJsonArray = proJson.getJSONArray("china"); - provinceList = new ArrayList(); + provinceList = new ArrayList(); if (proJsonArray != null) { for (int i = 0; i < proJsonArray.size(); i++) { - ProvinceEntity province = new ProvinceEntity(); + Province province = new Province(); JSONObject temp = proJsonArray.getJSONObject(i); province.setProvName(temp.getString("name")); province.setCreateDate(date); province.setRegionCode(temp.getString("code")); cityJsonArray = JSONArray.parseArray(temp.getString("cityList")); - cityList = new ArrayList(); + cityList = new ArrayList(); if (cityJsonArray != null) { for (int j = 0; j < cityJsonArray.size(); j++) { - CityEntity city = new CityEntity(); + City city = new City(); cityJson = cityJsonArray.getJSONObject(j); city.setCityName(cityJson.getString("name")); city.setRegionCode(cityJson.getString("code")); city.setCreateDate(date); countyJsonArray = JSONArray.parseArray(cityJson.getString("areaList")); - countyList = new ArrayList(); + countyList = new ArrayList(); if (countyJsonArray != null) { for (int k = 0; k < countyJsonArray.size(); k++) { - CountyEntity county = new CountyEntity(); + County county = new County(); countyJson = countyJsonArray.getJSONObject(k); county.setCountyName(countyJson.getString("name")); county.setRegionCode(countyJson.getString("code")); diff --git a/src/main/java/com/peanut/modules/book/controller/BookController.java b/src/main/java/com/peanut/modules/book/controller/BookController.java index 7a57a9ed..2acb04c2 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookController.java @@ -745,18 +745,18 @@ public class BookController { @RequestMapping("/file") public String getFile() { String filePath = "C:\\Users\\Administrator\\IdeaProjects\\peanut_book\\2020年8月中华人民共和国县以上行政区划代码.json"; - List provinceList = ReadProvinceUtil.getFile(filePath); + List provinceList = ReadProvinceUtil.getFile(filePath); // System.out.println(provinceList); if (provinceList != null && provinceList.size() > 0) { - for (ProvinceEntity province : provinceList) { + for (Province province : provinceList) { // ProvinceEntity provinceEntity = new ProvinceEntity(); // provinceEntity.setProvName(province.getProvName()); // provinceEntity.setCreateDate(province.getCreateDate()); // provinceEntity.setRegionCode(province.getRegionCode()); provinceService.save(province); - List cityList = province.getCityList(); + List cityList = province.getCityList(); if (cityList != null && cityList.size() > 0) { - for (CityEntity city : cityList) { + for (City city : cityList) { // CityEntity cityEntity = new CityEntity(); // cityEntity.setCreateDate(city.getCreateDate()); // cityEntity.setCityName(city.getCityName()); @@ -764,9 +764,9 @@ public class BookController { // city.setProvId(province.getProvId()); city.setProvId(province.getProvId()); cityService.save(city); - List countyList = city.getCountyList(); + List countyList = city.getCountyList(); if (countyList != null && countyList.size() > 0) { - for (CountyEntity county : countyList) { + for (County county : countyList) { // CountyEntity countyEntity = new CountyEntity(); county.setCityId(city.getCityId()); // countyEntity.setCountyName(county.getCountyName()); diff --git a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java index d476a09a..2bd36b8e 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -10,10 +10,15 @@ import com.peanut.config.Constants; import com.peanut.config.DelayQueueConfig; import com.peanut.modules.book.entity.*; 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.UserAddressVo; import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo; 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 org.springframework.amqp.core.MessagePostProcessor; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -24,6 +29,7 @@ import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.math.BigDecimal; import java.math.MathContext; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -61,12 +67,16 @@ public class BuyOrderController { private WxpayService wxpayService; @Autowired private RabbitTemplate rabbitTemplate; - @Autowired private ShopProductBookService shopProductBookService; - @Autowired private ExpressOrderService expressOrderService; + @Autowired + private UserAddressService userAddressService; + @Autowired + private ExpressFeeService expressFeeService; + @Autowired + private SysConfigService sysConfigService; /** * 列表 @@ -91,11 +101,11 @@ public class BuyOrderController { @Transactional public R buySave(@RequestBody BuyOrder buyOrder) throws IOException { // 获取订单详情 - List products = buyOrder.getProducts(); + List buyOrderDetails = buyOrder.getProducts(); // 订单总金额 BigDecimal totalPrice = new BigDecimal(0); // 遍历商品总价计算 - for (BuyOrderDetail buyOrderDetail : products) { + for (BuyOrderDetail buyOrderDetail : buyOrderDetails) { Integer productId = buyOrderDetail.getProductId(); int quantity = buyOrderDetail.getQuantity(); ShopProductEntity product = shopProductService.getById(productId); @@ -120,16 +130,24 @@ public class BuyOrderController { String orderSn = IdWorker.getTimeId().substring(0, 32); buyOrder.setOrderSn(orderSn); buyOrder.setPaymentDate(new Date()); + QueryWrapper 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); - for (BuyOrderDetail buyOrderDetail : products) { + for (BuyOrderDetail buyOrderDetail : buyOrderDetails) { buyOrderDetail.setOrderId(buyOrder.getOrderId()); buyOrderDetail.setUserId(buyOrder.getUserId()); if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) { handleBuyCart(buyOrder, buyOrderDetail); } } - buyOrderDetailService.saveBatch(products); + buyOrderDetailService.saveBatch(buyOrderDetails); // 1. 虚拟币支付 if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) { buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED); @@ -138,7 +156,7 @@ public class BuyOrderController { // 更新订单状态 buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0"); recordTransaction(buyOrder, user, totalPrice); - addEbookToUser(products, buyOrder); + addEbookToUser(buyOrderDetails, buyOrder); } else { return R.error(500, "花生币余额不足!"); } @@ -163,6 +181,24 @@ public class BuyOrderController { return R.ok(result); } + @RequestMapping(path = "/calculateTransportPrice", method = RequestMethod.POST) + public R getTransportPrice(@RequestBody ProductTransportVo vo) { + String regionCode = vo.getRegionCode(); + List 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 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); + } + /** * 修改 diff --git a/src/main/java/com/peanut/modules/book/controller/ProvinceController.java b/src/main/java/com/peanut/modules/book/controller/ProvinceController.java index 237763ad..6726ffed 100644 --- a/src/main/java/com/peanut/modules/book/controller/ProvinceController.java +++ b/src/main/java/com/peanut/modules/book/controller/ProvinceController.java @@ -4,9 +4,9 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peanut.common.utils.R; -import com.peanut.modules.book.entity.CityEntity; -import com.peanut.modules.book.entity.CountyEntity; -import com.peanut.modules.book.entity.ProvinceEntity; +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; @@ -50,15 +50,15 @@ public class ProvinceController { } return R.ok().put("provinceEntity", listData); } - List provinceEntityList = provinceService.getCity(); - redisTemplate.opsForValue().set("Province", JSON.toJSONString(provinceEntityList)); - return R.ok().put("provinceEntity", provinceEntityList); + List provinceList = provinceService.getCity(); + redisTemplate.opsForValue().set("Province", JSON.toJSONString(provinceList)); + return R.ok().put("provinceEntity", provinceList); } //获取省列表 @RequestMapping("/getProvinceList") public R getProvinceList() { - List provinceList = provinceService.getBaseMapper().selectList(new QueryWrapper()); + List provinceList = provinceService.getBaseMapper().selectList(new QueryWrapper()); return R.ok().put("provinceList", provinceList); } @@ -66,7 +66,7 @@ public class ProvinceController { //获取市列表 @RequestMapping("/getCityList") public R getCityList(@RequestParam("provId") Integer provId) { - List prov = cityService.getBaseMapper().selectList(new QueryWrapper() + List prov = cityService.getBaseMapper().selectList(new QueryWrapper() .eq("prov_id", provId)); return R.ok().put("prov", prov); } @@ -74,7 +74,7 @@ public class ProvinceController { //获取区列表 @RequestMapping("/getCountyList") public R getCountyList(@RequestParam("cityId") Integer cityId) { - List countyList = countyService.getBaseMapper().selectList(new QueryWrapper().eq("city_id", cityId)); + List countyList = countyService.getBaseMapper().selectList(new QueryWrapper().eq("city_id", cityId)); return R.ok().put("countyList", countyList); } } diff --git a/src/main/java/com/peanut/modules/book/controller/UserAddressController.java b/src/main/java/com/peanut/modules/book/controller/UserAddressController.java index 752f9af5..ae054199 100644 --- a/src/main/java/com/peanut/modules/book/controller/UserAddressController.java +++ b/src/main/java/com/peanut/modules/book/controller/UserAddressController.java @@ -1,15 +1,16 @@ package com.peanut.modules.book.controller; +import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.R; import com.peanut.modules.book.entity.UserAddress; import com.peanut.modules.book.service.UserAddressService; +import com.peanut.modules.book.vo.UserAddressVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @RestController @@ -18,19 +19,6 @@ public class UserAddressController { @Autowired private UserAddressService userAddressService; - /** - * 用户地址列表 - * - * @param params param - * @return R - */ - @RequestMapping("/list") - public R list(@RequestParam Map params) { - PageUtils page = userAddressService.queryPage(params); - return R.ok().put("page", page); - } - - /** * 获取地址信息 * @@ -40,18 +28,34 @@ public class UserAddressController { @RequestMapping("/info/{addressId}") public R info(@PathVariable("addressId") Integer 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 用户地址 * @return R */ @RequestMapping("/save") 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(); } @@ -79,6 +83,13 @@ public class UserAddressController { queryWrapper.eq("user_id", userId); queryWrapper.orderByDesc("is_default"); List userAddressList = userAddressService.list(queryWrapper); - return R.ok().put("list", userAddressList); + List 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); } } diff --git a/src/main/java/com/peanut/modules/book/dao/CityDao.java b/src/main/java/com/peanut/modules/book/dao/CityDao.java index cdc88d77..c1aa7b4d 100644 --- a/src/main/java/com/peanut/modules/book/dao/CityDao.java +++ b/src/main/java/com/peanut/modules/book/dao/CityDao.java @@ -1,7 +1,7 @@ package com.peanut.modules.book.dao; 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; /** @@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper; * @date 2022-10-27 16:07:59 */ @Mapper -public interface CityDao extends BaseMapper { +public interface CityDao extends BaseMapper { } diff --git a/src/main/java/com/peanut/modules/book/dao/CountyDao.java b/src/main/java/com/peanut/modules/book/dao/CountyDao.java index 225d79b8..6700a633 100644 --- a/src/main/java/com/peanut/modules/book/dao/CountyDao.java +++ b/src/main/java/com/peanut/modules/book/dao/CountyDao.java @@ -1,7 +1,7 @@ package com.peanut.modules.book.dao; 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; /** @@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper; * @date 2022-10-27 16:07:59 */ @Mapper -public interface CountyDao extends BaseMapper { +public interface CountyDao extends BaseMapper { } diff --git a/src/main/java/com/peanut/modules/book/dao/ProvinceDao.java b/src/main/java/com/peanut/modules/book/dao/ProvinceDao.java index d9fb0a71..f6cb89ad 100644 --- a/src/main/java/com/peanut/modules/book/dao/ProvinceDao.java +++ b/src/main/java/com/peanut/modules/book/dao/ProvinceDao.java @@ -1,7 +1,7 @@ package com.peanut.modules.book.dao; 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; /** @@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper; * @date 2022-10-27 16:07:59 */ @Mapper -public interface ProvinceDao extends BaseMapper { +public interface ProvinceDao extends BaseMapper { } diff --git a/src/main/java/com/peanut/modules/book/entity/CityEntity.java b/src/main/java/com/peanut/modules/book/entity/City.java similarity index 90% rename from src/main/java/com/peanut/modules/book/entity/CityEntity.java rename to src/main/java/com/peanut/modules/book/entity/City.java index 30b3b7c4..69c0aef2 100644 --- a/src/main/java/com/peanut/modules/book/entity/CityEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/City.java @@ -20,7 +20,7 @@ import lombok.Data; */ @Data @TableName("base_city") -public class CityEntity implements Serializable { +public class City implements Serializable { private static final long serialVersionUID = 1L; /** @@ -46,5 +46,5 @@ public class CityEntity implements Serializable { private String regionCode; @TableField(exist = false) - private List countyList; + private List countyList; } diff --git a/src/main/java/com/peanut/modules/book/entity/CountyEntity.java b/src/main/java/com/peanut/modules/book/entity/County.java similarity index 84% rename from src/main/java/com/peanut/modules/book/entity/CountyEntity.java rename to src/main/java/com/peanut/modules/book/entity/County.java index 947d01fd..5f8e8477 100644 --- a/src/main/java/com/peanut/modules/book/entity/CountyEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/County.java @@ -1,13 +1,11 @@ package com.peanut.modules.book.entity; import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; import java.util.Date; -import java.util.List; import lombok.Data; @@ -20,7 +18,7 @@ import lombok.Data; */ @Data @TableName("base_county") -public class CountyEntity implements Serializable { +public class County implements Serializable { private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/com/peanut/modules/book/entity/ProvinceEntity.java b/src/main/java/com/peanut/modules/book/entity/Province.java similarity index 89% rename from src/main/java/com/peanut/modules/book/entity/ProvinceEntity.java rename to src/main/java/com/peanut/modules/book/entity/Province.java index 2214d7c2..a8607a2d 100644 --- a/src/main/java/com/peanut/modules/book/entity/ProvinceEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/Province.java @@ -20,7 +20,7 @@ import lombok.Data; */ @Data @TableName("base_province") -public class ProvinceEntity implements Serializable { +public class Province implements Serializable { private static final long serialVersionUID = 1L; /** @@ -42,5 +42,5 @@ public class ProvinceEntity implements Serializable { private String regionCode; @TableField(exist = false) - private List cityList; + private List cityList; } diff --git a/src/main/java/com/peanut/modules/book/entity/ShopProductEntity.java b/src/main/java/com/peanut/modules/book/entity/ShopProductEntity.java index a3d34798..80795766 100644 --- a/src/main/java/com/peanut/modules/book/entity/ShopProductEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/ShopProductEntity.java @@ -167,6 +167,4 @@ public class ShopProductEntity implements Serializable { @TableField(exist = false) private List shoproudLabels; - - private int expressOrderId; } diff --git a/src/main/java/com/peanut/modules/book/service/CityService.java b/src/main/java/com/peanut/modules/book/service/CityService.java index 6fa535b6..937362cd 100644 --- a/src/main/java/com/peanut/modules/book/service/CityService.java +++ b/src/main/java/com/peanut/modules/book/service/CityService.java @@ -2,7 +2,7 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; -import com.peanut.modules.book.entity.CityEntity; +import com.peanut.modules.book.entity.City; import java.util.Map; @@ -13,7 +13,7 @@ import java.util.Map; * @email yl328572838@163.com * @date 2022-10-27 16:07:59 */ -public interface CityService extends IService { +public interface CityService extends IService { PageUtils queryPage(Map params); } diff --git a/src/main/java/com/peanut/modules/book/service/CountyService.java b/src/main/java/com/peanut/modules/book/service/CountyService.java index 9fb0a4e5..c70b5ebb 100644 --- a/src/main/java/com/peanut/modules/book/service/CountyService.java +++ b/src/main/java/com/peanut/modules/book/service/CountyService.java @@ -2,7 +2,7 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; -import com.peanut.modules.book.entity.CountyEntity; +import com.peanut.modules.book.entity.County; import java.util.Map; @@ -13,7 +13,7 @@ import java.util.Map; * @email yl328572838@163.com * @date 2022-10-27 16:07:59 */ -public interface CountyService extends IService { +public interface CountyService extends IService { PageUtils queryPage(Map params); } diff --git a/src/main/java/com/peanut/modules/book/service/ProvinceService.java b/src/main/java/com/peanut/modules/book/service/ProvinceService.java index 235f8bd2..d2e4f7de 100644 --- a/src/main/java/com/peanut/modules/book/service/ProvinceService.java +++ b/src/main/java/com/peanut/modules/book/service/ProvinceService.java @@ -2,7 +2,7 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; 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.Map; @@ -14,10 +14,10 @@ import java.util.Map; * @email yl328572838@163.com * @date 2022-10-27 16:07:59 */ -public interface ProvinceService extends IService { +public interface ProvinceService extends IService { PageUtils queryPage(Map params); - List getCity(); + List getCity(); } diff --git a/src/main/java/com/peanut/modules/book/service/UserAddressService.java b/src/main/java/com/peanut/modules/book/service/UserAddressService.java index 59fb6a40..ca508749 100644 --- a/src/main/java/com/peanut/modules/book/service/UserAddressService.java +++ b/src/main/java/com/peanut/modules/book/service/UserAddressService.java @@ -3,12 +3,11 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; import com.peanut.modules.book.entity.UserAddress; +import com.peanut.modules.book.vo.UserAddressVo; import java.util.Map; /** - * - * * @author yl * @email yl328572838@163.com * @date 2022-10-31 11:20:32 @@ -16,5 +15,9 @@ import java.util.Map; public interface UserAddressService extends IService { PageUtils queryPage(Map params); + + UserAddressVo getAddressName(UserAddressVo vo, String regionCode); + + int getUserDefaultAddressCount(Integer userId); } diff --git a/src/main/java/com/peanut/modules/book/service/impl/BuyOrderServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BuyOrderServiceImpl.java index 432632e1..b0902570 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/BuyOrderServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/BuyOrderServiceImpl.java @@ -265,9 +265,9 @@ public class BuyOrderServiceImpl extends ServiceImpl impl // 获取用户地址 Integer orderId = buyOrderDetailList.get(0).getOrderId(); BuyOrder buyOrder = getById(orderId); - QueryWrapper countyQueryWrapper = new QueryWrapper<>(); + QueryWrapper countyQueryWrapper = new QueryWrapper<>(); countyQueryWrapper.eq("county_name", buyOrder.getDistrict()); - CountyEntity county = countyService.getOne(countyQueryWrapper); + County county = countyService.getOne(countyQueryWrapper); // 计算快递费用 BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, county.getRegionCode()); ExpressOrder expressOrder = new ExpressOrder(); diff --git a/src/main/java/com/peanut/modules/book/service/impl/CityServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/CityServiceImpl.java index b1327a33..ee93c53e 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/CityServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/CityServiceImpl.java @@ -1,6 +1,6 @@ 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 java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -14,13 +14,13 @@ import com.peanut.modules.book.service.CityService; @Service("cityService") -public class CityServiceImpl extends ServiceImpl implements CityService { +public class CityServiceImpl extends ServiceImpl implements CityService { @Override public PageUtils queryPage(Map params) { - IPage page = this.page( - new Query().getPage(params), - new QueryWrapper() + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper() ); return new PageUtils(page); diff --git a/src/main/java/com/peanut/modules/book/service/impl/CountyServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/CountyServiceImpl.java index 370b371d..cf8ffa08 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/CountyServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/CountyServiceImpl.java @@ -1,6 +1,6 @@ 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 java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -14,13 +14,13 @@ import com.peanut.modules.book.service.CountyService; @Service("countyService") -public class CountyServiceImpl extends ServiceImpl implements CountyService { +public class CountyServiceImpl extends ServiceImpl implements CountyService { @Override public PageUtils queryPage(Map params) { - IPage page = this.page( - new Query().getPage(params), - new QueryWrapper() + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper() ); return new PageUtils(page); diff --git a/src/main/java/com/peanut/modules/book/service/impl/ExpressFeeServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ExpressFeeServiceImpl.java index 9f6838b1..0efbd645 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/ExpressFeeServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/ExpressFeeServiceImpl.java @@ -40,7 +40,7 @@ public class ExpressFeeServiceImpl extends ServiceImpl= 0 && weight.compareTo(new BigDecimal(3)) < 0) { weightInterval = 1; additionalWeight = weight.subtract(new BigDecimal(1)); @@ -72,7 +72,7 @@ public class ExpressFeeServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.eq("dest_code", regionCode); queryWrapper.eq("express_code", "YD"); diff --git a/src/main/java/com/peanut/modules/book/service/impl/ExpressOrderServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ExpressOrderServiceImpl.java index 8184c863..7d32e9a1 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/ExpressOrderServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/ExpressOrderServiceImpl.java @@ -10,6 +10,7 @@ import com.peanut.modules.book.entity.ExpressOrder; import com.peanut.modules.book.entity.ExpressQueryResponse; import com.peanut.modules.book.service.ExpressOrderService; import com.peanut.modules.book.vo.*; +import com.peanut.modules.book.vo.request.ExpressOrderRequestVo; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/peanut/modules/book/service/impl/ProvinceServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ProvinceServiceImpl.java index 9194e843..ee2420e0 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/ProvinceServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/ProvinceServiceImpl.java @@ -1,8 +1,8 @@ package com.peanut.modules.book.service.impl; -import com.peanut.modules.book.entity.CityEntity; -import com.peanut.modules.book.entity.CountyEntity; -import com.peanut.modules.book.entity.ProvinceEntity; +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 org.springframework.beans.factory.annotation.Autowired; @@ -21,7 +21,7 @@ import com.peanut.modules.book.service.ProvinceService; @Service("provinceService") -public class ProvinceServiceImpl extends ServiceImpl implements ProvinceService { +public class ProvinceServiceImpl extends ServiceImpl implements ProvinceService { @Autowired private CityService cityService; @@ -30,26 +30,26 @@ public class ProvinceServiceImpl extends ServiceImpl params) { - IPage page = this.page( - new Query().getPage(params), - new QueryWrapper() + IPage page = this.page( + new Query().getPage(params), + new QueryWrapper() ); return new PageUtils(page); } @Override - public List getCity() { - List provinceList = this.baseMapper.selectList(new QueryWrapper()); - for (ProvinceEntity province:provinceList){ - List prov = cityService.getBaseMapper().selectList(new QueryWrapper() + public List getCity() { + List provinceList = this.baseMapper.selectList(new QueryWrapper()); + for (Province province:provinceList){ + List prov = cityService.getBaseMapper().selectList(new QueryWrapper() .eq("prov_id", province.getProvId())); if (prov.size() > 0) { - for (CityEntity cityEntity : prov) { - List countyList = countyService.getBaseMapper().selectList(new QueryWrapper().eq("city_id", cityEntity.getCityId())); + for (City city : prov) { + List countyList = countyService.getBaseMapper().selectList(new QueryWrapper().eq("city_id", city.getCityId())); if (countyList != null) { - cityEntity.setCountyList(countyList); + city.setCountyList(countyList); } } province.setCityList(prov); diff --git a/src/main/java/com/peanut/modules/book/service/impl/UserAddressServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/UserAddressServiceImpl.java index 16d2d1dd..a6905cd5 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/UserAddressServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/UserAddressServiceImpl.java @@ -1,7 +1,17 @@ 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 java.util.Map; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -15,6 +25,14 @@ import com.peanut.modules.book.service.UserAddressService; @Service("userAddressService") public class UserAddressServiceImpl extends ServiceImpl implements UserAddressService { + @Autowired + private CountyService countyService; + + @Autowired + private CityService cityService; + + @Autowired + private ProvinceService provinceService; @Override public PageUtils queryPage(Map params) { @@ -24,4 +42,34 @@ public class UserAddressServiceImpl extends ServiceImpl 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 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("user_id", userId); + queryWrapper.eq("is_default", 1); + return this.count(queryWrapper); + } } \ No newline at end of file diff --git a/src/main/java/com/peanut/modules/book/vo/ExpressOrderResponseVo.java b/src/main/java/com/peanut/modules/book/vo/ExpressOrderResponseVo.java index 19023798..52e54a96 100644 --- a/src/main/java/com/peanut/modules/book/vo/ExpressOrderResponseVo.java +++ b/src/main/java/com/peanut/modules/book/vo/ExpressOrderResponseVo.java @@ -1,5 +1,6 @@ package com.peanut.modules.book.vo; +import com.peanut.modules.book.vo.response.ExpressResponseOrderVo; import lombok.Data; /** diff --git a/src/main/java/com/peanut/modules/book/vo/UserAddressVo.java b/src/main/java/com/peanut/modules/book/vo/UserAddressVo.java new file mode 100644 index 00000000..2f46f8b0 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/vo/UserAddressVo.java @@ -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; +} diff --git a/src/main/java/com/peanut/modules/book/vo/ExpressOrderRequestVo.java b/src/main/java/com/peanut/modules/book/vo/request/ExpressOrderRequestVo.java similarity index 93% rename from src/main/java/com/peanut/modules/book/vo/ExpressOrderRequestVo.java rename to src/main/java/com/peanut/modules/book/vo/request/ExpressOrderRequestVo.java index 9510faad..f0289d91 100644 --- a/src/main/java/com/peanut/modules/book/vo/ExpressOrderRequestVo.java +++ b/src/main/java/com/peanut/modules/book/vo/request/ExpressOrderRequestVo.java @@ -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.vo.ExpressUserInfoVo; import lombok.Data; import java.util.List; diff --git a/src/main/java/com/peanut/modules/book/vo/request/ProductRequestVo.java b/src/main/java/com/peanut/modules/book/vo/request/ProductRequestVo.java new file mode 100644 index 00000000..432588fa --- /dev/null +++ b/src/main/java/com/peanut/modules/book/vo/request/ProductRequestVo.java @@ -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; +} diff --git a/src/main/java/com/peanut/modules/book/vo/request/ProductTransportVo.java b/src/main/java/com/peanut/modules/book/vo/request/ProductTransportVo.java new file mode 100644 index 00000000..51e4640e --- /dev/null +++ b/src/main/java/com/peanut/modules/book/vo/request/ProductTransportVo.java @@ -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 products; +} diff --git a/src/main/java/com/peanut/modules/book/vo/ExpressQueryResponseVo.java b/src/main/java/com/peanut/modules/book/vo/response/ExpressQueryResponseVo.java similarity index 90% rename from src/main/java/com/peanut/modules/book/vo/ExpressQueryResponseVo.java rename to src/main/java/com/peanut/modules/book/vo/response/ExpressQueryResponseVo.java index da941edd..547bb25e 100644 --- a/src/main/java/com/peanut/modules/book/vo/ExpressQueryResponseVo.java +++ b/src/main/java/com/peanut/modules/book/vo/response/ExpressQueryResponseVo.java @@ -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 lombok.Data; diff --git a/src/main/java/com/peanut/modules/book/vo/ExpressResponseOrderVo.java b/src/main/java/com/peanut/modules/book/vo/response/ExpressResponseOrderVo.java similarity index 92% rename from src/main/java/com/peanut/modules/book/vo/ExpressResponseOrderVo.java rename to src/main/java/com/peanut/modules/book/vo/response/ExpressResponseOrderVo.java index 2a74a961..b559097a 100644 --- a/src/main/java/com/peanut/modules/book/vo/ExpressResponseOrderVo.java +++ b/src/main/java/com/peanut/modules/book/vo/response/ExpressResponseOrderVo.java @@ -1,9 +1,9 @@ -package com.peanut.modules.book.vo; +package com.peanut.modules.book.vo.response; import lombok.Data; /** - * @Description: TODO + * @Description: 快递查询相应 Order Value Object * @Author: Cauchy * @CreateTime: 2023/10/17 */ diff --git a/src/main/resources/mapper/book/CityDao.xml b/src/main/resources/mapper/book/CityDao.xml index a6d99107..dffa3064 100644 --- a/src/main/resources/mapper/book/CityDao.xml +++ b/src/main/resources/mapper/book/CityDao.xml @@ -4,7 +4,7 @@ - + diff --git a/src/main/resources/mapper/book/CountyDao.xml b/src/main/resources/mapper/book/CountyDao.xml index 530fc35b..5a45e96e 100644 --- a/src/main/resources/mapper/book/CountyDao.xml +++ b/src/main/resources/mapper/book/CountyDao.xml @@ -4,7 +4,7 @@ - + diff --git a/src/main/resources/mapper/book/ProvinceDao.xml b/src/main/resources/mapper/book/ProvinceDao.xml index 6f44a931..47b9b238 100644 --- a/src/main/resources/mapper/book/ProvinceDao.xml +++ b/src/main/resources/mapper/book/ProvinceDao.xml @@ -4,7 +4,7 @@ - +