p #6

Closed
piblenqhp wants to merge 0 commits from dev into master

@ -6,23 +6,23 @@ package com.shanzhu.flower.config;
* *
*/ */
public class Constant { public class Constant {
// 默认分页大小,用于分页查询时每页显示的记录数。 // 默认分页大小,用于分页查询时每页显示的记录数。
// 默认值为5可根据实际需求调整。 // 默认值为5可根据实际需求调整。
public static int PAGE_SIZE = 5; public static int PAGE_SIZE = 5;
// //
// 商品展示页面的分页大小。 // 商品展示页面的分页大小。
// 用于商品列表展示时每页显示的商品数量。 // 用于商品列表展示时每页显示的商品数量。
// 默认值为9可根据页面布局调整。 // 默认值为9可根据页面布局调整。
// //
public static int SHOW_PAGE_SIZE = 9; public static int SHOW_PAGE_SIZE = 9;
// 图片静态文件的存储路径。 // 图片静态文件的存储路径。
// 用于存放项目中使用的图片资源。 // 用于存放项目中使用的图片资源。
// 路径为项目根目录下的static/imgs/文件夹。 // 路径为项目根目录下的static/imgs/文件夹。
public static String IMG_USE_PATH = "static/imgs/"; public static String IMG_USE_PATH = "static/imgs/";
// 默认图片文件名。 // 默认图片文件名。
// 当没有指定图片时,使用此默认图片作为占位图。 // 当没有指定图片时,使用此默认图片作为占位图。
// 文件名为img.jpg位于IMG_USE_PATH路径下。 // 文件名为img.jpg位于IMG_USE_PATH路径下。
public static String DEFAULT_IMG = "img.jpg"; public static String DEFAULT_IMG = "img.jpg";

@ -9,7 +9,7 @@ package com.shanzhu.flower.config;
* @date: 2024-01-24 * @date: 2024-01-24
*/ */
public class HttpMsg { public class HttpMsg {
// 表单输入错误的提示信息。 // 表单输入错误的提示信息。
// 当用户提交的表单数据不符合要求时返回此消息。 // 当用户提交的表单数据不符合要求时返回此消息。
public static String ERROR_INPUT = "表单信息不正确"; public static String ERROR_INPUT = "表单信息不正确";
@ -44,7 +44,7 @@ public class HttpMsg {
public static String DELETE_USER_OK = "删除用户信息成功"; public static String DELETE_USER_OK = "删除用户信息成功";
// 删除用户信息失败的提示信息。 // 删除用户信息失败的提示信息。
// 当管理员删除用户信息失败时返回此消息。 // 当管理员删除用户信息失败时返回此消息。
public static String DELETE_USER_FAILED = "删除用户信息失败"; public static String DELETE_USER_FAILED = "删除用户信息失败";
@ -53,7 +53,7 @@ public class HttpMsg {
public static String DELETE_TYPE_OK = "删除类型成功"; public static String DELETE_TYPE_OK = "删除类型成功";
// 删除类型失败的提示信息(有商品绑定此类型)。 // 删除类型失败的提示信息(有商品绑定此类型)。
// 当管理员删除花朵类型失败(因为有商品绑定此类型)时返回此消息。 // 当管理员删除花朵类型失败(因为有商品绑定此类型)时返回此消息。
// //
public static String DELETE_TYPE_FAILED = "有商品绑定此类型,删除类型失败"; public static String DELETE_TYPE_FAILED = "有商品绑定此类型,删除类型失败";
@ -64,12 +64,12 @@ public class HttpMsg {
public static String UPDATE_TYPE_OK = "修改类型成功"; public static String UPDATE_TYPE_OK = "修改类型成功";
// 修改类型失败的提示信息(有商品绑定此类型)。 // 修改类型失败的提示信息(有商品绑定此类型)。
// 当管理员修改花朵类型失败(因为有商品绑定此类型)时返回此消息。 // 当管理员修改花朵类型失败(因为有商品绑定此类型)时返回此消息。
public static String UPDATE_TYPE_FAILED = "有商品绑定此类型,修改类型失败"; public static String UPDATE_TYPE_FAILED = "有商品绑定此类型,修改类型失败";
// 新建类型成功的提示信息。 // 新建类型成功的提示信息。
// 当管理员新建花朵类型成功时返回此消息。 // 当管理员新建花朵类型成功时返回此消息。
public static String ADD_TYPE_OK = "新建类型成功"; public static String ADD_TYPE_OK = "新建类型成功";
@ -78,107 +78,107 @@ public class HttpMsg {
// 当管理员新建花朵类型失败(因为该类型名称已存在)时返回此消息。 // 当管理员新建花朵类型失败(因为该类型名称已存在)时返回此消息。
public static String ADD_TYPE_FAILED = "新建类型失败,该类型名称已存在"; public static String ADD_TYPE_FAILED = "新建类型失败,该类型名称已存在";
// 删除商品成功的提示信息。 // 删除商品成功的提示信息。
// 当管理员删除商品成功时返回此消息。 // 当管理员删除商品成功时返回此消息。
public static String DELETE_FLOWER_OK = "删除商品成功"; public static String DELETE_FLOWER_OK = "删除商品成功";
// //
// 删除商品失败的提示信息(有商品绑定此类型)。 // 删除商品失败的提示信息(有商品绑定此类型)。
// 当管理员删除商品失败(因为有商品绑定此类型)时返回此消息。 // 当管理员删除商品失败(因为有商品绑定此类型)时返回此消息。
// //
public static String DELETE_FLOWER_FAILED = "有商品绑定此类型,删除商品失败"; public static String DELETE_FLOWER_FAILED = "有商品绑定此类型,删除商品失败";
// //
// 修改商品成功的提示信息。 // 修改商品成功的提示信息。
// 当管理员修改商品成功时返回此消息。 // 当管理员修改商品成功时返回此消息。
// //
public static String UPDATE_FLOWER_OK = "修改商品成功"; public static String UPDATE_FLOWER_OK = "修改商品成功";
// //
// 修改商品失败的提示信息(有商品绑定此类型)。 // 修改商品失败的提示信息(有商品绑定此类型)。
// 当管理员修改商品失败(因为有商品绑定此类型)时返回此消息。 // 当管理员修改商品失败(因为有商品绑定此类型)时返回此消息。
// //
public static String UPDATE_FLOWER_FAILED = "有商品绑定此类型,修改商品失败"; public static String UPDATE_FLOWER_FAILED = "有商品绑定此类型,修改商品失败";
// //
// 新建商品成功的提示信息。 // 新建商品成功的提示信息。
// 当管理员新建商品成功时返回此消息。 // 当管理员新建商品成功时返回此消息。
// //
public static String ADD_FLOWER_OK = "新建商品成功"; public static String ADD_FLOWER_OK = "新建商品成功";
// //
// 新建商品失败的提示信息(该商品名称已存在)。 // 新建商品失败的提示信息(该商品名称已存在)。
// 当管理员新建商品失败(因为该商品名称已存在)时返回此消息。 // 当管理员新建商品失败(因为该商品名称已存在)时返回此消息。
// //
public static String ADD_FLOWER_FAILED = "新建商品失败,该商品名称已存在"; public static String ADD_FLOWER_FAILED = "新建商品失败,该商品名称已存在";
// //
// 当前没有花朵种类的提示信息。 // 当前没有花朵种类的提示信息。
// 当系统中没有花朵种类时返回此消息,提示管理员需要先创建种类。 // 当系统中没有花朵种类时返回此消息,提示管理员需要先创建种类。
// //
public static String NO_TYPE_NOW = "当前没有花朵种类,请先创建!"; public static String NO_TYPE_NOW = "当前没有花朵种类,请先创建!";
// //
// 更新图片成功的提示信息。 // 更新图片成功的提示信息。
// 当用户或管理员更新图片成功时返回此消息。 // 当用户或管理员更新图片成功时返回此消息。
// //
public static String UPDATE_PIC_OK = "更新图片成功"; public static String UPDATE_PIC_OK = "更新图片成功";
// //
// 更新图片失败的提示信息。 // 更新图片失败的提示信息。
// 当用户或管理员更新图片失败时返回此消息。 // 当用户或管理员更新图片失败时返回此消息。
// //
public static String UPDATE_PIC_FAILED = "更新图片失败"; public static String UPDATE_PIC_FAILED = "更新图片失败";
// //
// 参数不合法的提示信息。 // 参数不合法的提示信息。
// 当请求中包含的参数不符合要求时返回此消息。 // 当请求中包含的参数不符合要求时返回此消息。
// //
public static String INVALID_PARAM = "参数不合法"; public static String INVALID_PARAM = "参数不合法";
// //
// 登录失效的提示信息。 // 登录失效的提示信息。
// 当用户登录状态失效时返回此消息,提示用户重新登录。 // 当用户登录状态失效时返回此消息,提示用户重新登录。
// //
public static String INVALID_USER = "登录失效,请重新登录"; public static String INVALID_USER = "登录失效,请重新登录";
// //
// 加入购物车成功的提示信息。 // 加入购物车成功的提示信息。
// 当用户将商品加入购物车成功时返回此消息。 // 当用户将商品加入购物车成功时返回此消息。
// //
public static String ADD_CART_OK = "加入购物车成功"; public static String ADD_CART_OK = "加入购物车成功";
// //
// 加入购物车失败的提示信息。 // 加入购物车失败的提示信息。
// 当用户将商品加入购物车失败时返回此消息。 // 当用户将商品加入购物车失败时返回此消息。
// //
public static String ADD_CART_FAILED = "加入购物车失败"; public static String ADD_CART_FAILED = "加入购物车失败";
// //
// 下单成功的提示信息。 // 下单成功的提示信息。
// 当用户下单成功时返回此消息。 // 当用户下单成功时返回此消息。
// //
public static String BUY_OK = "下单成功"; public static String BUY_OK = "下单成功";
// //
// 订单发货状态更新成功的提示信息。 // 订单发货状态更新成功的提示信息。
// 当管理员更新订单发货状态成功时返回此消息。 // 当管理员更新订单发货状态成功时返回此消息。
// //
public static String UPDATE_ORDER_OK = "订单发货状态更新成功"; public static String UPDATE_ORDER_OK = "订单发货状态更新成功";
// //
// 错误的文件类型的提示信息。 // 错误的文件类型的提示信息。
// 当上传的文件类型不符合要求时返回此消息。 // 当上传的文件类型不符合要求时返回此消息。
// //
public static String ERROR_FILE_TYPE = "错误的文件类型"; public static String ERROR_FILE_TYPE = "错误的文件类型";
// //
// 商品上架成功的提示信息。 // 商品上架成功的提示信息。
// 当管理员将商品上架成功时返回此消息。 // 当管理员将商品上架成功时返回此消息。
// //
public static String GOODS_UP_OK = "商品上架成功"; public static String GOODS_UP_OK = "商品上架成功";
// //
// 商品下架成功的提示信息。 // 商品下架成功的提示信息。
// 当管理员将商品下架成功时返回此消息。 // 当管理员将商品下架成功时返回此消息。
// //

@ -29,12 +29,12 @@ import java.util.UUID;
public class FlowerController { public class FlowerController {
@Value("${uploadPath}") @Value("${uploadPath}")
private String uploadPath; // 注入文件上传路径配置 private String uploadPath;
@Resource @Resource
private FlowersService flowerService; // 注入鲜花业务逻辑服务 private FlowersService flowerService;
@Resource @Resource
private FlowersDao flowersDao; // 注入鲜花数据访问对象 private FlowersDao flowersDao;
/** /**
* *
@ -42,7 +42,7 @@ public class FlowerController {
* @param page * @param page
* @param searchKey * @param searchKey
* @param searchType * @param searchType
* @return * @return
*/ */
@RequestMapping("/find") @RequestMapping("/find")
R find( R find(
@ -51,13 +51,13 @@ public class FlowerController {
@RequestParam("searchType") String searchType @RequestParam("searchType") String searchType
) { ) {
R r = new R(); R r = new R();
List<Flower> flowers = flowerService.find(searchKey, searchType); // 调用服务层查询鲜花列表 List<Flower> flowers = flowerService.find(searchKey, searchType);
if (flowers == null) { if (flowers == null) {
return r.setCode(2000); // 返回查询失败状态码 return r.setCode(2000);
} }
return getResponse(flowers, page, Constant.SHOW_PAGE_SIZE, r); // 构建分页响应数据 return getResponse(flowers, page, Constant.SHOW_PAGE_SIZE, r);
} }
/** /**
@ -70,13 +70,13 @@ public class FlowerController {
@RequestMapping("/findAll") @RequestMapping("/findAll")
R findAll(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) { R findAll(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
R r = new R(); R r = new R();
List<Flower> flowers = flowerService.findAll(searchKey); // 调用服务层查询所有鲜花 List<Flower> flowers = flowerService.findAll(searchKey);
if (flowers == null) { if (flowers == null) {
return r.setCode(2000); // 返回查询失败状态码 return r.setCode(2000);
} }
return getResponse(flowers, page, Constant.PAGE_SIZE, r); // 构建分页响应数据 return getResponse(flowers, page, Constant.PAGE_SIZE, r);
} }
/** /**
@ -89,12 +89,12 @@ public class FlowerController {
R create(@RequestBody Flower flower) { R create(@RequestBody Flower flower) {
R r = new R(); R r = new R();
int ans = flowerService.add(flower); // 调用服务层添加鲜花 int ans = flowerService.add(flower);
if (ans == 1) { if (ans == 1) {
return r.setCode(2000).setMsg(HttpMsg.ADD_FLOWER_OK); // 返回添加成功信息 return r.setCode(2000).setMsg(HttpMsg.ADD_FLOWER_OK);
} }
return r.setCode(4000).setMsg(HttpMsg.ADD_FLOWER_FAILED); // 返回添加失败信息 return r.setCode(4000).setMsg(HttpMsg.ADD_FLOWER_FAILED);
} }
/** /**
@ -107,12 +107,12 @@ public class FlowerController {
R update(@RequestBody Flower flower) { R update(@RequestBody Flower flower) {
R r = new R(); R r = new R();
int ans = flowerService.update(flower); // 调用服务层更新鲜花信息 int ans = flowerService.update(flower);
if (ans >= 0) { if (ans >= 0) {
return r.setCode(2000).setMsg(HttpMsg.UPDATE_FLOWER_OK); // 返回更新成功信息 return r.setCode(2000).setMsg(HttpMsg.UPDATE_FLOWER_OK);
} }
return r.setCode(4000).setMsg(HttpMsg.UPDATE_FLOWER_FAILED); // 返回更新失败信息 return r.setCode(4000).setMsg(HttpMsg.UPDATE_FLOWER_FAILED);
} }
/** /**
@ -125,10 +125,10 @@ public class FlowerController {
R changeState(@RequestBody Flower flower) { R changeState(@RequestBody Flower flower) {
R r = new R(); R r = new R();
flowersDao.changeState(flower); // 直接调用DAO层修改商品状态 flowersDao.changeState(flower);
String msg = flower.getState() == 1 ? HttpMsg.GOODS_UP_OK : HttpMsg.GOODS_DOWN_OK; // 判断上下架状态 String msg = flower.getState() == 1 ? HttpMsg.GOODS_UP_OK : HttpMsg.GOODS_DOWN_OK;
return r.setCode(2000).setMsg(msg); // 返回操作成功信息 return r.setCode(2000).setMsg(msg);
} }
/** /**
@ -144,16 +144,16 @@ public class FlowerController {
// 只接收 jpg/png 图片 // 只接收 jpg/png 图片
String filename = file.getOriginalFilename(); String filename = file.getOriginalFilename();
if (!filename.endsWith(".jpg") && !filename.endsWith(".png")) { if (!filename.endsWith(".jpg") && !filename.endsWith(".png")) {
return r.setCode(4000).setMsg(HttpMsg.ERROR_FILE_TYPE); // 返回文件类型错误信息 return r.setCode(4000).setMsg(HttpMsg.ERROR_FILE_TYPE);
} }
String img_guid = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg"; // 生成唯一图片文件名 String img_guid = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
try { try {
savePic(file.getInputStream(), img_guid); // 保存图片文件 savePic(file.getInputStream(), img_guid);
return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK).setData(img_guid); // 返回上传成功信息 return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK).setData(img_guid);
} catch (IOException e) { } catch (IOException e) {
return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED); // 返回上传失败信息 return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED);
} }
} }
@ -169,12 +169,12 @@ public class FlowerController {
R updateImgGuid(@RequestParam("guid") String guid, @RequestParam("id") int id) { R updateImgGuid(@RequestParam("guid") String guid, @RequestParam("id") int id) {
R r = new R(); R r = new R();
int ans = flowerService.updateImg(guid, id); // 调用服务层更新图片GUID int ans = flowerService.updateImg(guid, id);
if (ans == 1) { if (ans == 1) {
return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK); // 返回更新成功信息 return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK);
} }
return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED); // 返回更新失败信息 return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED);
} }
/** /**
@ -187,19 +187,14 @@ public class FlowerController {
R delete(@RequestParam("id") int id) { R delete(@RequestParam("id") int id) {
R r = new R(); R r = new R();
int ans = flowerService.delete(id); // 调用服务层删除鲜花 int ans = flowerService.delete(id);
if (ans == 1) { if (ans == 1) {
return r.setCode(2000).setMsg(HttpMsg.DELETE_FLOWER_OK); // 返回删除成功信息 return r.setCode(2000).setMsg(HttpMsg.DELETE_FLOWER_OK);
} }
return r.setCode(4000).setMsg(HttpMsg.DELETE_FLOWER_FAILED); // 返回删除失败信息 return r.setCode(4000).setMsg(HttpMsg.DELETE_FLOWER_FAILED);
} }
/**
*
* @param inputStream
* @param fileName
*/
private void savePic(InputStream inputStream, String fileName) { private void savePic(InputStream inputStream, String fileName) {
OutputStream os = null; OutputStream os = null;
try { try {
@ -212,48 +207,38 @@ public class FlowerController {
os = new FileOutputStream(new File(path + fileName)); os = new FileOutputStream(new File(path + fileName));
// 开始读取 // 开始读取
while ((len = inputStream.read(bs)) != -1) { while ((len = inputStream.read(bs)) != -1) {
os.write(bs, 0, len); // 将数据写入文件 os.write(bs, 0, len);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); // 打印异常堆栈信息 e.printStackTrace();
} finally { } finally {
// 完毕,关闭所有链接 // 完毕,关闭所有链接
try { try {
os.close(); os.close();
inputStream.close(); inputStream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); // 打印关闭流异常信息 e.printStackTrace();
} }
} }
} }
/**
*
* @param flowers
* @param page
* @param pageSize
* @param r
* @return
*/
private R getResponse(List<Flower> flowers, int page, int pageSize, R r) { private R getResponse(List<Flower> flowers, int page, int pageSize, R r) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
// 计算当前页数据
List<Flower> items = flowers.size() >= page * pageSize ? List<Flower> items = flowers.size() >= page * pageSize ?
flowers.subList((page - 1) * pageSize, page * pageSize) flowers.subList((page - 1) * pageSize, page * pageSize)
: flowers.subList((page - 1) * pageSize, flowers.size()); : flowers.subList((page - 1) * pageSize, flowers.size());
// 计算总页数
int len = flowers.size() % pageSize == 0 ? flowers.size() / pageSize int len = flowers.size() % pageSize == 0 ? flowers.size() / pageSize
: (flowers.size() / pageSize + 1); : (flowers.size() / pageSize + 1);
// 处理图片路径
for (Flower item : items) { for (Flower item : items) {
if (item.getImg_guid() == null) { if (item.getImg_guid() == null) {
item.setImg_guid(Constant.DEFAULT_IMG); // 设置默认图片 item.setImg_guid(Constant.DEFAULT_IMG);
} }
item.setImg_guid(Constant.IMG_USE_PATH + item.getImg_guid()); // 添加图片访问路径前缀 item.setImg_guid(Constant.IMG_USE_PATH + item.getImg_guid());
} }
map.put("items", items); // 分页数据 map.put("items", items);
map.put("len", len); // 总页数 map.put("len", len);
return r.setCode(2000).setData(map); // 返回分页响应 return r.setCode(2000).setData(map);
} }
} }

@ -21,97 +21,68 @@ import java.util.Map;
public class FlowerTypeController { public class FlowerTypeController {
@Resource @Resource
private SpeciesService speciesService; // 注入鲜花种类业务逻辑服务 private SpeciesService speciesService;
/**
*
* @return
*/
@RequestMapping("/findAll") @RequestMapping("/findAll")
R findAll() { R findAll() {
R r = new R(); R r = new R();
List<Species> all = speciesService.findAll(); // 调用服务层查询所有鲜花种类 List<Species> all = speciesService.findAll();
if (all.size() <= 0) { if (all.size()<=0){
return r.setCode(4000).setMsg(HttpMsg.NO_TYPE_NOW); // 返回无种类信息 return r.setCode(4000).setMsg(HttpMsg.NO_TYPE_NOW);
} }
return r.setCode(2000).setData(all); // 返回成功及种类列表 return r.setCode(2000).setData(all);
} }
/**
*
* @param page
* @param searchKey
* @return
*/
@RequestMapping("/find") @RequestMapping("/find")
R find(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) { R find(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
R r = new R(); R r = new R();
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
List<Species> list = speciesService.find(searchKey); // 调用服务层查询符合条件的种类 List<Species> list = speciesService.find(searchKey);
if (list == null) { if (list == null) {
return r.setCode(2000); // 返回查询失败状态 return r.setCode(2000);
} }
// 分页逻辑 - 获取当前页数据
List<Species> items = list.size() >= page * Constant.PAGE_SIZE ? List<Species> items = list.size() >= page * Constant.PAGE_SIZE ?
list.subList((page - 1) * Constant.PAGE_SIZE, page * Constant.PAGE_SIZE) list.subList((page - 1) * Constant.PAGE_SIZE, page * Constant.PAGE_SIZE)
: list.subList((page - 1) * Constant.PAGE_SIZE, list.size()); : list.subList((page - 1) * Constant.PAGE_SIZE, list.size());
// 计算总页数
int len = list.size() % Constant.PAGE_SIZE == 0 ? list.size() / Constant.PAGE_SIZE int len = list.size() % Constant.PAGE_SIZE == 0 ? list.size() / Constant.PAGE_SIZE
: (list.size() / Constant.PAGE_SIZE + 1); : (list.size() / Constant.PAGE_SIZE + 1);
map.put("items", items);
map.put("items", items); // 当前页数据 map.put("len", len);
map.put("len", len); // 总页数 return r.setCode(2000).setData(map);
return r.setCode(2000).setData(map); // 返回分页结果
} }
/**
*
* @param species
* @return
*/
@RequestMapping("/create") @RequestMapping("/create")
R create(@RequestBody Species species) { R create(@RequestBody Species species) {
R r = new R(); R r = new R();
try { try {
speciesService.add(species); // 调用服务层添加种类 speciesService.add(species);
return r.setCode(2000).setMsg(HttpMsg.ADD_TYPE_OK); // 返回添加成功信息 return r.setCode(2000).setMsg(HttpMsg.ADD_TYPE_OK);
} catch (Exception e) { } catch (Exception e) {
return r.setCode(4000).setMsg(HttpMsg.ADD_TYPE_FAILED); // 返回添加失败信息 return r.setCode(4000).setMsg(HttpMsg.ADD_TYPE_FAILED);
} }
} }
/**
*
* @param species
* @return
*/
@RequestMapping("/update") @RequestMapping("/update")
R update(@RequestBody Species species) { R update(@RequestBody Species species) {
R r = new R(); R r = new R();
try { try {
speciesService.update(species); // 调用服务层更新种类信息 speciesService.update(species);
return r.setCode(2000).setMsg(HttpMsg.UPDATE_TYPE_OK); // 返回更新成功信息 return r.setCode(2000).setMsg(HttpMsg.UPDATE_TYPE_OK);
} catch (Exception e) { } catch (Exception e) {
return r.setCode(4000).setMsg(HttpMsg.UPDATE_TYPE_FAILED); // 返回更新失败信息 return r.setCode(4000).setMsg(HttpMsg.UPDATE_TYPE_FAILED);
} }
} }
/**
*
* @param id ID
* @return
*/
@DeleteMapping("/delete") @DeleteMapping("/delete")
R delete(@RequestParam("id") int id) { R delete(@RequestParam("id") int id) {
R r = new R(); R r = new R();
try { try {
speciesService.delete(id); // 调用服务层删除种类 speciesService.delete(id);
return r.setCode(2000).setMsg(HttpMsg.DELETE_TYPE_OK); // 返回删除成功信息 return r.setCode(2000).setMsg(HttpMsg.DELETE_TYPE_OK);
} catch (Exception e) { } catch (Exception e) {
return r.setCode(4000).setMsg(HttpMsg.DELETE_TYPE_FAILED); // 返回删除失败信息 return r.setCode(4000).setMsg(HttpMsg.DELETE_TYPE_FAILED);
} }
} }
} }

@ -9,7 +9,7 @@ import java.util.List;
@Repository @Repository
public interface CartDao { public interface CartDao {
// //
// 根据搜索关键词和用户账号查询购物车 // 根据搜索关键词和用户账号查询购物车
// 查询购物车中包含指定搜索关键词的商品,并且属于指定用户账号的记录。 // 查询购物车中包含指定搜索关键词的商品,并且属于指定用户账号的记录。
// //
@ -20,7 +20,7 @@ public interface CartDao {
@Select("select * from carts where flower like concat('%',#{searchKey},'%') and account = #{account};") @Select("select * from carts where flower like concat('%',#{searchKey},'%') and account = #{account};")
List<Cart> find(@Param("searchKey") String searchKey, @Param("account") String account); List<Cart> find(@Param("searchKey") String searchKey, @Param("account") String account);
// //
// 查询所有购物车记录 // 查询所有购物车记录
// 查询购物车表中的所有记录。 // 查询购物车表中的所有记录。
// //
@ -29,7 +29,7 @@ public interface CartDao {
@Select("select * from carts;") @Select("select * from carts;")
List<Cart> findAll(); List<Cart> findAll();
// //
// 检查商品是否已添加到购物车 // 检查商品是否已添加到购物车
// 查询指定用户是否已将指定商品添加到购物车。 // 查询指定用户是否已将指定商品添加到购物车。
// //
@ -39,7 +39,7 @@ public interface CartDao {
@Select("select * from carts where fid = #{fid} and uid = #{uid};") @Select("select * from carts where fid = #{fid} and uid = #{uid};")
Cart checkIsAdded(Cart cart); Cart checkIsAdded(Cart cart);
// //
// 增加购物车中商品的数量 // 增加购物车中商品的数量
// 将指定用户购物车中指定商品的数量加1。 // 将指定用户购物车中指定商品的数量加1。
// //
@ -49,7 +49,7 @@ public interface CartDao {
@Update("update carts set amount = amount + 1 where fid = #{fid} and uid = #{uid};") @Update("update carts set amount = amount + 1 where fid = #{fid} and uid = #{uid};")
int addAmount(Cart cart); int addAmount(Cart cart);
// //
// 根据用户ID查询购物车 // 根据用户ID查询购物车
// 查询指定用户购物车中的所有商品。 // 查询指定用户购物车中的所有商品。
// //
@ -59,7 +59,7 @@ public interface CartDao {
@Select("select * from carts where uid = #{uid};") @Select("select * from carts where uid = #{uid};")
List<Cart> queryByUid(int uid); List<Cart> queryByUid(int uid);
// //
// 更新购物车记录 // 更新购物车记录
// 更新购物车中的记录,包括商品名称、密码、电话和地址。 // 更新购物车中的记录,包括商品名称、密码、电话和地址。
// //
@ -69,7 +69,7 @@ public interface CartDao {
@Update("update carts set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};") @Update("update carts set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};")
int update(Cart cart); int update(Cart cart);
// //
// 删除购物车记录 // 删除购物车记录
// 根据购物车ID删除记录。 // 根据购物车ID删除记录。
// //
@ -79,7 +79,7 @@ public interface CartDao {
@Delete("delete from carts where id = #{id};") @Delete("delete from carts where id = #{id};")
int delete(int id); int delete(int id);
// //
// 添加购物车记录 // 添加购物车记录
// 将新的购物车记录插入到数据库中。 // 将新的购物车记录插入到数据库中。
// //

@ -6,76 +6,36 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
//
// 鲜花数据访问接口,定义与鲜花表相关的数据库操作
//
@Repository @Repository
public interface FlowersDao { public interface FlowersDao {
//
// 根据搜索关键词和种类分页查询上架鲜花
// @param searchKey 搜索关键词,匹配鲜花名称
// @param searchType 种类名称,匹配鲜花种类
// @return 符合条件的鲜花列表
//
@Select("select * from flowers where name like concat('%',#{searchKey},'%') " + @Select("select * from flowers where name like concat('%',#{searchKey},'%') " +
"and species_name like concat('%',#{searchType},'%') and state = 1;") "and species_name like concat('%',#{searchType},'%') and state = 1;")
List<Flower> find(@Param("searchKey") String searchKey, @Param("searchType") String searchType); List<Flower> find(@Param("searchKey") String searchKey, @Param("searchType")String searchType);
//
// 管理员查询所有鲜花(含未上架)
// @param searchKey 搜索关键词,匹配鲜花名称
// @return 符合条件的鲜花列表
//
@Select("select * from flowers where name like concat('%',#{searchKey},'%');") @Select("select * from flowers where name like concat('%',#{searchKey},'%');")
List<Flower> findAll(String searchKey); List<Flower> findAll(String searchKey);
//
// 查询指定ID鲜花的价格
// @param fid 鲜花ID
// @return 鲜花价格
//
@Select("select price from flowers where id = #{fid};") @Select("select price from flowers where id = #{fid};")
Float queryPrice(int fid); Float queryPrice(int fid);
//
// 更新鲜花基本信息
// @param flower 包含ID和要更新信息的鲜花对象
// @return 受影响的行数
//
@Update("update flowers set name = #{name}, species_name = #{species_name}, price = #{price}, detail = #{detail} where id = #{id};") @Update("update flowers set name = #{name}, species_name = #{species_name}, price = #{price}, detail = #{detail} where id = #{id};")
Integer update(Flower flower); Integer update(Flower flower);
//
// 更新鲜花图片GUID
// @param img_guid 新的图片GUID
// @param id 鲜花ID
// @return 受影响的行数
//
@Update("update flowers set img_guid = #{img_guid} where id = #{id};") @Update("update flowers set img_guid = #{img_guid} where id = #{id};")
Integer updateImg(@Param("img_guid") String img_guid, @Param("id") Integer id); Integer updateImg(@Param("img_guid") String img_guid,@Param("id") Integer id);
//
// 修改鲜花状态(上架/下架)
// @param flower 包含ID和状态的鲜花对象
// @return 受影响的行数
//
@Update("update flowers set state = ${state} where id = #{id};") @Update("update flowers set state = ${state} where id = #{id};")
Integer changeState(Flower flower); Integer changeState(Flower flower);
//
// 删除指定ID的鲜花
// @param id 鲜花ID
// @return 受影响的行数
//
@Delete("delete from flowers where id = #{id};") @Delete("delete from flowers where id = #{id};")
Integer delete(int id); Integer delete(int id);
//
// 添加新鲜花
// @param flower 鲜花对象ID自增状态默认为1-上架)
// @return 受影响的行数
//
@Insert("insert into flowers(name,species_name,price,detail,state) values(#{name},#{species_name},${price},#{detail},1);") @Insert("insert into flowers(name,species_name,price,detail,state) values(#{name},#{species_name},${price},#{detail},1);")
Integer add(Flower flower); Integer add(Flower flower);
} }

@ -7,7 +7,7 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface LoginDao { public interface LoginDao {
// //
// //
// 用户登录验证 // 用户登录验证
// 根据登录表单信息(账号、密码和角色)查询用户信息。 // 根据登录表单信息(账号、密码和角色)查询用户信息。

@ -10,7 +10,7 @@ import java.util.List;
@Repository @Repository
public interface OrderDao { public interface OrderDao {
// //
// 根据搜索关键词和用户ID查询订单 // 根据搜索关键词和用户ID查询订单
// 查询指定用户的所有订单,订单中的商品名称包含指定的搜索关键词。 // 查询指定用户的所有订单,订单中的商品名称包含指定的搜索关键词。
// //
@ -21,7 +21,7 @@ public interface OrderDao {
@Select("select * from orders where flower like concat('%',#{searchKey},'%') and uid = #{uid};") @Select("select * from orders where flower like concat('%',#{searchKey},'%') and uid = #{uid};")
List<Order> find(@Param("searchKey") String searchKey, @Param("uid") int uid); List<Order> find(@Param("searchKey") String searchKey, @Param("uid") int uid);
// //
// 根据搜索关键词查询所有订单 // 根据搜索关键词查询所有订单
// 查询所有订单,订单中的商品名称包含指定的搜索关键词。 // 查询所有订单,订单中的商品名称包含指定的搜索关键词。
// //
@ -31,7 +31,7 @@ public interface OrderDao {
@Select("select * from orders where flower like concat('%',#{searchKey},'%');") @Select("select * from orders where flower like concat('%',#{searchKey},'%');")
List<Order> findAll(String searchKey); List<Order> findAll(String searchKey);
// //
// 检查订单是否已存在 // 检查订单是否已存在
// 查询指定用户是否已存在指定商品的订单。 // 查询指定用户是否已存在指定商品的订单。
// //
@ -41,7 +41,7 @@ public interface OrderDao {
@Select("select * from orders where fid = #{fid} and uid = #{uid};") @Select("select * from orders where fid = #{fid} and uid = #{uid};")
Order checkIsAdded(Order order); Order checkIsAdded(Order order);
// //
// 更新订单状态 // 更新订单状态
// 根据订单ID更新订单的状态。 // 根据订单ID更新订单的状态。
// //
@ -51,7 +51,7 @@ public interface OrderDao {
@Update("update orders set state = #{state} where id = #{id};") @Update("update orders set state = #{state} where id = #{id};")
int changeState(Order order); int changeState(Order order);
// //
// 根据用户ID查询订单 // 根据用户ID查询订单
// 查询指定用户的所有订单。 // 查询指定用户的所有订单。
// //
@ -61,7 +61,7 @@ public interface OrderDao {
@Select("select * from orders where uid = #{uid};") @Select("select * from orders where uid = #{uid};")
List<Order> queryByUid(int uid); List<Order> queryByUid(int uid);
// //
// 更新订单信息 // 更新订单信息
// 更新订单的详细信息,包括商品名称、密码、电话和地址。 // 更新订单的详细信息,包括商品名称、密码、电话和地址。
// //
@ -71,7 +71,7 @@ public interface OrderDao {
@Update("update orders set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};") @Update("update orders set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};")
int update(Order order); int update(Order order);
// //
// 删除订单 // 删除订单
// 根据订单ID删除订单。 // 根据订单ID删除订单。
// //
@ -81,7 +81,7 @@ public interface OrderDao {
@Delete("delete from orders where id = #{id};") @Delete("delete from orders where id = #{id};")
int delete(int id); int delete(int id);
// //
// 添加订单 // 添加订单
// 将新的订单记录插入到数据库中。 // 将新的订单记录插入到数据库中。
// //

@ -9,51 +9,26 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
//
// 鲜花种类数据访问对象接口,用于定义对鲜花种类表的数据库操作方法
//
@Repository @Repository
public interface SpeciesDao { public interface SpeciesDao {
//
// 根据模糊查询关键词搜索鲜花种类
// 使用 LIKE 语句进行模糊匹配,查询数据库中名称包含指定关键词的鲜花种类记录
// @param searchKey 用于模糊查询的关键词,会拼接在 SQL 的 LIKE 语句中
// @return 符合查询条件的鲜花种类列表,若没有匹配记录则返回空列表
//
@Select("select * from species where species_name like concat('%',#{searchKey},'%');") @Select("select * from species where species_name like concat('%',#{searchKey},'%');")
List<Species> find(String searchKey); List<Species> find(String searchKey);
//
// 查询数据库中所有的鲜花种类记录
// @return 包含所有鲜花种类的列表,若表中没有记录则返回空列表
//
@Select("select * from species;") @Select("select * from species;")
List<Species> findAll(); List<Species> findAll();
//
// 更新鲜花种类的名称
// 根据传入的鲜花种类对象中的 ID更新数据库中对应记录的种类名称
// @param species 包含要更新的鲜花种类信息的对象,其中包含 ID 和新的种类名称
// @return 受影响的行数,若成功更新则返回大于 0 的值,若未找到对应记录则返回 0
//
@Update("update species set species_name = #{species_name} where id = #{id};") @Update("update species set species_name = #{species_name} where id = #{id};")
int update(Species species); int update(Species species);
//
// 根据 ID 删除数据库中的鲜花种类记录
// @param id 要删除的鲜花种类的 ID
// @return 受影响的行数,若成功删除则返回 1若未找到对应记录则返回 0
//
@Delete("delete from species where id = #{id};") @Delete("delete from species where id = #{id};")
int delete(int id); int delete(int id);
//
// 向数据库中插入新的鲜花种类记录
// @param species 包含要插入的鲜花种类名称的对象
// @return 受影响的行数,若成功插入则返回 1若插入失败则返回 0
//
@Insert("insert into species(species_name) values(#{species_name});") @Insert("insert into species(species_name) values(#{species_name});")
int add(Species species); int add(Species species);
} }

@ -12,7 +12,7 @@ import java.util.List;
@Repository @Repository
public interface UserDao { public interface UserDao {
// //
// 根据搜索关键词查询用户 // 根据搜索关键词查询用户
// 查询用户表中账号或姓名包含指定搜索关键词的普通用户(角色为'user')。 // 查询用户表中账号或姓名包含指定搜索关键词的普通用户(角色为'user')。
// //
@ -22,7 +22,7 @@ public interface UserDao {
@Select("select * from users where (account like concat('%',#{searchKey},'%') or name like concat('%',#{searchKey},'%')) and role = 'user';") @Select("select * from users where (account like concat('%',#{searchKey},'%') or name like concat('%',#{searchKey},'%')) and role = 'user';")
List<User> find(String searchKey); List<User> find(String searchKey);
// //
// 根据用户ID查询用户 // 根据用户ID查询用户
// 查询指定ID的用户信息。 // 查询指定ID的用户信息。
// //
@ -32,7 +32,7 @@ public interface UserDao {
@Select("select * from users where id = #{id};") @Select("select * from users where id = #{id};")
User queryById(Integer id); User queryById(Integer id);
// //
// 查询所有用户 // 查询所有用户
// 查询用户表中的所有用户信息。 // 查询用户表中的所有用户信息。
// //
@ -41,7 +41,7 @@ public interface UserDao {
@Select("select * from users;") @Select("select * from users;")
List<User> findAll(); List<User> findAll();
// //
// 根据账号查询用户信息 // 根据账号查询用户信息
// 查询指定账号的普通用户信息(角色为'user')。 // 查询指定账号的普通用户信息(角色为'user')。
// //
@ -51,7 +51,7 @@ public interface UserDao {
@Select("select * from users where account = #{account} and role = 'user';") @Select("select * from users where account = #{account} and role = 'user';")
User queryInfo(String account); User queryInfo(String account);
// //
// 根据账号查询用户ID // 根据账号查询用户ID
// 查询指定账号的普通用户的ID。 // 查询指定账号的普通用户的ID。
// //
@ -61,7 +61,7 @@ public interface UserDao {
@Select("select id from users where account = #{account} and role = 'user';") @Select("select id from users where account = #{account} and role = 'user';")
Integer queryIdByAccount(String account); Integer queryIdByAccount(String account);
// //
// 更新用户信息 // 更新用户信息
// 更新用户的基本信息,包括姓名、密码、电话和地址。 // 更新用户的基本信息,包括姓名、密码、电话和地址。
// //
@ -71,7 +71,7 @@ public interface UserDao {
@Update("update users set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};") @Update("update users set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};")
int update(User user); int update(User user);
// //
// 删除用户 // 删除用户
// 根据用户ID删除用户记录。 // 根据用户ID删除用户记录。
// //
@ -81,7 +81,7 @@ public interface UserDao {
@Delete("delete from users where id = #{id};") @Delete("delete from users where id = #{id};")
int delete(int id); int delete(int id);
// //
// 添加用户 // 添加用户
// 将新的用户记录插入到数据库中,用户角色默认为'user'。 // 将新的用户记录插入到数据库中,用户角色默认为'user'。
// //

@ -7,39 +7,39 @@ import lombok.experimental.Accessors;
@Accessors(chain = true) @Accessors(chain = true)
public class Cart { public class Cart {
// //
// 购物车记录的唯一标识符。 // 购物车记录的唯一标识符。
// 用于在数据库中唯一标识每条购物车记录。 // 用于在数据库中唯一标识每条购物车记录。
// //
private int id; private int id;
// //
// 商品的唯一标识符。 // 商品的唯一标识符。
// 用于标识购物车中的具体商品。 // 用于标识购物车中的具体商品。
// //
private int fid; private int fid;
// //
// 商品名称。 // 商品名称。
// 用于存储购物车中商品的名称。 // 用于存储购物车中商品的名称。
// //
private String flower; private String flower;
// //
// 商品数量。 // 商品数量。
// 用于存储购物车中商品的数量。 // 用于存储购物车中商品的数量。
// //
private int amount; private int amount;
// //
// 商品总价。 // 商品总价。
// 用于存储购物车中商品的总价,计算方式为单价乘以数量。 // 用于存储购物车中商品的总价,计算方式为单价乘以数量。
// //
private float price; private float price;
// 用户的唯一标识符。 // 用户的唯一标识符。
// 用于标识购物车记录所属的用户。 // 用于标识购物车记录所属的用户。
private int uid; private int uid;
// 用户账号。 // 用户账号。
// 用于存储购物车记录所属用户的账号信息。 // 用于存储购物车记录所属用户的账号信息。
private String account; private String account;
} }

@ -3,23 +3,23 @@ package com.shanzhu.flower.entity;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
// 鲜花实体类,用于封装鲜花相关的信息
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class Flower { public class Flower {
// 鲜花的唯一标识 ID数据库表中的主键通常用于唯一确定一条鲜花记录
private int id; private int id;
// 鲜花的名称,用于描述鲜花的具体品种或类型
private String name; private String name;
// 鲜花所属的种类名称,用于分类管理不同种类的鲜花 // 分类名称
private String species_name; private String species_name;
// 鲜花的价格,记录该鲜花的售卖价格,以浮点数类型存储
private float price; private float price;
// 鲜花的详细描述信息,可包含鲜花的特征、产地、养护方法等内容 // 详细介绍
private String detail; private String detail;
// 鲜花图片的唯一标识符GUID用于关联存储在服务器上的鲜花图片资源 // 图片
private String img_guid; private String img_guid;
// 鲜花的状态,通常 1 表示上架可售卖0 表示下架(不可售卖) // 是否上架
private int state; private int state;
} }

@ -6,10 +6,7 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class LoginForm { public class LoginForm {
// 计数
private String account; private String account;
// 密码
private String password; private String password;
// 角色
private String role; private String role;
} }

@ -7,43 +7,43 @@ import lombok.experimental.Accessors;
@Accessors(chain = true) @Accessors(chain = true)
public class Order { public class Order {
// //
// 订单的唯一标识符。 // 订单的唯一标识符。
// 用于在数据库中唯一标识每条订单记录。 // 用于在数据库中唯一标识每条订单记录。
// //
private int id; private int id;
// //
// 订单的全局唯一标识符GUID // 订单的全局唯一标识符GUID
// 用于在系统中唯一标识订单,便于跟踪和管理。 // 用于在系统中唯一标识订单,便于跟踪和管理。
// //
private String order_guid; private String order_guid;
// //
// 订单中的商品名称。 // 订单中的商品名称。
// 用于存储订单中商品的名称。 // 用于存储订单中商品的名称。
// //
private String flower; private String flower;
// //
// 商品数量。 // 商品数量。
// 用于存储订单中商品的数量。 // 用于存储订单中商品的数量。
// //
private int amount; private int amount;
// //
// 商品总价。 // 商品总价。
// 用于存储订单中商品的总价,计算方式为单价乘以数量。 // 用于存储订单中商品的总价,计算方式为单价乘以数量。
// //
private float price; private float price;
// //
// 订单状态。 // 订单状态。
// 用于标识订单的当前状态例如0表示未发货1表示已发货2表示已完成等。 // 用于标识订单的当前状态例如0表示未发货1表示已发货2表示已完成等。
// //
private float state; private float state;
// //
// 用户ID。 // 用户ID。
// 用于标识订单所属的用户。 // 用于标识订单所属的用户。
// //

@ -6,11 +6,9 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class OrderVo extends Order{ public class OrderVo extends Order{
//姓名
private String username; private String username;
// 电话
private String phone; private String phone;
// 地址
private String address; private String address;
} }

@ -6,8 +6,6 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class Param { public class Param {
// 秘钥
private String searchKey; private String searchKey;
// 张数
private int page; private int page;
} }

@ -6,9 +6,7 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class Species { public class Species {
// ID
private int id; private int id;
// 重命名
private String species_name; private String species_name;
} }

@ -6,43 +6,43 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class User { public class User {
// //
// 用户的唯一标识符。 // 用户的唯一标识符。
// 用于在数据库中唯一标识每个用户。 // 用于在数据库中唯一标识每个用户。
// //
private int id; private int id;
// //
// 用户账号。 // 用户账号。
// 用于用户登录和身份验证。 // 用于用户登录和身份验证。
// //
private String account; private String account;
// //
// 用户姓名。 // 用户姓名。
// 用于存储用户的真实姓名或昵称。 // 用于存储用户的真实姓名或昵称。
// //
private String name; private String name;
// //
// 用户密码。 // 用户密码。
// 用于用户登录验证,存储时应加密处理以保证安全。 // 用于用户登录验证,存储时应加密处理以保证安全。
// //
private String password; private String password;
// //
// 用户电话号码。 // 用户电话号码。
// 用于联系用户或验证用户身份。 // 用于联系用户或验证用户身份。
// //
private String phone; private String phone;
// //
// 用户地址。 // 用户地址。
// 用于存储用户的配送地址或其他联系地址。 // 用于存储用户的配送地址或其他联系地址。
// //
private String address; private String address;
// //
// 用户角色。 // 用户角色。
// 用于标识用户在系统中的权限级别,例如:"admin" 表示管理员,"user" 表示普通用户。 // 用于标识用户在系统中的权限级别,例如:"admin" 表示管理员,"user" 表示普通用户。
// //

@ -12,7 +12,7 @@ import java.util.List;
*/ */
public interface CartService { public interface CartService {
// //
// 添加商品到购物车 // 添加商品到购物车
// 如果商品已存在于购物车中,则增加该商品的数量;否则,将商品作为新的记录添加到购物车。 // 如果商品已存在于购物车中,则增加该商品的数量;否则,将商品作为新的记录添加到购物车。
// //
@ -21,7 +21,7 @@ public interface CartService {
// //
int add(Cart cart); int add(Cart cart);
// //
// 删除购物车中的商品 // 删除购物车中的商品
// 根据用户ID删除购物车中的所有商品。 // 根据用户ID删除购物车中的所有商品。
// //
@ -30,7 +30,7 @@ public interface CartService {
// //
int delete(int uid); int delete(int uid);
// //
// 更新购物车中的商品信息 // 更新购物车中的商品信息
// 更新购物车中指定商品的数量或其他信息。 // 更新购物车中指定商品的数量或其他信息。
// //
@ -39,7 +39,7 @@ public interface CartService {
// //
int update(Cart cart); int update(Cart cart);
// //
// 根据搜索关键词和用户账号查询购物车 // 根据搜索关键词和用户账号查询购物车
// 查询购物车中商品名称包含指定搜索关键词的记录,并且属于指定用户账号。 // 查询购物车中商品名称包含指定搜索关键词的记录,并且属于指定用户账号。
// //
@ -49,7 +49,7 @@ public interface CartService {
// //
List<Cart> find(String searchKey, String account); List<Cart> find(String searchKey, String account);
// //
// 根据用户账号查询购物车 // 根据用户账号查询购物车
// 查询指定用户账号的购物车中的所有商品。 // 查询指定用户账号的购物车中的所有商品。
// //

@ -4,62 +4,18 @@ import com.shanzhu.flower.entity.Flower;
import java.util.List; import java.util.List;
// /**
// * 鲜花商品 服务层接口,定义了与鲜花商品相关的业务操作方法, *
// * 具体的实现由实现类来完成,用于处理鲜花商品的增删改查以及图片更新等业务逻辑。 *
// * * @author: ShanZhu
// * @author: ShanZhu * @date: 2024-01-24
// * @date: 2024-01-24 */
//
public interface FlowersService { public interface FlowersService {
//
// * 向系统中添加一个新的鲜花商品记录。
// *
// * @param flower 要添加的鲜花商品对象,包含了鲜花的详细信息,如名称、种类、价格等。
// * @return 成功添加时返回 1添加失败返回 0可以根据具体业务逻辑扩展返回值含义
//
int add(Flower flower); int add(Flower flower);
//
// * 根据给定的鲜花商品 ID从系统中删除对应的鲜花商品记录。
// *
// * @param id 要删除的鲜花商品的 ID。
// * @return 成功删除时返回 1删除失败返回 0可以根据具体业务逻辑扩展返回值含义
//
int delete(int id); int delete(int id);
//
// * 更新系统中已有的鲜花商品记录信息。
// *
// * @param flower 包含更新后鲜花商品信息的对象,其中 ID 用于定位要更新的记录。
// * @return 成功更新时返回大于等于 0 的值,该值表示受影响的行数;更新失败返回 0。
//
int update(Flower flower); int update(Flower flower);
List<Flower> find(String searchKey,String searchType);
//
// * 根据给定的搜索关键词和搜索类型,从系统中查询匹配的鲜花商品记录。
// *
// * @param searchKey 用于模糊查询的关键词,会根据该关键词搜索鲜花的名称或其他相关信息。
// * @param searchType 搜索的类型,例如可以是鲜花的种类等,用于更精确地筛选查询结果。
// * @return 包含所有符合查询条件的鲜花商品对象的列表,如果没有匹配的记录则返回空列表。
//
List<Flower> find(String searchKey, String searchType);
//
// * 根据给定的搜索关键词,从系统中查询所有匹配的鲜花商品记录(包括上架和下架的商品)。
// *
// * @param searchKey 用于模糊查询的关键词,会根据该关键词搜索鲜花的名称或其他相关信息。
// * @return 包含所有符合查询条件的鲜花商品对象的列表,如果没有匹配的记录则返回空列表。
//
List<Flower> findAll(String searchKey); List<Flower> findAll(String searchKey);
int updateImg(String img_guid,Integer id);
//
// * 根据给定的图片唯一标识符GUID和鲜花商品 ID更新系统中对应鲜花商品的图片信息。
// *
// * @param img_guid 新的图片唯一标识符,用于关联新的图片资源。
// * @param id 要更新图片的鲜花商品的 ID。
// * @return 成功更新时返回 1更新失败返回 0可以根据具体业务逻辑扩展返回值含义
//
int updateImg(String img_guid, Integer id);
} }

@ -24,13 +24,49 @@ public interface OrderService {
// //
int add(Cart cart); int add(Cart cart);
//
// 删除订单
// 根据用户ID删除所有订单。
//
// @param uid 用户ID
// @return 删除结果成功返回1失败返回0
//
int delete(int uid); int delete(int uid);
//
// 更新订单
// 更新订单的状态或其他信息。
//
// @param order 订单对象,包含需要更新的订单信息
// @return 更新结果成功返回1失败返回0
//
int update(Order order); int update(Order order);
//
// 根据搜索关键词和用户账号查询订单
// 查询订单中商品名称包含指定搜索关键词的记录,并且属于指定用户账号。
//
// @param searchKey 搜索关键词
// @param account 用户账号
// @return 订单记录列表
//
List<Order> find(String searchKey, String account); List<Order> find(String searchKey, String account);
//
// 根据搜索关键词查询所有订单
// 查询所有订单中商品名称包含指定搜索关键词的记录。
//
// @param searchKey 搜索关键词
// @return 订单记录列表
//
List<Order> findAll(String searchKey); List<Order> findAll(String searchKey);
// /**
// 根据用户账号查询订单
// 查询指定用户账号的所有订单。
//
// @param account 用户账号
// @return 订单记录列表
//
List<Order> queryByAccount(String account); List<Order> queryByAccount(String account);
} }

@ -4,48 +4,11 @@ import com.shanzhu.flower.entity.Species;
import java.util.List; import java.util.List;
//
// * 鲜花种类服务层接口,定义了与鲜花种类相关的业务操作方法,
// * 具体的实现由对应的实现类来完成,用于处理鲜花种类的增删改查等业务逻辑。
//
public interface SpeciesService { public interface SpeciesService {
//
// * 向系统中添加一个新的鲜花种类记录。
// *
// * @param species 要添加的鲜花种类对象,包含了种类的名称等信息。
// * @return 成功添加时返回 1添加失败返回 0可根据实际业务逻辑扩展返回值含义
//
int add(Species species); int add(Species species);
//
// * 根据给定的鲜花种类 ID从系统中删除对应的鲜花种类记录。
// *
// * @param id 要删除的鲜花种类的 ID。
// * @return 成功删除时返回 1删除失败返回 0可根据实际业务逻辑扩展返回值含义
//
int delete(int id); int delete(int id);
//
// * 更新系统中已有的鲜花种类记录信息。
// *
// * @param species 包含更新后鲜花种类信息的对象,其中 ID 用于定位要更新的记录。
// * @return 成功更新时返回大于等于 0 的值,该值表示受影响的行数;更新失败返回 0。
//
int update(Species species); int update(Species species);
//
// * 根据给定的搜索关键词,从系统中查询匹配的鲜花种类记录。
// *
// * @param searchKey 用于模糊查询的关键词,会根据该关键词搜索种类名称中包含它的记录。
// * @return 包含所有符合查询条件的鲜花种类对象的列表,如果没有匹配的记录则返回空列表。
//
List<Species> find(String searchKey); List<Species> find(String searchKey);
//
// * 从系统中查询所有的鲜花种类记录。
// *
// * @return 包含所有鲜花种类对象的列表,如果系统中没有记录则返回空列表。
//
List<Species> findAll(); List<Species> findAll();
} }

@ -12,7 +12,7 @@ import java.util.List;
*/ */
public interface UserService { public interface UserService {
// //
// 添加用户 // 添加用户
// 将新的用户记录插入到数据库中。 // 将新的用户记录插入到数据库中。
// //
@ -21,7 +21,7 @@ public interface UserService {
// //
int add(User user); int add(User user);
// //
// 删除用户 // 删除用户
// 根据用户ID删除用户记录。 // 根据用户ID删除用户记录。
// //
@ -30,7 +30,7 @@ public interface UserService {
// //
int delete(int uid); int delete(int uid);
// //
// 更新用户信息 // 更新用户信息
// 更新用户的基本信息,如姓名、密码、电话和地址。 // 更新用户的基本信息,如姓名、密码、电话和地址。
// //
@ -39,7 +39,7 @@ public interface UserService {
// //
int update(User user); int update(User user);
// //
// 根据搜索关键词查询用户 // 根据搜索关键词查询用户
// 查询用户表中账号或姓名包含指定搜索关键词的用户。 // 查询用户表中账号或姓名包含指定搜索关键词的用户。
// //
@ -48,7 +48,7 @@ public interface UserService {
// //
List<User> find(String searchKey); List<User> find(String searchKey);
// //
// 根据账号查询用户信息 // 根据账号查询用户信息
// 查询指定账号的用户详细信息。 // 查询指定账号的用户详细信息。
// //

@ -8,74 +8,39 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
//
// * 鲜花业务逻辑实现类,处理鲜花相关的业务操作
//
@Service @Service
public class FlowersServiceImpl implements FlowersService { public class FlowersServiceImpl implements FlowersService {
@Resource @Resource
private FlowersDao flowersDao; // 注入鲜花数据访问对象 private FlowersDao flowersDao;
//
// * 添加鲜花信息
// * @param flower 鲜花实体对象
// * @return 数据库操作影响的行数
//
@Override @Override
public int add(Flower flower) { public int add(Flower flower) {
return flowersDao.add(flower); // 调用DAO层添加鲜花 return flowersDao.add(flower);
} }
//
// * 根据ID删除鲜花
// * @param id 鲜花ID
// * @return 数据库操作影响的行数
//
@Override @Override
public int delete(int id) { public int delete(int id) {
return flowersDao.delete(id); // 调用DAO层删除鲜花 return flowersDao.delete(id);
} }
//
// * 更新鲜花信息
// * @param flower 包含更新信息的鲜花实体对象
// * @return 数据库操作影响的行数
//
@Override @Override
public int update(Flower flower) { public int update(Flower flower) {
return flowersDao.update(flower); // 调用DAO层更新鲜花信息 return flowersDao.update(flower);
} }
//
// * 根据搜索条件查询鲜花列表(用户视角,仅包含上架商品)
// * @param searchKey 搜索关键词(名称)
// * @param searchType 搜索类型(种类)
// * @return 符合条件的鲜花列表
//
@Override @Override
public List<Flower> find(String searchKey, String searchType) { public List<Flower> find(String searchKey,String searchType) {
return flowersDao.find(searchKey, searchType); // 调用DAO层查询鲜花列表 return flowersDao.find(searchKey,searchType);
} }
//
// * 管理员查询所有鲜花(包含下架商品)
// * @param searchKey 搜索关键词(名称)
// * @return 符合条件的鲜花列表
//
@Override @Override
public List<Flower> findAll(String searchKey) { public List<Flower> findAll(String searchKey) {
return flowersDao.findAll(searchKey); // 调用DAO层查询所有鲜花 return flowersDao.findAll(searchKey);
} }
//
// * 更新鲜花图片
// * @param img_guid 图片唯一标识
// * @param id 鲜花ID
// * @return 数据库操作影响的行数
//
@Override @Override
public int updateImg(String img_guid, Integer id) { public int updateImg(String img_guid,Integer id) {
return flowersDao.updateImg(img_guid, id); // 调用DAO层更新鲜花图片 return flowersDao.updateImg(img_guid,id);
} }
} }

@ -8,67 +8,34 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
/**
* SpeciesService
* SpeciesDao 访
*/
@Service @Service
public class SpeciesServiceImpl implements SpeciesService { public class SpeciesServiceImpl implements SpeciesService {
@Resource @Resource
private SpeciesDao speciesDao; // 注入鲜花种类数据访问对象,用于操作数据库 private SpeciesDao speciesDao;
//
// * 向数据库中添加一个新的鲜花种类记录。
// *
// * @param species 要添加的鲜花种类对象,包含种类名称等信息。
// * @return 执行数据库插入操作后受影响的行数,成功插入时返回 1失败返回 0。
//
@Override @Override
public int add(Species species) { public int add(Species species) {
return speciesDao.add(species); // 调用 SpeciesDao 的 add 方法执行插入操作 return speciesDao.add(species);
} }
//
// * 根据给定的鲜花种类 ID从数据库中删除对应的鲜花种类记录。
// *
// * @param uid 要删除的鲜花种类的 ID。
// * @return 执行数据库删除操作后受影响的行数,成功删除时返回 1失败返回 0。
//
@Override @Override
public int delete(int uid) { public int delete(int uid) {
return speciesDao.delete(uid); // 调用 SpeciesDao 的 delete 方法执行删除操作 return speciesDao.delete(uid);
} }
//
// * 更新数据库中指定鲜花种类的记录信息。
// *
// * @param species 包含更新后鲜花种类信息的对象,其中 ID 用于定位要更新的记录。
// * @return 执行数据库更新操作后受影响的行数,成功更新时返回大于 0 的值,未找到对应记录返回 0。
//
@Override @Override
public int update(Species species) { public int update(Species species) {
return speciesDao.update(species); // 调用 SpeciesDao 的 update 方法执行更新操作 return speciesDao.update(species);
} }
//
// * 根据给定的搜索关键词,从数据库中查询匹配的鲜花种类记录。
// *
// * @param searchKey 用于模糊查询的关键词,会根据该关键词搜索种类名称中包含它的记录。
// * @return 包含所有符合查询条件的鲜花种类对象的列表,如果没有匹配的记录则返回空列表。
//
@Override @Override
public List<Species> find(String searchKey) { public List<Species> find(String searchKey) {
return speciesDao.find(searchKey); // 调用 SpeciesDao 的 find 方法执行查询操作 return speciesDao.find(searchKey);
} }
//
// * 从数据库中查询所有的鲜花种类记录。
// *
// * @return 包含所有鲜花种类对象的列表,如果数据库中没有记录则返回空列表。
//
@Override @Override
public List<Species> findAll() { public List<Species> findAll() {
return speciesDao.findAll(); // 调用 SpeciesDao 的 findAll 方法执行查询操作 return speciesDao.findAll();
} }
} }

@ -1,33 +1,19 @@
package com.shanzhu.flower.util; package com.shanzhu.flower.util;
import com.shanzhu.flower.entity.LoginForm; import com.shanzhu.flower.entity.LoginForm;
import tk.mybatis.mapper.util.StringUtil; import tk.mybatis.mapper.util.StringUtil;
/**
*
*/
public class VerifyUtil { public class VerifyUtil {
/**
*
* @param form
* @return truefalse
*/
public static boolean verifyLoginForm(LoginForm form) { public static boolean verifyLoginForm(LoginForm form) {
// 检查表单对象是否为空,或必填字段是否为空 if (form==null || StringUtil.isEmpty(form.getAccount())|| StringUtil.isEmpty(form.getPassword())|| StringUtil.isEmpty(form.getRole())) {
if (form == null
|| StringUtil.isEmpty(form.getAccount())
|| StringUtil.isEmpty(form.getPassword())
|| StringUtil.isEmpty(form.getRole())) {
return false; return false;
} }
if (form.getRole().equals("user") || form.getRole().equals("admin")){
// 检查角色是否为允许的类型
if (form.getRole().equals("user") || form.getRole().equals("admin")) {
return true; return true;
} }
// 角色类型不合法
return false; return false;
} }
} }

Loading…
Cancel
Save