wangjinhao_branch
wangjinhao 9 months ago
parent 0e4dd83712
commit cda43bd9b4

@ -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);
}
}
Loading…
Cancel
Save