├── apidoc.jpg ├── src ├── main │ ├── java │ │ └── cn │ │ │ └── enilu │ │ │ └── elm │ │ │ └── api │ │ │ ├── entity │ │ │ ├── BaseEntity.java │ │ │ ├── KeyValue.java │ │ │ ├── sub │ │ │ │ ├── OrderFee.java │ │ │ │ ├── OrderStatusBar.java │ │ │ │ ├── OrderTimelineNode.java │ │ │ │ ├── OrderGroup.java │ │ │ │ └── OrderBasket.java │ │ │ ├── Delivery.java │ │ │ ├── Activity.java │ │ │ ├── Admin.java │ │ │ ├── Entry.java │ │ │ ├── Menu.java │ │ │ ├── Ids.java │ │ │ ├── SpecFood.java │ │ │ ├── Address.java │ │ │ ├── Food.java │ │ │ ├── Shop.java │ │ │ └── Order.java │ │ │ ├── vo │ │ │ ├── Constants.java │ │ │ ├── CityInfo.java │ │ │ └── Rets.java │ │ │ ├── ApplicationStart.java │ │ │ ├── controller │ │ │ ├── RestaurantController.java │ │ │ ├── IndexController.java │ │ │ ├── EntryController.java │ │ │ ├── DeliveryController.java │ │ │ ├── ActivityController.java │ │ │ ├── CartController.java │ │ │ ├── RatingController.java │ │ │ ├── CaptchaController.java │ │ │ ├── AddressController.java │ │ │ ├── OrderController.java │ │ │ ├── BaseController.java │ │ │ ├── BaseErrorController.java │ │ │ ├── PositionController.java │ │ │ ├── FileController.java │ │ │ ├── UserController.java │ │ │ ├── FoodController.java │ │ │ ├── AdminController.java │ │ │ └── ShopController.java │ │ │ ├── utils │ │ │ ├── Beans.java │ │ │ ├── Maps.java │ │ │ ├── AppConfiguration.java │ │ │ ├── CaptchaCode.java │ │ │ ├── MD5.java │ │ │ └── HttpClients.java │ │ │ ├── conf │ │ │ ├── CORSConfiguration.java │ │ │ └── Swagger2Configuration.java │ │ │ ├── service │ │ │ ├── IdsService.java │ │ │ └── PositionService.java │ │ │ └── repository │ │ │ └── BaseDao.java │ └── resources │ │ └── application.properties └── test │ └── java │ └── cn │ └── enilu │ └── elm │ └── api │ ├── ApiJunitTest.java │ ├── repository │ ├── IdsDaoTest.java │ └── BaseDaoTest.java │ ├── service │ └── PositionServiceTest.java │ └── utils │ └── GsonsTest.java ├── README.md └── pom.xml /apidoc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enilu/springboot-elm/HEAD/apidoc.jpg -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | /** 4 | * Created on 2018/1/2 0002. 5 | * 6 | * @author zt 7 | */ 8 | public interface BaseEntity { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/vo/Constants.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.vo; 2 | 3 | /** 4 | * Created on 2017/12/29 0029. 5 | * 6 | * @author zt 7 | */ 8 | public class Constants { 9 | public static final String SESSION_ID="login_user_session"; 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/cn/enilu/elm/api/ApiJunitTest.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.annotation.Rollback; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | /** 9 | * Created by zt on 17/3/18. 10 | * @author zt 11 | */ 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @SpringBootTest(classes = ApplicationStart.class) 14 | @Rollback(true) 15 | public class ApiJunitTest { 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/ApplicationStart.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.support.SpringBootServletInitializer; 6 | 7 | /** 8 | * Created by zt on 2017/12/12 0012. 9 | */ 10 | @SpringBootApplication 11 | public class ApplicationStart extends SpringBootServletInitializer { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ApplicationStart.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/KeyValue.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | /** 4 | * Created on 2018/1/3 0003. 5 | * 6 | * @author zt 7 | */ 8 | public class KeyValue { 9 | private String name; 10 | private String value; 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | public String getValue() { 21 | return value; 22 | } 23 | 24 | public void setValue(String value) { 25 | this.value = value; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/RestaurantController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * Created on 2018/1/5 0005. 7 | * todo 未完成 8 | * @author zt 9 | */ 10 | @RestController 11 | public class RestaurantController extends BaseController { 12 | @RequestMapping(value = "/v4/restaurants",method = RequestMethod.GET) 13 | 14 | public Object restaurants(@RequestParam("geohash")String geoHash, 15 | @RequestParam("keyword")String keyWord){ 16 | 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8011 2 | logging.level.root=INFO 3 | spring.data.mongodb.uri=mongodb://localhost:27017/elm 4 | 5 | ##全局参数 6 | cfg.tencentkey=RLHBZ-WMPRP-Q3JDS-V2IQA-JNRFH-EJBHL 7 | cfg.tencentkey2=RRXBZ-WC6KF-ZQSJT-N2QU7-T5QIT-6KF5X 8 | cfg.tencentkey3=OHTBZ-7IFRG-JG2QF-IHFUK-XTTK6-VXFBN 9 | cfg.baidukey=fjke3YUipM9N64GdOIh1DNeK2APO2WcT 10 | cfg.baidukey2=fjke3YUipM9N64GdOIh1DNeK2APO2WcT 11 | 12 | ## api 13 | api.qq.get.location=http://apis.map.qq.com/ws/location/v1/ip 14 | api.qq.search.place=http://apis.map.qq.com/ws/place/v1/search 15 | 16 | ## 图片地址 17 | img.dir=/data/springboot-elm/img/ -------------------------------------------------------------------------------- /src/test/java/cn/enilu/elm/api/repository/IdsDaoTest.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.repository; 2 | 3 | import cn.enilu.elm.api.ApiJunitTest; 4 | import cn.enilu.elm.api.service.IdsService; 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | /** 9 | * Created on 2017/12/29 0029. 10 | * 11 | * @author zt 12 | */ 13 | public class IdsDaoTest extends ApiJunitTest{ 14 | @Autowired 15 | private IdsService idsService; 16 | @Test 17 | public void getId() throws Exception { 18 | Long cartId = idsService.getId("cart_id"); 19 | System.out.println(cartId); 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RequestMethod; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * Created by zt on 2017/12/12 0012. 11 | */ 12 | @RestController 13 | @RequestMapping("/") 14 | public class IndexController { 15 | 16 | 17 | 18 | @RequestMapping(method = RequestMethod.GET) 19 | 20 | public Object index(Map map){ 21 | return "欢迎光临springboot-elm的api服务,点击进入api文档"; 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/vo/CityInfo.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.vo; 2 | 3 | /** 4 | * Created on 2017/12/29 0029. 5 | * 6 | * @author zt 7 | */ 8 | public class CityInfo { 9 | private String lat; 10 | private String lng; 11 | private String city; 12 | 13 | public String getLat() { 14 | return lat; 15 | } 16 | 17 | public void setLat(String lat) { 18 | this.lat = lat; 19 | } 20 | 21 | public String getLng() { 22 | return lng; 23 | } 24 | 25 | public void setLng(String lng) { 26 | this.lng = lng; 27 | } 28 | 29 | public String getCity() { 30 | return city; 31 | } 32 | 33 | public void setCity(String city) { 34 | this.city = city; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/utils/Beans.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.utils; 2 | 3 | import org.springframework.beans.BeanWrapper; 4 | import org.springframework.beans.BeanWrapperImpl; 5 | 6 | /** 7 | * Created on 2017/12/29 0029. 8 | * 9 | * @author zt 10 | */ 11 | public class Beans { 12 | static BeanWrapper beanWrapper = null; 13 | public static Beans me( T obj) { 14 | return new Beans(obj); 15 | } 16 | private Beans(T obj){ 17 | beanWrapper = new BeanWrapperImpl(obj); 18 | } 19 | public Object get(String propName){ 20 | 21 | return beanWrapper.getPropertyValue(propName); 22 | } 23 | 24 | public void set(String propName, Object propVal) { 25 | beanWrapper.setPropertyValue(propName,propVal); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/EntryController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Entry; 4 | import cn.enilu.elm.api.repository.BaseDao; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | * Created on 2018/1/4 0004. 12 | * 13 | * @author zt 14 | */ 15 | @RestController 16 | public class EntryController extends BaseController { 17 | @Autowired 18 | private BaseDao baseDao; 19 | @RequestMapping(value = "/v2/index_entry",method = RequestMethod.GET) 20 | public Object list(){ 21 | return baseDao.findAll(Entry.class); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/DeliveryController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Delivery; 4 | import cn.enilu.elm.api.repository.BaseDao; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | /** 9 | * Created on 2018/1/5 0005. 10 | * 11 | * @author zt 12 | */ 13 | @RestController 14 | public class DeliveryController extends BaseController { 15 | @Autowired 16 | private BaseDao baseDao; 17 | 18 | @RequestMapping(value = "/shopping/v1/restaurants/delivery_modes",method = RequestMethod.GET) 19 | public Object list(@RequestParam(value = "latitude",required = false) String latitude, 20 | @RequestParam(value = "longitude",required = false) String longitude){ 21 | return baseDao.findAll(Delivery.class); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/ActivityController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Activity; 4 | import cn.enilu.elm.api.repository.BaseDao; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | /** 9 | * Created on 2018/1/5 0005. 10 | * 11 | * @author zt 12 | */ 13 | @RestController 14 | public class ActivityController extends BaseController { 15 | @Autowired 16 | private BaseDao baseDao; 17 | 18 | @RequestMapping(value = "/shopping/v1/restaurants/activity_attributes",method = RequestMethod.GET) 19 | @ResponseBody 20 | public Object list(@RequestParam(value = "latitude",required = false) String latitude, 21 | @RequestParam(value = "longitude",required = false) String longitude){ 22 | return baseDao.findAll(Activity.class); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/cn/enilu/elm/api/service/PositionServiceTest.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.service; 2 | 3 | 4 | import cn.enilu.elm.api.ApiJunitTest; 5 | import cn.enilu.elm.api.vo.CityInfo; 6 | import org.junit.Test; 7 | import org.nutz.json.Json; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | 10 | /** 11 | * Created on 2017/12/29 0029. 12 | * 13 | * @author zt 14 | */ 15 | public class PositionServiceTest extends ApiJunitTest { 16 | @Autowired 17 | private PositionService positionService; 18 | @Test 19 | public void getPostion() throws Exception { 20 | CityInfo cityInfo = positionService.getPostion("101.81.121.39"); 21 | System.out.println(Json.toJson(cityInfo)); 22 | } 23 | @Test 24 | public void searchPlace()throws Exception{ 25 | Object obj = positionService.searchPlace("上海","文通大厦"); 26 | System.out.println(Json.toJson(obj)); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/conf/CORSConfiguration.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.conf; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 8 | 9 | /** 10 | * Created by zt on 2017/12/29 0029. 11 | */ 12 | @Configuration 13 | public class CORSConfiguration { 14 | @Bean 15 | public WebMvcConfigurer corsConfigurer() { 16 | return new WebMvcConfigurerAdapter() { 17 | @Override 18 | public void addCorsMappings(CorsRegistry registry) { 19 | registry.addMapping("/**") 20 | .allowedHeaders("*") 21 | .allowedMethods("*") 22 | .allowedOrigins("*"); 23 | } 24 | }; 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/utils/Maps.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.utils; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * Created on 2018/1/3 0003. 7 | * 8 | * @author zt 9 | */ 10 | public class Maps { 11 | private Maps() { 12 | } 13 | 14 | public static HashMap newHashMap(K k, V v) { 15 | HashMap map = new HashMap(); 16 | map.put(k, v); 17 | return map; 18 | } 19 | 20 | public static HashMap newHashMap(K k, V v, Object... extraKeyValues) { 21 | if(extraKeyValues.length % 2 != 0) { 22 | throw new IllegalArgumentException(); 23 | } else { 24 | HashMap map = new HashMap(); 25 | map.put(k, v); 26 | 27 | for(int i = 0; i < extraKeyValues.length; i += 2) { 28 | k = (K) extraKeyValues[i]; 29 | v = (V) extraKeyValues[i + 1]; 30 | map.put(k, v); 31 | } 32 | 33 | return map; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/sub/OrderFee.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity.sub; 2 | 3 | /** 4 | * Created on 2018/1/5 0005. 5 | * 6 | * @author zt 7 | */ 8 | public class OrderFee { 9 | private Long category_id; 10 | private String name; 11 | private Double price; 12 | private Double quantity; 13 | 14 | public Long getCategory_id() { 15 | return category_id; 16 | } 17 | 18 | public void setCategory_id(Long category_id) { 19 | this.category_id = category_id; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public Double getPrice() { 31 | return price; 32 | } 33 | 34 | public void setPrice(Double price) { 35 | this.price = price; 36 | } 37 | 38 | public Double getQuantity() { 39 | return quantity; 40 | } 41 | 42 | public void setQuantity(Double quantity) { 43 | this.quantity = quantity; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/sub/OrderStatusBar.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity.sub; 2 | 3 | /** 4 | * Created on 2018/1/7 0007. 5 | * 6 | * @author zt 7 | */ 8 | public class OrderStatusBar { 9 | private String color; 10 | private String image_type; 11 | private String sub_title; 12 | private String title; 13 | 14 | public String getColor() { 15 | return color; 16 | } 17 | 18 | public void setColor(String color) { 19 | this.color = color; 20 | } 21 | 22 | public String getImage_type() { 23 | return image_type; 24 | } 25 | 26 | public void setImage_type(String image_type) { 27 | this.image_type = image_type; 28 | } 29 | 30 | public String getSub_title() { 31 | return sub_title; 32 | } 33 | 34 | public void setSub_title(String sub_title) { 35 | this.sub_title = sub_title; 36 | } 37 | 38 | public String getTitle() { 39 | return title; 40 | } 41 | 42 | public void setTitle(String title) { 43 | this.title = title; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Delivery.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | /** 7 | * Created on 2018/1/5 0005. 8 | * 9 | * @author zt 10 | */ 11 | @Document(collection = "deliveries") 12 | public class Delivery implements BaseEntity { 13 | @Id 14 | private String _id; 15 | private Long id; 16 | private String color; 17 | private Boolean is_solid; 18 | private String text; 19 | 20 | public String get_id() { 21 | return _id; 22 | } 23 | 24 | public void set_id(String _id) { 25 | this._id = _id; 26 | } 27 | 28 | public Long getId() { 29 | return id; 30 | } 31 | 32 | public void setId(Long id) { 33 | this.id = id; 34 | } 35 | 36 | public String getColor() { 37 | return color; 38 | } 39 | 40 | public void setColor(String color) { 41 | this.color = color; 42 | } 43 | 44 | public Boolean getIs_solid() { 45 | return is_solid; 46 | } 47 | 48 | public void setIs_solid(Boolean is_solid) { 49 | this.is_solid = is_solid; 50 | } 51 | 52 | public String getText() { 53 | return text; 54 | } 55 | 56 | public void setText(String text) { 57 | this.text = text; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/sub/OrderTimelineNode.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity.sub; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created on 2018/1/7 0007. 7 | * 8 | * @author zt 9 | */ 10 | public class OrderTimelineNode { 11 | private List actions; 12 | private String description; 13 | private String sub_description; 14 | private String title; 15 | private Integer in_processing; 16 | 17 | public List getActions() { 18 | return actions; 19 | } 20 | 21 | public void setActions(List actions) { 22 | this.actions = actions; 23 | } 24 | 25 | public String getDescription() { 26 | return description; 27 | } 28 | 29 | public void setDescription(String description) { 30 | this.description = description; 31 | } 32 | 33 | public String getSub_description() { 34 | return sub_description; 35 | } 36 | 37 | public void setSub_description(String sub_description) { 38 | this.sub_description = sub_description; 39 | } 40 | 41 | public String getTitle() { 42 | return title; 43 | } 44 | 45 | public void setTitle(String title) { 46 | this.title = title; 47 | } 48 | 49 | public Integer getIn_processing() { 50 | return in_processing; 51 | } 52 | 53 | public void setIn_processing(Integer in_processing) { 54 | this.in_processing = in_processing; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/CartController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Ids; 4 | import cn.enilu.elm.api.repository.BaseDao; 5 | import cn.enilu.elm.api.service.IdsService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.util.Map; 14 | 15 | /** 16 | * Created on 2018/1/5 0005. 17 | * 18 | * @author zt 19 | */ 20 | @RestController 21 | public class CartController extends BaseController { 22 | @Autowired 23 | private BaseDao baseDao; 24 | @Autowired 25 | private IdsService idsService; 26 | @RequestMapping(value = "/v1/carts/checkout",method = RequestMethod.POST) 27 | public Object checkout(HttpServletRequest request){ 28 | Map data = getRequestPayload(Map.class); 29 | data.put("id",idsService.getId(Ids.CATEGORY_ID)); 30 | baseDao.save(data,"carts"); 31 | return null; 32 | } 33 | @RequestMapping(value = "v1/carts/${cart_id}/remarks",method = RequestMethod.GET) 34 | public Object remarks(@PathVariable("cart_id")Long cartId){ 35 | return baseDao.findOne("remarks"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/service/IdsService.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.service; 2 | 3 | import cn.enilu.elm.api.entity.Ids; 4 | import cn.enilu.elm.api.repository.BaseDao; 5 | import cn.enilu.elm.api.utils.Beans; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * Created on 2018/1/2 0002. 11 | * 12 | * @author zt 13 | */ 14 | @Service 15 | public class IdsService { 16 | @Autowired 17 | private BaseDao baseDao; 18 | public synchronized Long getId(String propName){ 19 | Ids ids = baseDao.findOne(Ids.class); 20 | if(ids==null){ 21 | ids = new Ids(); 22 | Beans beans = Beans.me(ids); 23 | ids.setRestaurant_id(0L); 24 | ids.setFood_id(0L); 25 | ids.setOrder_id(0L); 26 | ids.setUser_id(0L); 27 | ids.setAddress_id(0L); 28 | ids.setCart_id(0L); 29 | ids.setImg_id(0L); 30 | ids.setSku_id(0L); 31 | ids.setAdmin_id(0L); 32 | ids.setStatis_id(0L); 33 | beans.set(propName,1L); 34 | baseDao.save(ids); 35 | return 1L; 36 | }else{ 37 | Beans beans = Beans.me(ids); 38 | Long val = (Long) beans.get(propName); 39 | val++; 40 | beans.set(propName,val); 41 | baseDao.save(ids); 42 | return val; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/conf/Swagger2Configuration.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.conf; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | 13 | /** 14 | * Created on 2018/1/4 0004. 15 | * 16 | * @author zt 17 | */ 18 | 19 | @Configuration 20 | @EnableSwagger2 21 | public class Swagger2Configuration { 22 | @Bean 23 | public Docket createRestApi() { 24 | return new Docket(DocumentationType.SWAGGER_2) 25 | .apiInfo(apiInfo()) 26 | .select() 27 | .apis(RequestHandlerSelectors.basePackage("cn.enilu.elm.api.controller")) 28 | .paths(PathSelectors.any()) 29 | .build(); 30 | } 31 | 32 | private ApiInfo apiInfo() { 33 | return new ApiInfoBuilder() 34 | .title("node-elm的spring boot版") 35 | .description("本文档参考官方文档:https://github.com/bailicangdu/node-elm/blob/master/API.md") 36 | .termsOfServiceUrl("www.enilu.cn") 37 | .contact("enilu.cn") 38 | .version("1.0") 39 | .build(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/sub/OrderGroup.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity.sub; 2 | 3 | import org.springframework.data.annotation.Id; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created on 2018/1/5 0005. 9 | * 10 | * @author zt 11 | */ 12 | public class OrderGroup { 13 | @Id 14 | private String _id; 15 | private String name; 16 | private Double price; 17 | private Double quantity; 18 | 19 | private List specs; 20 | private List attrs; 21 | private List new_specs; 22 | 23 | public String get_id() { 24 | return _id; 25 | } 26 | 27 | public void set_id(String _id) { 28 | this._id = _id; 29 | } 30 | 31 | public void setSpecs(List specs) { 32 | this.specs = specs; 33 | } 34 | 35 | public List getAttrs() { 36 | return attrs; 37 | } 38 | 39 | public void setAttrs(List attrs) { 40 | this.attrs = attrs; 41 | } 42 | 43 | public List getNew_specs() { 44 | return new_specs; 45 | } 46 | 47 | public void setNew_specs(List new_specs) { 48 | this.new_specs = new_specs; 49 | } 50 | 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | public void setName(String name) { 56 | this.name = name; 57 | } 58 | 59 | public Double getPrice() { 60 | return price; 61 | } 62 | 63 | public void setPrice(Double price) { 64 | this.price = price; 65 | } 66 | 67 | public Double getQuantity() { 68 | return quantity; 69 | } 70 | 71 | public void setQuantity(Double quantity) { 72 | this.quantity = quantity; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/RatingController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.repository.BaseDao; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * Created on 2018/1/5 0005. 14 | * 15 | * @author zt 16 | */ 17 | @RestController 18 | public class RatingController extends BaseController { 19 | @Autowired 20 | private BaseDao baseDao; 21 | @RequestMapping(value = "/ugc/v2/restaurants/${restaurant_id}/ratings",method = RequestMethod.GET) 22 | public Object ratings(@PathVariable("restaurant_id")Long restaurantId){ 23 | Map map = baseDao.findOne("ratings","restaurant_id",restaurantId); 24 | return map.get("ratings"); 25 | } 26 | @RequestMapping(value = "ugc/v2/restaurants/${restaurant_id}/ratings/scores",method = RequestMethod.GET) 27 | public Object score(@PathVariable("restaurant_id")Long restaurantId){ 28 | Map map = baseDao.findOne("ratings","restaurant_id",restaurantId); 29 | return map.get("scores"); 30 | } 31 | @RequestMapping(value = "ugc/v2/restaurants/${restaurant_id}/ratings/tags",method = RequestMethod.GET) 32 | public Object tags(@PathVariable("restaurant_id")Long restaurantId){ 33 | Map map = baseDao.findOne("ratings","restaurant_id",restaurantId); 34 | return map.get("tags"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/CaptchaController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.utils.CaptchaCode; 4 | import cn.enilu.elm.api.vo.Rets; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import sun.misc.BASE64Encoder; 9 | 10 | import javax.imageio.ImageIO; 11 | import java.awt.image.BufferedImage; 12 | import java.io.ByteArrayOutputStream; 13 | import java.io.IOException; 14 | import java.util.Map; 15 | 16 | /** 17 | * Created on 2018/1/5 0005. 18 | * 19 | * @author zt 20 | */ 21 | @RestController 22 | public class CaptchaController extends BaseController { 23 | @RequestMapping(value = "/v1/captchas",method = RequestMethod.POST) 24 | public Object get() throws IOException { 25 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 26 | Map map = CaptchaCode.getImageCode(60, 20, outputStream); 27 | 28 | setSession(CaptchaCode.CAPTCH_KEY, map.get("strEnsure").toString().toLowerCase()); 29 | setSession("codeTime",System.currentTimeMillis()); 30 | try { 31 | ImageIO.write((BufferedImage) map.get("image"), "png", outputStream); 32 | BASE64Encoder encoder = new BASE64Encoder(); 33 | String base64 = encoder.encode(outputStream.toByteArray()); 34 | String captchaBase64 = "data:image/png;base64," + base64.replaceAll("\r\n", ""); 35 | return Rets.success("code",captchaBase64); 36 | } catch (IOException e) { 37 | return Rets.failure(e.getMessage()); 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot-elm 2 | 3 | [node-elm](https://github.com/bailicangdu/node-elm)的java版,使用Spring Boot构建。 4 | 目前主要完成后台管理系统[vue2-manage](https://github.com/bailicangdu/vue2-manage)的主要接口,还没有做权限控制。 5 | 6 | 7 | 8 | ## 接口实现情况 9 | - [x] 1、获取城市列表 10 | - [x] 2、获取所选城市信息 11 | - [x] 3、搜索地址 12 | - [ ] 4、根据经纬度详细定位 13 | - [x] 5、食品分类列表 14 | - [x] 6、获取商铺列表 15 | - [ ] 7、搜索餐馆 16 | - [x] 8、获取所有商铺分类列表 17 | - [x] 9、获取配送方式 18 | - [x] 10、商家属性活动列表 19 | - [x] 11、餐馆详情 20 | - [x] 12、上传图片 21 | - [x] 13、添加餐馆 22 | - [x] 14、添加食品种类 23 | - [x] 15、添加食品 24 | - [x] 16、获取食品列表 25 | - [x] 17、获取评价信息 26 | - [x] 18、获取评价分数 27 | - [x] 19、获取评价分类 28 | - [x] 20、加入购物车 29 | - [x] 21、获取备注信息 30 | - [x] 22、获取收货地址列表 31 | - [x] 23、获取验证码 32 | - [x] 24、获取用户信息 33 | - [ ] 25、登录 34 | - [ ] 26、退出 35 | - [x] 27、修改密码 36 | - [x] 28、增加收货地址 37 | - [x] 29、删除收货地址 38 | - [ ] 30、下单 39 | - [x] 31、订单列表 40 | - [ ] 32、订单详情 41 | - [ ] 33、服务中心 42 | - [ ] 34、可用红包 43 | - [ ] 35、过期红包 44 | - [ ] 36、兑换红包 45 | - [ ] 37、管理员登录 46 | - [ ] 38、管理员退出登录 47 | - [x] 39、管理员信息 48 | - [ ] 40、获取某日API请求量 49 | - [ ] 41、获取所有API请求量 50 | - [ ] 42、获取某天用户注册量 51 | - [ ] 43、获取所有用户注册量 52 | - [ ] 44、获取某天订单数量 53 | - [ ] 45、获取所有订单数量 54 | - [x] 46、管理员列表 55 | - [x] 47、获取管理员数量 56 | - [x] 48、获取店铺食品种类 57 | - [x] 49、获取餐馆数量 58 | - [x] 50、更新餐馆 59 | - [x] 51、删除餐馆 60 | - [x] 52、获取食品列表 61 | - [x] 53、获取食品数量 62 | - [x] 54、获取食品种类详情 63 | - [x] 55、更新食品 64 | - [x] 56、删除食品 65 | - [x] 57、获取用户列表 66 | - [ ] 58、获取订单列表 67 | - [ ] 59、获取地址信息 68 | - [ ] 60、获取用户分布信息 69 | - [ ] 61、获取某天管理员注册量 70 | 71 | ## 在线文档: 72 | 使用swagger2生成在线文档: 73 | ![在线文档](apidoc.jpg) 74 | 75 | ## 技术栈 76 | Spring Boot + Mongodb 77 | 78 | ## 项目运行 79 | - 启动springboot-elm 80 | 直接运行ApplicationStart 主类即可 81 | 82 | - 更改vue2-manage的接口路径 83 | ``` 84 | baseUrl = 'http://localhost:8001'; 85 | baseImgPath = 'http://localhost:8001/img/'; 86 | 将端口更改为8011即可 87 | `` -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/sub/OrderBasket.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity.sub; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created on 2018/1/5 0005. 8 | * 9 | * @author zt 10 | */ 11 | public class OrderBasket { 12 | 13 | private List abandoned_extra = new ArrayList(); 14 | private OrderFee deliver_fee = new OrderFee(); 15 | private OrderFee packing_fee = new OrderFee(); 16 | private List extra = new ArrayList(); 17 | private List pindan_map = new ArrayList(); 18 | private List> group = new ArrayList>(); 19 | 20 | public List getAbandoned_extra() { 21 | return abandoned_extra; 22 | } 23 | 24 | public void setAbandoned_extra(List abandoned_extra) { 25 | this.abandoned_extra = abandoned_extra; 26 | } 27 | 28 | public OrderFee getDeliver_fee() { 29 | return deliver_fee; 30 | } 31 | 32 | public void setDeliver_fee(OrderFee deliver_fee) { 33 | this.deliver_fee = deliver_fee; 34 | } 35 | 36 | public OrderFee getPacking_fee() { 37 | return packing_fee; 38 | } 39 | 40 | public void setPacking_fee(OrderFee packing_fee) { 41 | this.packing_fee = packing_fee; 42 | } 43 | 44 | public List getExtra() { 45 | return extra; 46 | } 47 | 48 | public void setExtra(List extra) { 49 | this.extra = extra; 50 | } 51 | 52 | public List getPindan_map() { 53 | return pindan_map; 54 | } 55 | 56 | public void setPindan_map(List pindan_map) { 57 | this.pindan_map = pindan_map; 58 | } 59 | 60 | public List> getGroup() { 61 | return group; 62 | } 63 | 64 | public void setGroup(List> group) { 65 | this.group = group; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/cn/enilu/elm/api/repository/BaseDaoTest.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.repository; 2 | 3 | import cn.enilu.elm.api.ApiJunitTest; 4 | import cn.enilu.elm.api.entity.Address; 5 | import cn.enilu.elm.api.entity.Order; 6 | import org.junit.Test; 7 | import org.nutz.json.Json; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | 10 | import java.util.Date; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * Created on 2017/12/29 0029. 16 | * 17 | * @author zt 18 | */ 19 | public class BaseDaoTest extends ApiJunitTest { 20 | @Autowired 21 | private BaseDao baseDao; 22 | @Test 23 | public void save() throws Exception { 24 | 25 | } 26 | @Test 27 | public void findOne() throws Exception{ 28 | Object data = baseDao.findOne(11L,"shops"); 29 | System.out.println(Json.toJson(data)); 30 | } 31 | @Test 32 | public void find() throws Exception { 33 | Map map = (Map) baseDao.findOne(1L,"admins"); 34 | System.out.println(Json.toJson(map)); 35 | } 36 | 37 | @Test 38 | public void find1() throws Exception { 39 | 40 | } 41 | @Test 42 | public void near() throws Exception{ 43 | Object obj = baseDao.near(125.51181,11.26169,"shops"); 44 | System.out.println(Json.toJson(obj)); 45 | } 46 | @Test 47 | public void count() throws Exception { 48 | 49 | } 50 | 51 | @Test 52 | public void query() throws Exception { 53 | 54 | } 55 | 56 | @Test 57 | public void update() throws Exception { 58 | Address address = baseDao.findOne(Address.class,"user_id",1L); 59 | address.setCreated_at(new Date()); 60 | baseDao.update(address); 61 | } 62 | 63 | @Test 64 | public void queryAll1() throws Exception { 65 | List list = baseDao.findAll(Order.class); 66 | System.out.println(Json.toJson(list)); 67 | } 68 | } -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Activity.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | /** 7 | * Created on 2018/1/4 0004. 8 | * 9 | * @author zt 10 | */ 11 | @Document(collection = "activities") 12 | public class Activity implements BaseEntity { 13 | @Id 14 | private String _id; 15 | private Long id; 16 | private String name; 17 | private String description; 18 | private String icon_color; 19 | private String icon_name; 20 | private Integer ranking_weight; 21 | 22 | public String get_id() { 23 | return _id; 24 | } 25 | 26 | public void set_id(String _id) { 27 | this._id = _id; 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 String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public String getDescription() { 47 | return description; 48 | } 49 | 50 | public void setDescription(String description) { 51 | this.description = description; 52 | } 53 | 54 | public String getIcon_color() { 55 | return icon_color; 56 | } 57 | 58 | public void setIcon_color(String icon_color) { 59 | this.icon_color = icon_color; 60 | } 61 | 62 | public String getIcon_name() { 63 | return icon_name; 64 | } 65 | 66 | public void setIcon_name(String icon_name) { 67 | this.icon_name = icon_name; 68 | } 69 | 70 | public Integer getRanking_weight() { 71 | return ranking_weight; 72 | } 73 | 74 | public void setRanking_weight(Integer ranking_weight) { 75 | this.ranking_weight = ranking_weight; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/vo/Rets.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.vo; 2 | 3 | import com.google.common.collect.Maps; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Created on 2017/12/29 0029. 9 | * @author zt 10 | */ 11 | public class Rets { 12 | public static final int STATUS_SUCCESS=1; 13 | public static final int STATUS_FAILURE=0; 14 | public static Map success(){ 15 | Map result = Maps.newHashMap(); 16 | result.put("status",STATUS_SUCCESS); 17 | return result; 18 | } 19 | public static Map success(String message){ 20 | Map result = Maps.newHashMap(); 21 | result.put("status",STATUS_SUCCESS); 22 | result.put("success",message); 23 | return result; 24 | } 25 | public static Map success(String key,Object data){ 26 | Map result = Maps.newHashMap(); 27 | result.put("status",STATUS_SUCCESS); 28 | result.put(key,data); 29 | return result; 30 | } 31 | public static Map failure(){ 32 | Map result = Maps.newHashMap(); 33 | result.put("status",STATUS_FAILURE); 34 | return result; 35 | } 36 | public static Map failure(String key,Object data){ 37 | Map result = Maps.newHashMap(); 38 | result.put("status",STATUS_FAILURE); 39 | result.put(key,data); 40 | return result; 41 | } 42 | public static Map failure(Map data){ 43 | data.put("status",STATUS_FAILURE); 44 | return data; 45 | } 46 | public static Map failure(String message){ 47 | Map result = Maps.newHashMap(); 48 | result.put("status",STATUS_FAILURE); 49 | result.put("message",message); 50 | return result; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/AddressController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Address; 4 | import cn.enilu.elm.api.entity.Ids; 5 | import cn.enilu.elm.api.repository.BaseDao; 6 | import cn.enilu.elm.api.service.IdsService; 7 | import cn.enilu.elm.api.utils.Maps; 8 | import cn.enilu.elm.api.vo.Rets; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestMethod; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | /** 16 | * Created on 2018/1/5 0005. 17 | * 18 | * @author zt 19 | */ 20 | @RestController 21 | public class AddressController extends BaseController{ 22 | @Autowired 23 | private BaseDao baseDao; 24 | @Autowired 25 | private IdsService idsService; 26 | @RequestMapping(value = "/v1/users/${user_id}/addresses",method = RequestMethod.GET) 27 | public Object address(@PathVariable("user_id")Long userId){ 28 | return baseDao.findAll(Address.class,"user_id",userId); 29 | } 30 | @RequestMapping(value = "/v1/usres/${user_id}/addresses",method = RequestMethod.POST) 31 | public Object save(@PathVariable("user_id")Long userId){ 32 | Address address = getRequestPayload(Address.class); 33 | address.setUser_id(userId); 34 | address.setId(idsService.getId(Ids.ADDRESS_ID)); 35 | baseDao.save(address); 36 | return Rets.success("添加地址成功"); 37 | } 38 | @RequestMapping(value = "/v1/usres/${user_id}/addresses/${address_id}",method = RequestMethod.POST) 39 | public Object delete(@PathVariable("user_id")Long userId,@PathVariable("address_id") Long addressId){ 40 | baseDao.delete("addresses",Maps.newHashMap("user_id",userId,"id",addressId)); 41 | return Rets.success("删除地址成功"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Order; 4 | import cn.enilu.elm.api.repository.BaseDao; 5 | import cn.enilu.elm.api.utils.Maps; 6 | import cn.enilu.elm.api.vo.Rets; 7 | import org.nutz.lang.Strings; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | /** 12 | * Created on 2018/1/5 0005. 13 | * 14 | * @author zt 15 | */ 16 | @RestController 17 | public class OrderController extends BaseController { 18 | @Autowired 19 | private BaseDao baseDao; 20 | @RequestMapping("/bos/v2/users/${user_id}/orders") 21 | public Object orders(@PathVariable("user_id")Long userId){ 22 | return baseDao.findAll(Order.class,"user_id",userId); 23 | 24 | } 25 | @RequestMapping(value = "/bos/orders/count",method = RequestMethod.GET) 26 | public Object count(@RequestParam("restaurant_id")String restaurantId){ 27 | long count = 0; 28 | if(Strings.isBlank(restaurantId)&&Strings.equals("undefined",restaurantId)){ 29 | count = baseDao.count(Order.class, Maps.newHashMap("restaurant_id",Long.valueOf(restaurantId))); 30 | }else { 31 | count = baseDao.count(Order.class); 32 | } 33 | return Rets.success("count",count); 34 | } 35 | @RequestMapping(value="/bos/orders",method = RequestMethod.GET) 36 | public Object list(@RequestParam("restaurant_id") String restaurantId, 37 | @RequestParam(value = "offset", defaultValue = "0") Integer offset, 38 | @RequestParam(value = "limit", defaultValue = "20") Integer limit) { 39 | restaurantId="11"; 40 | if (Strings.isBlank(restaurantId)||Strings.equals("undefined",restaurantId)){ 41 | return baseDao.findAll(Order.class,"restaurant_id",Long.valueOf(restaurantId)); 42 | } else { 43 | return baseDao.findAll(Order.class); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/cn/enilu/elm/api/utils/GsonsTest.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.utils; 2 | 3 | import org.junit.Test; 4 | import org.nutz.json.Json; 5 | 6 | import static org.nutz.castor.castor.String2Class.map; 7 | 8 | /** 9 | * Created on 2018/1/3 0003. 10 | * 11 | * @author zt 12 | */ 13 | public class GsonsTest { 14 | 15 | @Test 16 | public void fromJson() throws Exception { 17 | String json = "{\n" + 18 | " \"name\":\"星巴克\",\n" + 19 | " \"address\":\"上海市杨浦区昆明路739号\",\n" + 20 | " \"description\":\"爱爱爱\",\n" + 21 | " \"phone\":11001100,\n" + 22 | " \"promotion_info\":\"端到端\",\n" + 23 | " \"float_delivery_fee\":6,\n" + 24 | " \"float_minimum_order_amount\":21,\n" + 25 | " \"is_premium\":true,\n" + 26 | " \"delivery_mode\":true,\n" + 27 | " \"new\":true,\n" + 28 | " \"bao\":true,\n" + 29 | " \"zhun\":true,\n" + 30 | " \"piao\":true,\n" + 31 | " \"startTime\":\"05:30\",\n" + 32 | " \"endTime\":\"10:45\",\n" + 33 | " \"image_path\":\"shop_1514965660456.jpg\",\n" + 34 | " \"business_license_image\":\"shop_1514965662962.jpg\",\n" + 35 | " \"catering_service_license_image\":\"shop_1514965665218.jpg\",\n" + 36 | " \"activities\":[\n" + 37 | " {\n" + 38 | " \"icon_name\":\"减\",\n" + 39 | " \"name\":\"满减优惠\",\n" + 40 | " \"description\":\"满30减5,满60减8\"\n" + 41 | " },\n" + 42 | " {\n" + 43 | " \"icon_name\":\"特\",\n" + 44 | " \"name\":\"优惠大酬宾\",\n" + 45 | " \"description\":\"酬宾啦\"\n" + 46 | " }\n" + 47 | " ],\n" + 48 | " \"category\":\"甜品饮品/咖啡\"\n" + 49 | "}"; 50 | 51 | Object obj = Json.fromJson(json); 52 | System.out.println(map.get("item_id")); 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Admin.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | /** 7 | * Created by zt on 2017/12/29 0029. 8 | */ 9 | @Document(collection = "admins") 10 | public class Admin implements BaseEntity { 11 | @Id 12 | private String _id; 13 | private Long id; 14 | private String user_name; 15 | private String password; 16 | private String create_time; 17 | private Integer status; 18 | private String city; 19 | private String avatar; 20 | private String admin; 21 | 22 | public String get_id() { 23 | return _id; 24 | } 25 | 26 | public void set_id(String _id) { 27 | this._id = _id; 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 String getUser_name() { 39 | return user_name; 40 | } 41 | 42 | public void setUser_name(String user_name) { 43 | this.user_name = user_name; 44 | } 45 | 46 | public String getPassword() { 47 | return password; 48 | } 49 | 50 | public void setPassword(String password) { 51 | this.password = password; 52 | } 53 | 54 | public String getCreate_time() { 55 | return create_time; 56 | } 57 | 58 | public void setCreate_time(String create_time) { 59 | this.create_time = create_time; 60 | } 61 | 62 | public Integer getStatus() { 63 | return status; 64 | } 65 | 66 | public void setStatus(Integer status) { 67 | this.status = status; 68 | } 69 | 70 | public String getCity() { 71 | return city; 72 | } 73 | 74 | public void setCity(String city) { 75 | this.city = city; 76 | } 77 | 78 | public String getAvatar() { 79 | return avatar; 80 | } 81 | 82 | public void setAvatar(String avatar) { 83 | this.avatar = avatar; 84 | } 85 | 86 | public String getAdmin() { 87 | return admin; 88 | } 89 | 90 | public void setAdmin(String admin) { 91 | this.admin = admin; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Entry.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | /** 7 | * Created on 2018/1/4 0004. 8 | * 9 | * @author zt 10 | */ 11 | @Document(collection = "entries") 12 | public class Entry implements BaseEntity { 13 | @Id 14 | private String _id; 15 | 16 | private Long id; 17 | private Boolean is_in_serving; 18 | private String title; 19 | private String description; 20 | private String link; 21 | private String image_url; 22 | private String icon_url; 23 | private String title_color; 24 | 25 | public String get_id() { 26 | return _id; 27 | } 28 | 29 | public void set_id(String _id) { 30 | this._id = _id; 31 | } 32 | 33 | public Long getId() { 34 | return id; 35 | } 36 | 37 | public void setId(Long id) { 38 | this.id = id; 39 | } 40 | 41 | public Boolean getIs_in_serving() { 42 | return is_in_serving; 43 | } 44 | 45 | public void setIs_in_serving(Boolean is_in_serving) { 46 | this.is_in_serving = is_in_serving; 47 | } 48 | 49 | public String getTitle() { 50 | return title; 51 | } 52 | 53 | public void setTitle(String title) { 54 | this.title = title; 55 | } 56 | 57 | public String getDescription() { 58 | return description; 59 | } 60 | 61 | public void setDescription(String description) { 62 | this.description = description; 63 | } 64 | 65 | public String getLink() { 66 | return link; 67 | } 68 | 69 | public void setLink(String link) { 70 | this.link = link; 71 | } 72 | 73 | public String getImage_url() { 74 | return image_url; 75 | } 76 | 77 | public void setImage_url(String image_url) { 78 | this.image_url = image_url; 79 | } 80 | 81 | public String getIcon_url() { 82 | return icon_url; 83 | } 84 | 85 | public void setIcon_url(String icon_url) { 86 | this.icon_url = icon_url; 87 | } 88 | 89 | public String getTitle_color() { 90 | return title_color; 91 | } 92 | 93 | public void setTitle_color(String title_color) { 94 | this.title_color = title_color; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Created on 2018/1/3 0003. 11 | * 12 | * @author zt 13 | */ 14 | @Document(collection = "menus") 15 | public class Menu implements BaseEntity{ 16 | @Id 17 | private String _id; 18 | private String name; 19 | private String description; 20 | private Long id; 21 | private Long restaurant_id; 22 | private List foods=new ArrayList(); 23 | private Integer type=1; 24 | private String icon_url=""; 25 | private Boolean is_selected=true; 26 | 27 | public String get_id() { 28 | return _id; 29 | } 30 | 31 | public void set_id(String _id) { 32 | this._id = _id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public String getDescription() { 44 | return description; 45 | } 46 | 47 | public void setDescription(String description) { 48 | this.description = description; 49 | } 50 | 51 | public Long getId() { 52 | return id; 53 | } 54 | 55 | public void setId(Long id) { 56 | this.id = id; 57 | } 58 | 59 | public Long getRestaurant_id() { 60 | return restaurant_id; 61 | } 62 | 63 | public void setRestaurant_id(Long restaurant_id) { 64 | this.restaurant_id = restaurant_id; 65 | } 66 | 67 | public List getFoods() { 68 | return foods; 69 | } 70 | 71 | public void setFoods(List foods) { 72 | this.foods = foods; 73 | } 74 | 75 | public Integer getType() { 76 | return type; 77 | } 78 | 79 | public void setType(Integer type) { 80 | this.type = type; 81 | } 82 | 83 | public String getIcon_url() { 84 | return icon_url; 85 | } 86 | 87 | public void setIcon_url(String icon_url) { 88 | this.icon_url = icon_url; 89 | } 90 | 91 | public Boolean getIs_selected() { 92 | return is_selected; 93 | } 94 | 95 | public void setIs_selected(Boolean is_selected) { 96 | this.is_selected = is_selected; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/BaseController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import com.google.common.base.Strings; 4 | import org.nutz.json.Json; 5 | import org.springframework.web.context.request.RequestAttributes; 6 | import org.springframework.web.context.request.RequestContextHolder; 7 | import org.springframework.web.context.request.ServletRequestAttributes; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import java.io.BufferedReader; 11 | import java.io.IOException; 12 | import java.util.Map; 13 | 14 | /** 15 | * Created on 2017/12/29 0029. 16 | * @author zt 17 | */ 18 | public class BaseController { 19 | 20 | protected String getRequestPayload( ){ 21 | StringBuilder sb = new StringBuilder(); 22 | try (BufferedReader reader = getRequest().getReader();) { 23 | char[] buff = new char[1024]; 24 | int len; 25 | while ((len = reader.read(buff)) != -1) { 26 | sb.append(buff, 0, len); 27 | } 28 | } catch (IOException e) { 29 | e.printStackTrace(); 30 | } 31 | return sb.toString(); 32 | } 33 | protected T getRequestPayload( Class klass) { 34 | String json = getRequestPayload(); 35 | try { 36 | T result = null; 37 | if(klass==Map.class||klass==null){ 38 | result = (T) Json.fromJson(json); 39 | }else { 40 | result = Json.fromJson( klass,json); 41 | } 42 | return result; 43 | }catch (Exception e){ 44 | 45 | } 46 | return null; 47 | } 48 | protected HttpServletRequest getRequest(){ 49 | RequestAttributes ra = RequestContextHolder.getRequestAttributes(); 50 | ServletRequestAttributes sra = (ServletRequestAttributes) ra; 51 | return sra.getRequest(); 52 | } 53 | protected Object getSession(String key){ 54 | return getRequest().getSession().getAttribute(key); 55 | } 56 | protected void setSession( String key,Object val){ 57 | getRequest().getSession().setAttribute(key,val); 58 | } 59 | 60 | public String getIp(){ 61 | String ip = getRequest().getHeader("x-forwarded-for"); 62 | if(Strings.isNullOrEmpty(ip)){ 63 | //测试ip 64 | ip = "101.81.121.39"; 65 | } 66 | return ip; 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/BaseErrorController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.autoconfigure.web.ErrorAttributes; 5 | import org.springframework.boot.autoconfigure.web.ErrorController; 6 | import org.springframework.util.Assert; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.context.request.RequestAttributes; 11 | import org.springframework.web.context.request.ServletRequestAttributes; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import java.util.Map; 15 | 16 | /** 17 | * Created by zt on 2017/12/12 0012. 18 | */ 19 | @RestController 20 | @RequestMapping("/error") 21 | public class BaseErrorController implements ErrorController { 22 | 23 | private final ErrorAttributes errorAttributes; 24 | 25 | @Autowired 26 | public BaseErrorController(ErrorAttributes errorAttributes) { 27 | Assert.notNull(errorAttributes, "ErrorAttributes must not be null"); 28 | this.errorAttributes = errorAttributes; 29 | } 30 | 31 | @Override 32 | public String getErrorPath() { 33 | return "error"; 34 | } 35 | 36 | @RequestMapping(method = RequestMethod.GET) 37 | public Map error(HttpServletRequest aRequest){ 38 | Map body = getErrorAttributes(aRequest,getTraceParameter(aRequest)); 39 | String trace = (String) body.get("trace"); 40 | if(trace != null){ 41 | String[] lines = trace.split("\n\t"); 42 | body.put("trace", lines); 43 | } 44 | return body; 45 | } 46 | 47 | private boolean getTraceParameter(HttpServletRequest request) { 48 | String parameter = request.getParameter("trace"); 49 | if (parameter == null) { 50 | return false; 51 | } 52 | return !"false".equals(parameter.toLowerCase()); 53 | } 54 | 55 | private Map getErrorAttributes(HttpServletRequest aRequest, boolean includeStackTrace) { 56 | RequestAttributes requestAttributes = new ServletRequestAttributes(aRequest); 57 | return errorAttributes.getErrorAttributes(requestAttributes, includeStackTrace); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/utils/AppConfiguration.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.utils; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created on 2017/12/29 0029. 8 | * 9 | * @author zt 10 | */ 11 | @Component 12 | public class AppConfiguration { 13 | @Value("${api.qq.get.location}") 14 | private String apiQqGetLocation; 15 | @Value("${api.qq.search.place}") 16 | private String apiQqSearchPlace; 17 | @Value("${cfg.tencentkey}") 18 | private String tencentKey; 19 | @Value("${cfg.tencentkey2}") 20 | private String tencentKey2; 21 | @Value("${cfg.tencentkey3}") 22 | private String tencentKey3; 23 | @Value("${cfg.baidukey}") 24 | private String baiduKey; 25 | @Value("${cfg.baidukey2}") 26 | private String baiduKey2; 27 | @Value("${img.dir}") 28 | private String imgDir; 29 | 30 | public String getApiQqGetLocation() { 31 | return apiQqGetLocation; 32 | } 33 | 34 | public void setApiQqGetLocation(String apiQqGetLocation) { 35 | this.apiQqGetLocation = apiQqGetLocation; 36 | } 37 | 38 | public String getApiQqSearchPlace() { 39 | return apiQqSearchPlace; 40 | } 41 | 42 | public void setApiQqSearchPlace(String apiQqSearchPlace) { 43 | this.apiQqSearchPlace = apiQqSearchPlace; 44 | } 45 | 46 | public String getTencentKey() { 47 | return tencentKey; 48 | } 49 | 50 | public void setTencentKey(String tencentKey) { 51 | this.tencentKey = tencentKey; 52 | } 53 | 54 | public String getTencentKey2() { 55 | return tencentKey2; 56 | } 57 | 58 | public void setTencentKey2(String tencentKey2) { 59 | this.tencentKey2 = tencentKey2; 60 | } 61 | 62 | public String getTencentKey3() { 63 | return tencentKey3; 64 | } 65 | 66 | public void setTencentKey3(String tencentKey3) { 67 | this.tencentKey3 = tencentKey3; 68 | } 69 | 70 | public String getBaiduKey() { 71 | return baiduKey; 72 | } 73 | 74 | public void setBaiduKey(String baiduKey) { 75 | this.baiduKey = baiduKey; 76 | } 77 | 78 | public String getBaiduKey2() { 79 | return baiduKey2; 80 | } 81 | 82 | public void setBaiduKey2(String baiduKey2) { 83 | this.baiduKey2 = baiduKey2; 84 | } 85 | 86 | public String getImgDir() { 87 | return imgDir; 88 | } 89 | 90 | public void setImgDir(String imgDir) { 91 | this.imgDir = imgDir; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/PositionController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.repository.BaseDao; 4 | import cn.enilu.elm.api.service.PositionService; 5 | import cn.enilu.elm.api.vo.CityInfo; 6 | import cn.enilu.elm.api.vo.Rets; 7 | import com.google.common.base.Strings; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import java.util.Map; 13 | 14 | /** 15 | * Created on 2017/12/29 0029. 16 | * 17 | * @author zt 18 | */ 19 | @RestController 20 | public class PositionController extends BaseController { 21 | @Autowired 22 | private BaseDao baseDao; 23 | @Autowired 24 | private PositionService positionService; 25 | 26 | @RequestMapping(value = "/v1/cities",method = RequestMethod.GET) 27 | 28 | public Object cities(@RequestParam("type") String type, HttpServletRequest request) { 29 | Map cities = baseDao.findOne("cities"); 30 | Map data = (Map) cities.get("data"); 31 | switch (type){ 32 | case "guess": 33 | CityInfo cityInfo = positionService.getPostion(getIp()); 34 | String city = cityInfo.getCity(); 35 | if (Strings.isNullOrEmpty(city)) { 36 | return Rets.failure(); 37 | } 38 | return positionService.findByName(city); 39 | 40 | case "hot": 41 | 42 | return data.get("hotCities"); 43 | 44 | case "group": 45 | return data; 46 | 47 | 48 | default: 49 | break; 50 | 51 | 52 | } 53 | return Rets.failure(); 54 | 55 | } 56 | @RequestMapping(value = "/v1/cities/{id}",method = RequestMethod.GET) 57 | 58 | public Object getCity(@PathVariable("id")Integer id){ 59 | return positionService.findById(id); 60 | } 61 | @RequestMapping(value = "/v1/pois",method = RequestMethod.GET) 62 | 63 | public Object getPoiByCityAndKeyword(@RequestParam(value = "type",defaultValue = "search")String type, 64 | @RequestParam("city_id")Integer cityId, 65 | @RequestParam("keyword")String keyword){ 66 | 67 | Map map = positionService.findById(cityId); 68 | return positionService.searchPlace(map.get("name").toString(),keyword); 69 | } 70 | //todo 未完成 71 | @RequestMapping(value = "/v2/pois/{geoHash}",method = RequestMethod.GET) 72 | 73 | public Object getPoiByGeoHash(@PathVariable("geoHash")String geoHash){ 74 | return Rets.failure(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/utils/CaptchaCode.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.utils; 2 | 3 | import java.awt.*; 4 | import java.awt.image.BufferedImage; 5 | import java.io.OutputStream; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.Random; 9 | 10 | /** 11 | * Created on 2018/1/5 0005. 12 | * 13 | * @author zt 14 | */ 15 | public class CaptchaCode { 16 | public static String CAPTCH_KEY = "captcha"; 17 | private static char mapTable[] = { 18 | '0', '1', '2', '3', '4', '5', 19 | '6', '7', '8', '9', '0', '1', 20 | '2', '3', '4', '5', '6', '7', 21 | '8', '9'}; 22 | 23 | public static Map getImageCode(int width, int height, OutputStream os) { 24 | Map returnMap = new HashMap(); 25 | if (width <= 0) width = 60; 26 | if (height <= 0) height = 20; 27 | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 28 | // 获取图形上下文 29 | Graphics g = image.getGraphics(); 30 | //生成随机类 31 | Random random = new Random(); 32 | // 设定背景色 33 | g.setColor(getRandColor(200, 250)); 34 | g.fillRect(0, 0, width, height); 35 | //设定字体 36 | g.setFont(new Font("Times New Roman", Font.PLAIN, 18)); 37 | // 随机产生168条干扰线,使图象中的认证码不易被其它程序探测到 38 | g.setColor(getRandColor(160, 200)); 39 | for (int i = 0; i < 168; i++) { 40 | int x = random.nextInt(width); 41 | int y = random.nextInt(height); 42 | int xl = random.nextInt(12); 43 | int yl = random.nextInt(12); 44 | g.drawLine(x, y, x + xl, y + yl); 45 | } 46 | //取随机产生的码 47 | String strEnsure = ""; 48 | //4代表4位验证码,如果要生成更多位的认证码,则加大数值 49 | for (int i = 0; i < 4; ++i) { 50 | strEnsure += mapTable[(int) (mapTable.length * Math.random())]; 51 | // 将认证码显示到图象中 52 | g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110))); 53 | //直接生成 54 | String str = strEnsure.substring(i, i + 1); 55 | g.drawString(str, 13 * i + 6, 16); 56 | } 57 | // 释放图形上下文 58 | g.dispose(); 59 | returnMap.put("image", image); 60 | returnMap.put("strEnsure", strEnsure); 61 | return returnMap; 62 | } 63 | 64 | //给定范围获得随机颜色 65 | static Color getRandColor(int fc, int bc) { 66 | Random random = new Random(); 67 | if (fc > 255) { 68 | fc = 255; 69 | } 70 | if (bc > 255) { 71 | bc = 255; 72 | } 73 | int r = fc + random.nextInt(bc - fc); 74 | int g = fc + random.nextInt(bc - fc); 75 | int b = fc + random.nextInt(bc - fc); 76 | return new Color(r, g, b); 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/FileController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.utils.AppConfiguration; 4 | import cn.enilu.elm.api.vo.Rets; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.core.io.ResourceLoader; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.web.bind.annotation.*; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | import java.io.IOException; 15 | import java.nio.file.Files; 16 | import java.nio.file.Paths; 17 | 18 | /** 19 | * Created on 2018/1/2 0002. 20 | * 21 | * @author zt 22 | */ 23 | @Controller 24 | public class FileController extends BaseController { 25 | private static final Logger log = LoggerFactory.getLogger(FileController.class); 26 | 27 | @Autowired 28 | private AppConfiguration appConfiguration; 29 | @Autowired 30 | private ResourceLoader resourceLoader; 31 | @RequestMapping(method = RequestMethod.POST, value = "/v1/addimg/{type}") 32 | @ResponseBody 33 | public Object add(@PathVariable("type") String type, @RequestParam("file") MultipartFile file) { 34 | if (!file.isEmpty()) { 35 | try { 36 | String fileName= type+"_"+System.currentTimeMillis()+"."+file.getOriginalFilename().split("\\.")[1]; 37 | Files.copy(file.getInputStream(), Paths.get(appConfiguration.getImgDir(), fileName)); 38 | return Rets.success("image_path",fileName); 39 | } catch (IOException | RuntimeException e) { 40 | e.printStackTrace(); 41 | 42 | } 43 | } 44 | return Rets.failure(); 45 | 46 | 47 | } 48 | 49 | // @RequestMapping(method = RequestMethod.GET, value = "/img") 50 | // public String provideUploadInfo(Model model) throws IOException { 51 | // 52 | // model.addAttribute("files", Files.walk(Paths.get(appConfiguration.getImgDir())) 53 | // .filter(path -> !path.equals(Paths.get(appConfiguration.getImgDir()))) 54 | // .map(path -> Paths.get(appConfiguration.getImgDir()).relativize(path)) 55 | // .map(path -> linkTo(methodOn(FileController.class).getFile(path.toString())).withRel(path.toString())) 56 | // .collect(Collectors.toList())); 57 | // 58 | // return "uploadForm"; 59 | // } 60 | 61 | @RequestMapping(method = RequestMethod.GET, value = "/img/{filename:.+}") 62 | @ResponseBody 63 | public ResponseEntity get(@PathVariable String filename) { 64 | 65 | try { 66 | return ResponseEntity.ok(resourceLoader.getResource("file:" + Paths.get(appConfiguration.getImgDir(), filename).toString())); 67 | } catch (Exception e) { 68 | return ResponseEntity.notFound().build(); 69 | } 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/utils/MD5.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.utils; 2 | 3 | import com.google.common.base.Strings; 4 | import org.apache.tomcat.util.http.fileupload.IOUtils; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.nio.ByteBuffer; 11 | import java.nio.channels.FileChannel; 12 | import java.security.MessageDigest; 13 | 14 | /** 15 | * Created on 2017/12/12 0012. 16 | * @author zt 17 | */ 18 | public class MD5 { 19 | 20 | public static final Logger logger = LoggerFactory.getLogger(MD5.class); 21 | 22 | /** 23 | * 16进制字符集 24 | */ 25 | private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 26 | 27 | /** 28 | * 指定算法为MD5的MessageDigest 29 | */ 30 | private static MessageDigest messageDigest = null; 31 | 32 | /** 初始化messageDigest的加密算法为MD5 */ 33 | static { 34 | try { 35 | messageDigest = MessageDigest.getInstance("MD5"); 36 | } catch (Exception e) { 37 | logger.error(e.getMessage(), e); 38 | } 39 | } 40 | 41 | /** 42 | * * MD5加密字符串 43 | * 44 | * @param str 目标字符串 45 | * @return MD5加密后的字符串 46 | */ 47 | 48 | public static String getMD5String(String str) { 49 | if (Strings.isNullOrEmpty(str)) { 50 | return null; 51 | } 52 | return getMD5String(str.getBytes()); 53 | } 54 | 55 | /** 56 | * * MD5加密以byte数组表示的字符串 57 | * 58 | * @param bytes 目标byte数组 59 | * @return MD5加密后的字符串 60 | */ 61 | 62 | public static String getMD5String(byte[] bytes) { 63 | messageDigest.update(bytes); 64 | return bytesToHex(messageDigest.digest()); 65 | } 66 | 67 | /** 68 | * 获取文件的MD5值 69 | * 70 | * @param file 目标文件 71 | * @return MD5字符串 72 | */ 73 | public static String getFileMD5String(File file) { 74 | String ret = ""; 75 | FileInputStream in = null; 76 | FileChannel ch = null; 77 | try { 78 | in = new FileInputStream(file); 79 | ch = in.getChannel(); 80 | ByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); 81 | messageDigest.update(byteBuffer); 82 | ret = bytesToHex(messageDigest.digest()); 83 | } catch (Exception e) { 84 | logger.error(e.getMessage(), e); 85 | } finally { 86 | IOUtils.closeQuietly(in); 87 | IOUtils.closeQuietly(ch); 88 | } 89 | return ret; 90 | } 91 | 92 | /** 93 | * * 获取文件的MD5值 94 | * 95 | * @param fileName 目标文件的完整名称 96 | * @return MD5字符串 97 | */ 98 | public static String getFileMD5String(String fileName) { 99 | return getFileMD5String(new File(fileName)); 100 | } 101 | 102 | 103 | /** 104 | * * 将字节数组转换成16进制字符串 105 | * 106 | * @param bytes 目标字节数组 107 | * @return 转换结果 108 | */ 109 | public static String bytesToHex(byte[] bytes) { 110 | return bytesToHex(bytes, 0, bytes.length); 111 | } 112 | 113 | /** 114 | * * 将字节数组中指定区间的子数组转换成16进制字符串 115 | * 116 | * @param bytes 目标字节数组 117 | * @param start 起始位置(包括该位置) 118 | * @param end 结束位置(不包括该位置) 119 | * @return 转换结果 120 | */ 121 | public static String bytesToHex(byte[] bytes, int start, int end) { 122 | StringBuilder sb = new StringBuilder(); 123 | for (int i = start; i < start + end; i++) { 124 | sb.append(byteToHex(bytes[i])); 125 | } 126 | return sb.toString(); 127 | } 128 | 129 | /** 130 | * * 将单个字节码转换成16进制字符串 131 | * 132 | * @param bt 目标字节 133 | * @return 转换结果 134 | */ 135 | public static String byteToHex(byte bt) { 136 | return HEX_DIGITS[(bt & 0xf0) >> 4] + "" + HEX_DIGITS[bt & 0xf]; 137 | } 138 | 139 | } -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Ids.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | /** 7 | * Created on 2017/12/29 0029. 8 | * 9 | * @author zt 10 | */ 11 | @Document(collection = "ids") 12 | public class Ids implements BaseEntity { 13 | public static final String ADMIN_ID="admin_id"; 14 | public static final String RESTAURANT_ID="restaurant_id"; 15 | public static final String ITEM_ID="item_id"; 16 | public static final String FOOD_ID="food_id"; 17 | public static final String SKU_ID="sku_id"; 18 | public static final String CATEGORY_ID="category_id"; 19 | public static final String CART_ID = "cart_id"; 20 | public static final String ADDRESS_ID="address_id"; 21 | @Id 22 | private String _id; 23 | private Long restaurant_id; 24 | private Long food_id; 25 | private Long order_id; 26 | private Long user_id; 27 | private Long address_id; 28 | private Long cart_id; 29 | private Long img_id; 30 | private Long category_id; 31 | private Long item_id; 32 | private Long sku_id; 33 | private Long admin_id; 34 | private Long statis_id; 35 | 36 | public String get_id() { 37 | return _id; 38 | } 39 | 40 | public void set_id(String _id) { 41 | this._id = _id; 42 | } 43 | 44 | public Long getRestaurant_id() { 45 | return restaurant_id; 46 | } 47 | 48 | public void setRestaurant_id(Long restaurant_id) { 49 | this.restaurant_id = restaurant_id; 50 | } 51 | 52 | public Long getFood_id() { 53 | return food_id; 54 | } 55 | 56 | public void setFood_id(Long food_id) { 57 | this.food_id = food_id; 58 | } 59 | 60 | public Long getOrder_id() { 61 | return order_id; 62 | } 63 | 64 | public void setOrder_id(Long order_id) { 65 | this.order_id = order_id; 66 | } 67 | 68 | public Long getUser_id() { 69 | return user_id; 70 | } 71 | 72 | public void setUser_id(Long user_id) { 73 | this.user_id = user_id; 74 | } 75 | 76 | public Long getAddress_id() { 77 | return address_id; 78 | } 79 | 80 | public void setAddress_id(Long address_id) { 81 | this.address_id = address_id; 82 | } 83 | 84 | public Long getCart_id() { 85 | return cart_id; 86 | } 87 | 88 | public void setCart_id(Long cart_id) { 89 | this.cart_id = cart_id; 90 | } 91 | 92 | public Long getImg_id() { 93 | return img_id; 94 | } 95 | 96 | public void setImg_id(Long img_id) { 97 | this.img_id = img_id; 98 | } 99 | 100 | public Long getCategory_id() { 101 | return category_id; 102 | } 103 | 104 | public void setCategory_id(Long category_id) { 105 | this.category_id = category_id; 106 | } 107 | 108 | public Long getItem_id() { 109 | return item_id; 110 | } 111 | 112 | public void setItem_id(Long item_id) { 113 | this.item_id = item_id; 114 | } 115 | 116 | public Long getSku_id() { 117 | return sku_id; 118 | } 119 | 120 | public void setSku_id(Long sku_id) { 121 | this.sku_id = sku_id; 122 | } 123 | 124 | public Long getAdmin_id() { 125 | return admin_id; 126 | } 127 | 128 | public void setAdmin_id(Long admin_id) { 129 | this.admin_id = admin_id; 130 | } 131 | 132 | public Long getStatis_id() { 133 | return statis_id; 134 | } 135 | 136 | public void setStatis_id(Long statis_id) { 137 | this.statis_id = statis_id; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.repository.BaseDao; 4 | import cn.enilu.elm.api.utils.CaptchaCode; 5 | import cn.enilu.elm.api.utils.Maps; 6 | import cn.enilu.elm.api.vo.Rets; 7 | import org.nutz.lang.Strings; 8 | import org.nutz.mapl.Mapl; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | /** 21 | * Created by zt on 2017/12/12 0012. 22 | */ 23 | @RestController 24 | @RequestMapping("/v1/users") 25 | public class UserController extends BaseController { 26 | private Logger logger = LoggerFactory.getLogger(UserController.class); 27 | @Autowired 28 | private BaseDao baseDao; 29 | 30 | @RequestMapping(value = "/v1/user",method = RequestMethod.GET) 31 | public Object getUser(){ 32 | return getSession("currentUser"); 33 | } 34 | 35 | @RequestMapping(value = "/list",method = RequestMethod.GET) 36 | public Object list(@RequestParam("offset") Integer offset,@RequestParam("limit") Integer limit){ 37 | List list = baseDao.findAll("userinfos"); 38 | return list; 39 | } 40 | @RequestMapping(value = "/count",method = RequestMethod.GET) 41 | public Object count(){ 42 | return Rets.success("count",2); 43 | } 44 | 45 | @RequestMapping(value = "/v2/login",method = RequestMethod.POST) 46 | public Object login(@RequestParam("username")String userName, 47 | @RequestParam("password")String password, 48 | @RequestParam("captcha_code") String captchaCode 49 | ){ 50 | String captch = (String) getSession(CaptchaCode.CAPTCH_KEY); 51 | if(!Strings.equals(captchaCode,captch)){ 52 | return Rets.failure(Maps.newHashMap("type","ERROR_CAPTCHA","message","验证码不正确")); 53 | } 54 | Map user = baseDao.findOne("users","username",userName,"password",password); 55 | if(user!=null) { 56 | Map userInfo = baseDao.findOne("userinfos", "user_id", Long.valueOf(user.get("user_id").toString())); 57 | Object result = Mapl.merge(user, userInfo); 58 | setSession("currentUser",result); 59 | return result; 60 | } 61 | return Rets.failure(Maps.newHashMap("type","ERROR_PASSWORD","message","密码错误")); 62 | 63 | } 64 | @RequestMapping(value = "/v2/signout",method = RequestMethod.GET) 65 | public Object signOut(){ 66 | getRequest().getSession().removeAttribute("currentUser"); 67 | return Rets.success(); 68 | } 69 | @RequestMapping(value = "/v2/changepassword",method = RequestMethod.POST) 70 | public Object changePassword(@RequestParam("username")String userName, 71 | @RequestParam("oldpassWord")String oldPassword, 72 | @RequestParam("newpassword")String newPassword, 73 | @RequestParam("confirmpassword")String confirmPassword, 74 | @RequestParam("captcha_code")String captchaCode){ 75 | 76 | String captch = (String) getSession(CaptchaCode.CAPTCH_KEY); 77 | if(!Strings.equals(captchaCode,captch)){ 78 | return Rets.failure(Maps.newHashMap("type","ERROR_CAPTCHA","message","验证码不正确")); 79 | } 80 | Map user = baseDao.findOne("users","username",userName); 81 | if(user==null){ 82 | return Rets.failure(Maps.newHashMap("type","ERROR_QUERY","message","用户不存在")); 83 | } 84 | if(!Strings.equals(oldPassword,Strings.sNull(user.get("password")))){ 85 | return Rets.failure(Maps.newHashMap("type","ERROR_QUERY","message","原密码错误")); 86 | } 87 | if(Strings.equals(newPassword,confirmPassword)){ 88 | return Rets.failure(Maps.newHashMap("type","ERROR_QUERY","message","新密码不一致")); 89 | } 90 | 91 | user.put("password",newPassword); 92 | baseDao.update(Long.valueOf(user.get("id").toString()),"users",user); 93 | 94 | return Rets.success(); 95 | } 96 | 97 | 98 | 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/SpecFood.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created on 2018/1/3 0003. 7 | * 8 | * @author zt 9 | */ 10 | public class SpecFood { 11 | private Double original_price; 12 | private Integer sku_id; 13 | private String name; 14 | private String pinyin_name; 15 | private Long restaurant_id; 16 | private Long food_id; 17 | private Double packing_fee=0.0; 18 | private Double recent_rating=0.0; 19 | private Double promotion_stock=-1.0; 20 | private Double price; 21 | private Boolean sold_out; 22 | private Double recent_popularity=0.0; 23 | private Boolean is_essential=false; 24 | private Long item_id; 25 | private Integer checkout_mode=0; 26 | private Integer stock=1000; 27 | private String specs_name; 28 | private List specs; 29 | 30 | public Double getOriginal_price() { 31 | return original_price; 32 | } 33 | 34 | public void setOriginal_price(Double original_price) { 35 | this.original_price = original_price; 36 | } 37 | 38 | public Integer getSku_id() { 39 | return sku_id; 40 | } 41 | 42 | public void setSku_id(Integer sku_id) { 43 | this.sku_id = sku_id; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public String getPinyin_name() { 55 | return pinyin_name; 56 | } 57 | 58 | public void setPinyin_name(String pinyin_name) { 59 | this.pinyin_name = pinyin_name; 60 | } 61 | 62 | public Long getRestaurant_id() { 63 | return restaurant_id; 64 | } 65 | 66 | public void setRestaurant_id(Long restaurant_id) { 67 | this.restaurant_id = restaurant_id; 68 | } 69 | 70 | public Long getFood_id() { 71 | return food_id; 72 | } 73 | 74 | public void setFood_id(Long food_id) { 75 | this.food_id = food_id; 76 | } 77 | 78 | public Double getPacking_fee() { 79 | return packing_fee; 80 | } 81 | 82 | public void setPacking_fee(Double packing_fee) { 83 | this.packing_fee = packing_fee; 84 | } 85 | 86 | public Double getRecent_rating() { 87 | return recent_rating; 88 | } 89 | 90 | public void setRecent_rating(Double recent_rating) { 91 | this.recent_rating = recent_rating; 92 | } 93 | 94 | public Double getPromotion_stock() { 95 | return promotion_stock; 96 | } 97 | 98 | public void setPromotion_stock(Double promotion_stock) { 99 | this.promotion_stock = promotion_stock; 100 | } 101 | 102 | public Double getPrice() { 103 | return price; 104 | } 105 | 106 | public void setPrice(Double price) { 107 | this.price = price; 108 | } 109 | 110 | public Boolean getSold_out() { 111 | return sold_out; 112 | } 113 | 114 | public void setSold_out(Boolean sold_out) { 115 | this.sold_out = sold_out; 116 | } 117 | 118 | public Double getRecent_popularity() { 119 | return recent_popularity; 120 | } 121 | 122 | public void setRecent_popularity(Double recent_popularity) { 123 | this.recent_popularity = recent_popularity; 124 | } 125 | 126 | public Boolean getIs_essential() { 127 | return is_essential; 128 | } 129 | 130 | public void setIs_essential(Boolean is_essential) { 131 | this.is_essential = is_essential; 132 | } 133 | 134 | public Long getItem_id() { 135 | return item_id; 136 | } 137 | 138 | public void setItem_id(Long item_id) { 139 | this.item_id = item_id; 140 | } 141 | 142 | public Integer getCheckout_mode() { 143 | return checkout_mode; 144 | } 145 | 146 | public void setCheckout_mode(Integer checkout_mode) { 147 | this.checkout_mode = checkout_mode; 148 | } 149 | 150 | public Integer getStock() { 151 | return stock; 152 | } 153 | 154 | public void setStock(Integer stock) { 155 | this.stock = stock; 156 | } 157 | 158 | public String getSpecs_name() { 159 | return specs_name; 160 | } 161 | 162 | public void setSpecs_name(String specs_name) { 163 | this.specs_name = specs_name; 164 | } 165 | 166 | public List getSpecs() { 167 | return specs; 168 | } 169 | 170 | public void setSpecs(List specs) { 171 | this.specs = specs; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/FoodController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Food; 4 | import cn.enilu.elm.api.entity.Ids; 5 | import cn.enilu.elm.api.entity.KeyValue; 6 | import cn.enilu.elm.api.entity.SpecFood; 7 | import cn.enilu.elm.api.repository.BaseDao; 8 | import cn.enilu.elm.api.service.IdsService; 9 | import cn.enilu.elm.api.utils.Maps; 10 | import cn.enilu.elm.api.vo.Rets; 11 | import com.google.common.base.Strings; 12 | import org.nutz.json.Json; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | import java.math.BigDecimal; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * Created on 2017/12/29 0029. 24 | * 25 | * @author zt 26 | */ 27 | @RestController 28 | @RequestMapping("/shopping") 29 | public class FoodController extends BaseController { 30 | 31 | @Autowired 32 | private BaseDao baseDao; 33 | 34 | @Autowired 35 | private IdsService idsService; 36 | 37 | @RequestMapping(value = "addfood",method = RequestMethod.GET) 38 | 39 | public Object add(HttpServletRequest request) { 40 | String json = getRequestPayload(); 41 | Food food = Json.fromJson(Food.class, json); 42 | food.setItem_id(idsService.getId(Ids.ITEM_ID)); 43 | List specFoods = new ArrayList(2); 44 | specFoods.add(buidSpecFood(food)); 45 | food.setSpecfoods(specFoods); 46 | setTips(food); 47 | food.setSatisfy_rate(new BigDecimal(Math.ceil(Math.random() * 100)).setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue()); 48 | food.setSatisfy_count(new BigDecimal(Math.ceil(Math.random() * 1000)).setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue()); 49 | food.setRating(new BigDecimal(Math.random() * 5).setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue()); 50 | baseDao.save(food); 51 | return Rets.success(); 52 | } 53 | @RequestMapping(value="/v2/foods",method = RequestMethod.GET) 54 | public Object list(@RequestParam("restaurant_id") String restaurantId, 55 | @RequestParam(value = "offset", defaultValue = "0") Integer offset, 56 | @RequestParam(value = "limit", defaultValue = "20") Integer limit) { 57 | restaurantId="11"; 58 | if (Strings.isNullOrEmpty(restaurantId) || "undefined".equals(restaurantId)) { 59 | return baseDao.findAll(Food.class); 60 | } else { 61 | return baseDao.findAll(Food.class,"restaurant_id",Long.valueOf(restaurantId)); 62 | } 63 | } 64 | 65 | @RequestMapping(value = "/v2/foods/count",method = RequestMethod.GET) 66 | 67 | public Object count() { 68 | long count = baseDao.count("foods"); 69 | return Rets.success("count", count); 70 | } 71 | @RequestMapping(value = "/v2/food/{id}",method = RequestMethod.DELETE) 72 | 73 | public Object delete(@PathVariable("id") Long id) { 74 | baseDao.delete("foods",Maps.newHashMap("item_id",id)); 75 | return Rets.success(); 76 | } 77 | //todo 未完成 78 | @RequestMapping(value = "/v2/updatefood",method = RequestMethod.POST) 79 | public Object update(HttpServletRequest request){ 80 | Map data = getRequestPayload(Map.class); 81 | System.out.println(Json.toJson(data)); 82 | return Rets.success(); 83 | } 84 | 85 | 86 | 87 | 88 | 89 | 90 | private void setTips(Food food) { 91 | Double ratingCount = Math.ceil(Math.random() * 1000); 92 | Double monthSales = Math.ceil(Math.random() * 1000); 93 | food.setRating_count(ratingCount.intValue()); 94 | food.setMonth_sales(monthSales.intValue()); 95 | food.setTips(ratingCount.intValue() + "评价 月售" + monthSales.intValue() + "份"); 96 | 97 | 98 | } 99 | 100 | private SpecFood buidSpecFood(Food food) { 101 | SpecFood specFood = new SpecFood(); 102 | specFood.setItem_id(food.getItem_id()); 103 | specFood.setFood_id(idsService.getId(Ids.FOOD_ID)); 104 | specFood.setName(food.getName()); 105 | specFood.setRestaurant_id(food.getRestaurant_id()); 106 | BigDecimal recentRating = new BigDecimal(Math.random() * 5).setScale(BigDecimal.ROUND_HALF_DOWN, 1); 107 | specFood.setRecent_rating(recentRating.doubleValue()); 108 | BigDecimal recentPopularity = new BigDecimal(Math.random() * 1000).setScale(BigDecimal.ROUND_HALF_DOWN, 1); 109 | specFood.setRecent_popularity(recentPopularity.doubleValue()); 110 | specFood.setSpecs(new ArrayList()); 111 | return specFood; 112 | 113 | } 114 | 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Address.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | import java.util.Date; 7 | 8 | 9 | /** 10 | * Created on 2018/1/5 0005. 11 | * 12 | * @author zt 13 | */ 14 | @Document(collection = "addresses") 15 | public class Address implements BaseEntity { 16 | @Id 17 | private String _id; 18 | private Long id; 19 | private String address; 20 | private String phone; 21 | private String phone_bk; 22 | private String name; 23 | private String st_geohash; 24 | private String address_detail; 25 | private Integer tag_type; 26 | private Long user_id; 27 | private Boolean phone_had_bound; 28 | private Integer deliver_amount; 29 | private Integer agent_fee; 30 | private Boolean is_deliverable; 31 | private Boolean is_user_default; 32 | private String tag; 33 | private Integer city_id; 34 | private Integer sex; 35 | private Integer poi_type; 36 | private Date created_at; 37 | private Integer is_valid; 38 | 39 | public String get_id() { 40 | return _id; 41 | } 42 | 43 | public void set_id(String _id) { 44 | this._id = _id; 45 | } 46 | 47 | public Long getId() { 48 | return id; 49 | } 50 | 51 | public void setId(Long id) { 52 | this.id = id; 53 | } 54 | 55 | public String getAddress() { 56 | return address; 57 | } 58 | 59 | public void setAddress(String address) { 60 | this.address = address; 61 | } 62 | 63 | public String getPhone() { 64 | return phone; 65 | } 66 | 67 | public void setPhone(String phone) { 68 | this.phone = phone; 69 | } 70 | 71 | public String getPhone_bk() { 72 | return phone_bk; 73 | } 74 | 75 | public void setPhone_bk(String phone_bk) { 76 | this.phone_bk = phone_bk; 77 | } 78 | 79 | public String getName() { 80 | return name; 81 | } 82 | 83 | public void setName(String name) { 84 | this.name = name; 85 | } 86 | 87 | public String getSt_geohash() { 88 | return st_geohash; 89 | } 90 | 91 | public void setSt_geohash(String st_geohash) { 92 | this.st_geohash = st_geohash; 93 | } 94 | 95 | public String getAddress_detail() { 96 | return address_detail; 97 | } 98 | 99 | public void setAddress_detail(String address_detail) { 100 | this.address_detail = address_detail; 101 | } 102 | 103 | public Integer getTag_type() { 104 | return tag_type; 105 | } 106 | 107 | public void setTag_type(Integer tag_type) { 108 | this.tag_type = tag_type; 109 | } 110 | 111 | public Long getUser_id() { 112 | return user_id; 113 | } 114 | 115 | public void setUser_id(Long user_id) { 116 | this.user_id = user_id; 117 | } 118 | 119 | public Boolean getPhone_had_bound() { 120 | return phone_had_bound; 121 | } 122 | 123 | public void setPhone_had_bound(Boolean phone_had_bound) { 124 | this.phone_had_bound = phone_had_bound; 125 | } 126 | 127 | public Integer getDeliver_amount() { 128 | return deliver_amount; 129 | } 130 | 131 | public void setDeliver_amount(Integer deliver_amount) { 132 | this.deliver_amount = deliver_amount; 133 | } 134 | 135 | public Integer getAgent_fee() { 136 | return agent_fee; 137 | } 138 | 139 | public void setAgent_fee(Integer agent_fee) { 140 | this.agent_fee = agent_fee; 141 | } 142 | 143 | public Boolean getIs_deliverable() { 144 | return is_deliverable; 145 | } 146 | 147 | public void setIs_deliverable(Boolean is_deliverable) { 148 | this.is_deliverable = is_deliverable; 149 | } 150 | 151 | public Boolean getIs_user_default() { 152 | return is_user_default; 153 | } 154 | 155 | public void setIs_user_default(Boolean is_user_default) { 156 | this.is_user_default = is_user_default; 157 | } 158 | 159 | public String getTag() { 160 | return tag; 161 | } 162 | 163 | public void setTag(String tag) { 164 | this.tag = tag; 165 | } 166 | 167 | public Integer getCity_id() { 168 | return city_id; 169 | } 170 | 171 | public void setCity_id(Integer city_id) { 172 | this.city_id = city_id; 173 | } 174 | 175 | public Integer getSex() { 176 | return sex; 177 | } 178 | 179 | public void setSex(Integer sex) { 180 | this.sex = sex; 181 | } 182 | 183 | public Integer getPoi_type() { 184 | return poi_type; 185 | } 186 | 187 | public void setPoi_type(Integer poi_type) { 188 | this.poi_type = poi_type; 189 | } 190 | 191 | public Date getCreated_at() { 192 | return created_at; 193 | } 194 | 195 | public void setCreated_at(Date created_at) { 196 | this.created_at = created_at; 197 | } 198 | 199 | public Integer getIs_valid() { 200 | return is_valid; 201 | } 202 | 203 | public void setIs_valid(Integer is_valid) { 204 | this.is_valid = is_valid; 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/service/PositionService.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.service; 2 | 3 | import cn.enilu.elm.api.repository.BaseDao; 4 | import cn.enilu.elm.api.utils.AppConfiguration; 5 | import cn.enilu.elm.api.utils.HttpClients; 6 | import cn.enilu.elm.api.vo.CityInfo; 7 | import com.google.common.collect.Maps; 8 | import org.nutz.json.Json; 9 | import org.nutz.mapl.Mapl; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.net.URLEncoder; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | 20 | /** 21 | * Created on 2017/12/29 0029. 22 | * 23 | * @author zt 24 | */ 25 | @Service 26 | public class PositionService { 27 | private Logger logger = LoggerFactory.getLogger(PositionService.class); 28 | @Autowired 29 | private AppConfiguration appConfiguration; 30 | @Autowired 31 | private BaseDao baseDao; 32 | 33 | public CityInfo getPostion(String ip) { 34 | Map map = Maps.newHashMap(); 35 | map.put("ip", ip); 36 | map.put("key", appConfiguration.getTencentKey()); 37 | Map result = null; 38 | try { 39 | String str = HttpClients.get(appConfiguration.getApiQqGetLocation(), map); 40 | result = (Map) Json.fromJson(str);// new JsonParser().parse(str).getAsJsonObject(); 41 | } catch (Exception e) { 42 | logger.error("获取地理位置异常",e); 43 | } 44 | if (result == null || Integer.valueOf(result.get("status").toString()) != 0) { 45 | try { 46 | map.put("key", appConfiguration.getTencentKey2()); 47 | String str = HttpClients.get(appConfiguration.getApiQqGetLocation(), map); 48 | result = (Map) Json.fromJson(str); 49 | } catch (Exception e) { 50 | logger.error("获取地理位置异常",e); 51 | } 52 | } 53 | if (result == null || Integer.valueOf(result.get("status").toString()) != 0) { 54 | try { 55 | map.put("key", appConfiguration.getTencentKey3()); 56 | String str = HttpClients.get(appConfiguration.getApiQqGetLocation(), map); 57 | result = (Map) Json.fromJson(str); 58 | } catch (Exception e) { 59 | logger.error("获取地理位置异常",e); 60 | } 61 | 62 | } 63 | if ( Integer.valueOf(result.get("status").toString()) == 0) { 64 | Map resultData = (Map) result.get("result"); 65 | 66 | String lat = String.valueOf(Mapl.cell(resultData,"location.lat")); 67 | String lng = String.valueOf( Mapl.cell(resultData,"location.lng")); 68 | String city = (String) Mapl.cell(resultData,"ad_info.city"); 69 | city = city.replace("市",""); 70 | CityInfo cityInfo = new CityInfo(); 71 | cityInfo.setCity(city); 72 | cityInfo.setLat(lat); 73 | cityInfo.setLng(lng); 74 | return cityInfo; 75 | 76 | } 77 | return null; 78 | } 79 | 80 | public List searchPlace(String cityName,String keyword){ 81 | Map params = Maps.newHashMap(); 82 | params.put("key",appConfiguration.getTencentKey()); 83 | params.put("keyword", URLEncoder.encode(keyword)); 84 | params.put("boundary","region("+URLEncoder.encode(cityName)+",0)"); 85 | params.put("page_size","10"); 86 | try { 87 | String str = HttpClients.get(appConfiguration.getApiQqSearchPlace(), params); 88 | Map result = (Map) Json.fromJson(str); 89 | if (Integer.valueOf(result.get("status").toString()).intValue() == 0) { 90 | return (List) result.get("data"); 91 | } 92 | }catch (Exception e){ 93 | throw new RuntimeException(e.getMessage()); 94 | } 95 | return null; 96 | 97 | } 98 | public Map findById(Integer id){ 99 | Map cities = baseDao.findOne("cities"); 100 | Map data = (Map) cities.get("data"); 101 | Map result = null; 102 | for (Map.Entry entry : data.entrySet()) { 103 | List list = entry.getValue(); 104 | for (int i = 0; i < list.size(); i++) { 105 | Map rec = (Map) list.get(i); 106 | if (id == Double.valueOf(rec.get("id").toString()).intValue()) { 107 | result = rec; 108 | break; 109 | } 110 | } 111 | } 112 | return result; 113 | } 114 | public Map findByName(String cityName){ 115 | Map cities = baseDao.findOne("cities"); 116 | Map data = (Map) cities.get("data"); 117 | Map result = null; 118 | for (Map.Entry entry : data.entrySet()) { 119 | List list = entry.getValue(); 120 | for (int i = 0; i < list.size(); i++) { 121 | Map rec = (Map) list.get(i); 122 | if (cityName.equals(rec.get("name"))) { 123 | result = rec; 124 | break; 125 | } 126 | } 127 | } 128 | return result; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/AdminController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Admin; 4 | import cn.enilu.elm.api.entity.Ids; 5 | import cn.enilu.elm.api.repository.BaseDao; 6 | import cn.enilu.elm.api.service.IdsService; 7 | import cn.enilu.elm.api.service.PositionService; 8 | import cn.enilu.elm.api.utils.AppConfiguration; 9 | import cn.enilu.elm.api.utils.MD5; 10 | import cn.enilu.elm.api.vo.CityInfo; 11 | import cn.enilu.elm.api.vo.Constants; 12 | import cn.enilu.elm.api.vo.Rets; 13 | import com.google.common.collect.Maps; 14 | import org.joda.time.DateTime; 15 | import org.joda.time.format.DateTimeFormat; 16 | import org.nutz.json.Json; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.web.bind.annotation.*; 21 | import org.springframework.web.multipart.MultipartFile; 22 | 23 | import javax.servlet.http.Cookie; 24 | import javax.servlet.http.HttpServletRequest; 25 | import java.io.IOException; 26 | import java.nio.file.Files; 27 | import java.nio.file.Paths; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | import static cn.enilu.elm.api.utils.MD5.getMD5String; 32 | 33 | /** 34 | * Created on 2017/12/12 0012. 35 | * @author zt 36 | */ 37 | 38 | @RestController 39 | @RequestMapping("/admin") 40 | public class AdminController extends BaseController { 41 | private Logger logger = LoggerFactory.getLogger(AdminController.class); 42 | 43 | public static final String ROOT = "upload-dir"; 44 | 45 | @Autowired 46 | private BaseDao baseDao; 47 | @Autowired 48 | private AppConfiguration appConfiguration; 49 | @Autowired 50 | private PositionService positionService; 51 | @Autowired 52 | private IdsService idsService; 53 | @RequestMapping(value = "login",method = RequestMethod.POST) 54 | @ResponseBody 55 | public Object login(HttpServletRequest request) { 56 | Admin admins= getRequestPayload(Admin.class); 57 | Admin result = baseDao.findOne(Admin.class,"user_name",admins.getUser_name()); 58 | String password = admins.getPassword(); 59 | String newPwd = MD5.getMD5String(getMD5String(password).substring(2,7)+ getMD5String(password)); 60 | if(result!=null){ 61 | if(newPwd.equals(result.getPassword())) { 62 | 63 | Cookie[] cookies = request.getCookies(); 64 | logger.info("cookies:{}", Json.toJson(cookies)); 65 | setSession( Constants.SESSION_ID,admins); 66 | return Rets.success("success", "登录成功"); 67 | 68 | }else{ 69 | return Rets.failure("message","密码错误"); 70 | } 71 | }else{ 72 | admins.setCreate_time(DateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss"))); 73 | admins.setStatus(1); 74 | admins.setAvatar("default.jpg"); 75 | admins.setAdmin("管理员"); 76 | String ip = getIp(); 77 | CityInfo cityInfo = positionService.getPostion(ip); 78 | admins.setCity(cityInfo!=null?cityInfo.getCity():null); 79 | admins.setId(idsService.getId(Ids.ADMIN_ID)); 80 | admins.setPassword(newPwd); 81 | baseDao.save(admins); 82 | setSession(Constants.SESSION_ID,admins); 83 | return Rets.success("success", "登录成功"); 84 | } 85 | 86 | } 87 | @RequestMapping(value = "info",method = RequestMethod.GET) 88 | @ResponseBody 89 | public Object info(HttpServletRequest request) { 90 | return Rets.success("data",baseDao.findOne(1L,"admins")); 91 | } 92 | 93 | @RequestMapping(value = "count",method = RequestMethod.GET) 94 | @ResponseBody 95 | public Object count(HttpServletRequest request) { 96 | long count = baseDao.count("admins"); 97 | return Rets.success("count",count); 98 | } 99 | 100 | @RequestMapping(value="all",method = RequestMethod.GET) 101 | @ResponseBody 102 | public Object all(@RequestParam( name="offset") Integer offset, 103 | @RequestParam(name="limit") Integer limit) { 104 | List list = baseDao.findAll("admins"); 105 | return Rets.success("data",list); 106 | } 107 | 108 | /** 109 | * 更新管理员头像 110 | * @param adminId 111 | * @param file 112 | * @return 113 | */ 114 | @RequestMapping(method = RequestMethod.POST, value = "/update/avatar/{id}") 115 | @ResponseBody 116 | public Object uploadImg(@PathVariable("id") Long adminId,@RequestParam("file") MultipartFile file) { 117 | if (!file.isEmpty()) { 118 | try { 119 | String fileName= System.currentTimeMillis()+"."+file.getOriginalFilename().split("\\.")[1]; 120 | Files.copy(file.getInputStream(), Paths.get(appConfiguration.getImgDir(), fileName)); 121 | Map map =Maps.newHashMap(); 122 | map.put("avatar",fileName); 123 | baseDao.update(adminId,"admins", map); 124 | return Rets.success("image_path",fileName); 125 | } catch (IOException | RuntimeException e) { 126 | e.printStackTrace(); 127 | 128 | } 129 | } 130 | return Rets.failure(); 131 | 132 | 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | cn.enilu 8 | springboot-elm 9 | 1.0 10 | 11 | 1.5.9.RELEASE 12 | 4.4.1 13 | 4.12 14 | 4.3.5.RELEASE 15 | 2.8.2 16 | 2.9.9 17 | 1.r.63.r2 18 | 18.0 19 | 2.2.2 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | ${spring-boot-version} 28 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-data-mongodb 34 | ${spring-boot-version} 35 | 36 | 37 | 38 | 39 | com.google.guava 40 | guava 41 | ${guava-version} 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | joda-time 50 | joda-time 51 | ${joda-time-version} 52 | 53 | 54 | org.nutz 55 | nutz 56 | ${nutz-version} 57 | 58 | 59 | 60 | 61 | org.apache.httpcomponents 62 | httpclient 63 | ${httpcomponents-version} 64 | 65 | 66 | org.apache.httpcomponents 67 | httpcore 68 | ${httpcomponents-version} 69 | 70 | 71 | org.apache.httpcomponents 72 | httpmime 73 | ${httpcomponents-version} 74 | 75 | 76 | 77 | org.springframework.hateoas 78 | spring-hateoas 79 | 0.24.0.RELEASE 80 | 81 | 82 | 83 | 84 | io.springfox 85 | springfox-swagger2 86 | ${swagger-version} 87 | 88 | 89 | io.springfox 90 | springfox-swagger-ui 91 | ${swagger-version} 92 | 93 | 94 | 95 | 96 | org.springframework 97 | spring-test 98 | ${springframework-version} 99 | test 100 | 101 | 102 | junit 103 | junit 104 | ${junit-version} 105 | test 106 | 107 | 108 | org.springframework.boot 109 | spring-boot-starter-test 110 | ${spring-boot-version} 111 | test 112 | 113 | 114 | junit 115 | junit 116 | RELEASE 117 | test 118 | 119 | 120 | 121 | 122 | 123 | springboot-elm 124 | 125 | 126 | org.springframework.boot 127 | spring-boot-maven-plugin 128 | 129 | true 130 | 131 | 132 | 133 | maven-compiler-plugin 134 | 135 | 1.8 136 | 1.8 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Food.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created on 2018/1/3 0003. 10 | * 11 | * @author zt 12 | */ 13 | @Document(collection = "foods") 14 | public class Food implements BaseEntity { 15 | @Id 16 | private String _id; 17 | private Double rating; 18 | private Integer is_featured=0; 19 | private Long restaurant_id; 20 | private Long category_id; 21 | private String pinyin_name; 22 | private List display_times; 23 | private List attrs; 24 | private String description; 25 | private Integer month_sales; 26 | private Integer rating_count; 27 | private String tips; 28 | private String image_path; 29 | private List specifications; 30 | private String server_utc; 31 | private boolean is_essential; 32 | private List attributes; 33 | private Long item_id; 34 | private List limitation; 35 | private String name; 36 | private Double satisfy_count; 37 | private String activity; 38 | private Double satisfy_rate; 39 | private List specfoods; 40 | 41 | public String get_id() { 42 | return _id; 43 | } 44 | 45 | public void set_id(String _id) { 46 | this._id = _id; 47 | } 48 | 49 | public Double getRating() { 50 | return rating; 51 | } 52 | 53 | public void setRating(Double rating) { 54 | this.rating = rating; 55 | } 56 | 57 | public Integer getIs_featured() { 58 | return is_featured; 59 | } 60 | 61 | public void setIs_featured(Integer is_featured) { 62 | this.is_featured = is_featured; 63 | } 64 | 65 | public Long getRestaurant_id() { 66 | return restaurant_id; 67 | } 68 | 69 | public void setRestaurant_id(Long restaurant_id) { 70 | this.restaurant_id = restaurant_id; 71 | } 72 | 73 | public Long getCategory_id() { 74 | return category_id; 75 | } 76 | 77 | public void setCategory_id(Long category_id) { 78 | this.category_id = category_id; 79 | } 80 | 81 | public String getPinyin_name() { 82 | return pinyin_name; 83 | } 84 | 85 | public void setPinyin_name(String pinyin_name) { 86 | this.pinyin_name = pinyin_name; 87 | } 88 | 89 | public List getDisplay_times() { 90 | return display_times; 91 | } 92 | 93 | public void setDisplay_times(List display_times) { 94 | this.display_times = display_times; 95 | } 96 | 97 | public List getAttrs() { 98 | return attrs; 99 | } 100 | 101 | public void setAttrs(List attrs) { 102 | this.attrs = attrs; 103 | } 104 | 105 | public String getDescription() { 106 | return description; 107 | } 108 | 109 | public void setDescription(String description) { 110 | this.description = description; 111 | } 112 | 113 | public Integer getMonth_sales() { 114 | return month_sales; 115 | } 116 | 117 | public void setMonth_sales(Integer month_sales) { 118 | this.month_sales = month_sales; 119 | } 120 | 121 | public Integer getRating_count() { 122 | return rating_count; 123 | } 124 | 125 | public void setRating_count(Integer rating_count) { 126 | this.rating_count = rating_count; 127 | } 128 | 129 | public String getTips() { 130 | return tips; 131 | } 132 | 133 | public void setTips(String tips) { 134 | this.tips = tips; 135 | } 136 | 137 | public String getImage_path() { 138 | return image_path; 139 | } 140 | 141 | public void setImage_path(String image_path) { 142 | this.image_path = image_path; 143 | } 144 | 145 | public List getSpecifications() { 146 | return specifications; 147 | } 148 | 149 | public void setSpecifications(List specifications) { 150 | this.specifications = specifications; 151 | } 152 | 153 | public String getServer_utc() { 154 | return server_utc; 155 | } 156 | 157 | public void setServer_utc(String server_utc) { 158 | this.server_utc = server_utc; 159 | } 160 | 161 | public boolean is_essential() { 162 | return is_essential; 163 | } 164 | 165 | public void setIs_essential(boolean is_essential) { 166 | this.is_essential = is_essential; 167 | } 168 | 169 | public List getAttributes() { 170 | return attributes; 171 | } 172 | 173 | public void setAttributes(List attributes) { 174 | this.attributes = attributes; 175 | } 176 | 177 | public Long getItem_id() { 178 | return item_id; 179 | } 180 | 181 | public void setItem_id(Long item_id) { 182 | this.item_id = item_id; 183 | } 184 | 185 | public List getLimitation() { 186 | return limitation; 187 | } 188 | 189 | public void setLimitation(List limitation) { 190 | this.limitation = limitation; 191 | } 192 | 193 | public String getName() { 194 | return name; 195 | } 196 | 197 | public void setName(String name) { 198 | this.name = name; 199 | } 200 | 201 | public Double getSatisfy_count() { 202 | return satisfy_count; 203 | } 204 | 205 | public void setSatisfy_count(Double satisfy_count) { 206 | this.satisfy_count = satisfy_count; 207 | } 208 | 209 | public String getActivity() { 210 | return activity; 211 | } 212 | 213 | public void setActivity(String activity) { 214 | this.activity = activity; 215 | } 216 | 217 | public Double getSatisfy_rate() { 218 | return satisfy_rate; 219 | } 220 | 221 | public void setSatisfy_rate(Double satisfy_rate) { 222 | this.satisfy_rate = satisfy_rate; 223 | } 224 | 225 | public List getSpecfoods() { 226 | return specfoods; 227 | } 228 | 229 | public void setSpecfoods(List specfoods) { 230 | this.specfoods = specfoods; 231 | } 232 | } 233 | 234 | 235 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/repository/BaseDao.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.repository; 2 | 3 | import cn.enilu.elm.api.entity.BaseEntity; 4 | import com.mongodb.WriteResult; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.geo.GeoResults; 7 | import org.springframework.data.mongodb.core.MongoTemplate; 8 | import org.springframework.data.mongodb.core.query.Criteria; 9 | import org.springframework.data.mongodb.core.query.NearQuery; 10 | import org.springframework.data.mongodb.core.query.Query; 11 | import org.springframework.data.mongodb.core.query.Update; 12 | import org.springframework.stereotype.Repository; 13 | 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * Created on 2017/12/29 0029. 19 | * 20 | * @author zt 21 | */ 22 | @Repository 23 | public class BaseDao { 24 | @Autowired 25 | private MongoTemplate mongoTemplate; 26 | 27 | public void save(BaseEntity entity) { 28 | mongoTemplate.save(entity); 29 | } 30 | 31 | public void save(Object data, String collectionName) { 32 | mongoTemplate.save(data, collectionName); 33 | 34 | } 35 | 36 | public void delete(Long id, String collectionName) { 37 | mongoTemplate.remove(Query.query(Criteria.where("id").is(id)), collectionName); 38 | } 39 | public void delete(String collectionName,Map keyValues){ 40 | mongoTemplate.remove(Query.query(criteria(keyValues)),collectionName); 41 | } 42 | 43 | public void update(BaseEntity entity){ 44 | mongoTemplate.save(entity); 45 | } 46 | public WriteResult update(Long id, String collectionName, Map keyValues) { 47 | Update update = null; 48 | for (Map.Entry entry : keyValues.entrySet()) { 49 | if (update == null) { 50 | update = Update.update(entry.getKey(), entry.getValue()); 51 | } else { 52 | update.set(entry.getKey(), entry.getValue()); 53 | } 54 | } 55 | return mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(id)), update, collectionName); 56 | } 57 | public T findOne(Class klass,P key) { 58 | return findOne(klass,"id",key); 59 | } 60 | public T findOne(Class klass, String key,Object value) { 61 | return mongoTemplate.findOne(Query.query(Criteria.where(key).is(value)),klass); 62 | } 63 | 64 | public Object findOne(Long id, String collectionName) { 65 | return mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), Map.class, collectionName); 66 | } 67 | 68 | 69 | public Map findOne(String collectionName, Object... extraKeyValues) { 70 | Criteria criteria = criteria(extraKeyValues); 71 | if (criteria == null) { 72 | List list = mongoTemplate.findAll(Map.class, collectionName); 73 | if (list != null) { 74 | return list.get(0); 75 | } 76 | return null; 77 | } 78 | return mongoTemplate.findOne(Query.query(criteria), Map.class, collectionName); 79 | } 80 | 81 | public T findOne(Class klass, Object... keyValues) { 82 | Criteria criteria = criteria(keyValues); 83 | 84 | if (criteria == null) { 85 | List list = mongoTemplate.findAll(klass); 86 | if (list != null) { 87 | return list.get(0); 88 | } 89 | return null; 90 | } 91 | return mongoTemplate.findOne(Query.query(criteria), klass); 92 | } 93 | 94 | 95 | public List findAll(Class klass) { 96 | return mongoTemplate.findAll(klass); 97 | } 98 | public List findAll(Class klass,Object... keyValues) { 99 | Criteria criteria = criteria(keyValues); 100 | return mongoTemplate.find(Query.query(criteria),klass); 101 | } 102 | public List findAll(Class klass,Map keyValues) { 103 | Criteria criteria = criteria(keyValues); 104 | return mongoTemplate.find(Query.query(criteria),klass); 105 | } 106 | 107 | public List findAll(String collection) { 108 | return mongoTemplate.findAll(Map.class, collection); 109 | } 110 | public List findAll(String collectionName,Object... keyValues){ 111 | Criteria criteria = criteria(keyValues); 112 | return mongoTemplate.find(Query.query(criteria),Map.class,collectionName); 113 | } 114 | public GeoResults near(double x, double y, String collectionName){ 115 | return mongoTemplate.geoNear(NearQuery.near(x,y),Map.class,collectionName); 116 | } 117 | 118 | public long count(Class klass) { 119 | return count( klass,null); 120 | } 121 | public long count(Class klass,Map params) { 122 | Criteria criteria = criteria(params); 123 | if(criteria==null){ 124 | return mongoTemplate.count(null,klass); 125 | }else { 126 | return mongoTemplate.count(Query.query(criteria), klass); 127 | } 128 | } 129 | 130 | public long count(String collection) { 131 | return mongoTemplate.count(null, collection); 132 | } 133 | public long count(String collection,Map params) { 134 | Criteria criteria = criteria(params); 135 | if(criteria==null){ 136 | return mongoTemplate.count(null,collection); 137 | }else { 138 | return mongoTemplate.count(Query.query(criteria), collection); 139 | } 140 | } 141 | 142 | 143 | 144 | private Criteria criteria(Map map) { 145 | Criteria criteria = null; 146 | if(map!=null) { 147 | for (Map.Entry entry : map.entrySet()) { 148 | if (criteria == null) { 149 | criteria = Criteria.where(entry.getKey()).is(entry.getValue()); 150 | } else { 151 | criteria.and(entry.getKey()).is(entry.getValue()); 152 | } 153 | } 154 | } 155 | return criteria; 156 | } 157 | 158 | private Criteria criteria(Object... extraKeyValues) { 159 | Criteria criteria = null; 160 | if (extraKeyValues.length % 2 != 0) { 161 | throw new IllegalArgumentException(); 162 | } else { 163 | for (int i = 0; i < extraKeyValues.length; i += 2) { 164 | Object k = extraKeyValues[i]; 165 | Object v = extraKeyValues[i + 1]; 166 | if (i == 0) { 167 | criteria = Criteria.where(k.toString()).is(v); 168 | } else { 169 | criteria.and(k.toString()).is(v); 170 | } 171 | } 172 | 173 | } 174 | return criteria; 175 | } 176 | 177 | 178 | } 179 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Shop.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * Created on 2017/12/29 0029. 11 | * 12 | * @author zt 13 | */ 14 | @Document(collection = "shops") 15 | public class Shop implements BaseEntity { 16 | @Id 17 | private String _id; 18 | private String name; 19 | private String address; 20 | private Long id; 21 | private Double latitude; 22 | private Double longitude; 23 | private List location; 24 | private String phone; 25 | private String category; 26 | private List supports; 27 | private Integer status=1; 28 | private Integer recent_order_num=500; 29 | private Integer rating_count=200; 30 | private Double rating=4.5; 31 | private String promotion_info; 32 | private Map piecewise_agent_fee; 33 | 34 | private List opening_hours; 35 | 36 | private Map license; 37 | private Boolean is_new; 38 | private String is_premium; 39 | private String image_path; 40 | private Map identification; 41 | private String float_minimum_order_amount; 42 | private String float_delivery_fee; 43 | private String distance; 44 | private String order_lead_time; 45 | private String description; 46 | private Map delivery_mode; 47 | private List activities; 48 | 49 | public String get_id() { 50 | return _id; 51 | } 52 | 53 | public void set_id(String _id) { 54 | this._id = _id; 55 | } 56 | 57 | public String getName() { 58 | return name; 59 | } 60 | 61 | public void setName(String name) { 62 | this.name = name; 63 | } 64 | 65 | public String getAddress() { 66 | return address; 67 | } 68 | 69 | public void setAddress(String address) { 70 | this.address = address; 71 | } 72 | 73 | public Long getId() { 74 | return id; 75 | } 76 | 77 | public void setId(Long id) { 78 | this.id = id; 79 | } 80 | 81 | public Double getLatitude() { 82 | return latitude; 83 | } 84 | 85 | public void setLatitude(Double latitude) { 86 | this.latitude = latitude; 87 | } 88 | 89 | public Double getLongitude() { 90 | return longitude; 91 | } 92 | 93 | public void setLongitude(Double longitude) { 94 | this.longitude = longitude; 95 | } 96 | 97 | public List getLocation() { 98 | return location; 99 | } 100 | 101 | public void setLocation(List location) { 102 | this.location = location; 103 | } 104 | 105 | public String getPhone() { 106 | return phone; 107 | } 108 | 109 | public void setPhone(String phone) { 110 | this.phone = phone; 111 | } 112 | 113 | public String getCategory() { 114 | return category; 115 | } 116 | 117 | public void setCategory(String category) { 118 | this.category = category; 119 | } 120 | 121 | public List getSupports() { 122 | return supports; 123 | } 124 | 125 | public void setSupports(List supports) { 126 | this.supports = supports; 127 | } 128 | 129 | public Integer getStatus() { 130 | return status; 131 | } 132 | 133 | public void setStatus(Integer status) { 134 | this.status = status; 135 | } 136 | 137 | public Integer getRecent_order_num() { 138 | return recent_order_num; 139 | } 140 | 141 | public void setRecent_order_num(Integer recent_order_num) { 142 | this.recent_order_num = recent_order_num; 143 | } 144 | 145 | public Integer getRating_count() { 146 | return rating_count; 147 | } 148 | 149 | public void setRating_count(Integer rating_count) { 150 | this.rating_count = rating_count; 151 | } 152 | 153 | public Double getRating() { 154 | return rating; 155 | } 156 | 157 | public void setRating(Double rating) { 158 | this.rating = rating; 159 | } 160 | 161 | public String getPromotion_info() { 162 | return promotion_info; 163 | } 164 | 165 | public void setPromotion_info(String promotion_info) { 166 | this.promotion_info = promotion_info; 167 | } 168 | 169 | public Map getPiecewise_agent_fee() { 170 | return piecewise_agent_fee; 171 | } 172 | 173 | public void setPiecewise_agent_fee(Map piecewise_agent_fee) { 174 | this.piecewise_agent_fee = piecewise_agent_fee; 175 | } 176 | 177 | public List getOpening_hours() { 178 | return opening_hours; 179 | } 180 | 181 | public void setOpening_hours(List opening_hours) { 182 | this.opening_hours = opening_hours; 183 | } 184 | 185 | public Map getLicense() { 186 | return license; 187 | } 188 | 189 | public void setLicense(Map license) { 190 | this.license = license; 191 | } 192 | 193 | public Boolean getIs_new() { 194 | return is_new; 195 | } 196 | 197 | public void setIs_new(Boolean is_new) { 198 | this.is_new = is_new; 199 | } 200 | 201 | public String getIs_premium() { 202 | return is_premium; 203 | } 204 | 205 | public void setIs_premium(String is_premium) { 206 | this.is_premium = is_premium; 207 | } 208 | 209 | public String getImage_path() { 210 | return image_path; 211 | } 212 | 213 | public void setImage_path(String image_path) { 214 | this.image_path = image_path; 215 | } 216 | 217 | public Map getIdentification() { 218 | return identification; 219 | } 220 | 221 | public void setIdentification(Map identification) { 222 | this.identification = identification; 223 | } 224 | 225 | public String getFloat_minimum_order_amount() { 226 | return float_minimum_order_amount; 227 | } 228 | 229 | public void setFloat_minimum_order_amount(String float_minimum_order_amount) { 230 | this.float_minimum_order_amount = float_minimum_order_amount; 231 | } 232 | 233 | public String getFloat_delivery_fee() { 234 | return float_delivery_fee; 235 | } 236 | 237 | public void setFloat_delivery_fee(String float_delivery_fee) { 238 | this.float_delivery_fee = float_delivery_fee; 239 | } 240 | 241 | public String getDistance() { 242 | return distance; 243 | } 244 | 245 | public void setDistance(String distance) { 246 | this.distance = distance; 247 | } 248 | 249 | public String getOrder_lead_time() { 250 | return order_lead_time; 251 | } 252 | 253 | public void setOrder_lead_time(String order_lead_time) { 254 | this.order_lead_time = order_lead_time; 255 | } 256 | 257 | public String getDescription() { 258 | return description; 259 | } 260 | 261 | public void setDescription(String description) { 262 | this.description = description; 263 | } 264 | 265 | public Map getDelivery_mode() { 266 | return delivery_mode; 267 | } 268 | 269 | public void setDelivery_mode(Map delivery_mode) { 270 | this.delivery_mode = delivery_mode; 271 | } 272 | 273 | public List getActivities() { 274 | return activities; 275 | } 276 | 277 | public void setActivities(List activities) { 278 | this.activities = activities; 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/utils/HttpClients.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.utils; 2 | 3 | import org.apache.http.HttpEntity; 4 | import org.apache.http.HttpResponse; 5 | import org.apache.http.NameValuePair; 6 | import org.apache.http.client.ClientProtocolException; 7 | import org.apache.http.client.HttpClient; 8 | import org.apache.http.client.entity.UrlEncodedFormEntity; 9 | import org.apache.http.client.methods.HttpDelete; 10 | import org.apache.http.client.methods.HttpGet; 11 | import org.apache.http.client.methods.HttpPost; 12 | import org.apache.http.client.methods.HttpPut; 13 | import org.apache.http.client.utils.URLEncodedUtils; 14 | import org.apache.http.entity.StringEntity; 15 | import org.apache.http.impl.client.DefaultHttpClient; 16 | import org.apache.http.message.BasicNameValuePair; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | import java.io.*; 21 | import java.net.HttpURLConnection; 22 | import java.net.URI; 23 | import java.net.URL; 24 | import java.net.URLEncoder; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | import java.util.Map; 28 | import java.util.Set; 29 | 30 | /** 31 | * Created by dell on 2015/1/13. 32 | */ 33 | public class HttpClients { 34 | private static Logger logger = LoggerFactory.getLogger(HttpClients.class); 35 | 36 | /** 37 | * 封装HTTP POST方法 38 | * 39 | * @param 40 | * @param 41 | * @return 42 | * @throws ClientProtocolException 43 | * @throws IOException 44 | */ 45 | public static String post(String url, Map paramMap) throws ClientProtocolException, IOException { 46 | HttpClient httpClient = new DefaultHttpClient(); 47 | HttpPost httpPost = new HttpPost(url); 48 | List formparams = setHttpParams(paramMap); 49 | UrlEncodedFormEntity param = new UrlEncodedFormEntity(formparams, "UTF-8"); 50 | httpPost.setEntity(param); 51 | HttpResponse response = httpClient.execute(httpPost); 52 | String httpEntityContent = getHttpEntityContent(response); 53 | httpPost.abort(); 54 | return httpEntityContent; 55 | } 56 | 57 | /** 58 | * 封装HTTP POST方法 59 | * 60 | * @param 61 | * @param (如JSON串) 62 | * @return 63 | * @throws ClientProtocolException 64 | * @throws IOException 65 | */ 66 | public static String post(String url, String data) throws ClientProtocolException, IOException { 67 | HttpClient httpClient = new DefaultHttpClient(); 68 | HttpPost httpPost = new HttpPost(url); 69 | httpPost.setHeader("Content-Type", "text/json; charset=utf-8"); 70 | httpPost.setEntity(new StringEntity(URLEncoder.encode(data, "UTF-8"))); 71 | HttpResponse response = httpClient.execute(httpPost); 72 | String httpEntityContent = getHttpEntityContent(response); 73 | httpPost.abort(); 74 | return httpEntityContent; 75 | } 76 | 77 | /** 78 | * 封装HTTP GET方法 79 | * 80 | * @param 81 | * @return 82 | * @throws ClientProtocolException 83 | * @throws IOException 84 | */ 85 | public static String get(String url) throws ClientProtocolException, IOException { 86 | HttpClient httpClient = new DefaultHttpClient(); 87 | HttpGet httpGet = new HttpGet(); 88 | httpGet.setURI(URI.create(url)); 89 | HttpResponse response = httpClient.execute(httpGet); 90 | String httpEntityContent = getHttpEntityContent(response); 91 | httpGet.abort(); 92 | return httpEntityContent; 93 | } 94 | 95 | /** 96 | * 封装HTTP GET方法 97 | * 98 | * @param 99 | * @param 100 | * @return 101 | * @throws ClientProtocolException 102 | * @throws IOException 103 | */ 104 | public static String get(String url, Map paramMap) throws ClientProtocolException, IOException { 105 | HttpClient httpClient = new DefaultHttpClient(); 106 | HttpGet httpGet = new HttpGet(); 107 | List formparams = setHttpParams(paramMap); 108 | String param = URLEncodedUtils.format(formparams, "UTF-8"); 109 | httpGet.setURI(URI.create(url + "?" + param)); 110 | HttpResponse response = httpClient.execute(httpGet); 111 | String httpEntityContent = getHttpEntityContent(response); 112 | httpGet.abort(); 113 | return httpEntityContent; 114 | } 115 | 116 | /** 117 | * 封装HTTP PUT方法 118 | * 119 | * @param 120 | * @param 121 | * @return 122 | * @throws ClientProtocolException 123 | * @throws IOException 124 | */ 125 | public static String put(String url, Map paramMap) throws ClientProtocolException, IOException { 126 | HttpClient httpClient = new DefaultHttpClient(); 127 | HttpPut httpPut = new HttpPut(url); 128 | List formparams = setHttpParams(paramMap); 129 | UrlEncodedFormEntity param = new UrlEncodedFormEntity(formparams, "UTF-8"); 130 | httpPut.setEntity(param); 131 | HttpResponse response = httpClient.execute(httpPut); 132 | String httpEntityContent = getHttpEntityContent(response); 133 | httpPut.abort(); 134 | return httpEntityContent; 135 | } 136 | 137 | /** 138 | * 封装HTTP DELETE方法 139 | * 140 | * @param 141 | * @return 142 | * @throws ClientProtocolException 143 | * @throws IOException 144 | */ 145 | public static String delete(String url) throws ClientProtocolException, IOException { 146 | HttpClient httpClient = new DefaultHttpClient(); 147 | HttpDelete httpDelete = new HttpDelete(); 148 | httpDelete.setURI(URI.create(url)); 149 | HttpResponse response = httpClient.execute(httpDelete); 150 | String httpEntityContent = getHttpEntityContent(response); 151 | httpDelete.abort(); 152 | return httpEntityContent; 153 | } 154 | 155 | /** 156 | * 封装HTTP DELETE方法 157 | * 158 | * @param 159 | * @param 160 | * @return 161 | * @throws ClientProtocolException 162 | * @throws IOException 163 | */ 164 | public static String delete(String url, Map paramMap) throws ClientProtocolException, IOException { 165 | HttpClient httpClient = new DefaultHttpClient(); 166 | HttpDelete httpDelete = new HttpDelete(); 167 | List formparams = setHttpParams(paramMap); 168 | String param = URLEncodedUtils.format(formparams, "UTF-8"); 169 | httpDelete.setURI(URI.create(url + "?" + param)); 170 | HttpResponse response = httpClient.execute(httpDelete); 171 | String httpEntityContent = getHttpEntityContent(response); 172 | httpDelete.abort(); 173 | return httpEntityContent; 174 | } 175 | 176 | 177 | /** 178 | * 设置请求参数 179 | * 180 | * @param 181 | * @return 182 | */ 183 | private static List setHttpParams(Map paramMap) { 184 | List formparams = new ArrayList(); 185 | Set> set = paramMap.entrySet(); 186 | for (Map.Entry entry : set) { 187 | formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); 188 | } 189 | return formparams; 190 | } 191 | 192 | /** 193 | * 获得响应HTTP实体内容 194 | * 195 | * @param response 196 | * @return 197 | * @throws IOException 198 | * @throws UnsupportedEncodingException 199 | */ 200 | private static String getHttpEntityContent(HttpResponse response) throws IOException, UnsupportedEncodingException { 201 | HttpEntity entity = response.getEntity(); 202 | if (entity != null) { 203 | InputStream is = entity.getContent(); 204 | BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); 205 | String line = br.readLine(); 206 | StringBuilder sb = new StringBuilder(); 207 | while (line != null) { 208 | sb.append(line + "\n"); 209 | line = br.readLine(); 210 | } 211 | return sb.toString(); 212 | } 213 | return ""; 214 | } 215 | 216 | public static String downloadImg(String imgUrl, String path) { 217 | try { 218 | logger.debug("imgUrl:{}\r\npath:{}",imgUrl,path); 219 | URL url = new URL(imgUrl); 220 | //链接网络地址 221 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 222 | //获取链接的输出流 223 | InputStream is = connection.getInputStream(); 224 | //创建文件,fileName为编码之前的文件名 225 | File file = new File(path); 226 | if (!file.getParentFile().exists()) { 227 | file.getParentFile().mkdirs(); 228 | } 229 | //根据输入流写入文件 230 | FileOutputStream out = new FileOutputStream(file); 231 | int i = 0; 232 | while ((i = is.read()) != -1) { 233 | out.write(i); 234 | } 235 | out.close(); 236 | is.close(); 237 | return path; 238 | }catch (Exception e) { 239 | logger.debug("抓取图片异常imgUrl:{}\r\npath:{}",imgUrl,path,e); 240 | } 241 | return null; 242 | 243 | } 244 | 245 | 246 | } 247 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/entity/Order.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.entity; 2 | 3 | import cn.enilu.elm.api.entity.sub.OrderBasket; 4 | import cn.enilu.elm.api.entity.sub.OrderStatusBar; 5 | import cn.enilu.elm.api.entity.sub.OrderTimelineNode; 6 | import org.springframework.data.annotation.Id; 7 | import org.springframework.data.mongodb.core.mapping.Document; 8 | 9 | /** 10 | * Created on 2018/1/5 0005. 11 | * todo 未完成 12 | * @author zt 13 | */ 14 | @Document(collection = "orders") 15 | public class Order implements BaseEntity { 16 | @Id 17 | private String _id; 18 | private Long id; 19 | private Double total_amount; 20 | private Double total_quantity; 21 | private Long unique_id; 22 | private Long user_id; 23 | private Long address_id; 24 | private Integer top_show=0; 25 | private OrderBasket basket = new OrderBasket(); 26 | private OrderStatusBar status_bar; 27 | private OrderTimelineNode timeline_node; 28 | private String formatted_create_at; 29 | private Double order_time; 30 | private Integer time_pass; 31 | private Integer is_brand; 32 | private Integer is_deletable; 33 | private Integer is_new_pay; 34 | private Integer is_pindan; 35 | private Integer operation_confirm; 36 | private Integer operation_rate; 37 | private Integer operation_rebuy; 38 | private Integer operation_upload_photo; 39 | private Integer pay_remain_seconds; 40 | private Integer rated_point; 41 | private Integer remind_reply_count; 42 | private Long restaurant_id; 43 | private String restaurant_image_hash; 44 | private String restaurant_image_url; 45 | private String restaurant_name; 46 | private Integer restaurant_type; 47 | private Integer status_code; 48 | 49 | public Long getId() { 50 | return id; 51 | } 52 | 53 | public void setId(Long id) { 54 | this.id = id; 55 | } 56 | 57 | public Double getTotal_amount() { 58 | return total_amount; 59 | } 60 | 61 | public void setTotal_amount(Double total_amount) { 62 | this.total_amount = total_amount; 63 | } 64 | 65 | public Double getTotal_quantity() { 66 | return total_quantity; 67 | } 68 | 69 | public void setTotal_quantity(Double total_quantity) { 70 | this.total_quantity = total_quantity; 71 | } 72 | 73 | public Long getUnique_id() { 74 | return unique_id; 75 | } 76 | 77 | public void setUnique_id(Long unique_id) { 78 | this.unique_id = unique_id; 79 | } 80 | 81 | public Long getUser_id() { 82 | return user_id; 83 | } 84 | 85 | public void setUser_id(Long user_id) { 86 | this.user_id = user_id; 87 | } 88 | 89 | public Long getAddress_id() { 90 | return address_id; 91 | } 92 | 93 | public void setAddress_id(Long address_id) { 94 | this.address_id = address_id; 95 | } 96 | 97 | public Integer getTop_show() { 98 | return top_show; 99 | } 100 | 101 | public void setTop_show(Integer top_show) { 102 | this.top_show = top_show; 103 | } 104 | 105 | public OrderBasket getBasket() { 106 | return basket; 107 | } 108 | 109 | public void setBasket(OrderBasket basket) { 110 | this.basket = basket; 111 | } 112 | 113 | public OrderStatusBar getStatus_bar() { 114 | return status_bar; 115 | } 116 | 117 | public void setStatus_bar(OrderStatusBar status_bar) { 118 | this.status_bar = status_bar; 119 | } 120 | 121 | public OrderTimelineNode getTimeline_node() { 122 | return timeline_node; 123 | } 124 | 125 | public void setTimeline_node(OrderTimelineNode timeline_node) { 126 | this.timeline_node = timeline_node; 127 | } 128 | 129 | public String getFormatted_create_at() { 130 | return formatted_create_at; 131 | } 132 | 133 | public void setFormatted_create_at(String formatted_create_at) { 134 | this.formatted_create_at = formatted_create_at; 135 | } 136 | 137 | public Double getOrder_time() { 138 | return order_time; 139 | } 140 | 141 | public void setOrder_time(Double order_time) { 142 | this.order_time = order_time; 143 | } 144 | 145 | public Integer getTime_pass() { 146 | return time_pass; 147 | } 148 | 149 | public void setTime_pass(Integer time_pass) { 150 | this.time_pass = time_pass; 151 | } 152 | 153 | public Integer getIs_brand() { 154 | return is_brand; 155 | } 156 | 157 | public void setIs_brand(Integer is_brand) { 158 | this.is_brand = is_brand; 159 | } 160 | 161 | public Integer getIs_deletable() { 162 | return is_deletable; 163 | } 164 | 165 | public void setIs_deletable(Integer is_deletable) { 166 | this.is_deletable = is_deletable; 167 | } 168 | 169 | public Integer getIs_new_pay() { 170 | return is_new_pay; 171 | } 172 | 173 | public void setIs_new_pay(Integer is_new_pay) { 174 | this.is_new_pay = is_new_pay; 175 | } 176 | 177 | public Integer getIs_pindan() { 178 | return is_pindan; 179 | } 180 | 181 | public void setIs_pindan(Integer is_pindan) { 182 | this.is_pindan = is_pindan; 183 | } 184 | 185 | public Integer getOperation_confirm() { 186 | return operation_confirm; 187 | } 188 | 189 | public void setOperation_confirm(Integer operation_confirm) { 190 | this.operation_confirm = operation_confirm; 191 | } 192 | 193 | public Integer getOperation_rate() { 194 | return operation_rate; 195 | } 196 | 197 | public void setOperation_rate(Integer operation_rate) { 198 | this.operation_rate = operation_rate; 199 | } 200 | 201 | public Integer getOperation_rebuy() { 202 | return operation_rebuy; 203 | } 204 | 205 | public void setOperation_rebuy(Integer operation_rebuy) { 206 | this.operation_rebuy = operation_rebuy; 207 | } 208 | 209 | public Integer getOperation_upload_photo() { 210 | return operation_upload_photo; 211 | } 212 | 213 | public void setOperation_upload_photo(Integer operation_upload_photo) { 214 | this.operation_upload_photo = operation_upload_photo; 215 | } 216 | 217 | public Integer getPay_remain_seconds() { 218 | return pay_remain_seconds; 219 | } 220 | 221 | public void setPay_remain_seconds(Integer pay_remain_seconds) { 222 | this.pay_remain_seconds = pay_remain_seconds; 223 | } 224 | 225 | public Integer getRated_point() { 226 | return rated_point; 227 | } 228 | 229 | public void setRated_point(Integer rated_point) { 230 | this.rated_point = rated_point; 231 | } 232 | 233 | public Integer getRemind_reply_count() { 234 | return remind_reply_count; 235 | } 236 | 237 | public void setRemind_reply_count(Integer remind_reply_count) { 238 | this.remind_reply_count = remind_reply_count; 239 | } 240 | 241 | public String get_id() { 242 | return _id; 243 | } 244 | 245 | public void set_id(String _id) { 246 | this._id = _id; 247 | } 248 | 249 | public Long getRestaurant_id() { 250 | return restaurant_id; 251 | } 252 | 253 | public void setRestaurant_id(Long restaurant_id) { 254 | this.restaurant_id = restaurant_id; 255 | } 256 | 257 | public String getRestaurant_image_hash() { 258 | return restaurant_image_hash; 259 | } 260 | 261 | public void setRestaurant_image_hash(String restaurant_image_hash) { 262 | this.restaurant_image_hash = restaurant_image_hash; 263 | } 264 | 265 | public String getRestaurant_image_url() { 266 | return restaurant_image_url; 267 | } 268 | 269 | public void setRestaurant_image_url(String restaurant_image_url) { 270 | this.restaurant_image_url = restaurant_image_url; 271 | } 272 | 273 | public String getRestaurant_name() { 274 | return restaurant_name; 275 | } 276 | 277 | public void setRestaurant_name(String restaurant_name) { 278 | this.restaurant_name = restaurant_name; 279 | } 280 | 281 | public Integer getRestaurant_type() { 282 | return restaurant_type; 283 | } 284 | 285 | public void setRestaurant_type(Integer restaurant_type) { 286 | this.restaurant_type = restaurant_type; 287 | } 288 | 289 | public Integer getStatus_code() { 290 | return status_code; 291 | } 292 | 293 | public void setStatus_code(Integer status_code) { 294 | this.status_code = status_code; 295 | } 296 | } 297 | -------------------------------------------------------------------------------- /src/main/java/cn/enilu/elm/api/controller/ShopController.java: -------------------------------------------------------------------------------- 1 | package cn.enilu.elm.api.controller; 2 | 3 | import cn.enilu.elm.api.entity.Ids; 4 | import cn.enilu.elm.api.entity.Menu; 5 | import cn.enilu.elm.api.entity.Shop; 6 | import cn.enilu.elm.api.repository.BaseDao; 7 | import cn.enilu.elm.api.service.IdsService; 8 | import cn.enilu.elm.api.service.PositionService; 9 | import cn.enilu.elm.api.utils.Maps; 10 | import cn.enilu.elm.api.vo.CityInfo; 11 | import cn.enilu.elm.api.vo.Rets; 12 | import com.google.common.collect.Lists; 13 | import org.nutz.json.Json; 14 | import org.nutz.lang.Strings; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.data.geo.GeoResult; 17 | import org.springframework.data.geo.GeoResults; 18 | import org.springframework.web.bind.annotation.*; 19 | 20 | import javax.servlet.http.HttpServletRequest; 21 | import java.util.*; 22 | 23 | /** 24 | * Created on 2018/1/2 0002. 25 | * 26 | * @author zt 27 | */ 28 | @RestController 29 | @RequestMapping("/shopping") 30 | public class ShopController extends BaseController { 31 | @Autowired 32 | private BaseDao baseDao; 33 | @Autowired 34 | private IdsService idsService; 35 | @Autowired 36 | private PositionService positionService; 37 | @RequestMapping(value = "/restaurant/{id}",method = RequestMethod.GET) 38 | 39 | public Object getShop(@PathVariable("id")Long id) { 40 | Object data = baseDao.findOne(id,"shops"); 41 | return data ; 42 | } 43 | 44 | @RequestMapping(value = "restaurants",method = RequestMethod.GET) 45 | 46 | public Object listShop(@RequestParam("latitude") String latitude, @RequestParam("longitude") String longitude, 47 | @RequestParam( "offset") Integer offset, 48 | @RequestParam("limit") Integer limit) { 49 | if (com.google.common.base.Strings.isNullOrEmpty(latitude) || "undefined".equals(latitude) 50 | || com.google.common.base.Strings.isNullOrEmpty(longitude) || "undefined".equals(longitude)) { 51 | return baseDao.findAll("shops"); 52 | } else { 53 | //查询指定经纬度范围内的餐厅 54 | GeoResults geoResults = baseDao.near(Double.valueOf(longitude),Double.valueOf(latitude),"shops"); 55 | List> geoResultList = geoResults.getContent(); 56 | List list = Lists.newArrayList(); 57 | for(int i=0;i updateMap = new HashMap(16); 82 | updateMap.put("name", Strings.sNull(data.get("name"))); 83 | updateMap.put("address", Strings.sNull(data.get("address"))); 84 | updateMap.put("description", Strings.sNull(data.get("description"))); 85 | updateMap.put("category", Strings.sNull(data.get("category"))); 86 | updateMap.put("phone", Strings.sNull(data.get("phone"))); 87 | updateMap.put("rating", Double.valueOf(data.get("rating").toString())); 88 | updateMap.put("recent_order_num", Integer.valueOf(data.get("recent_order_num").toString())); 89 | updateMap.put("image_path", Strings.sNull(data.get("image_path"))); 90 | baseDao.update(Long.valueOf(data.get("id").toString()), "shops", updateMap); 91 | return Rets.success(); 92 | } 93 | 94 | @RequestMapping(value = "/addShop",method = RequestMethod.POST) 95 | 96 | public Object addShop(HttpServletRequest request) { 97 | String json = getRequestPayload(); 98 | Map data = (Map) Json.fromJson(json); 99 | Shop shop = Json.fromJson(Shop.class, json); 100 | shop.setId(idsService.getId(Ids.RESTAURANT_ID)); 101 | List supports = new ArrayList(4); 102 | if ((boolean) data.get("bao")) { 103 | supports.add(buildSupport("已加入“外卖保”计划,食品安全有保障", "999999", "保", 7, "外卖保")); 104 | } 105 | if ((boolean) data.get("zhun")) { 106 | supports.add(buildSupport("准时必达,超时秒赔", "57A9FF", "准", 9, "准时达")); 107 | } 108 | if ((boolean) data.get("piao")) { 109 | supports.add(buildSupport("该商家支持开发票,请在下单时填写好发票抬头", "999999", "票", 4, "开发票")); 110 | } 111 | shop.setSupports(supports); 112 | shop.setIs_new((boolean) data.get("new")); 113 | 114 | if ((boolean) data.get("delivery_mode")) { 115 | Map deliveryMode = Maps.newHashMap("color", "57A9FF", "id", 1, "is_solid", true, "text", "蜂鸟专送"); 116 | shop.setDelivery_mode(deliveryMode); 117 | } 118 | Map tips = new HashMap(2); 119 | tips.put("tips", "配送费约¥" + data.get("float_delivery_fee")); 120 | shop.setPiecewise_agent_fee(tips); 121 | List openingHours = new ArrayList(); 122 | if (Strings.isNotBlank(Strings.sNull(data.get("startTime"))) && 123 | Strings.isNotBlank(Strings.sNull(data.get("endTime")))) { 124 | openingHours.add(data.get("startTime").toString() + "/" + data.get("endTime").toString()); 125 | } else { 126 | openingHours.add("08:30/20:30"); 127 | } 128 | 129 | shop.setOpening_hours(openingHours); 130 | 131 | Map license = new HashMap(); 132 | if (Strings.isNotBlank(Strings.sNull(data.get("business_license_image")))) { 133 | license.put("business_license_image", data.get("business_license_image").toString()); 134 | } 135 | if (Strings.isNotBlank(Strings.sNull(data.get("catering_service_license_image")))) { 136 | license.put("catering_service_license_image", data.get("catering_service_license_image").toString()); 137 | } 138 | shop.setLicense(license); 139 | 140 | 141 | Map identification = Maps.newHashMap("company_name", "", 142 | "identificate_agency", "", 143 | "identificate_date", "", 144 | "legal_person", "", 145 | "licenses_date", "", 146 | "licenses_number", "", 147 | "licenses_scope", "", 148 | "operation_period", "", 149 | "registered_address", "", 150 | "registered_number", ""); 151 | shop.setIdentification(identification); 152 | 153 | List activities = (List) data.get("activities"); 154 | int index = 0; 155 | for (int i = 0; i < activities.size(); i++) { 156 | Map activity = (Map) activities.get(i); 157 | String iconName = activity.get("icon_name").toString(); 158 | switch (iconName) { 159 | case "减": 160 | activity.put("icon_color", "f07373"); 161 | activity.put("id", index++); 162 | break; 163 | case "特": 164 | activity.put("icon_color", "EDC123"); 165 | activity.put("id", index++); 166 | break; 167 | case "新": 168 | activity.put("icon_color ", "70bc46"); 169 | activity.put("id", index++); 170 | break; 171 | case "领": 172 | activity.put("icon_color ", "E3EE0D"); 173 | activity.put("id ", index++); 174 | break; 175 | default: 176 | break; 177 | } 178 | } 179 | shop.setActivities(activities); 180 | 181 | CityInfo cityInfo = positionService.getPostion(getIp()); 182 | if (cityInfo != null) { 183 | shop.setLatitude(Double.valueOf(cityInfo.getLat())); 184 | shop.setLongitude(Double.valueOf(cityInfo.getLng())); 185 | List locations = new LinkedList(); 186 | locations.add(Double.valueOf(cityInfo.getLng())); 187 | locations.add(Double.valueOf(cityInfo.getLat())); 188 | shop.setLocation(locations); 189 | } 190 | baseDao.save(shop); 191 | 192 | return Rets.success(); 193 | } 194 | 195 | @RequestMapping(value = "addcategory",method = RequestMethod.POST) 196 | 197 | public Object addCategory(HttpServletRequest request) { 198 | Menu menu = getRequestPayload( Menu.class); 199 | menu.setId(idsService.getId(Ids.CATEGORY_ID)); 200 | System.out.println(Json.toJson(menu)); 201 | //todo 进行处理后保存 202 | baseDao.save(menu); 203 | return Rets.success(); 204 | } 205 | @RequestMapping(value = "/v2/restaurant/category",method = RequestMethod.GET) 206 | 207 | public Object categories() { 208 | return baseDao.findAll("categories"); 209 | } 210 | 211 | @RequestMapping(value = "/getcategory/{id}",method = RequestMethod.GET) 212 | 213 | public Object getCategory(@PathVariable("id") Long restaurantId) { 214 | List list = baseDao.findAll("menus", "restaurant_id", restaurantId); 215 | return Rets.success("category_list", list); 216 | } 217 | 218 | 219 | @RequestMapping(value = "/v2/menu{id}",method = RequestMethod.GET) 220 | 221 | public Object getMenus(@PathVariable("id")Long id){ 222 | return baseDao.findOne(id,"menus"); 223 | } 224 | @RequestMapping(value = "/v2/menu",method = RequestMethod.GET) 225 | 226 | public Object getMenu(@RequestParam("restaurant_id")Long restaurantId, @RequestParam("allMenu")boolean allMEnu){ 227 | return baseDao.findAll("menus","restaurant_id",restaurantId); 228 | } 229 | 230 | 231 | private Map buildSupport(String description, String iconColor, String iconName, Integer id, String name) { 232 | Map map = new HashMap(8); 233 | map.put("description", description); 234 | map.put("icon_color", iconColor); 235 | map.put("icon_name", iconName); 236 | map.put("id", id); 237 | map.put("name", name); 238 | return map; 239 | } 240 | } 241 | --------------------------------------------------------------------------------