From b7501f4e392744c63891ed8f4010f7b60d67e902 Mon Sep 17 00:00:00 2001 From: joker <1403296647@qq.com> Date: Sat, 15 Sep 2018 19:44:05 +0800 Subject: [PATCH] address --- leyou-portal/home-setting-address.html | 347 +++++++++++------- .../src/main/resources/application.yml | 1 + leyou/ly-location/hello/.keep | 0 leyou/ly-location/hello/hello.txt | 1 + leyou/ly-location/pom.xml | 54 +++ .../src/main/java/com/leyou/LyLocation.java | 11 + .../controller/AddressController.java | 50 +++ .../leyou/location/mapper/AddressMapper.java | 7 + .../leyou/location/mapper/AreasMapper.java | 7 + .../leyou/location/mapper/CitiesMapper.java | 7 + .../location/mapper/ProvincesMapper.java | 7 + .../java/com/leyou/location/pojo/Address.java | 108 ++++++ .../java/com/leyou/location/pojo/Areas.java | 58 +++ .../java/com/leyou/location/pojo/Cities.java | 59 +++ .../com/leyou/location/pojo/Provinces.java | 48 +++ .../location/service/AddressService.java | 86 +++++ .../src/main/resources/application.yml | 19 + 17 files changed, 731 insertions(+), 139 deletions(-) create mode 100644 leyou/ly-location/hello/.keep create mode 100644 leyou/ly-location/hello/hello.txt create mode 100644 leyou/ly-location/pom.xml create mode 100644 leyou/ly-location/src/main/java/com/leyou/LyLocation.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/controller/AddressController.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/mapper/AddressMapper.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/mapper/AreasMapper.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/mapper/CitiesMapper.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/mapper/ProvincesMapper.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/pojo/Address.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/pojo/Areas.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/pojo/Cities.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/pojo/Provinces.java create mode 100644 leyou/ly-location/src/main/java/com/leyou/location/service/AddressService.java create mode 100644 leyou/ly-location/src/main/resources/application.yml diff --git a/leyou-portal/home-setting-address.html b/leyou-portal/home-setting-address.html index 17ff971..6b83136 100644 --- a/leyou-portal/home-setting-address.html +++ b/leyou-portal/home-setting-address.html @@ -4,35 +4,35 @@ - + 设置-个人信息 - + - - + + - - - - + + + + @@ -40,102 +40,105 @@ $(function(){ + + + + - -
-
-
- -
- -
-
- -
-
-
-
-
· 订单中心
-
我的订单
-
待付款
-
待发货
-
待收货
-
待评价
-
-
-
· 我的中心
-
我的收藏
-
我的足迹
-
-
-
· 物流消息
-
-
-
· 设置
-
个人信息
-
地址管理
-
安全管理
-
+ +
+
+
+ +
+ +
+
+ +
- -
-
-
- 地址管理 - 添加新地址 - -
-
- - - - - - - - - - - - - - - - - - - - - - - - -
姓名地址联系电话操作
刘田田北京 北京市 海淀区 上地街道东北旺西路8号中关村软件园9号楼1774***********4 - 编辑 - 删除 - 默认地址 -
沈沉北京 北京市 海淀区 上地街道东北旺西路8号中关村软件园9号楼1774***********4 - 编辑 - 删除 - 设为默认 -
-
- - +
- - - - - + + + + + + + + + \ No newline at end of file diff --git a/leyou/ly-api-gateway/src/main/resources/application.yml b/leyou/ly-api-gateway/src/main/resources/application.yml index d300a3f..1dec90c 100644 --- a/leyou/ly-api-gateway/src/main/resources/application.yml +++ b/leyou/ly-api-gateway/src/main/resources/application.yml @@ -25,6 +25,7 @@ zuul: auth-service: /auth/** # 将授权微服务映射到/auth/** cart-service: /cart/** order-service: /order/** + location-service: /location/** add-host-header: true sensitive-headers: #设置zuul的过滤头为空(所有的头信息全部展示) diff --git a/leyou/ly-location/hello/.keep b/leyou/ly-location/hello/.keep new file mode 100644 index 0000000..e69de29 diff --git a/leyou/ly-location/hello/hello.txt b/leyou/ly-location/hello/hello.txt new file mode 100644 index 0000000..fe5430b --- /dev/null +++ b/leyou/ly-location/hello/hello.txt @@ -0,0 +1 @@ +ʮ \ No newline at end of file diff --git a/leyou/ly-location/pom.xml b/leyou/ly-location/pom.xml new file mode 100644 index 0000000..29d164a --- /dev/null +++ b/leyou/ly-location/pom.xml @@ -0,0 +1,54 @@ + + + + leyou + com.leyou.parent + 1.0.0-SNAPSHOT + + 4.0.0 + + com.leyou.service + ly-location + 1.0.0-SNAPSHOT + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.boot + spring-boot-starter-web + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + + tk.mybatis + mapper-spring-boot-starter + + + + com.github.pagehelper + pagehelper-spring-boot-starter + + + + mysql + mysql-connector-java + + + org.springframework.boot + spring-boot-starter-test + test + + + + + \ No newline at end of file diff --git a/leyou/ly-location/src/main/java/com/leyou/LyLocation.java b/leyou/ly-location/src/main/java/com/leyou/LyLocation.java new file mode 100644 index 0000000..d59f03a --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/LyLocation.java @@ -0,0 +1,11 @@ +package com.leyou; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class LyLocation { + public static void main(String[] args) { + SpringApplication.run(LyLocation.class,args); + } +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/controller/AddressController.java b/leyou/ly-location/src/main/java/com/leyou/location/controller/AddressController.java new file mode 100644 index 0000000..ee111f5 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/controller/AddressController.java @@ -0,0 +1,50 @@ +package com.leyou.location.controller; + +import com.leyou.location.pojo.Address; +import com.leyou.location.service.AddressService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +public class AddressController { + @Autowired + private AddressService addressService; + + /** + * 查询数据库所有地址 + * @return + */ + @GetMapping("query") + public ResponseEntity> query(){ + List
addressList=addressService.queryLocation(); + if (addressList == null||addressList.size()==0) { + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + return ResponseEntity.ok(addressList); + } + + /** + * 修改默认地址 + * @param id + * @return + */ + @PutMapping("/modifyDefultAddress/{id}") + private ResponseEntity modifyDefultAddress(@PathVariable("id")Long id){ + addressService.modifyDefultAddress(id); + return ResponseEntity.ok().build(); + } + /** + * 删除地址地址 + * @param id + * @return + */ + @DeleteMapping("/deleteAddress/{id}") + private ResponseEntity deleteAddress(@PathVariable("id")Long id){ + addressService.deleteAddress(id); + return ResponseEntity.ok().build(); + } +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/mapper/AddressMapper.java b/leyou/ly-location/src/main/java/com/leyou/location/mapper/AddressMapper.java new file mode 100644 index 0000000..3f33423 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/mapper/AddressMapper.java @@ -0,0 +1,7 @@ +package com.leyou.location.mapper; + +import com.leyou.location.pojo.Address; +import tk.mybatis.mapper.common.Mapper; +@org.apache.ibatis.annotations.Mapper +public interface AddressMapper extends Mapper
{ +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/mapper/AreasMapper.java b/leyou/ly-location/src/main/java/com/leyou/location/mapper/AreasMapper.java new file mode 100644 index 0000000..ffc6420 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/mapper/AreasMapper.java @@ -0,0 +1,7 @@ +package com.leyou.location.mapper; + +import com.leyou.location.pojo.Areas; +import tk.mybatis.mapper.common.Mapper; +@org.apache.ibatis.annotations.Mapper +public interface AreasMapper extends Mapper { +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/mapper/CitiesMapper.java b/leyou/ly-location/src/main/java/com/leyou/location/mapper/CitiesMapper.java new file mode 100644 index 0000000..eaa0e07 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/mapper/CitiesMapper.java @@ -0,0 +1,7 @@ +package com.leyou.location.mapper; + +import com.leyou.location.pojo.Cities; +import tk.mybatis.mapper.common.Mapper; +@org.apache.ibatis.annotations.Mapper +public interface CitiesMapper extends Mapper { +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/mapper/ProvincesMapper.java b/leyou/ly-location/src/main/java/com/leyou/location/mapper/ProvincesMapper.java new file mode 100644 index 0000000..156f505 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/mapper/ProvincesMapper.java @@ -0,0 +1,7 @@ +package com.leyou.location.mapper; + +import com.leyou.location.pojo.Provinces; +import tk.mybatis.mapper.common.Mapper; +@org.apache.ibatis.annotations.Mapper +public interface ProvincesMapper extends Mapper { +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/pojo/Address.java b/leyou/ly-location/src/main/java/com/leyou/location/pojo/Address.java new file mode 100644 index 0000000..c44d2e3 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/pojo/Address.java @@ -0,0 +1,108 @@ +package com.leyou.location.pojo; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Table(name = "tb_address") +public class Address { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String addresseeName; + private String provincesId; + private String citiesId; + private String areasId; + private String addressDetail; + private String phone; + private String email; + private Long isDefultAddress; + + @Override + public String toString() { + return "Address{" + + "id=" + id + + ", addresseeName='" + addresseeName + '\'' + + ", provincesId=" + provincesId + + ", citiesId=" + citiesId + + ", areasId=" + areasId + + ", addressDetail='" + addressDetail + '\'' + + ", phone='" + phone + '\'' + + ", email='" + email + '\'' + + ", isDefultAddress=" + isDefultAddress + + '}'; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getAddresseeName() { + return addresseeName; + } + + public void setAddresseeName(String addresseeName) { + this.addresseeName = addresseeName; + } + + public String getProvincesId() { + return provincesId; + } + + public void setProvincesId(String provincesId) { + this.provincesId = provincesId; + } + + public String getCitiesId() { + return citiesId; + } + + public void setCitiesId(String citiesId) { + this.citiesId = citiesId; + } + + public String getAreasId() { + return areasId; + } + + public void setAreasId(String areasId) { + this.areasId = areasId; + } + + public String getAddressDetail() { + return addressDetail; + } + + public void setAddressDetail(String addressDetail) { + this.addressDetail = addressDetail; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Long getIsDefultAddress() { + return isDefultAddress; + } + + public void setIsDefultAddress(Long isDefultAddress) { + this.isDefultAddress = isDefultAddress; + } +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/pojo/Areas.java b/leyou/ly-location/src/main/java/com/leyou/location/pojo/Areas.java new file mode 100644 index 0000000..43fea43 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/pojo/Areas.java @@ -0,0 +1,58 @@ +package com.leyou.location.pojo; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Table(name = "tb_areas") +public class Areas { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String areaid; + private String area; + private String cityid; + + @Override + public String toString() { + return "Areas{" + + "id=" + id + + ", areaid='" + areaid + '\'' + + ", area='" + area + '\'' + + ", cityid='" + cityid + '\'' + + '}'; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getAreaid() { + return areaid; + } + + public void setAreaid(String areaid) { + this.areaid = areaid; + } + + public String getArea() { + return area; + } + + public void setArea(String area) { + this.area = area; + } + + public String getCityid() { + return cityid; + } + + public void setCityid(String cityid) { + this.cityid = cityid; + } +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/pojo/Cities.java b/leyou/ly-location/src/main/java/com/leyou/location/pojo/Cities.java new file mode 100644 index 0000000..debbee0 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/pojo/Cities.java @@ -0,0 +1,59 @@ +package com.leyou.location.pojo; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Table(name = "tb_cities") +public class Cities { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String cityid; + private String city; + private String provinceid; + + @Override + public String toString() { + return "Cities{" + + "id=" + id + + ", cityid='" + cityid + '\'' + + ", city='" + city + '\'' + + ", provinceid='" + provinceid + '\'' + + '}'; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getCityid() { + return cityid; + } + + public void setCityid(String cityid) { + this.cityid = cityid; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getProvinceid() { + return provinceid; + } + + public void setProvinceid(String provinceid) { + this.provinceid = provinceid; + } +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/pojo/Provinces.java b/leyou/ly-location/src/main/java/com/leyou/location/pojo/Provinces.java new file mode 100644 index 0000000..65817c5 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/pojo/Provinces.java @@ -0,0 +1,48 @@ +package com.leyou.location.pojo; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Table(name = "tb_provinces") +public class Provinces { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String provinceid; + private String province; + + @Override + public String toString() { + return "Provinces{" + + "id=" + id + + ", provinceid='" + provinceid + '\'' + + ", province='" + province + '\'' + + '}'; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getProvinceid() { + return provinceid; + } + + public void setProvinceid(String provinceid) { + this.provinceid = provinceid; + } + + public String getProvince() { + return province; + } + + public void setProvince(String province) { + this.province = province; + } +} diff --git a/leyou/ly-location/src/main/java/com/leyou/location/service/AddressService.java b/leyou/ly-location/src/main/java/com/leyou/location/service/AddressService.java new file mode 100644 index 0000000..650fc01 --- /dev/null +++ b/leyou/ly-location/src/main/java/com/leyou/location/service/AddressService.java @@ -0,0 +1,86 @@ +package com.leyou.location.service; + +import com.leyou.location.mapper.AddressMapper; +import com.leyou.location.mapper.AreasMapper; +import com.leyou.location.mapper.CitiesMapper; +import com.leyou.location.mapper.ProvincesMapper; +import com.leyou.location.pojo.Address; +import com.leyou.location.pojo.Areas; +import com.leyou.location.pojo.Cities; +import com.leyou.location.pojo.Provinces; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +@Service +public class AddressService { + @Autowired + private AddressMapper addressMapper; + + @Autowired + private ProvincesMapper provincesMapper; + + @Autowired + private CitiesMapper citiesMapper; + + @Autowired + private AreasMapper areasMapper; + + + public List
queryLocation() { + List
addressList = addressMapper.selectAll(); + + Provinces p = new Provinces(); + Cities c = new Cities(); + Areas a = new Areas(); + + for (Address address : addressList) { + String provincesId = address.getProvincesId(); + String citiesId = address.getCitiesId(); + String areasId = address.getAreasId(); + + + p.setProvinceid(provincesId); + c.setCityid(citiesId); + a.setAreaid(areasId); + + + Provinces provinces = provincesMapper.selectOne(p); + String province = provinces.getProvince(); + address.setProvincesId(province); + + Areas areas = areasMapper.selectOne(a); + String area = areas.getArea(); + address.setAreasId(area); + + + + Cities cities = citiesMapper.selectOne(c); + String city = cities.getCity(); + address.setCitiesId(city); + + + + } + return addressList; + } + @Transactional + public void modifyDefultAddress(Long id) { + + List
addressList = addressMapper.selectAll(); + for (Address add : addressList) { + if (add.getIsDefultAddress()==1){ + add.setIsDefultAddress((long) 0); + addressMapper.updateByPrimaryKeySelective(add); + } + } + Address address = addressMapper.selectByPrimaryKey(id); + address.setIsDefultAddress((long) 1); + addressMapper.updateByPrimaryKeySelective(address); + } + + public void deleteAddress(Long id) { + addressMapper.deleteByPrimaryKey(id); + } +} diff --git a/leyou/ly-location/src/main/resources/application.yml b/leyou/ly-location/src/main/resources/application.yml new file mode 100644 index 0000000..920ae0a --- /dev/null +++ b/leyou/ly-location/src/main/resources/application.yml @@ -0,0 +1,19 @@ +server: + port: 8090 +spring: + application: + name: location-service + datasource: + url: jdbc:mysql://localhost:3306/heima + username: root + password: root +eureka: + client: + service-url: + defaultZone: http://127.0.0.1:10086/eureka + instance: + lease-renewal-interval-in-seconds: 5 # 每隔5秒发送一次心跳 + lease-expiration-duration-in-seconds: 10 # 10秒不发送就过期 + prefer-ip-address: true + ip-address: 127.0.0.1 + instance-id: ${spring.application.name}:${server.port} \ No newline at end of file -- Gitee