添加项目前缀,报404接口补全
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
package com.zf.foodpurchase.fdsafe.web.merchant;
|
||||
|
||||
import com.zf.foodpurchase.common.core.controller.BaseController;
|
||||
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysUser;
|
||||
import com.zf.foodpurchase.common.core.page.TableDataInfo;
|
||||
import com.zf.foodpurchase.common.utils.poi.ExcelUtil;
|
||||
import com.zf.foodpurchase.fdsafe.entity.Carousel;
|
||||
import com.zf.foodpurchase.fdsafe.service.ICarouselService;
|
||||
import com.zf.foodpurchase.fdsafe.utils.ImagesPrefixUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商户轮播图Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-11-29
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/merchant/carousel")
|
||||
public class CarouselController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICarouselService carouselService;
|
||||
|
||||
/**
|
||||
* 查询商户轮播图列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(Carousel carousel)
|
||||
{
|
||||
startPage();
|
||||
SysUser loginUser = getLoginUser().getUser();
|
||||
if(!loginUser.isAdmin()){
|
||||
carousel.setMerchantId(loginUser.getDeptId());
|
||||
}
|
||||
List<Carousel> list = carouselService.selectCarouselList(carousel);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出商户轮播图列表
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Carousel carousel)
|
||||
{
|
||||
List<Carousel> list = carouselService.selectCarouselList(carousel);
|
||||
ExcelUtil<Carousel> util = new ExcelUtil<Carousel>(Carousel.class);
|
||||
util.exportExcel(response, list, "商户轮播图数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商户轮播图详细信息
|
||||
*/
|
||||
@GetMapping(value = "/{carouselId}")
|
||||
public AjaxResult getInfo(@PathVariable("carouselId") Long carouselId)
|
||||
{
|
||||
return success(carouselService.selectCarouselByCarouselId(carouselId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商户轮播图
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody Carousel carousel)
|
||||
{
|
||||
SysUser loginUser = getLoginUser().getUser();
|
||||
if(!loginUser.isAdmin()){
|
||||
carousel.setMerchantId(loginUser.getDeptId());
|
||||
}else if(carousel.getMerchantId() == null){
|
||||
return AjaxResult.error("请指定轮播图所属商户");
|
||||
}
|
||||
List<Carousel> carousels = carouselService.selectCarouselList(carousel);
|
||||
if(carousels!=null && carousels.size() > 0){
|
||||
return AjaxResult.error("该商户已存在该轮播图,无法新增");
|
||||
}
|
||||
StringBuilder firstImages=new StringBuilder();
|
||||
StringBuilder destImages=new StringBuilder();
|
||||
ImagesPrefixUtil.dealImagesPath(carousel.getCarouselIamges(), firstImages, destImages);
|
||||
carousel.setCarouselIamges(destImages.toString());
|
||||
|
||||
return toAjax(carouselService.insertCarousel(carousel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改商户轮播图
|
||||
*/
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody Carousel carousel)
|
||||
{
|
||||
StringBuilder firstImages=new StringBuilder();
|
||||
StringBuilder destImages=new StringBuilder();
|
||||
ImagesPrefixUtil.dealImagesPath(carousel.getCarouselIamges(), firstImages, destImages);
|
||||
carousel.setCarouselIamges(destImages.toString());
|
||||
return toAjax(carouselService.updateCarousel(carousel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商户轮播图
|
||||
*/
|
||||
@DeleteMapping("/{carouselIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] carouselIds)
|
||||
{
|
||||
return toAjax(carouselService.deleteCarouselByCarouselIds(carouselIds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.zf.foodpurchase.fdsafe.web.merchant;
|
||||
|
||||
|
||||
import com.zf.foodpurchase.common.core.controller.BaseController;
|
||||
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysUser;
|
||||
import com.zf.foodpurchase.common.core.page.TableDataInfo;
|
||||
import com.zf.foodpurchase.fdsafe.entity.Browse;
|
||||
import com.zf.foodpurchase.fdsafe.service.IBrowseService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商品浏览记录表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author lilj
|
||||
* @since 2024-11-15
|
||||
*/
|
||||
@Api(tags = "商品浏览记录")
|
||||
@RestController
|
||||
@RequestMapping("/merchant/browse")
|
||||
public class MeBrowseController extends BaseController {
|
||||
@Autowired
|
||||
private IBrowseService browseService;
|
||||
|
||||
// 需要关联商品信息,关联查询.
|
||||
@ApiOperation("查询用户浏览记录")
|
||||
@GetMapping("list")
|
||||
public AjaxResult list() {
|
||||
SysUser user = getLoginUser().getUser();
|
||||
Browse browse = new Browse();
|
||||
if (!user.isAdmin()) {
|
||||
browse.setMerchantId(user.getDeptId());
|
||||
}
|
||||
List<Browse> list = browseService.joinQueryList(browse);
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@ApiOperation("查询用户浏览记录")
|
||||
@GetMapping("pageList")
|
||||
public TableDataInfo pageList(Browse browse) {
|
||||
startPage();
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (!user.isAdmin()) {
|
||||
browse.setMerchantId(user.getDeptId());
|
||||
}else{
|
||||
browse.setMerchantId(null);
|
||||
}
|
||||
List<Browse> list = browseService.joinQueryList(browse);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.zf.foodpurchase.fdsafe.web.merchant;
|
||||
|
||||
import com.zf.foodpurchase.common.constant.Constants;
|
||||
import com.zf.foodpurchase.common.constant.UserConstants;
|
||||
import com.zf.foodpurchase.common.core.controller.BaseController;
|
||||
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysDept;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysUser;
|
||||
import com.zf.foodpurchase.system.service.ISysDeptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author:lilj
|
||||
* @date:2024/12/17
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("admin/merchant")
|
||||
public class MerchantController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ISysDeptService sysDeptService;
|
||||
|
||||
@GetMapping("/merchantQuery")
|
||||
public AjaxResult merchantQuery(){
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if(!user.isAdmin()){
|
||||
return error("非管理员账号无法调用此接口");
|
||||
}
|
||||
|
||||
SysDept queryDept = new SysDept();
|
||||
// 只查询商户部门
|
||||
queryDept.setMerchantFlag("1");
|
||||
queryDept.setDelFlag(Constants.DEL_FLAG_NORMAL);
|
||||
queryDept.setStatus(UserConstants.DEPT_NORMAL);
|
||||
List<SysDept> depts = sysDeptService.selectDeptList(queryDept);
|
||||
return success(depts);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.zf.foodpurchase.fdsafe.web.merchant;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zf.foodpurchase.common.constant.Constants;
|
||||
import com.zf.foodpurchase.common.core.controller.BaseController;
|
||||
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysUser;
|
||||
import com.zf.foodpurchase.common.core.page.TableDataInfo;
|
||||
import com.zf.foodpurchase.common.exception.ServiceException;
|
||||
import com.zf.foodpurchase.common.utils.DateUtils;
|
||||
import com.zf.foodpurchase.common.utils.StringUtils;
|
||||
import com.zf.foodpurchase.common.utils.poi.ExcelUtil;
|
||||
import com.zf.foodpurchase.fdsafe.entity.Products;
|
||||
import com.zf.foodpurchase.fdsafe.entity.ProductsSpec;
|
||||
import com.zf.foodpurchase.fdsafe.entity.SpecValues;
|
||||
import com.zf.foodpurchase.fdsafe.service.IProductsService;
|
||||
import com.zf.foodpurchase.fdsafe.service.IProductsSpecService;
|
||||
import com.zf.foodpurchase.fdsafe.service.ISpecValuesService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-11-16
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/merchant/products")
|
||||
public class ProductsController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IProductsService productsService;
|
||||
|
||||
@Autowired
|
||||
private IProductsSpecService productsSpecService;
|
||||
|
||||
@Autowired
|
||||
private ISpecValuesService specValuesService;
|
||||
|
||||
private boolean isAllowDeleteSpecs = true;
|
||||
|
||||
/**
|
||||
* 查询商品列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(Products products)
|
||||
{
|
||||
startPage();
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
if(!sysUser.isAdmin()){
|
||||
products.setMerchantId(sysUser.getDeptId());
|
||||
}
|
||||
List<Products> list = productsService.selectProductsList(products);
|
||||
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
|
||||
// 遍历products
|
||||
list.forEach(item->{
|
||||
LambdaQueryWrapper<ProductsSpec> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ProductsSpec::getProductId,item.getProductId());
|
||||
List<ProductsSpec> productsSpecs = productsSpecService.listWithProductSpecValues(queryWrapper);
|
||||
if(CollectionUtils.isNotEmpty(productsSpecs)){
|
||||
item.setProductsSpecList(productsSpecs);
|
||||
|
||||
// 遍历productsSpecList
|
||||
for(ProductsSpec productsSpec:productsSpecs){
|
||||
List<Integer> specValuesIds = productsSpec.getSpecValuesIds();
|
||||
List<List<Integer>> specValueArray =new ArrayList<>();
|
||||
if(CollectionUtils.isNotEmpty(specValuesIds)){
|
||||
for(Integer integer : specValuesIds){
|
||||
if(integer!=null){
|
||||
SpecValues specValues = specValuesService.getById(integer);
|
||||
if(specValues!=null){
|
||||
List<Integer> arrayItem = new ArrayList<>();
|
||||
arrayItem.add(specValues.getSpecType());
|
||||
arrayItem.add(specValues.getId());
|
||||
specValueArray.add(arrayItem);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
productsSpec.setSpecValueArray(specValueArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
item.setProductsSpecList(new ArrayList<>());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出商品列表
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Products products)
|
||||
{
|
||||
List<Products> list = productsService.selectProductsList(products);
|
||||
ExcelUtil<Products> util = new ExcelUtil<Products>(Products.class);
|
||||
util.exportExcel(response, list, "商品数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品详细信息
|
||||
*/
|
||||
@GetMapping(value = "/{productId}")
|
||||
public AjaxResult getInfo(@PathVariable("productId") Integer productId)
|
||||
{
|
||||
return success(productsService.selectProductsByProductId(productId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商品
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody Products products)
|
||||
{
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
if(sysUser.isAdmin() ){
|
||||
if( products.getMerchantId() == null){
|
||||
return AjaxResult.warn("请选择所属商家");
|
||||
}
|
||||
} else{
|
||||
products.setMerchantId(sysUser.getDeptId());
|
||||
}
|
||||
|
||||
if(StringUtils.isBlank(products.getImages())){
|
||||
return AjaxResult.error("商品图片不能为空");
|
||||
}
|
||||
products.setProductId(null);
|
||||
products.setOperId(sysUser.getUserId());
|
||||
products.setCreateTime(DateUtils.getNowDate());
|
||||
// 多规格商品的库存添加对应规格商品时,自动累加
|
||||
if(Constants.MULTI_SPEC.equals(products.getIsSpecs())){
|
||||
products.setTotalStock(0);
|
||||
}else{
|
||||
if(Constants.GOODS_MONEY_BUY.equals(products.getType()) && products.getBasePrice()<=0){
|
||||
throw new ServiceException("人民币购买商品价格要大于0");
|
||||
}
|
||||
|
||||
if(Constants.GOODS_INTEGRAL_BUY.equals(products.getType()) && products.getBaseIntegral()<=0){
|
||||
throw new ServiceException("积分兑换商品积分要大于0");
|
||||
}
|
||||
}
|
||||
|
||||
return toAjax(productsService.insertProducts(products));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改商品
|
||||
*/
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody Products products)
|
||||
{
|
||||
if(products.getUpdateTime()==null){
|
||||
products.setUpdateTime(DateUtils.getNowDate());
|
||||
}
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
if(sysUser.isAdmin() ){
|
||||
if(products.getMerchantId() == null){
|
||||
return AjaxResult.warn("请选择所属商家");
|
||||
}
|
||||
} else{
|
||||
products.setMerchantId(sysUser.getDeptId());
|
||||
}
|
||||
products.setOperId(sysUser.getUserId());
|
||||
products.setUpdateTime(DateUtils.getNowDate());
|
||||
if(products.getIsSpecs()==null){
|
||||
return AjaxResult.error("请指定商品是否多规格");
|
||||
}
|
||||
if(Constants.SINGLE_SPEC.equals(products.getIsSpecs())){
|
||||
// return toAjax(productsService.updateProducts(products));
|
||||
// 商品类型为但规格处理
|
||||
boolean flag = productsSpecService.updateSingleProducts(products);
|
||||
return flag ? success("修改成功") : error("修改失败");
|
||||
}
|
||||
|
||||
else if(Constants.MULTI_SPEC.equals(products.getIsSpecs())){
|
||||
// 实现多规格商品信息变更的逻辑
|
||||
boolean flag = productsSpecService.updateMulSpecProducts(products);
|
||||
return flag ? success("修改成功") : error("修改失败");
|
||||
}
|
||||
|
||||
else{
|
||||
return AjaxResult.error("请指定商品是否多规格");
|
||||
}
|
||||
// return toAjax(productsSpecService.commonUpdateProducts(products));
|
||||
// return toAjax(productsService.updateProductsAndSpec(products));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*/
|
||||
@DeleteMapping("/{productIds}")
|
||||
public AjaxResult remove(@PathVariable Integer[] productIds)
|
||||
{
|
||||
return toAjax(productsService.deleteProductsByProductIds(productIds,isAllowDeleteSpecs));
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除商品
|
||||
*/
|
||||
@DeleteMapping("/logic/{productIds}")
|
||||
public AjaxResult logicDelete(@PathVariable Integer[] productIds)
|
||||
{
|
||||
return toAjax(productsService.deleteProductsLogicByProductIds(productIds));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.zf.foodpurchase.fdsafe.web.merchant;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zf.foodpurchase.common.core.controller.BaseController;
|
||||
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysUser;
|
||||
import com.zf.foodpurchase.common.core.page.TableDataInfo;
|
||||
import com.zf.foodpurchase.common.utils.DateUtils;
|
||||
import com.zf.foodpurchase.fdsafe.entity.Repository;
|
||||
import com.zf.foodpurchase.fdsafe.service.IRepositoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 仓库列表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author lilj
|
||||
* @since 2024-11-20
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/merchant/repository")
|
||||
public class RepositoryController extends BaseController {
|
||||
@Autowired
|
||||
private IRepositoryService repositoryService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list(Repository repository) {
|
||||
List<Repository> list = repositoryService.joinQueryList(getQuryRepository(repository));
|
||||
return AjaxResult.success("查询成功", list);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/pageList")
|
||||
public TableDataInfo pageList(Repository repository) {
|
||||
List<Repository> list = repositoryService.joinQueryList(getQuryRepository(repository));
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@PostMapping("/addRepo")
|
||||
public AjaxResult addRepo(@Validated @RequestBody Repository repository) {
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (!user.isAdmin()) {
|
||||
repository.setMerchantId(user.getDeptId());
|
||||
}else {
|
||||
if(repository.getMerchantId() == null){
|
||||
return error("必须指定要添加的仓库所属商户");
|
||||
}
|
||||
}
|
||||
repository.setCreateTime(DateUtils.getNowDate());
|
||||
repository.setOperId(getUserId());
|
||||
return repositoryService.saveRepo(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改前增加一步校验
|
||||
*
|
||||
* @param repository
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/modifyRepo")
|
||||
public AjaxResult modifyRepo(@Validated @RequestBody Repository repository) {
|
||||
if (repository.getId() == null) {
|
||||
return error("必须指定要修改的仓库id");
|
||||
}
|
||||
if (!verifyUpdateAuth(repository)) {
|
||||
return error("传入的商店下没有该仓库");
|
||||
}
|
||||
return repositoryService.modifyRepo(repository);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
public AjaxResult delete(Long[] ids) {
|
||||
SysUser user = getLoginUser().getUser();
|
||||
boolean flag = false;
|
||||
List<Long> list = Arrays.asList(ids);
|
||||
if (!user.isAdmin()) {
|
||||
LambdaQueryWrapper<Repository> queryWrapper = new LambdaQueryWrapper<Repository>();
|
||||
queryWrapper.in(Repository::getId, list);
|
||||
queryWrapper.eq(Repository::getMerchantId, user.getDeptId());
|
||||
flag = repositoryService.remove(queryWrapper);
|
||||
}else{
|
||||
flag = repositoryService.removeByIds(list);
|
||||
}
|
||||
return flag?AjaxResult.success("删除成功"):AjaxResult.error("删除失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件构建
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Repository getQuryRepository(Repository repository) {
|
||||
if (repository == null) {
|
||||
repository = new Repository();
|
||||
}
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (!user.isAdmin()) {
|
||||
repository.setMerchantId(user.getDeptId());
|
||||
} else {
|
||||
repository.setMerchantId(null);
|
||||
}
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是够具有修改记录的权限
|
||||
*
|
||||
* @param repository
|
||||
* @return
|
||||
*/
|
||||
public boolean verifyUpdateAuth(Repository repository) {
|
||||
|
||||
LambdaQueryWrapper<Repository> queryWrapper = new LambdaQueryWrapper<Repository>();
|
||||
queryWrapper.eq(Repository::getId, repository.getId());
|
||||
queryWrapper.eq(Repository::getMerchantId, getLoginUser().getUser().getDeptId());
|
||||
long count = repositoryService.count(queryWrapper);
|
||||
if (getLoginUser().getUser().isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package com.zf.foodpurchase.fdsafe.web.merchant;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zf.foodpurchase.common.core.controller.BaseController;
|
||||
import com.zf.foodpurchase.common.core.domain.AjaxResult;
|
||||
import com.zf.foodpurchase.common.core.domain.entity.SysUser;
|
||||
import com.zf.foodpurchase.common.core.page.TableDataInfo;
|
||||
import com.zf.foodpurchase.common.utils.DateUtils;
|
||||
import com.zf.foodpurchase.fdsafe.entity.Cascade;
|
||||
import com.zf.foodpurchase.fdsafe.entity.SpecTypes;
|
||||
import com.zf.foodpurchase.fdsafe.entity.SpecValues;
|
||||
import com.zf.foodpurchase.fdsafe.service.ISpecTypesService;
|
||||
import com.zf.foodpurchase.fdsafe.service.ISpecValuesService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商品规格类型表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author lilj
|
||||
* @since 2024-11-16
|
||||
*/
|
||||
@Api(tags = "规格类型管理")
|
||||
@RestController
|
||||
@RequestMapping("/merchant/specTypes")
|
||||
public class SpecTypesController extends BaseController {
|
||||
@Autowired
|
||||
private ISpecTypesService specTypesService;
|
||||
|
||||
@Autowired
|
||||
private ISpecValuesService specValuesService;
|
||||
|
||||
@ApiOperation("查询规格类型列表")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(String specName) {
|
||||
startPage();
|
||||
List<SpecTypes> typeList = new ArrayList<>();
|
||||
SysUser user=getLoginUser().getUser();
|
||||
Long merchantId = user.isAdmin()? null:user.getDeptId();
|
||||
|
||||
// 管理员
|
||||
if(merchantId == null){
|
||||
if(StringUtils.isNotBlank(specName)){
|
||||
LambdaQueryWrapper<SpecTypes> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.like(SpecTypes::getSpecName, specName);
|
||||
typeList = specTypesService.list(queryWrapper);
|
||||
}else{
|
||||
typeList = specTypesService.list();
|
||||
}
|
||||
}
|
||||
// 非管理员
|
||||
else{
|
||||
LambdaQueryWrapper<SpecTypes> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SpecTypes::getMerchantId, merchantId);
|
||||
queryWrapper.like(StringUtils.isNotBlank(specName),SpecTypes::getSpecName, specName);
|
||||
typeList = specTypesService.list(queryWrapper);
|
||||
}
|
||||
|
||||
for (SpecTypes specTypes : typeList) {
|
||||
LambdaQueryWrapper<SpecValues> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SpecValues::getSpecType, specTypes.getSpecType());
|
||||
List<SpecValues> specValuesList = specValuesService.list(queryWrapper);
|
||||
specTypes.setSpecValuesList(specValuesList);
|
||||
// 是否有子节点
|
||||
boolean hasChildren = !CollectionUtils.isEmpty(specValuesList);
|
||||
specTypes.setHasChildren(hasChildren);
|
||||
|
||||
if(hasChildren){
|
||||
specTypes.getSpecValuesList().forEach(specValues -> specValues.setSpecName(specTypes.getSpecName()));
|
||||
}
|
||||
}
|
||||
return getDataTable(typeList);
|
||||
}
|
||||
|
||||
@ApiOperation("规格列表级联结构")
|
||||
@GetMapping("/cascade")
|
||||
public AjaxResult cascade(Long merchantId) {
|
||||
List<SpecTypes> typeList = new ArrayList<>();
|
||||
SysUser user=getLoginUser().getUser();
|
||||
if(user.isAdmin()){
|
||||
if(merchantId == null){
|
||||
return error("请传入商户id");
|
||||
}else{
|
||||
typeList = specTypesService.list(new LambdaQueryWrapper<SpecTypes>().eq(SpecTypes::getMerchantId, merchantId));
|
||||
}
|
||||
}else{
|
||||
merchantId = user.getDeptId();
|
||||
typeList = specTypesService.list(new LambdaQueryWrapper<SpecTypes>().eq(SpecTypes::getMerchantId, merchantId));
|
||||
}
|
||||
HashMap<String,List<Cascade>> map = new HashMap<>();
|
||||
List<Cascade> parentList = new ArrayList<>();
|
||||
// 逐层构建
|
||||
for (SpecTypes specTypes : typeList) {
|
||||
Cascade parentNode = new Cascade();
|
||||
parentNode.setLabel(specTypes.getSpecName());
|
||||
parentNode.setValue(specTypes.getSpecType());
|
||||
// 级联结构构件
|
||||
List<Cascade> childrenList = new ArrayList<>();
|
||||
LambdaQueryWrapper<SpecValues> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SpecValues::getSpecType, specTypes.getSpecType());
|
||||
List<SpecValues> specValuesList = specValuesService.list(queryWrapper);
|
||||
// 是否有子节点
|
||||
boolean hasChildren = !CollectionUtils.isEmpty(specValuesList);
|
||||
if(hasChildren){
|
||||
specValuesList.forEach(specValues -> {
|
||||
Cascade cascade = new Cascade();
|
||||
if(StringUtils.isNotBlank(specValues.getSpecUnit())){
|
||||
cascade.setLabel(specValues.getSpecValue()+specValues.getSpecUnit());
|
||||
}else {
|
||||
cascade.setLabel(specValues.getSpecValue());
|
||||
}
|
||||
cascade.setValue(specValues.getId());
|
||||
childrenList.add(cascade);
|
||||
|
||||
} );
|
||||
parentNode.setChildren(childrenList);
|
||||
parentList.add(parentNode);
|
||||
}
|
||||
}
|
||||
|
||||
return success(parentList);
|
||||
}
|
||||
|
||||
@ApiOperation("添加规格类型列表")
|
||||
@PostMapping("/addSpecTypes")
|
||||
public AjaxResult addSpecTypes(@Validated @RequestBody SpecTypes specTypes) {
|
||||
SysUser user=getLoginUser().getUser();
|
||||
if(user.isAdmin()){
|
||||
if(specTypes.getMerchantId() == null){
|
||||
return error("请指定商户");
|
||||
}
|
||||
}else{
|
||||
specTypes.setMerchantId(user.getDeptId());
|
||||
}
|
||||
specTypes.setOperId(getUserId());
|
||||
specTypes.setCreateTime(DateUtils.getNowDate());
|
||||
return specTypesService.saveTypes(specTypes);
|
||||
}
|
||||
|
||||
// @ApiOperation("修改规格类型列表")
|
||||
// @PostMapping("/modifySpecName")
|
||||
// public AjaxResult modifySpecName(@Validated @RequestBody SpecTypes specTypes) {
|
||||
// SysUser user=getLoginUser().getUser();
|
||||
// specTypes.setOperId(getUserId());
|
||||
// specTypes.setUpdateTime(DateUtils.getNowDate());
|
||||
// if(user.isAdmin()){
|
||||
// if(specTypes.getMerchantId() == null){
|
||||
// return error("请指定商户");
|
||||
// }
|
||||
// }else{
|
||||
// specTypes.setMerchantId(user.getDeptId());
|
||||
// }
|
||||
// return specTypesService.updateType(specTypes,user.isAdmin());
|
||||
// }
|
||||
|
||||
// @ApiOperation("删除规格类型列表-单个")
|
||||
// @DeleteMapping("/deleteById")
|
||||
// public AjaxResult deleteById(Long id) {
|
||||
// if (id == null) {
|
||||
// return warn("请选择要删除的数据");
|
||||
// }
|
||||
//
|
||||
// // todo:如果有类型值关联,需要先删除对应的类型值
|
||||
// LambdaQueryWrapper<SpecValues> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// queryWrapper.eq(SpecValues::getSpecType, id);
|
||||
// if (specValuesService.count(queryWrapper) > 0) {
|
||||
// return error("该规格类型下有规格值,请先删除规格值");
|
||||
// }
|
||||
//
|
||||
// return toAjax(specTypesService.removeById(id));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 注意: 需要确保改ids不存在关联的规格值,否则无法删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("删除规格类型列表-多个")
|
||||
@DeleteMapping("/deleteByIds")
|
||||
public AjaxResult deleteByIds(Long id) {
|
||||
if (id == null ) {
|
||||
return warn("请选择要删除的数据");
|
||||
}
|
||||
List<Long> list = new ArrayList<>();
|
||||
list.add(id);
|
||||
SysUser user=getLoginUser().getUser();
|
||||
Long merchantId = user.isAdmin()? null:user.getDeptId();
|
||||
return specTypesService.removeSpecTypes(list,merchantId);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("删除规格类型列表-多个")
|
||||
@DeleteMapping("/deleteMoreIds")
|
||||
public AjaxResult deleteMoreIds(Long[] ids) {
|
||||
if (ids == null || ids.length <= 0) {
|
||||
return warn("请选择要删除的数据");
|
||||
}
|
||||
List<Long> list = Arrays.asList(ids);
|
||||
SysUser user=getLoginUser().getUser();
|
||||
Long merchantId = user.isAdmin()? null:user.getDeptId();
|
||||
return specTypesService.removeSpecTypes(list,merchantId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,13 +12,6 @@ spring:
|
||||
url: jdbc:mysql://39.165.209.170:3307/zf_school_food?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: zheng_wXn_fan*QFs_6aNvFq@keji_qDr.gPYsfBL
|
||||
# 从库数据源
|
||||
slave:
|
||||
# 从数据源开关/默认关闭
|
||||
#enabled: false
|
||||
url: jdbc:mysql://39.165.209.170:3307/zf_shopping_mall?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: zheng_wXn_fan*QFs_6aNvFq@keji_qDr.gPYsfBL
|
||||
# 初始连接数
|
||||
initialSize: 5
|
||||
# 最小连接池数量
|
||||
|
||||
@@ -26,7 +26,7 @@ server:
|
||||
port: 8090
|
||||
servlet:
|
||||
# 应用的访问路径
|
||||
context-path: /
|
||||
context-path: /schoolfood
|
||||
tomcat:
|
||||
# tomcat的URI编码
|
||||
uri-encoding: UTF-8
|
||||
@@ -79,9 +79,15 @@ spring:
|
||||
redis:
|
||||
# host: localhost
|
||||
# port: 6379
|
||||
host: 125.46.39.9
|
||||
database: 11
|
||||
password: zhengfan999
|
||||
# 地址
|
||||
host: 39.165.209.170
|
||||
# 端口,默认为6379 服务器密码:zhengfan999
|
||||
port: 6379
|
||||
# 数据库索引
|
||||
database: 0
|
||||
# 密码
|
||||
password: zheng_wXn_fan*QFs_6aNvFq@keji_qDr.gPYsfBL
|
||||
# 连接超时时间
|
||||
timeout: 10s
|
||||
lettuce:
|
||||
pool:
|
||||
|
||||
Reference in New Issue
Block a user