Commit 7137c661dfbf05bea509a13d728262ea4761e191

Authored by fengliang
1 parent aae583d0

update:地址增加

etrade-order/src/main/java/com/diligrp/etrade/order/api/OrderContactPersonController.java
@@ -5,8 +5,11 @@ import cn.hutool.core.lang.Assert; @@ -5,8 +5,11 @@ import cn.hutool.core.lang.Assert;
5 import com.diligrp.etrade.core.domain.Message; 5 import com.diligrp.etrade.core.domain.Message;
6 import com.diligrp.etrade.core.domain.PageMessage; 6 import com.diligrp.etrade.core.domain.PageMessage;
7 import com.diligrp.etrade.core.util.NameUtil; 7 import com.diligrp.etrade.core.util.NameUtil;
  8 +import com.diligrp.etrade.order.domain.contactPerson.BaseRegionCo;
  9 +import com.diligrp.etrade.order.domain.contactPerson.BaseRegionNextVo;
8 import com.diligrp.etrade.order.domain.contactPerson.OrderContactPersonCo; 10 import com.diligrp.etrade.order.domain.contactPerson.OrderContactPersonCo;
9 import com.diligrp.etrade.order.domain.contactPerson.OrderContactPersonListCo; 11 import com.diligrp.etrade.order.domain.contactPerson.OrderContactPersonListCo;
  12 +import com.diligrp.etrade.order.service.BaseRegionService;
10 import com.diligrp.etrade.order.service.OrderContactPersonService; 13 import com.diligrp.etrade.order.service.OrderContactPersonService;
11 import jakarta.annotation.Resource; 14 import jakarta.annotation.Resource;
12 import org.slf4j.Logger; 15 import org.slf4j.Logger;
@@ -14,6 +17,8 @@ import org.slf4j.LoggerFactory; @@ -14,6 +17,8 @@ import org.slf4j.LoggerFactory;
14 import org.springframework.validation.annotation.Validated; 17 import org.springframework.validation.annotation.Validated;
15 import org.springframework.web.bind.annotation.*; 18 import org.springframework.web.bind.annotation.*;
16 19
  20 +import java.util.List;
  21 +
17 /** 22 /**
18 * 订单配送地址 23 * 订单配送地址
19 * @author fengliang 24 * @author fengliang
@@ -25,6 +30,10 @@ public class OrderContactPersonController { @@ -25,6 +30,10 @@ public class OrderContactPersonController {
25 private static final Logger log = LoggerFactory.getLogger(OrderContactPersonController.class); 30 private static final Logger log = LoggerFactory.getLogger(OrderContactPersonController.class);
26 @Resource 31 @Resource
27 OrderContactPersonService orderContactPersonService; 32 OrderContactPersonService orderContactPersonService;
  33 +
  34 + @Resource
  35 + BaseRegionService baseRegionService;
  36 +
28 @GetMapping("/test") 37 @GetMapping("/test")
29 public Message<String> test() { 38 public Message<String> test() {
30 return Message.success("test"); 39 return Message.success("test");
@@ -72,5 +81,11 @@ public class OrderContactPersonController { @@ -72,5 +81,11 @@ public class OrderContactPersonController {
72 log.info("联系人列表查询 param={}", co); 81 log.info("联系人列表查询 param={}", co);
73 return orderContactPersonService.page(co); 82 return orderContactPersonService.page(co);
74 } 83 }
  84 +
  85 + @PostMapping(value = "/baseRegion")
  86 + public Message<List<BaseRegionNextVo>> setDefault(@RequestBody BaseRegionCo co) {
  87 + List<BaseRegionNextVo> baseRegionNextVoList = baseRegionService.getNextList(co);
  88 + return Message.success(baseRegionNextVoList);
  89 + }
75 } 90 }
76 91
etrade-order/src/main/java/com/diligrp/etrade/order/dao/BaseRegionMapper.java 0 → 100644
  1 +package com.diligrp.etrade.order.dao;
  2 +
  3 +
  4 +import com.diligrp.etrade.core.mybatis.MybatisMapperSupport;
  5 +import com.diligrp.etrade.order.domain.contactPerson.BaseRegionCo;
  6 +import com.diligrp.etrade.order.model.BaseRegion;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * <p>
  12 + * Mapper 接口
  13 + * </p>
  14 + *
  15 + * @author chenzhiwei
  16 + * @since 2023-12-27
  17 + */
  18 +public interface BaseRegionMapper extends MybatisMapperSupport {
  19 +
  20 + List<BaseRegion> selectNextList(BaseRegionCo co);
  21 +}
etrade-order/src/main/java/com/diligrp/etrade/order/domain/contactPerson/BaseRegionCo.java 0 → 100644
  1 +package com.diligrp.etrade.order.domain.contactPerson;
  2 +
  3 +public class BaseRegionCo {
  4 + /**
  5 + * 市场id
  6 + */
  7 + private Long marketId;
  8 +
  9 + /**
  10 + * 省份id
  11 + */
  12 + private Long provinceId;
  13 + /**
  14 + * 城市id
  15 + */
  16 + private Long cityId;
  17 + /**
  18 + * 区县id
  19 + */
  20 + private Long districtId;
  21 + /**
  22 + * 街道id
  23 + */
  24 + private Long streetId;
  25 + /**
  26 + * 市场id
  27 + */
  28 + private Integer state = 1;
  29 +
  30 + public Long getMarketId() {
  31 + return marketId;
  32 + }
  33 +
  34 + public void setMarketId(Long marketId) {
  35 + this.marketId = marketId;
  36 + }
  37 +
  38 + public Long getProvinceId() {
  39 + return provinceId;
  40 + }
  41 +
  42 + public void setProvinceId(Long provinceId) {
  43 + this.provinceId = provinceId;
  44 + }
  45 +
  46 + public Long getCityId() {
  47 + return cityId;
  48 + }
  49 +
  50 + public void setCityId(Long cityId) {
  51 + this.cityId = cityId;
  52 + }
  53 +
  54 + public Long getDistrictId() {
  55 + return districtId;
  56 + }
  57 +
  58 + public void setDistrictId(Long districtId) {
  59 + this.districtId = districtId;
  60 + }
  61 +
  62 + public Long getStreetId() {
  63 + return streetId;
  64 + }
  65 +
  66 + public void setStreetId(Long streetId) {
  67 + this.streetId = streetId;
  68 + }
  69 +
  70 + public Integer getState() {
  71 + return state;
  72 + }
  73 +
  74 + public void setState(Integer state) {
  75 + this.state = state;
  76 + }
  77 +}
etrade-order/src/main/java/com/diligrp/etrade/order/domain/contactPerson/BaseRegionNextVo.java 0 → 100644
  1 +package com.diligrp.etrade.order.domain.contactPerson;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class BaseRegionNextVo {
  6 + /**
  7 + * 名称
  8 + */
  9 + private String name;
  10 + /**
  11 + * id
  12 + */
  13 + private Long id;
  14 + /**
  15 + * 级别,省 1,市 2,区县 3,街道 4
  16 + */
  17 + private Integer leavel;
  18 + /**
  19 + * 下级区域
  20 + */
  21 + private List<BaseRegionNextVo> children;
  22 + public String getName() {
  23 + return name;
  24 + }
  25 +
  26 + public void setName(String name) {
  27 + this.name = name;
  28 + }
  29 +
  30 + public Long getId() {
  31 + return id;
  32 + }
  33 +
  34 + public void setId(Long id) {
  35 + this.id = id;
  36 + }
  37 +
  38 + public Integer getLeavel() {
  39 + return leavel;
  40 + }
  41 +
  42 + public void setLeavel(Integer leavel) {
  43 + this.leavel = leavel;
  44 + }
  45 +
  46 + public List<BaseRegionNextVo> getChildren() {
  47 + return children;
  48 + }
  49 +
  50 + public void setChildren(List<BaseRegionNextVo> children) {
  51 + this.children = children;
  52 + }
  53 +
  54 + public BaseRegionNextVo(){
  55 +
  56 + }
  57 + public BaseRegionNextVo(Long id,String name,Integer leavel){
  58 + this.id = id;
  59 + this.name = name;
  60 + this.leavel = leavel;
  61 + }
  62 +}
etrade-order/src/main/java/com/diligrp/etrade/order/model/BaseRegion.java 0 → 100644
  1 +package com.diligrp.etrade.order.model;
  2 +
  3 +import com.diligrp.etrade.core.domain.BaseDo;
  4 +
  5 +import java.io.Serializable;
  6 +import java.time.LocalDateTime;
  7 +
  8 +public class BaseRegion extends BaseDo implements Serializable {
  9 +
  10 + /**
  11 + * 主键
  12 + */
  13 + private Long id;
  14 + /**
  15 + * 市场id
  16 + */
  17 + private Long marketId;
  18 + /**
  19 + * 省份id
  20 + */
  21 + private Long provinceId;
  22 + /**
  23 + * 城市id
  24 + */
  25 + private Long cityId;
  26 +
  27 + /**
  28 + * 区id
  29 + */
  30 + private Long districtId;
  31 +
  32 + /**
  33 + * 街道id
  34 + */
  35 + private Long streetId;
  36 +
  37 + /**
  38 + * 省份名称
  39 + */
  40 + private String provinceName;
  41 +
  42 + /**
  43 + * 城市名称
  44 + */
  45 + private String cityName;
  46 + /**
  47 + * 区县名称
  48 + */
  49 + private String districtName;
  50 + /**
  51 + * 街道名称
  52 + */
  53 + private String streetName;
  54 +
  55 + /**
  56 + * 状态
  57 + */
  58 + private Integer state;
  59 +
  60 + @Override
  61 + public Long getId() {
  62 + return id;
  63 + }
  64 +
  65 + @Override
  66 + public void setId(Long id) {
  67 + this.id = id;
  68 + }
  69 +
  70 + public Long getMarketId() {
  71 + return marketId;
  72 + }
  73 +
  74 + public void setMarketId(Long marketId) {
  75 + this.marketId = marketId;
  76 + }
  77 +
  78 + public Long getProvinceId() {
  79 + return provinceId;
  80 + }
  81 +
  82 + public void setProvinceId(Long provinceId) {
  83 + this.provinceId = provinceId;
  84 + }
  85 +
  86 + public Long getCityId() {
  87 + return cityId;
  88 + }
  89 +
  90 + public void setCityId(Long cityId) {
  91 + this.cityId = cityId;
  92 + }
  93 +
  94 + public Long getDistrictId() {
  95 + return districtId;
  96 + }
  97 +
  98 + public void setDistrictId(Long districtId) {
  99 + this.districtId = districtId;
  100 + }
  101 +
  102 + public Long getStreetId() {
  103 + return streetId;
  104 + }
  105 +
  106 + public void setStreetId(Long streetId) {
  107 + this.streetId = streetId;
  108 + }
  109 +
  110 + public String getProvinceName() {
  111 + return provinceName;
  112 + }
  113 +
  114 + public void setProvinceName(String provinceName) {
  115 + this.provinceName = provinceName;
  116 + }
  117 +
  118 + public String getCityName() {
  119 + return cityName;
  120 + }
  121 +
  122 + public void setCityName(String cityName) {
  123 + this.cityName = cityName;
  124 + }
  125 +
  126 + public String getDistrictName() {
  127 + return districtName;
  128 + }
  129 +
  130 + public void setDistrictName(String districtName) {
  131 + this.districtName = districtName;
  132 + }
  133 +
  134 + public String getStreetName() {
  135 + return streetName;
  136 + }
  137 +
  138 + public void setStreetName(String streetName) {
  139 + this.streetName = streetName;
  140 + }
  141 +
  142 + @Override
  143 + public LocalDateTime getCreatedTime() {
  144 + return createdTime;
  145 + }
  146 +
  147 + @Override
  148 + public void setCreatedTime(LocalDateTime createdTime) {
  149 + this.createdTime = createdTime;
  150 + }
  151 +
  152 + @Override
  153 + public LocalDateTime getModifiedTime() {
  154 + return modifiedTime;
  155 + }
  156 +
  157 + @Override
  158 + public void setModifiedTime(LocalDateTime modifiedTime) {
  159 + this.modifiedTime = modifiedTime;
  160 + }
  161 +
  162 + public Integer getState() {
  163 + return state;
  164 + }
  165 +
  166 + public void setState(Integer state) {
  167 + this.state = state;
  168 + }
  169 +}
etrade-order/src/main/java/com/diligrp/etrade/order/service/BaseRegionService.java 0 → 100644
  1 +package com.diligrp.etrade.order.service;
  2 +
  3 +import com.diligrp.etrade.order.domain.contactPerson.*;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * <p>
  9 + * 服务类
  10 + * </p>
  11 + *
  12 + * @author chenzhiwei
  13 + * @since 2023-12-27
  14 + */
  15 +public interface BaseRegionService {
  16 + List<BaseRegionNextVo> getNextList(BaseRegionCo co);
  17 +}
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/BaseRegionServiceImpl.java 0 → 100644
  1 +package com.diligrp.etrade.order.service.impl;
  2 +
  3 +import com.diligrp.etrade.core.domain.Message;
  4 +import com.diligrp.etrade.core.domain.PageMessage;
  5 +import com.diligrp.etrade.core.util.JsonUtils;
  6 +import com.diligrp.etrade.order.dao.BaseRegionMapper;
  7 +import com.diligrp.etrade.order.dao.OrderContactPersonMapper;
  8 +import com.diligrp.etrade.order.domain.contactPerson.*;
  9 +import com.diligrp.etrade.order.exception.OrderErrorCode;
  10 +import com.diligrp.etrade.order.exception.OrderException;
  11 +import com.diligrp.etrade.order.model.BaseRegion;
  12 +import com.diligrp.etrade.order.model.OrderContactPerson;
  13 +import com.diligrp.etrade.order.service.BaseRegionService;
  14 +import com.diligrp.etrade.order.service.OrderContactPersonService;
  15 +import com.diligrp.etrade.order.type.OrderContactDefaultType;
  16 +import com.github.pagehelper.Page;
  17 +import com.github.pagehelper.PageHelper;
  18 +import jakarta.annotation.Resource;
  19 +import org.apache.commons.lang3.ObjectUtils;
  20 +import org.slf4j.Logger;
  21 +import org.slf4j.LoggerFactory;
  22 +import org.springframework.stereotype.Service;
  23 +
  24 +import java.util.ArrayList;
  25 +import java.util.HashMap;
  26 +import java.util.List;
  27 +import java.util.Map;
  28 +
  29 +/**
  30 + * <p>
  31 + * 服务实现类
  32 + * </p>
  33 + *
  34 + * @author chenzhiwei
  35 + * @since 2023-12-27
  36 + */
  37 +@Service
  38 +public class BaseRegionServiceImpl implements BaseRegionService {
  39 + private final static Logger logger = LoggerFactory.getLogger(BaseRegionServiceImpl.class);
  40 + @Resource
  41 + private BaseRegionMapper baseRegionMapper;
  42 +
  43 +
  44 + @Override
  45 + public List<BaseRegionNextVo> getNextList(BaseRegionCo co) {
  46 + if(co.getMarketId() == null){
  47 + throw new OrderException(OrderErrorCode.PARAM_ERROR, "市场不能为空");
  48 + }
  49 + List<BaseRegion> baseRegions = baseRegionMapper.selectNextList(co);
  50 + if (ObjectUtils.isEmpty(baseRegions)){
  51 + return new ArrayList<>();
  52 + }
  53 + Map<Long, BaseRegionNextVo> citiesMap = new HashMap<>();
  54 + Map<Long, BaseRegionNextVo> districtsMap = new HashMap<>();
  55 + List<BaseRegionNextVo> streetList = new ArrayList<>();
  56 + List<BaseRegionNextVo> provinces = new ArrayList<>();
  57 + BaseRegionNextVo baseDistrict = null;
  58 + BaseRegionNextVo baseCity = null;
  59 + BaseRegionNextVo baseProvince = null;
  60 +
  61 + BaseRegion lastBaseRegion = null;
  62 + for(BaseRegion baseRegion:baseRegions){
  63 + if(lastBaseRegion!=null&&!lastBaseRegion.getDistrictId().equals(baseRegion.getDistrictId())){
  64 + baseDistrict = new BaseRegionNextVo(lastBaseRegion.getDistrictId(), lastBaseRegion.getDistrictName(),3);
  65 + baseDistrict.setChildren(streetList);
  66 + streetList = new ArrayList<>();
  67 + if(lastBaseRegion!=null && !lastBaseRegion.getCityId().equals(baseRegion.getCityId())){
  68 + baseCity = new BaseRegionNextVo(lastBaseRegion.getCityId(), lastBaseRegion.getCityName(),2);
  69 + baseCity.setChildren(new ArrayList<>(districtsMap.values()));
  70 + districtsMap = new HashMap<>();
  71 + if(lastBaseRegion!=null && !lastBaseRegion.getProvinceId().equals(baseRegion.getProvinceId())){
  72 + baseProvince = new BaseRegionNextVo(lastBaseRegion.getProvinceId(), lastBaseRegion.getProvinceName(),1);
  73 + baseProvince.setChildren(new ArrayList<>(citiesMap.values()));
  74 + citiesMap = new HashMap<>();
  75 + provinces.add(baseProvince);
  76 + }
  77 + BaseRegionNextVo city = new BaseRegionNextVo(baseRegion.getCityId(), baseRegion.getCityName(),2);
  78 + citiesMap.put(baseRegion.getCityId(),city);
  79 + }/*else{
  80 + if(citiesMap.get(baseRegion.getCityId())==null){
  81 + BaseRegionNextVo city = new BaseRegionNextVo(baseRegion.getCityId(), baseRegion.getCityName(),2);
  82 + citiesMap.put(baseRegion.getCityId(),city);
  83 + }
  84 + }*/
  85 + BaseRegionNextVo district = new BaseRegionNextVo(baseRegion.getDistrictId(), baseRegion.getDistrictName(),3);
  86 + districtsMap.put(district.getId(),district);
  87 + }/*else{
  88 + if(districtsMap.get(baseRegion.getDistrictId())==null){
  89 + BaseRegionNextVo district = new BaseRegionNextVo(baseRegion.getDistrictId(), baseRegion.getDistrictName(),3);
  90 + districtsMap.put(baseRegion.getDistrictId(),district);
  91 + }
  92 +
  93 + }*/
  94 + BaseRegionNextVo street = new BaseRegionNextVo(lastBaseRegion.getStreetId(), lastBaseRegion.getStreetName(),4);
  95 + streetList.add(street);
  96 + lastBaseRegion = baseRegion;
  97 + }
  98 + if(baseDistrict!=null){
  99 + baseDistrict.setChildren(streetList);
  100 +
  101 + }else{
  102 + baseDistrict = new BaseRegionNextVo(lastBaseRegion.getDistrictId(), lastBaseRegion.getDistrictName(),3);
  103 + baseDistrict.setChildren(streetList);
  104 + }
  105 + districtsMap.put(baseDistrict.getId(),baseDistrict);
  106 + if(baseCity!=null){
  107 + baseCity.setChildren(new ArrayList<>(districtsMap.values()));
  108 + }else{
  109 + baseCity = new BaseRegionNextVo(lastBaseRegion.getCityId(), lastBaseRegion.getCityName(),2);
  110 + baseCity.setChildren(new ArrayList<>(districtsMap.values()));
  111 + }
  112 + citiesMap.put(baseCity.getId(),baseCity);
  113 + if(baseProvince!=null){
  114 + baseProvince.setChildren(new ArrayList<>(citiesMap.values()));
  115 + }else{
  116 + baseProvince = new BaseRegionNextVo(lastBaseRegion.getProvinceId(), lastBaseRegion.getProvinceName(),1);
  117 + baseProvince.setChildren(new ArrayList<>(citiesMap.values()));
  118 + }
  119 + provinces.add(baseProvince);
  120 +
  121 + return provinces;
  122 + }
  123 +}
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/order/BaseRegionMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.diligrp.etrade.order.dao.BaseRegionMapper">
  4 + <resultMap id="BaseResultMap" type="com.diligrp.etrade.order.model.BaseRegion">
  5 + <id column="id" jdbcType="BIGINT" property="id" />
  6 + <result column="market_id" jdbcType="BIGINT" property="marketId" />
  7 + <result column="state" jdbcType="TINYINT" property="state" />
  8 + <result column="province_id" jdbcType="BIGINT" property="provinceId" />
  9 + <result column="province_name" jdbcType="VARCHAR" property="provinceName" />
  10 + <result column="city_id" jdbcType="BIGINT" property="cityId" />
  11 + <result column="city_name" jdbcType="VARCHAR" property="cityName" />
  12 + <result column="district_id" jdbcType="BIGINT" property="districtId" />
  13 + <result column="district_name" jdbcType="VARCHAR" property="districtName" />
  14 + <result column="street_id" jdbcType="BIGINT" property="streetId" />
  15 + <result column="street_name" jdbcType="VARCHAR" property="streetName" />
  16 + <result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
  17 + <result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
  18 + <result column="version" jdbcType="INTEGER" property="version" />
  19 + </resultMap>
  20 + <sql id="Base_Column_List" >
  21 + id, market_id, state, province_id, province_name, city_id, city_name, district_id,
  22 + district_name, street_id, street_name, created_time, modified_time, version
  23 + </sql>
  24 + <select id="selectNextList" parameterType="com.diligrp.etrade.order.domain.contactPerson.BaseRegionCo" resultMap="BaseResultMap">
  25 + select
  26 + <include refid="Base_Column_List" />
  27 + from base_region
  28 + <where> 1=1
  29 + <if test="provinceId != null">
  30 + and province_id = #{provinceId,jdbcType=BIGINT}
  31 + </if>
  32 + <if test="cityId != null">
  33 + and city_id = #{cityId,jdbcType=BIGINT}
  34 + </if>
  35 + <if test="districtId != null">
  36 + and district_id= #{districtId,jdbcType=BIGINT}
  37 + </if>
  38 + <if test="streetId != null">
  39 + and street_id= #{streetId,jdbcType=BIGINT}
  40 + </if>
  41 + and state = 1
  42 + </where>
  43 + order by province_id,city_id,district_id,street_id
  44 + </select>
  45 +</mapper>
0 \ No newline at end of file 46 \ No newline at end of file