|
|
|
@ -0,0 +1,123 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* https://www.mall4j.com/
|
|
|
|
|
*
|
|
|
|
|
* 未经允许,不可做商业用途!
|
|
|
|
|
*
|
|
|
|
|
* 版权所有,侵权必究!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.yami.shop.admin.controller; // 定义类所在的包
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; // 引入MyBatis-Plus的条件查询包装器
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; // 引入MyBatis-Plus的分页接口
|
|
|
|
|
import com.yami.shop.bean.model.Transport; // 引入运费模板模型类
|
|
|
|
|
import com.yami.shop.common.util.PageParam; // 引入分页参数工具类
|
|
|
|
|
import com.yami.shop.security.admin.util.SecurityUtils; // 引入安全工具类
|
|
|
|
|
import com.yami.shop.service.TransportService; // 引入运费模板服务类
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; // 引入Apache Commons的StringUtils工具类
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 引入Spring的@Autowired注解
|
|
|
|
|
import com.yami.shop.common.response.ServerResponseEntity; // 引入服务器响应实体类
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize; // 引入Spring Security的PreAuthorize注解
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.Date; // 引入Java的Date类
|
|
|
|
|
import java.util.List; // 引入Java的List接口
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 运费模板管理控制器
|
|
|
|
|
* 该类包含分页获取、获取详细信息、保存、修改和删除运费模板的方法。
|
|
|
|
|
* @作者 lgh on 2018/11/16.
|
|
|
|
|
*/
|
|
|
|
|
@RestController // 标注这是一个控制器类,并且其返回结果直接写入HTTP响应体中,而不是视图名称
|
|
|
|
|
@RequestMapping("/shop/transport") // 定义请求路径的根地址为/shop/transport
|
|
|
|
|
public class TransportController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TransportService transportService; // 自动注入运费模板服务类
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页获取运费模板
|
|
|
|
|
* @param transport 运费模板查询条件
|
|
|
|
|
* @param page 分页参数
|
|
|
|
|
* @return 服务器响应实体,包含分页后的运费模板信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/page")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('shop:transport:page')") // 权限检查
|
|
|
|
|
public ServerResponseEntity<IPage<Transport>> page(Transport transport, PageParam<Transport> page) {
|
|
|
|
|
Long shopId = SecurityUtils.getSysUser().getShopId();
|
|
|
|
|
IPage<Transport> transports = transportService.page(page,
|
|
|
|
|
new LambdaQueryWrapper<Transport>()
|
|
|
|
|
.eq(Transport::getShopId, shopId)
|
|
|
|
|
.like(StringUtils.isNotBlank(transport.getTransName()), Transport::getTransName, transport.getTransName()));
|
|
|
|
|
return ServerResponseEntity.success(transports);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取运费模板详细信息
|
|
|
|
|
* @param id 运费模板ID
|
|
|
|
|
* @return 服务器响应实体,包含运费模板的详细信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/info/{id}")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('shop:transport:info')") // 权限检查
|
|
|
|
|
public ServerResponseEntity<Transport> info(@PathVariable("id") Long id) {
|
|
|
|
|
Transport transport = transportService.getTransportAndAllItems(id);
|
|
|
|
|
return ServerResponseEntity.success(transport);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存运费模板
|
|
|
|
|
* @param transport 运费模板信息
|
|
|
|
|
* @return 服务器响应实体
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('shop:transport:save')") // 权限检查
|
|
|
|
|
public ServerResponseEntity<Void> save(@RequestBody Transport transport) {
|
|
|
|
|
Long shopId = SecurityUtils.getSysUser().getShopId();
|
|
|
|
|
transport.setShopId(shopId);
|
|
|
|
|
Date createTime = new Date();
|
|
|
|
|
transport.setCreateTime(createTime);
|
|
|
|
|
transportService.insertTransportAndTransfee(transport);
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改运费模板
|
|
|
|
|
* @param transport 运费模板信息
|
|
|
|
|
* @return 服务器响应实体
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('shop:transport:update')") // 权限检查
|
|
|
|
|
public ServerResponseEntity<Void> update(@RequestBody Transport transport) {
|
|
|
|
|
transportService.updateTransportAndTransfee(transport);
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除运费模板
|
|
|
|
|
* @param ids 运费模板ID数组
|
|
|
|
|
* @return 服务器响应实体
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('shop:transport:delete')") // 权限检查
|
|
|
|
|
public ServerResponseEntity<Void> delete(@RequestBody Long[] ids) {
|
|
|
|
|
transportService.deleteTransportAndTransfeeAndTranscity(ids);
|
|
|
|
|
// 删除运费模板的缓存
|
|
|
|
|
for (Long id : ids) {
|
|
|
|
|
transportService.removeTransportAndAllItemsCache(id);
|
|
|
|
|
}
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取运费模板列表
|
|
|
|
|
* @return 服务器响应实体,包含运费模板列表信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
public ServerResponseEntity<List<Transport>> list() {
|
|
|
|
|
Long shopId = SecurityUtils.getSysUser().getShopId();
|
|
|
|
|
List<Transport> list = transportService.list(new LambdaQueryWrapper<Transport>().eq(Transport::getShopId, shopId));
|
|
|
|
|
return ServerResponseEntity.success(list);
|
|
|
|
|
}
|
|
|
|
|
}
|