Compare commits

..

No commits in common. "483ef1cabbdcbf7a63f7fc64468f0b8c985381aa" and "2892a48608ca2d845898d2ce868ba6ced5d2e105" have entirely different histories.

30 changed files with 118 additions and 632 deletions

View File

@ -25,7 +25,7 @@
<druid>1.2.1</druid>
<pagehelper>1.3.0</pagehelper>
<aliyun.sdk.oss>3.10.2</aliyun.sdk.oss>
<knife4j>3.0.3</knife4j>
<knife4j>3.0.2</knife4j>
<aspectj>1.9.4</aspectj>
<jjwt>0.9.1</jjwt>
<jaxb-api>2.3.1</jaxb-api>

View File

@ -6,8 +6,17 @@ import java.io.Serializable;
@Data
public class CategoryPageQueryDTO implements Serializable {
private int page;// 页码
private int pageSize;// 每页记录数
private String name;// 分类名称
private Integer type;//分类类型 1菜品分类 2套餐分类
//页码
private int page;
//每页记录数
private int pageSize;
//分类名称
private String name;
//分类类型 1菜品分类 2套餐分类
private Integer type;
}

View File

@ -115,13 +115,6 @@
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<!-- minio -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.5.2</version>
</dependency>
</dependencies>
<build>

View File

@ -1,16 +0,0 @@
package com.sky.annotation;
import com.sky.enumeration.OperationType;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
// 自定义注解用于表示某个方法需要进行字段自动填充处理
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoFill {
// 数据库操作类型UPDATE INSERT
OperationType value();
}

View File

@ -1,73 +0,0 @@
package com.sky.aspect;
import com.sky.annotation.AutoFill;
import com.sky.constant.AutoFillConstant;
import com.sky.context.BaseContext;
import com.sky.enumeration.OperationType;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.time.LocalTime;
// 自定义切面实现公共字段自动填充
@Aspect
@Component
@Slf4j
public class AutoFillAspect {
@Pointcut("execution(* com.sky.mapper.*.*(..)) && @annotation(com.sky.annotation.AutoFill)")
public void autoFillPointCut() {
}
@Before("autoFillPointCut()")
public void autoFill(JoinPoint joinPoint) {
log.info("开始进行自动填充");
// 获取当前被拦截数据库操作
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
AutoFill autoFill = signature.getMethod().getAnnotation(AutoFill.class);
OperationType operationType = autoFill.value();
// 获取实体对象
Object[] args = joinPoint.getArgs();
if (args == null || args.length == 0) {
return;
}
Object entity = args[0];
// 准备赋值数据
LocalDateTime localDateTime = LocalDateTime.now();
Long id = BaseContext.getCurrentId();
// 根据当前不同的操作类型为对应属性来反射赋值
if (operationType == OperationType.INSERT) {
try {
Method setCreateTime = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_CREATE_TIME, LocalDateTime.class);
Method setCreateUser = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_CREATE_USER, Long.class);
Method setUpdateTime = entity.getClass().getMethod(AutoFillConstant.SET_UPDATE_TIME, LocalDateTime.class);
Method setUpdateUser = entity.getClass().getMethod(AutoFillConstant.SET_UPDATE_USER, Long.class);
setCreateTime.invoke(entity, localDateTime);
setCreateUser.invoke(entity, id);
setUpdateTime.invoke(entity, localDateTime);
setUpdateUser.invoke(entity, id);
} catch (Exception e) {
e.printStackTrace();
}
} else if (operationType == OperationType.UPDATE) {
try {
Method setUpdateTime = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_TIME, LocalDateTime.class);
Method setUpdateUser = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_USER, Long.class);
setUpdateTime.invoke(entity, localDateTime);
setUpdateUser.invoke(entity, id);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,22 +0,0 @@
package com.sky.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.minio.MinioClient;
@Data
@Configuration
@ConfigurationProperties(prefix = "sky.minio")
public class MinioConfig {
private String endpointUrl;
private String accessKey;
private String secretKey;
private String bucketName;
@Bean
public MinioClient minioClient() {
return MinioClient.builder().endpoint(endpointUrl).credentials(accessKey, secretKey).build();
}
}

View File

@ -9,9 +9,8 @@ import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
@ -23,18 +22,17 @@ import java.util.List;
@Slf4j
public class CategoryController {
@Resource
@Autowired
private CategoryService categoryService;
/**
* 新增分类
*
* @param categoryDTO CategoryDTO
* @return Result<String>
* @param categoryDTO
* @return
*/
@PostMapping("")
@PostMapping
@ApiOperation("新增分类")
public Result<String> save(@RequestBody CategoryDTO categoryDTO) {
public Result<String> save(@RequestBody CategoryDTO categoryDTO){
log.info("新增分类:{}", categoryDTO);
categoryService.save(categoryDTO);
return Result.success();
@ -42,13 +40,12 @@ public class CategoryController {
/**
* 分类分页查询
*
* @param categoryPageQueryDTO CategoryPageQueryDTO
* @return Result<PageResult>
* @param categoryPageQueryDTO
* @return
*/
@GetMapping("/page")
@ApiOperation("分类分页查询")
public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
log.info("分页查询:{}", categoryPageQueryDTO);
PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
return Result.success(pageResult);
@ -56,13 +53,12 @@ public class CategoryController {
/**
* 删除分类
*
* @param id Long
* @return Result<String>
* @param id
* @return
*/
@DeleteMapping
@ApiOperation("删除分类")
public Result<String> deleteById(Long id) {
public Result<String> deleteById(Long id){
log.info("删除分类:{}", id);
categoryService.deleteById(id);
return Result.success();
@ -70,40 +66,37 @@ public class CategoryController {
/**
* 修改分类
*
* @param categoryDTO CategoryDTO
* @return Result<String>
* @param categoryDTO
* @return
*/
@PutMapping
@ApiOperation("修改分类")
public Result<String> update(@RequestBody CategoryDTO categoryDTO) {
public Result<String> update(@RequestBody CategoryDTO categoryDTO){
categoryService.update(categoryDTO);
return Result.success();
}
/**
* 启用禁用分类
*
* @param status Integer
* @param id Long
* @return Result<String>
* @param status
* @param id
* @return
*/
@PostMapping("/status/{status}")
@ApiOperation("启用禁用分类")
public Result<String> startOrStop(@PathVariable("status") Integer status, Long id) {
categoryService.startOrStop(status, id);
public Result<String> startOrStop(@PathVariable("status") Integer status, Long id){
categoryService.startOrStop(status,id);
return Result.success();
}
/**
* 根据类型查询分类
*
* @param type Integer
* @return Result<List < Category>>
* @param type
* @return
*/
@GetMapping("/list")
@ApiOperation("根据类型查询分类")
public Result<List<Category>> list(Integer type) {
public Result<List<Category>> list(Integer type){
List<Category> list = categoryService.list(type);
return Result.success(list);
}

View File

@ -1,44 +0,0 @@
package com.sky.controller.admin;
import com.sky.constant.MessageConstant;
import com.sky.result.Result;
import com.sky.service.MinioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
@RestController
@RequestMapping("/admin/common")
@Api(tags = "通用接口")
@Slf4j
public class CommonController {
@Resource
private MinioService minioService;
/**
* 文件上传
*
* @param file MultipartFile
* @return Result<String>
*/
@ApiOperation(value = "文件上传")
@PostMapping("/upload")
public Result<String> upload(MultipartFile file) {
log.info("文件上传:{}", file);
try {
String filename = minioService.upload(file);
return Result.success(filename);
} catch (IOException e) {
log.info("文件上传失败");
return Result.error(MessageConstant.UPLOAD_FAILED);
}
}
}

View File

@ -1,37 +0,0 @@
package com.sky.controller.admin;
import com.sky.dto.DishDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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;
import javax.annotation.Resource;
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
@Slf4j
public class DishController {
@Resource
private DishService dishService;
/**
* 新增菜品和口味
*
* @param dishDTO DishDTO
* @return Result
*/
@ApiOperation("新增菜品")
@PostMapping("")
public Result<String > save(@RequestBody DishDTO dishDTO) {
log.info("新增菜品:{}", dishDTO);
dishService.saveWithFlavor(dishDTO);
return Result.success();
}
}

View File

@ -12,8 +12,9 @@ import com.sky.service.EmployeeService;
import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -40,7 +41,7 @@ public class EmployeeController {
* @param employeeLoginDTO EmployeeLoginDTO
* @return Result<EmployeeLoginVO>
*/
@ApiOperation(value = "员工登录接口")
@Operation(summary = "员工登录接口")
@PostMapping("/login")
public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
log.info("员工登录:{}", employeeLoginDTO);
@ -68,9 +69,9 @@ public class EmployeeController {
/**
* 退出
*
* @return Result<String>
* @return
*/
@ApiOperation(value = "员工退出登录")
@Operation(summary = "员工退出登录")
@PostMapping("/logout")
public Result<String> logout() {
return Result.success();
@ -82,7 +83,7 @@ public class EmployeeController {
* @param employeeDTO 请求新增员工参数
* @return Result
*/
@ApiOperation(value = "新增员工")
@Operation(summary = "新增员工")
@PostMapping
public Result<String> save(@RequestBody EmployeeDTO employeeDTO) {
log.info("新增员工:{}", employeeDTO);
@ -95,7 +96,7 @@ public class EmployeeController {
*
* @return Result<PageResult>
*/
@ApiOperation(value = "员工分页查询")
@Operation(summary = "员工分页查询")
@GetMapping("/page")
public Result<PageResult> pageResultResult(EmployeePageQueryDTO employeePageQueryDTO) {
log.info("员工查找,参数为:{}", employeeService);
@ -110,7 +111,7 @@ public class EmployeeController {
* @param id Long
* @return Result
*/
@ApiOperation(value = "启用或禁用员工账号")
@Operation(summary = "启用或禁用员工账号")
@PostMapping("/status/{status}")
public Result<String> startOrStop(@PathVariable Integer status, Long id) {
log.info("启用或禁用员工账号:{}{}", status, id);
@ -124,18 +125,18 @@ public class EmployeeController {
* @param id Integer
* @return Result<Employee>
*/
@ApiOperation(value = "根据id查询员工信息")
@Operation(summary = "根据id查询员工信息")
@GetMapping("/{id}")
public Result<Employee> getById(@PathVariable Integer id) {
Employee employee = employeeService.getById(id);
return Result.success(employee);
}
@ApiOperation(value = "编辑员工信息")
@Operation(summary = "编辑员工信息")
@PutMapping()
public Result<String> update(@RequestBody EmployeeDTO employeeDTO) {
public Result update(@RequestBody EmployeeDTO employeeDTO) {
log.info("编辑员工信息:{}", employeeDTO);
employeeService.update(employeeDTO);
return Result.success("成功");
return Result.success();
}
}

View File

@ -1,7 +1,6 @@
package com.sky.mapper;
import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.enumeration.OperationType;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
@ -15,35 +14,37 @@ public interface CategoryMapper {
/**
* 插入数据
* @param category Category
* @param category
*/
@AutoFill(value = OperationType.INSERT)
@Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)" +
" VALUES" +
" (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
void insert(Category category);
/**
* 分页查询
* @param categoryPageQueryDTO CategoryPageQueryDTO
* @return Page<Category>
* @param categoryPageQueryDTO
* @return
*/
Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
/**
* 根据id删除分类
* @param id Long
* @param id
*/
@Delete("delete from category where id = #{id}")
void deleteById(Long id);
/**
* 根据id修改分类
* @param category Category
* @param category
*/
@AutoFill(value = OperationType.UPDATE)
void update(Category category);
/**
* 根据类型查询分类
* @param type Integer
* @return List<Category>
* @param type
* @return
*/
List<Category> list(Integer type);
}

View File

@ -1,14 +0,0 @@
package com.sky.mapper;
import com.sky.entity.DishFlavor;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface DishFlavorMapper {
/**
* 香口味表中插入n条数据
* @param flavors List<DishFlavor>
*/
void insertBatch(List<DishFlavor> flavors);
}

View File

@ -1,8 +1,5 @@
package com.sky.mapper;
import com.sky.annotation.AutoFill;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@ -11,17 +8,10 @@ public interface DishMapper {
/**
* 根据分类id查询菜品数量
*
* @param categoryId Long
* @return Integer
*/
@Select("select count(id) from dish where category_id = #{categoryId}")
Integer countByCategoryId(Long categoryId);
/**
* 新增菜品和口味
*
* @param dish Dish
*/
@AutoFill(value = OperationType.INSERT)
void insert(Dish dish);
}

View File

@ -1,10 +1,8 @@
package com.sky.mapper;
import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@ -15,9 +13,10 @@ public interface EmployeeMapper {
/**
* 根据用户名查询员工
*
* @param username String
* @return Employee
* @param username
* @return
*/
@Select("select * from employee where username = #{username}")
Employee getByUsername(String username);
/**
@ -25,7 +24,6 @@ public interface EmployeeMapper {
*
* @param employee 员工
*/
@AutoFill(value = OperationType.INSERT)
void insert(Employee employee);
/**
@ -41,7 +39,6 @@ public interface EmployeeMapper {
*
* @param employee Employee
*/
@AutoFill(value = OperationType.UPDATE)
void update(Employee employee);
/**

View File

@ -8,8 +8,10 @@ public interface SetmealMapper {
/**
* 根据分类id查询套餐的数量
* @param id Long
* @return Integer
* @param id
* @return
*/
@Select("select count(id) from setmeal where category_id = #{categoryId}")
Integer countByCategoryId(Long id);
}

View File

@ -10,40 +10,40 @@ public interface CategoryService {
/**
* 新增分类
* @param categoryDTO CategoryDTO
* @param categoryDTO
*/
void save(CategoryDTO categoryDTO);
/**
* 分页查询
* @param categoryPageQueryDTO CategoryPageQueryDTO
* @return PageResult
* @param categoryPageQueryDTO
* @return
*/
PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
/**
* 根据id删除分类
* @param id Long
* @param id
*/
void deleteById(Long id);
/**
* 修改分类
* @param categoryDTO CategoryDTO
* @param categoryDTO
*/
void update(CategoryDTO categoryDTO);
/**
* 启用禁用分类
* @param status Integer
* @param id Long
* @param status
* @param id
*/
void startOrStop(Integer status, Long id);
/**
* 根据类型查询分类
* @param type Integer
* @return List<Category>
* @param type
* @return
*/
List<Category> list(Integer type);
}

View File

@ -1,12 +0,0 @@
package com.sky.service;
import com.sky.dto.DishDTO;
public interface DishService {
/**
* 新增菜品和口味
*
* @param dishDTO DishDTO
*/
void saveWithFlavor(DishDTO dishDTO);
}

View File

@ -1,16 +0,0 @@
package com.sky.service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
public interface MinioService {
/**
* 上传文件
*
* @param file 文件
*/
String upload(MultipartFile file) throws IOException;
}

View File

@ -18,26 +18,26 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
// 分类业务层
/**
* 分类业务层
*/
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {
@Resource
@Autowired
private CategoryMapper categoryMapper;
@Resource
@Autowired
private DishMapper dishMapper;
@Resource
@Autowired
private SetmealMapper setmealMapper;
/**
* 新增分类
* @param categoryDTO CategoryDTO
* @param categoryDTO
*/
public void save(CategoryDTO categoryDTO) {
Category category = new Category();
@ -48,18 +48,18 @@ public class CategoryServiceImpl implements CategoryService {
category.setStatus(StatusConstant.DISABLE);
//设置创建时间修改时间创建人修改人
// category.setCreateTime(LocalDateTime.now());
// category.setUpdateTime(LocalDateTime.now());
// category.setCreateUser(BaseContext.getCurrentId());
// category.setUpdateUser(BaseContext.getCurrentId());
category.setCreateTime(LocalDateTime.now());
category.setUpdateTime(LocalDateTime.now());
category.setCreateUser(BaseContext.getCurrentId());
category.setUpdateUser(BaseContext.getCurrentId());
categoryMapper.insert(category);
}
/**
* 分页查询
* @param categoryPageQueryDTO CategoryPageQueryDTO
* @return PageResult
* @param categoryPageQueryDTO
* @return
*/
public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());
@ -70,7 +70,7 @@ public class CategoryServiceImpl implements CategoryService {
/**
* 根据id删除分类
* @param id Long
* @param id
*/
public void deleteById(Long id) {
//查询当前分类是否关联了菜品如果关联了就抛出业务异常
@ -93,32 +93,38 @@ public class CategoryServiceImpl implements CategoryService {
/**
* 修改分类
* @param categoryDTO CategoryDTO
* @param categoryDTO
*/
public void update(CategoryDTO categoryDTO) {
Category category = new Category();
BeanUtils.copyProperties(categoryDTO,category);
//设置修改时间修改人
category.setUpdateTime(LocalDateTime.now());
category.setUpdateUser(BaseContext.getCurrentId());
categoryMapper.update(category);
}
/**
* 启用禁用分类
* @param status Integer
* @param id Long
* @param status
* @param id
*/
public void startOrStop(Integer status, Long id) {
Category category = Category.builder()
.id(id)
.status(status)
.updateTime(LocalDateTime.now())
.updateUser(BaseContext.getCurrentId())
.build();
categoryMapper.update(category);
}
/**
* 根据类型查询分类
* @param type Integer
* @return List<Category>
* @param type
* @return
*/
public List<Category> list(Integer type) {
return categoryMapper.list(type);

View File

@ -1,49 +0,0 @@
package com.sky.service.impl;
import com.sky.dto.DishDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.mapper.DishFlavorMapper;
import com.sky.mapper.DishMapper;
import com.sky.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Slf4j
public class DishServiceImpl implements DishService {
@Resource
private DishMapper dishMapper;
@Resource
private DishFlavorMapper dishFlavorMapper;
/**
* 新增菜品和口味
*
* @param dishDTO DishDTO
*/
@Override
@Transactional
public void saveWithFlavor(DishDTO dishDTO) {
Dish dish = new Dish();
BeanUtils.copyProperties(dishDTO, dish);
// 插入数据
dishMapper.insert(dish);
// 获取Insert语句生成的主键值
Long dishId = dish.getId();
List<DishFlavor> flavors = dishDTO.getFlavors();
if (flavors != null && !flavors.isEmpty()) {
flavors.forEach(dishFlavor -> {
dishFlavor.setDishId(dishId);
});
// 香口味表中插入n条数据
dishFlavorMapper.insertBatch(flavors);
}
}
}

View File

@ -85,6 +85,14 @@ public class EmployeeServiceImpl implements EmployeeService {
employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
employee.setIdNumber(employeeDTO.getIdNumber());
// 设置当前时间
employee.setCreateTime(LocalDateTime.now());
employee.setUpdateTime(LocalDateTime.now());
// 设置当前记录创建人id
employee.setCreateUser(BaseContext.getCurrentId());
employee.setUpdateUser(BaseContext.getCurrentId());
employeeMapper.insert(employee);
BaseContext.removeCurrentId();
}
@ -112,6 +120,11 @@ public class EmployeeServiceImpl implements EmployeeService {
*/
@Override
public void startOrStop(Integer status, Long id) {
// 常见对象第一种方式
// Employee employee = new Employee();
// employee.setStatus(status);
// employee.setId(id);
// 创建对象第二种方式
Employee employee = Employee.builder().status(status).id(id).build();
employeeMapper.update(employee);
@ -138,6 +151,9 @@ public class EmployeeServiceImpl implements EmployeeService {
Employee employee = new Employee();
BeanUtils.copyProperties(employeeDTO, employee);
employee.setUpdateTime(LocalDateTime.now());
employee.setUpdateUser(BaseContext.getCurrentId());
employeeMapper.update(employee);
}
}

View File

@ -1,37 +0,0 @@
package com.sky.service.impl;
import com.sky.config.MinioConfig;
import com.sky.result.Result;
import com.sky.service.MinioService;
import com.sky.utils.MinioUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDate;
import java.util.UUID;
@Service
@Slf4j
public class MinioServiceImpl implements MinioService {
@Resource
MinioConfig minioConfig;
@Resource
private MinioUtils minioUtils;
@Override
public String upload(MultipartFile file) throws IOException {
String extension = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
String filename = LocalDate.now() + "/" + UUID.randomUUID().toString() + extension;
log.info("上传文件:{}", filename);
minioUtils.bucketCreate(minioConfig.getBucketName());
return minioUtils
.uploadFile(minioConfig.getBucketName(),
filename,
file.getInputStream(),
file.getSize());
}
}

View File

@ -1,122 +0,0 @@
package com.sky.utils;
import com.sky.config.MinioConfig;
import io.minio.*;
import io.minio.errors.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@Component
@Slf4j
public class MinioUtils {
@Resource
private MinioClient minioClient;
@Resource
private MinioConfig config;
/**
* 判断桶是否存在
*
* @param bucketName String
* @return found
*/
public boolean bucketExists(String bucketName) {
boolean found = false;
try {
found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
} catch (Exception e) {
e.printStackTrace();
}
return found;
}
/**
* 如果桶不存在就新建
*
* @param bucketName String
*/
public void bucketCreate(String bucketName) {
boolean exists = bucketExists(bucketName);
if (!exists) {
try {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 上传文件
*
* @param fileName 文件名
* @param inputStream 输入流
* @param size 文件大小
*/
public String uploadFile(String bucketName, String fileName, InputStream inputStream, Long size) {
try {
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
.object(fileName)
.stream(inputStream, size, -1)
.build());
return config.getEndpointUrl() + "/" + bucketName + "/" + fileName;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 上传文件
*
* @param fileName 文件名
* @param inputStream 输入流
* @param size 文件大小
* @param contentType 文件类型
*/
public String uploadFile(String bucketName, String fileName, InputStream inputStream, Long size, String contentType) {
try {
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
.object(fileName)
.stream(inputStream, size, -1)
.contentType(contentType)
.build());
return config.getEndpointUrl() + "/" + bucketName + "/" + fileName;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 获取文件
*
* @param bucketName 桶名称
* @param fileName 对象名称
*/
public InputStream getFile(String bucketName, String fileName) {
try {
return minioClient.getObject(GetObjectArgs.builder()
.bucket(bucketName)
.object(fileName)
.build());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -6,9 +6,3 @@ sky:
database: sky_take_out
username: root
password: "02120212"
minio:
endpointUrl: "http://129.211.31.58:9000"
bucket-name: sky
accessKey: "bunny"
secretKey: "02120212"

View File

@ -12,10 +12,6 @@ spring:
url: jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
username: ${sky.datasource.username}
password: ${sky.datasource.password}
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
mybatis:
#mapper配置文件
@ -41,9 +37,3 @@ sky:
admin-ttl: 66666666666666
# 设置前端传递过来的令牌名称
admin-token-name: token
minio:
endpointUrl: ${sky.minio.endpointUrl}
accessKey: ${sky.minio.accessKey}
secretKey: ${sky.minio.secretKey}
bucket-name: ${sky.minio.bucket-name}

View File

@ -3,20 +3,6 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.CategoryMapper">
<!-- 插入数据 -->
<insert id="insert">
insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)
VALUES (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})
</insert>
<!-- 根据id删除分类 -->
<delete id="deleteById">
delete
from category
where id = #{id}
</delete>
<!-- 分页查询 -->
<select id="pageQuery" resultType="com.sky.entity.Category">
select * from category
<where>
@ -30,7 +16,6 @@
order by sort asc , create_time desc
</select>
<!-- 根据id修改分类 -->
<update id="update" parameterType="Category">
update category
<set>
@ -56,7 +41,6 @@
where id = #{id}
</update>
<!-- 根据类型查询分类 -->
<select id="list" resultType="Category">
select * from category
where status = 1

View File

@ -1,13 +0,0 @@
<?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.DishFlavorMapper">
<!-- 香口味表中插入n条数据 -->
<insert id="insertBatch">
insert into dish_flavor (dish_id, name, value )
values
<foreach collection="flavors" item="df" separator=",">
( #{df.dishId},#{df.name},#{df.value})
</foreach>
</insert>
</mapper>

View File

@ -1,19 +0,0 @@
<?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.DishMapper">
<!-- 新增菜品和口味 -->
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into dish (id, name, category_id, price, image, description, status, create_time, update_time,
create_user, update_user)
values (#{id}, #{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime},
#{updateTime}, #{createUser}, #{updateUser});
</insert>
<!-- 根据分类id查询菜品数量 -->
<select id="countByCategoryId" resultType="java.lang.Integer" >
select count(id)
from dish
where category_id = #{categoryId}
</select>
</mapper>

View File

@ -63,9 +63,4 @@
from employee
where id = #{id};
</select>
<!-- 根据用户名查询员工 -->
<select id="getByUsername" resultType="com.sky.entity.Employee">
select * from employee where username = #{username}
</select>
</mapper>

View File

@ -1,11 +0,0 @@
<?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.SetmealMapper">
<!-- 根据分类id查询套餐的数量 -->
<select id="countByCategoryId" resultType="java.lang.Integer">
select count(id)
from setmeal
where category_id = #{categoryId}
</select>
</mapper>