潘海瑞 9 maanden geleden
bovenliggende
commit
85d3c6b6a1
20 gewijzigde bestanden met toevoegingen van 330 en 19 verwijderingen
  1. 7 0
      sky-pojo/src/main/java/com/sky/dto/DishDTO.java
  2. 6 0
      sky-pojo/src/main/java/com/sky/entity/Dish.java
  3. 34 0
      sky-pojo/src/main/java/com/sky/entity/Employee.java
  4. 49 0
      sky-pojo/src/main/java/com/sky/entity/TDemoland.java
  5. 3 3
      sky-server/src/main/java/com/sky/controller/admin/DishController.java
  6. 14 4
      sky-server/src/main/java/com/sky/controller/admin/EmployeeController.java
  7. 12 0
      sky-server/src/main/java/com/sky/controller/admin/MinAppController.java
  8. 30 0
      sky-server/src/main/java/com/sky/controller/user/ShoppingCartController.java
  9. 3 2
      sky-server/src/main/java/com/sky/interceptor/JwtTokenAdminInterceptor.java
  10. 9 1
      sky-server/src/main/java/com/sky/mapper/EmployeeMapper.java
  11. 33 0
      sky-server/src/main/java/com/sky/mapper/ShoppingCartMapper.java
  12. 2 0
      sky-server/src/main/java/com/sky/service/EmployeeService.java
  13. 11 0
      sky-server/src/main/java/com/sky/service/ShoppingCartService.java
  14. 3 3
      sky-server/src/main/java/com/sky/service/impl/DishServiceImpl.java
  15. 14 2
      sky-server/src/main/java/com/sky/service/impl/EmployeeServiceImpl.java
  16. 73 0
      sky-server/src/main/java/com/sky/service/impl/ShoppingCartServiceImpl.java
  17. 1 1
      sky-server/src/main/java/com/sky/service/impl/UserServiceImpl.java
  18. 1 1
      sky-server/src/main/resources/application-dev.yml
  19. 2 2
      sky-server/src/main/resources/mapper/DishMapper.xml
  20. 23 0
      sky-server/src/main/resources/mapper/ShoppingCartMapper.xml

+ 7 - 0
sky-pojo/src/main/java/com/sky/dto/DishDTO.java

@@ -4,6 +4,7 @@ import com.sky.entity.DishFlavor;
 import lombok.Data;
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -26,4 +27,10 @@ public class DishDTO implements Serializable {
     //口味
     private List<DishFlavor> flavors = new ArrayList<>();
 
+    private String author;
+    private String site;
+    private LocalDateTime pzdt;
+    private String imgurl;
+    private String bz;
+
 }

+ 6 - 0
sky-pojo/src/main/java/com/sky/entity/Dish.java

@@ -47,4 +47,10 @@ public class Dish implements Serializable {
 
     private Long updateUser;
 
+    private String author;
+    private String site;
+    private LocalDateTime pzdt;
+    private String imgurl;
+    private String bz;
+
 }

+ 34 - 0
sky-pojo/src/main/java/com/sky/entity/Employee.java

@@ -43,4 +43,38 @@ public class Employee implements Serializable {
 
     private Long updateUser;
 
+
+    //智慧田
+    private int bh;
+
+    private String city;
+
+
+    private String xian;
+
+
+    private String sflb;
+
+    private String yearmode;
+
+
+    private String site;
+
+
+    private float lat;
+
+
+    private float lng;
+
+
+    private int area;
+
+
+    private String experts;
+
+
+    private String year;
+
+
+    private String lx;
 }

+ 49 - 0
sky-pojo/src/main/java/com/sky/entity/TDemoland.java

@@ -0,0 +1,49 @@
+/*
+package com.sky.entity;
+
+import nonapi.io.github.classgraph.json.Id;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "t_demoland")
+public class TDemoland {
+    @Id
+    @Column(name = "bh")
+    private int bh;
+    @Column(name = "city")
+    private String city;
+
+    @Column(name = "xian")
+    private String xian;
+
+    @Column(name = "sflb")
+    private String sflb;
+
+    @Column(name = "yearmode")
+    private String yearmode;
+
+    @Column(name = "site")
+    private String site;
+
+    @Column(name = "lat")
+    private float lat;
+
+    @Column(name = "lng")
+    private float lng;
+
+    @Column(name = "area")
+    private int area;
+
+    @Column(name = "experts")
+    private String experts;
+
+    @Column(name = "year")
+    private String year;
+
+    @Column(name = "lx")
+    private String lx;
+}
+*/

+ 3 - 3
sky-server/src/main/java/com/sky/controller/admin/DishController.java

@@ -33,11 +33,11 @@ public class DishController {
      */
     @PostMapping
     public Result save(@RequestBody DishDTO dishDTO){
-        log.info("新增菜品:{}",dishDTO);
+        log.info("上传图片:{}",dishDTO);
         dishService.saveWithFlavor(dishDTO);
         //清理缓存数据
-        String key = "dish" + dishDTO.getCategoryId();
-        cleanCache(key);
+        /*String key = "dish" + dishDTO.getCategoryId();
+        cleanCache(key);*/
         return Result.success();
     }
 

+ 14 - 4
sky-server/src/main/java/com/sky/controller/admin/EmployeeController.java

@@ -17,7 +17,9 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -41,13 +43,13 @@ public class EmployeeController {
      * @return
      */
     @PostMapping("/login")
-    public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
+    public Result login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
         log.info("员工登录:{}", employeeLoginDTO);
 
         Employee employee = employeeService.login(employeeLoginDTO);
 
         //登录成功后,生成jwt令牌
-        Map<String, Object> claims = new HashMap<>();
+        /*Map<String, Object> claims = new HashMap<>();
         claims.put(JwtClaimsConstant.EMP_ID, employee.getId());
         String token = JwtUtil.createJWT(
                 jwtProperties.getAdminSecretKey(),
@@ -59,9 +61,17 @@ public class EmployeeController {
                 .userName(employee.getUsername())
                 .name(employee.getName())
                 .token(token)
-                .build();
+                .build();*/
+
+        return Result.success(employee);
+    }
+
+
+    @GetMapping("/location")
+    public List<Result> getlocation(@RequestParam double volatitude, @RequestParam double volongitude){
+        ArrayList<Object> list = new ArrayList<>();
+        return Result.success(employeeService.getlocation(volatitude,volongitude));
 
-        return Result.success(employeeLoginVO);
     }
 
     /**

+ 12 - 0
sky-server/src/main/java/com/sky/controller/admin/MinAppController.java

@@ -0,0 +1,12 @@
+package com.sky.controller.admin;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/admin/minapp")
+@Slf4j
+public class MinAppController {
+
+}

+ 30 - 0
sky-server/src/main/java/com/sky/controller/user/ShoppingCartController.java

@@ -0,0 +1,30 @@
+package com.sky.controller.user;
+
+import com.sky.dto.ShoppingCartDTO;
+import com.sky.result.Result;
+import com.sky.service.ShoppingCartService;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("/user/shoppingCart")
+@RestController
+@Slf4j
+public class ShoppingCartController {
+    @Autowired
+    private ShoppingCartService shoppingCartService;
+    /**
+     * 添加购物车
+     * @param shoppingCartDTO
+     * @return
+     */
+    @PostMapping("/add")
+    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
+        shoppingCartService.add(shoppingCartDTO);
+        return Result.success();
+    }
+}

+ 3 - 2
sky-server/src/main/java/com/sky/interceptor/JwtTokenAdminInterceptor.java

@@ -33,8 +33,9 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
      * @throws Exception
      */
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        return true;
         //判断当前拦截到的是Controller的方法还是其他资源
-        if (!(handler instanceof HandlerMethod)) {
+        /*if (!(handler instanceof HandlerMethod)) {
             //当前拦截到的不是动态方法,直接放行
             return true;
         }
@@ -55,6 +56,6 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
             //4、不通过,响应401状态码
             response.setStatus(401);
             return false;
-        }
+        }*/
     }
 }

+ 9 - 1
sky-server/src/main/java/com/sky/mapper/EmployeeMapper.java

@@ -13,15 +13,17 @@ public interface EmployeeMapper {
 
     /**
      * 根据用户名查询员工
+     *
      * @param username
      * @return
      */
-    @Select("select * from employee where username = #{username}")
+    @Select("select * from t_expert where username = #{username}")
     Employee getByUsername(String username);
 
 
     /**
      * 插入员工数据
+     *
      * @param employee
      */
     @Select("insert into employee (name, username, password, phone, " +
@@ -34,6 +36,7 @@ public interface EmployeeMapper {
 
     /**
      * 分页查询
+     *
      * @param employeePageQueryDTO
      * @return
      */
@@ -41,6 +44,7 @@ public interface EmployeeMapper {
 
     /**
      * 根据主键动态修改属性
+     *
      * @param employee
      */
     @AutoFill(value = OperationType.UPDATE)
@@ -48,9 +52,13 @@ public interface EmployeeMapper {
 
     /**
      * 根据id查询员工
+     *
      * @param id
      * @return
      */
     @Select("select * from employee where id = #{id}")
     Employee getById(Integer id);
+
+    @Select("SELECT * FROM t_loc64 WHERE SQRT( POW(PI() * 12656 * COS((#{volatitude} + lat) * PI() / 360) * (#{volongitude} - lng) / 180, 2) + POW(PI() * 12656 * ((#{volatitude} - lat) / 180), 2) ) < 100 ")
+    Employee getLocation( double volatitude, double volongitude);
 }

+ 33 - 0
sky-server/src/main/java/com/sky/mapper/ShoppingCartMapper.java

@@ -0,0 +1,33 @@
+package com.sky.mapper;
+
+import com.sky.entity.ShoppingCart;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import java.util.List;
+
+@Mapper
+public interface ShoppingCartMapper {
+    /**
+     * 动态查询购物车
+     *
+     * @param shoppingCart
+     * @return
+     */
+    List<ShoppingCart> list(ShoppingCart shoppingCart);
+
+
+    @Update("update shopping_cart set number = #{number} where id = #{id}")
+    void updateNumberById(ShoppingCart shoppingCart);
+
+    /**
+     * 插入购物车
+     * @param shoppingCart
+     */
+    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time)" +
+            " VALUES " +
+            "(#{name},#{image},#{userTd},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
+    void insert(ShoppingCart shoppingCart);
+}

+ 2 - 0
sky-server/src/main/java/com/sky/service/EmployeeService.java

@@ -47,4 +47,6 @@ public interface EmployeeService {
      * @param employeeDTO
      */
     void update(EmployeeDTO employeeDTO);
+
+    Employee getlocation(double volatitude, double volongitude);
 }

+ 11 - 0
sky-server/src/main/java/com/sky/service/ShoppingCartService.java

@@ -0,0 +1,11 @@
+package com.sky.service;
+
+import com.sky.dto.ShoppingCartDTO;
+
+public interface ShoppingCartService {
+    /**
+     * 添加购物车
+     * @param shoppingCartDTO
+     */
+    void add(ShoppingCartDTO shoppingCartDTO);
+}

+ 3 - 3
sky-server/src/main/java/com/sky/service/impl/DishServiceImpl.java

@@ -47,17 +47,17 @@ public class DishServiceImpl implements DishService {
         dishMapper.insert(dish);
 
         //获取insert语句生成的主键值
-        Long dishId = dish.getId();
+        //Long dishId = dish.getId();
 
 
-        List<DishFlavor> flavors = dishDTO.getFlavors();
+        /*List<DishFlavor> flavors = dishDTO.getFlavors();
         if(flavors != null && flavors.size() > 0){
             flavors.forEach(dishFlavor -> {
                 dishFlavor.setDishId(dishId);
             });
             //向口味表插入n条数据
             dishFlavorsMapper.insertBatch(flavors);
-        }
+        }*/
 
     }
 

+ 14 - 2
sky-server/src/main/java/com/sky/service/impl/EmployeeServiceImpl.java

@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.DigestUtils;
 
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -51,8 +52,8 @@ public class EmployeeServiceImpl implements EmployeeService {
 
         //密码比对
         // 对前端传来的明文密码进行md5加密处理
-        password = DigestUtils.md5DigestAsHex(password.getBytes());
-        if (!password.equals(employee.getPassword())) {
+        //password = DigestUtils.md5DigestAsHex(password.getBytes());
+        if (!password.equals(employee.getPhone())) {
             //密码错误
             throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
         }
@@ -67,6 +68,7 @@ public class EmployeeServiceImpl implements EmployeeService {
     }
 
 
+
     /**
      * 新增员工
      * @param employeeDTO
@@ -158,4 +160,14 @@ public class EmployeeServiceImpl implements EmployeeService {
         employeeMapper.update(employee);
     }
 
+    @Override
+    public List<Employee> getlocation(double volatitude, double volongitude) {
+        ArrayList<Employee> employeelist = new ArrayList<>();
+
+        Employee employee = employeeMapper.getLocation(volatitude, volongitude);
+
+
+        return null;
+    }
+
 }

+ 73 - 0
sky-server/src/main/java/com/sky/service/impl/ShoppingCartServiceImpl.java

@@ -0,0 +1,73 @@
+package com.sky.service.impl;
+
+import com.sky.context.BaseContext;
+import com.sky.dto.ShoppingCartDTO;
+import com.sky.entity.Dish;
+import com.sky.entity.Setmeal;
+import com.sky.entity.ShoppingCart;
+import com.sky.mapper.DishMapper;
+import com.sky.mapper.SetmealMapper;
+import com.sky.mapper.ShoppingCartMapper;
+import com.sky.service.DishService;
+import com.sky.service.ShoppingCartService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Service
+public class ShoppingCartServiceImpl implements ShoppingCartService {
+    @Autowired
+    private ShoppingCartMapper shoppingCartMapper;
+    @Autowired
+    private DishMapper dishMapper;
+    @Autowired
+    private SetmealMapper setmealMapper;
+    /**
+     * 添加购物车
+     * @param shoppingCartDTO
+     */
+    @Override
+    public void add(ShoppingCartDTO shoppingCartDTO) {
+
+        //先获取购物车内的数据
+        ShoppingCart shoppingCart = new ShoppingCart();
+        BeanUtils.copyProperties(shoppingCartDTO,shoppingCart);
+        Long userId = BaseContext.getCurrentId();
+        shoppingCart.setUserId(userId);
+
+        List<ShoppingCart> list =  shoppingCartMapper.list(shoppingCart);
+        //如果购物车内存在需要添加的物品,那么只需要将数量加1,再更新
+        if (list != null && list.size() > 0){
+            ShoppingCart cart = list.get(0);
+            cart.setNumber(cart.getNumber() + 1);//需要在数据库更新
+            shoppingCartMapper.updateNumberById(cart);
+        }else {
+            //如果购物车内没有要添加的物品,需要将物品信息插入购物车
+            //判断本次添加到购物车的是菜品还是套餐
+            Long dishId = shoppingCartDTO.getDishId();
+            if (dishId != null){
+                //本次添加到购物车的是菜品
+                Dish dish = dishMapper.getById(dishId);
+                shoppingCart.setName(dish.getName());
+                shoppingCart.setImage(dish.getImage());
+                shoppingCart.setAmount(dish.getPrice());
+
+            }else {
+                //本次添加到购物车的是套餐
+                Long setmealId = shoppingCartDTO.getSetmealId();
+                Setmeal setmeal = setmealMapper.getById(setmealId);
+
+                shoppingCart.setName(setmeal.getName());
+                shoppingCart.setImage(setmeal.getImage());
+                shoppingCart.setAmount(setmeal.getPrice());
+
+            }
+            shoppingCart.setNumber(1);
+            shoppingCart.setCreateTime(LocalDateTime.now());
+            shoppingCartMapper.insert(shoppingCart);
+        }
+    }
+}

+ 1 - 1
sky-server/src/main/java/com/sky/service/impl/UserServiceImp.java → sky-server/src/main/java/com/sky/service/impl/UserServiceImpl.java

@@ -20,7 +20,7 @@ import java.util.Map;
 
 @Service
 @Slf4j
-public class UserServiceImp implements UserService {
+public class UserServiceImpl implements UserService {
 
     @Autowired
     private UserMapper userMapper;

+ 1 - 1
sky-server/src/main/resources/application-dev.yml

@@ -3,7 +3,7 @@ sky:
     driver-class-name: com.mysql.cj.jdbc.Driver
     host: localhost
     port: 3306
-    database: sky_take_out
+    database: plantmap
     username: root
     password: 1234
   alioss:

+ 2 - 2
sky-server/src/main/resources/mapper/DishMapper.xml

@@ -4,9 +4,9 @@
 <mapper namespace="com.sky.mapper.DishMapper">
 
     <insert id="insert" useGeneratedKeys="true" keyProperty="id">/*获得插入数据的主键值*/
-        insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user, status)
+        insert into t_landimg (author, site, pzdt, imgurl, bz)
         VALUES
-            (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser},#{status})
+            (#{author},#{site},#{pzdt},#{imgurl},#{bz})
 
     </insert>
     <!--修改菜品信息-->

+ 23 - 0
sky-server/src/main/resources/mapper/ShoppingCartMapper.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.sky.mapper.ShoppingCartMapper">
+
+    <select id="list" resultType="com.sky.entity.ShoppingCart">
+        select * from shopping_cart
+        <where>
+            <if test="dish_id != null">
+                and dish_id = #{dishId}
+            </if>
+            <if test="user_id != null">
+                and user_id = #{userId}
+            </if>
+            <if test="setmeal_id != null">
+                and setmeal_id = #{setmealId}
+            </if>
+            <if test="dish_flavor != null">
+                and dish_flavor = #{dishFlavor}
+            </if>
+        </where>
+    </select>
+</mapper>