diff --git a/controller/CommonController.java b/controller/CommonController.java new file mode 100644 index 0000000..699cd0f --- /dev/null +++ b/controller/CommonController.java @@ -0,0 +1,80 @@ +package com.controller; + +import com.annotation.IgnoreAuth; +import com.util.ApiResponse; +import org.springframework.util.ResourceUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.util.Date; + +/** + * @ClassName CommonController + * @Description 通用方法模块控制层 + */ +@RestController +@RequestMapping("/common") +public class CommonController { + + /** + * 上传文件 + */ + @IgnoreAuth + @RequestMapping("/uploadfile") + public ApiResponse upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception { + if (file.isEmpty()) { + return ApiResponse.failed(400, "文件不能为空"); + } + String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); + File path = new File(ResourceUtils.getURL("classpath:static").getPath()); + if (!path.exists()) { + path = new File(""); + } + File upload = new File(path.getAbsolutePath(), "/upload/"); + if (!upload.exists()) { + upload.mkdirs(); + } + String fileName = new Date().getTime() + "." + fileExt; + File dest = new File(upload.getAbsolutePath() + "/" + fileName); + file.transferTo(dest); + + return ApiResponse.success(fileName); + } + + + /** + * 文件下载 + * + * @throws IOException + */ + @IgnoreAuth + @RequestMapping(value = "/download", method = RequestMethod.GET) + public void download(@RequestParam(value = "filename") String filename, + HttpServletRequest request, + HttpServletResponse response) throws IOException { + //需要下载的文件 + String path = ResourceUtils.getURL("classpath:static").getPath() + "/" + filename; + //获取输入流 + InputStream bis = new BufferedInputStream(new FileInputStream(new File(path))); + //转码,免得文件名中文乱码 + filename = URLEncoder.encode(filename, "UTF-8"); + //设置文件下载头 + response.addHeader("Content-Disposition", "attachment;filename=" + filename); + //1.设置文件ContentType类型,这样设置,会自动判断下载文件类型 + response.setContentType("multipart/form-data"); + BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); + int len = 0; + while ((len = bis.read()) != -1) { + out.write(len); + out.flush(); + } + out.close(); + } +} diff --git a/controller/DingdanController.java b/controller/DingdanController.java new file mode 100644 index 0000000..cadadac --- /dev/null +++ b/controller/DingdanController.java @@ -0,0 +1,335 @@ +package com.controller; + +import com.annotation.IgnoreAuth; +import com.entity.*; +import com.service.DingdanService; +import com.service.DingdanxiangService; +import com.service.GouwucheService; +import com.service.ShangpinService; +import com.util.ApiResponse; +import com.util.PageData; +import com.util.PageWrap; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.List; + +/** + * @ClassName DingdanController + * @Description 订单模块控制层 + */ +@RequestMapping("dingdan") +@RestController +public class DingdanController { + + @Autowired + private DingdanService dingdanService; + + @Autowired + private GouwucheService gouwucheService; + + @Autowired + private ShangpinService shangpinService; + + @Autowired + private DingdanxiangService dingdanxiangService; + + //前台-根据条件获取订单列表分页数据接口 + @RequestMapping("/manaqian") + public ApiResponse manaQian(Dingdan req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanList); + } + + //前台-根据条件获取我的订单列表分页数据接口 + @RequestMapping("/manamyqian") + public ApiResponse manaMyQian(Dingdan req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanList); + } + + //前台-根据条件获取订单图片列表分页数据接口 + @RequestMapping("/manaqiantp") + public ApiResponse manaQianTp(Dingdan req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanList); + } + + //前台-订单详情 + @RequestMapping("/detail/{id}") + public ApiResponse detail(@PathVariable("id") Integer id) { + Dingdan info = dingdanService.findById(id); + return ApiResponse.success(info); + } + + //前台-订单添加接口 + @PostMapping("/add") + public ApiResponse add(@RequestBody Dingdan req, HttpSession session, String shangPinId) { + Users users = (Users) session.getAttribute("users"); + List gouwucheList = new ArrayList<>(); + if (null != users && null != users.getId()) { + if (null == shangPinId || shangPinId.equals("0")) { + //从购物车里提交订单下单 + Gouwuche gouwuche = new Gouwuche(); + gouwuche.setUsersid(users.getId()); + gouwucheList = gouwucheService.find(gouwuche); + }else { + //商品详情页里直接购买下单 + Integer shangpinid = cn.hutool.core.convert.Convert.toInt(shangPinId); + Gouwuche gouwuche = new Gouwuche(); + gouwuche.setShangpinid(shangpinid); + gouwuche.setId(0); + //直接购买时购买数量为1 + gouwuche.setGoumaishuliang(1); + gouwucheList.add(gouwuche); + } + if (gouwucheList.size() == 0) { + return ApiResponse.failed("请先将商品添加到购物车再提交订单!"); + } else { + for (Gouwuche info : gouwucheList) { + Integer shangpinid = info.getShangpinid(); + if (null == shangpinid || shangpinid == 0) { + return ApiResponse.failed("购物车里的商品数据异常!"); + } + Integer goumaishuliang = info.getGoumaishuliang(); + //库存判断 + Shangpin shangpin = shangpinService.findById(shangpinid); + if (null != shangpin) { + Integer kucunshuliang = shangpin.getKucunshuliang(); + //判断库存是否大于或等于订单数量 + if (kucunshuliang < goumaishuliang) { + return ApiResponse.failed("购物车里的商品库存不足,请修正后再提交!"); + } + } else { + return ApiResponse.failed("购物车里的商品不存在!"); + } + } + } + } else { + return ApiResponse.failed("请登陆后再操作!"); + } + int result = dingdanService.saveOrUpdate(req); + //保存订单项数据、更新商品表数据以及删除购物车数据 + for (Gouwuche info : gouwucheList) { + Integer shangpinid = info.getShangpinid(); + Integer goumaishuliang = info.getGoumaishuliang(); + + //保存订单项数据 + Dingdanxiang dingdanxiang = new Dingdanxiang(); + dingdanxiang.setShangpinid(shangpinid); + dingdanxiang.setGoumaishuliang(goumaishuliang); + dingdanxiang.setUsersid(users.getId()); + dingdanxiang.setDingdanid(result); + dingdanxiangService.saveOrUpdate(dingdanxiang); + + //更新商品表数据 + Shangpin shangpin = shangpinService.findById(shangpinid); + Integer kucunshuliang = shangpin.getKucunshuliang(); + Integer xiaoshoushuliang = shangpin.getXiaoshoushuliang(); + //商品库存数量减去购买数量 + shangpin.setKucunshuliang(kucunshuliang - goumaishuliang); + //商品销售数量加上购买数量 + shangpin.setXiaoshoushuliang(xiaoshoushuliang + goumaishuliang); + shangpinService.saveOrUpdate(shangpin); + + //删除购物车数据 + gouwucheService.deleteById(info.getId()); + } + return ApiResponse.success(result); + } + + //后台-根据条件获取订单管理列表分页数据接口 + @RequestMapping("/mana") + public ApiResponse mana(Dingdan req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanList); + } + + //后台-根据条件获取订单管理我的列表分页数据接口 + @RequestMapping("/manamy") + public ApiResponse manaMy(Dingdan req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanList); + } + + //后台-根据条件获取订单查看列表分页数据接口 + @RequestMapping("/chakan") + public ApiResponse chakan(Dingdan req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanList); + } + + //后台-根据条件获取订单查看我的列表分页数据接口 + @RequestMapping("/chakanmy") + public ApiResponse chakanMy(Dingdan req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanList); + } + + //后台-订单详情 + @RequestMapping("/info/{id}") + public ApiResponse info(@PathVariable("id") Integer id) { + Dingdan info = dingdanService.findById(id); + return ApiResponse.success(info); + } + + //后台-订单添加接口 + @PostMapping("/save") + public ApiResponse save(@RequestBody Dingdan req, HttpSession session, String shangPinId) { + Users users = (Users) session.getAttribute("users"); + List gouwucheList = new ArrayList<>(); + if (null != users && null != users.getId()) { + if (null == shangPinId || shangPinId.equals("0")) { + //从购物车里提交订单下单 + Gouwuche gouwuche = new Gouwuche(); + gouwuche.setUsersid(users.getId()); + gouwucheList = gouwucheService.find(gouwuche); + }else { + //商品详情页里直接购买下单 + Integer shangpinid = cn.hutool.core.convert.Convert.toInt(shangPinId); + Gouwuche gouwuche = new Gouwuche(); + gouwuche.setShangpinid(shangpinid); + gouwuche.setId(0); + //直接购买时购买数量为1 + gouwuche.setGoumaishuliang(1); + gouwucheList.add(gouwuche); + } + if (gouwucheList.size() == 0) { + return ApiResponse.failed("请先将商品添加到购物车再提交订单!"); + } else { + for (Gouwuche info : gouwucheList) { + Integer shangpinid = info.getShangpinid(); + if (null == shangpinid || shangpinid == 0) { + return ApiResponse.failed("购物车里的商品数据异常!"); + } + Integer goumaishuliang = info.getGoumaishuliang(); + //库存判断 + Shangpin shangpin = shangpinService.findById(shangpinid); + if (null != shangpin) { + Integer kucunshuliang = shangpin.getKucunshuliang(); + //判断库存是否大于或等于订单数量 + if (kucunshuliang < goumaishuliang) { + return ApiResponse.failed("购物车里的商品库存不足,请修正后再提交!"); + } + } else { + return ApiResponse.failed("购物车里的商品不存在!"); + } + } + } + } else { + return ApiResponse.failed("请登陆后再操作!"); + } + int result = dingdanService.saveOrUpdate(req); + //保存订单项数据、更新商品表数据以及删除购物车数据 + for (Gouwuche info : gouwucheList) { + Integer shangpinid = info.getShangpinid(); + Integer goumaishuliang = info.getGoumaishuliang(); + + //保存订单项数据 + Dingdanxiang dingdanxiang = new Dingdanxiang(); + dingdanxiang.setShangpinid(shangpinid); + dingdanxiang.setGoumaishuliang(goumaishuliang); + dingdanxiang.setUsersid(users.getId()); + dingdanxiang.setDingdanid(result); + dingdanxiangService.saveOrUpdate(dingdanxiang); + + //更新商品表数据 + Shangpin shangpin = shangpinService.findById(shangpinid); + Integer kucunshuliang = shangpin.getKucunshuliang(); + Integer xiaoshoushuliang = shangpin.getXiaoshoushuliang(); + //商品库存数量减去购买数量 + shangpin.setKucunshuliang(kucunshuliang - goumaishuliang); + //商品销售数量加上购买数量 + shangpin.setXiaoshoushuliang(xiaoshoushuliang + goumaishuliang); + shangpinService.saveOrUpdate(shangpin); + + //删除购物车数据 + gouwucheService.deleteById(info.getId()); + } + return ApiResponse.success(result); + } + + //订单删除(含批量删除)接口 + @RequestMapping("/delete") + public ApiResponse delete(@RequestBody Integer[] ids) { + int result = 0; + for (Integer id : ids) { + result = dingdanService.deleteById(id); + } + return ApiResponse.success(result); + } + + //订单修改接口 + @PostMapping("/set") + public ApiResponse set(@RequestBody Dingdan req) { + int result = dingdanService.saveOrUpdate(req); + return ApiResponse.success(result); + } + + //根据条件获取订单总金额接口 + @RequestMapping("/totalamount") + public ApiResponse getTotalamount(Dingdan req) { + //计算订单总金额 + Integer totalAmount = 0; + List dingdanList = dingdanService.find(req); + for (Dingdan dingdan : dingdanList) { + totalAmount += dingdan.getJine(); + } + return ApiResponse.success(totalAmount); + } + + //获取所有订单数据接口 + @RequestMapping("/all") + public ApiResponse dingdanAll() { + List dingdanList = dingdanService.findAll(); + return ApiResponse.success(dingdanList); + } + + //根据条件(字符类型模糊匹配查询)获取订单数据接口 + @IgnoreAuth + @RequestMapping("/search") + public ApiResponse dingdanSearch(Dingdan req) { + List dingdanList = dingdanService.find(req); + return ApiResponse.success(dingdanList); + } + + //根据条件(字符类型完全匹配查询)获取订单数据接口 + @IgnoreAuth + @RequestMapping("/searchByEqualTo") + public ApiResponse dingdanSearchByEqualTo(Dingdan req) { + List dingdanList = dingdanService.findByEqualTo(req); + return ApiResponse.success(dingdanList); + } + + //按条件查询订单分页数据方法(模糊匹配查询) + private PageData getPageList(Dingdan req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = getPageWrap(req, pageNo, pageSize, sortProperty); + PageData dingdanList = dingdanService.findPage(pageWrap); + return dingdanList; + } + + //按条件查询订单分页数据方法(完全匹配查询) + private PageData getPageListByEqualTo(Dingdan req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = getPageWrap(req, pageNo, pageSize, sortProperty); + PageData dingdanList = dingdanService.findPageByEqualTo(pageWrap); + return dingdanList; + } + + //获取订单查询用户数据搜索条件 + private PageWrap getPageWrap(Dingdan req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = new PageWrap<>(); + pageWrap.setModel(req); + pageWrap.setPageNum(pageNo); + pageWrap.setPageSize(pageSize); + PageWrap.SortData sortData = new PageWrap.SortData(); + sortData.setDirection("DESC"); + sortData.setProperty(sortProperty); + List sorts = new ArrayList<>(); + sorts.add(sortData); + pageWrap.setSorts(sorts); + return pageWrap; + } + +} diff --git a/controller/DingdanxiangController.java b/controller/DingdanxiangController.java new file mode 100644 index 0000000..7cef992 --- /dev/null +++ b/controller/DingdanxiangController.java @@ -0,0 +1,179 @@ +package com.controller; + +import com.annotation.IgnoreAuth; +import com.entity.Dingdanxiang; +import com.service.DingdanxiangService; +import com.util.ApiResponse; +import com.util.PageData; +import com.util.PageWrap; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * @ClassName DingdanxiangController + * @Description 订单项模块控制层 + */ +@RequestMapping("dingdanxiang") +@RestController +public class DingdanxiangController { + + @Autowired + private DingdanxiangService dingdanxiangService; + + //前台-根据条件获取订单项列表分页数据接口 + @IgnoreAuth + @RequestMapping("/manaqian") + public ApiResponse manaQian(Dingdanxiang req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanxiangList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanxiangList); + } + + //前台-根据条件获取我的订单项列表分页数据接口 + @RequestMapping("/manamyqian") + public ApiResponse manaMyQian(Dingdanxiang req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanxiangList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanxiangList); + } + + //前台-根据条件获取订单项图片列表分页数据接口 + @IgnoreAuth + @RequestMapping("/manaqiantp") + public ApiResponse manaQianTp(Dingdanxiang req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanxiangList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanxiangList); + } + + //前台-订单项详情 + @IgnoreAuth + @RequestMapping("/detail/{id}") + public ApiResponse detail(@PathVariable("id") Integer id) { + Dingdanxiang info = dingdanxiangService.findById(id); + + return ApiResponse.success(info); + } + + //前台-订单项添加接口 + @PostMapping("/add") + public ApiResponse add(@RequestBody Dingdanxiang req) { + int result = dingdanxiangService.saveOrUpdate(req); + return ApiResponse.success(result); + } + + //后台-根据条件获取订单项管理列表分页数据接口 + @RequestMapping("/mana") + public ApiResponse mana(Dingdanxiang req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanxiangList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanxiangList); + } + + //后台-根据条件获取订单项管理我的列表分页数据接口 + @RequestMapping("/manamy") + public ApiResponse manaMy(Dingdanxiang req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanxiangList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanxiangList); + } + + //后台-根据条件获取订单项查看列表分页数据接口 + @RequestMapping("/chakan") + public ApiResponse chakan(Dingdanxiang req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanxiangList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanxiangList); + } + + //后台-根据条件获取订单项查看我的列表分页数据接口 + @RequestMapping("/chakanmy") + public ApiResponse chakanMy(Dingdanxiang req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dingdanxiangList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dingdanxiangList); + } + + //后台-订单项详情 + @RequestMapping("/info/{id}") + public ApiResponse info(@PathVariable("id") Integer id) { + Dingdanxiang info = dingdanxiangService.findById(id); + return ApiResponse.success(info); + } + + //后台-订单项添加接口 + @PostMapping("/save") + public ApiResponse save(@RequestBody Dingdanxiang req) { + int result = dingdanxiangService.saveOrUpdate(req); + return ApiResponse.success(result); + } + + //订单项删除(含批量删除)接口 + @RequestMapping("/delete") + public ApiResponse delete(@RequestBody Integer[] ids) { + int result = 0; + for (Integer id : ids) { + result = dingdanxiangService.deleteById(id); + } + return ApiResponse.success(result); + } + + //订单项修改接口 + @PostMapping("/set") + public ApiResponse set(@RequestBody Dingdanxiang req) { + int result = dingdanxiangService.saveOrUpdate(req); + return ApiResponse.success(result); + } + + //获取所有订单项数据接口 + @IgnoreAuth + @RequestMapping("/all") + public ApiResponse dingdanxiangAll() { + List dingdanxiangList = dingdanxiangService.findAll(); + return ApiResponse.success(dingdanxiangList); + } + + //根据条件(字符类型模糊匹配查询)获取订单项数据接口 + @IgnoreAuth + @RequestMapping("/search") + public ApiResponse dingdanxiangSearch(Dingdanxiang req) { + List dingdanxiangList = dingdanxiangService.find(req); + return ApiResponse.success(dingdanxiangList); + } + + //根据条件(字符类型完全匹配查询)获取订单项数据接口 + @IgnoreAuth + @RequestMapping("/searchByEqualTo") + public ApiResponse dingdanxiangSearchByEqualTo(Dingdanxiang req) { + List dingdanxiangList = dingdanxiangService.findByEqualTo(req); + return ApiResponse.success(dingdanxiangList); + } + + + + //按条件查询订单项分页数据方法(模糊匹配查询) + private PageData getPageList(Dingdanxiang req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = getPageWrap(req, pageNo, pageSize, sortProperty); + PageData dingdanxiangList = dingdanxiangService.findPage(pageWrap); + return dingdanxiangList; + } + + //按条件查询订单项分页数据方法(完全匹配查询) + private PageData getPageListByEqualTo(Dingdanxiang req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = getPageWrap(req, pageNo, pageSize, sortProperty); + PageData dingdanxiangList = dingdanxiangService.findPageByEqualTo(pageWrap); + return dingdanxiangList; + } + + //获取订单项查询数据搜索条件 + private PageWrap getPageWrap(Dingdanxiang req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = new PageWrap<>(); + pageWrap.setModel(req); + pageWrap.setPageNum(pageNo); + pageWrap.setPageSize(pageSize); + PageWrap.SortData sortData = new PageWrap.SortData(); + sortData.setDirection("DESC"); + sortData.setProperty(sortProperty); + List sorts = new ArrayList<>(); + sorts.add(sortData); + pageWrap.setSorts(sorts); + return pageWrap; + } + +} diff --git a/controller/DxController.java b/controller/DxController.java new file mode 100644 index 0000000..eb62cd3 --- /dev/null +++ b/controller/DxController.java @@ -0,0 +1,179 @@ +package com.controller; + +import com.annotation.IgnoreAuth; +import com.entity.Dx; +import com.service.DxService; +import com.util.ApiResponse; +import com.util.PageData; +import com.util.PageWrap; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * @ClassName DxController + * @Description 信息介绍模块控制层 + */ +@RequestMapping("dx") +@RestController +public class DxController { + + @Autowired + private DxService dxService; + + //前台-根据条件获取信息介绍列表分页数据接口 + @IgnoreAuth + @RequestMapping("/manaqian") + public ApiResponse manaQian(Dx req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dxList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dxList); + } + + //前台-根据条件获取我的信息介绍列表分页数据接口 + @RequestMapping("/manamyqian") + public ApiResponse manaMyQian(Dx req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dxList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dxList); + } + + //前台-根据条件获取信息介绍图片列表分页数据接口 + @IgnoreAuth + @RequestMapping("/manaqiantp") + public ApiResponse manaQianTp(Dx req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dxList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dxList); + } + + //前台-信息介绍详情 + @IgnoreAuth + @RequestMapping("/detail/{id}") + public ApiResponse detail(@PathVariable("id") Integer id) { + Dx info = dxService.findById(id); + + return ApiResponse.success(info); + } + + //前台-信息介绍添加接口 + @PostMapping("/add") + public ApiResponse add(@RequestBody Dx req) { + int result = dxService.saveOrUpdate(req); + return ApiResponse.success(result); + } + + //后台-根据条件获取信息介绍管理列表分页数据接口 + @RequestMapping("/mana") + public ApiResponse mana(Dx req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dxList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dxList); + } + + //后台-根据条件获取信息介绍管理我的列表分页数据接口 + @RequestMapping("/manamy") + public ApiResponse manaMy(Dx req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dxList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dxList); + } + + //后台-根据条件获取信息介绍查看列表分页数据接口 + @RequestMapping("/chakan") + public ApiResponse chakan(Dx req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dxList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dxList); + } + + //后台-根据条件获取信息介绍查看我的列表分页数据接口 + @RequestMapping("/chakanmy") + public ApiResponse chakanMy(Dx req, @RequestParam(defaultValue = "1", value = "pageNo") int pageNo, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam(defaultValue = "id", value = "sortProperty") String sortProperty) { + PageData dxList = getPageList(req, pageNo, pageSize, sortProperty); + return ApiResponse.success(dxList); + } + + //后台-信息介绍详情 + @RequestMapping("/info/{id}") + public ApiResponse info(@PathVariable("id") Integer id) { + Dx info = dxService.findById(id); + return ApiResponse.success(info); + } + + //后台-信息介绍添加接口 + @PostMapping("/save") + public ApiResponse save(@RequestBody Dx req) { + int result = dxService.saveOrUpdate(req); + return ApiResponse.success(result); + } + + //信息介绍删除(含批量删除)接口 + @RequestMapping("/delete") + public ApiResponse delete(@RequestBody Integer[] ids) { + int result = 0; + for (Integer id : ids) { + result = dxService.deleteById(id); + } + return ApiResponse.success(result); + } + + //信息介绍修改接口 + @PostMapping("/set") + public ApiResponse set(@RequestBody Dx req) { + int result = dxService.saveOrUpdate(req); + return ApiResponse.success(result); + } + + //获取所有信息介绍数据接口 + @IgnoreAuth + @RequestMapping("/all") + public ApiResponse dxAll() { + List dxList = dxService.findAll(); + return ApiResponse.success(dxList); + } + + //根据条件(字符类型模糊匹配查询)获取信息介绍数据接口 + @IgnoreAuth + @RequestMapping("/search") + public ApiResponse dxSearch(Dx req) { + List dxList = dxService.find(req); + return ApiResponse.success(dxList); + } + + //根据条件(字符类型完全匹配查询)获取信息介绍数据接口 + @IgnoreAuth + @RequestMapping("/searchByEqualTo") + public ApiResponse dxSearchByEqualTo(Dx req) { + List dxList = dxService.findByEqualTo(req); + return ApiResponse.success(dxList); + } + + + + //按条件查询信息介绍分页数据方法(模糊匹配查询) + private PageData getPageList(Dx req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = getPageWrap(req, pageNo, pageSize, sortProperty); + PageData dxList = dxService.findPage(pageWrap); + return dxList; + } + + //按条件查询信息介绍分页数据方法(完全匹配查询) + private PageData getPageListByEqualTo(Dx req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = getPageWrap(req, pageNo, pageSize, sortProperty); + PageData dxList = dxService.findPageByEqualTo(pageWrap); + return dxList; + } + + //获取信息介绍查询数据搜索条件 + private PageWrap getPageWrap(Dx req, int pageNo, int pageSize, String sortProperty) { + PageWrap pageWrap = new PageWrap<>(); + pageWrap.setModel(req); + pageWrap.setPageNum(pageNo); + pageWrap.setPageSize(pageSize); + PageWrap.SortData sortData = new PageWrap.SortData(); + sortData.setDirection("DESC"); + sortData.setProperty(sortProperty); + List sorts = new ArrayList<>(); + sorts.add(sortData); + pageWrap.setSorts(sorts); + return pageWrap; + } + +}