2025-03-17 18:08:50 +08:00
|
|
|
|
package com.ruoyi.web.bst;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
2025-04-12 16:15:50 +08:00
|
|
|
|
import com.ruoyi.bst.suit.domain.enums.SuitRentalUnit;
|
|
|
|
|
import com.ruoyi.bst.suit.domain.enums.SuitRidingRule;
|
|
|
|
|
import com.ruoyi.bst.suit.utils.SuitUtil;
|
2025-03-17 18:08:50 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2025-03-18 18:05:10 +08:00
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
2025-03-17 18:08:50 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.bst.suit.domain.Suit;
|
|
|
|
|
import com.ruoyi.bst.suit.domain.SuitQuery;
|
|
|
|
|
import com.ruoyi.bst.suit.domain.SuitVO;
|
|
|
|
|
import com.ruoyi.bst.suit.service.SuitService;
|
2025-03-18 18:05:10 +08:00
|
|
|
|
import com.ruoyi.bst.suit.service.SuitValidator;
|
2025-03-17 18:08:50 +08:00
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
2025-03-18 18:05:10 +08:00
|
|
|
|
import com.ruoyi.common.core.validate.ValidGroup;
|
2025-03-17 18:08:50 +08:00
|
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
2025-03-18 18:05:10 +08:00
|
|
|
|
import com.ruoyi.common.utils.ServiceUtil;
|
2025-03-17 18:08:50 +08:00
|
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
2025-03-21 17:47:51 +08:00
|
|
|
|
import com.ruoyi.system.user.service.UserValidator;
|
2025-03-17 18:08:50 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 套餐Controller
|
|
|
|
|
*
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
* @date 2025-03-17
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/bst/suit")
|
|
|
|
|
public class SuitController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
@Autowired
|
|
|
|
|
private SuitService suitService;
|
|
|
|
|
|
2025-03-18 18:05:10 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
private SuitValidator suitValidator;
|
|
|
|
|
|
2025-03-21 17:47:51 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
private UserValidator userValidator;
|
|
|
|
|
|
2025-03-17 18:08:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* 查询套餐列表
|
|
|
|
|
*/
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('bst:suit:list')")
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
public TableDataInfo list(SuitQuery query)
|
|
|
|
|
{
|
|
|
|
|
startPage();
|
|
|
|
|
startOrderBy();
|
2025-03-18 18:05:10 +08:00
|
|
|
|
query.setScope(true);
|
2025-03-17 18:08:50 +08:00
|
|
|
|
List<SuitVO> list = suitService.selectSuitList(query);
|
|
|
|
|
return getDataTable(list);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 17:47:51 +08:00
|
|
|
|
/**
|
|
|
|
|
* 查询套餐列表
|
|
|
|
|
*/
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('bst:suit:list')")
|
|
|
|
|
@PostMapping("/listByIds")
|
|
|
|
|
public AjaxResult listByIds(@RequestBody List<Long> ids)
|
|
|
|
|
{
|
|
|
|
|
SuitQuery query = new SuitQuery();
|
|
|
|
|
query.setIds(ids);
|
|
|
|
|
query.setScope(true);
|
|
|
|
|
List<SuitVO> list = suitService.selectSuitList(query);
|
|
|
|
|
return success(list);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-17 18:08:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* 导出套餐列表
|
|
|
|
|
*/
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('bst:suit:export')")
|
|
|
|
|
@Log(title = "套餐", businessType = BusinessType.EXPORT)
|
|
|
|
|
@PostMapping("/export")
|
|
|
|
|
public void export(HttpServletResponse response, SuitQuery query)
|
|
|
|
|
{
|
2025-03-18 18:05:10 +08:00
|
|
|
|
query.setScope(true);
|
2025-03-17 18:08:50 +08:00
|
|
|
|
List<SuitVO> list = suitService.selectSuitList(query);
|
|
|
|
|
ExcelUtil<SuitVO> util = new ExcelUtil<SuitVO>(SuitVO.class);
|
|
|
|
|
util.exportExcel(response, list, "套餐数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取套餐详细信息
|
|
|
|
|
*/
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('bst:suit:query')")
|
|
|
|
|
@GetMapping(value = "/{id}")
|
|
|
|
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
|
|
{
|
2025-03-18 18:05:10 +08:00
|
|
|
|
return success(suitService.selectSuitById(id, true));
|
2025-03-17 18:08:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增套餐
|
|
|
|
|
*/
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('bst:suit:add')")
|
|
|
|
|
@Log(title = "套餐", businessType = BusinessType.INSERT)
|
|
|
|
|
@PostMapping
|
2025-03-18 18:05:10 +08:00
|
|
|
|
public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Suit suit)
|
2025-03-17 18:08:50 +08:00
|
|
|
|
{
|
2025-03-21 17:47:51 +08:00
|
|
|
|
// 判断能否操作他人的套餐,不能则设置为当前用户
|
|
|
|
|
if (!userValidator.canView(suit.getUserId())) {
|
2025-03-18 18:05:10 +08:00
|
|
|
|
suit.setUserId(getUserId());
|
|
|
|
|
}
|
2025-03-17 18:08:50 +08:00
|
|
|
|
return toAjax(suitService.insertSuit(suit));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改套餐
|
|
|
|
|
*/
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('bst:suit:edit')")
|
|
|
|
|
@Log(title = "套餐", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PutMapping
|
2025-03-18 18:05:10 +08:00
|
|
|
|
public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) Suit suit) {
|
|
|
|
|
|
|
|
|
|
ServiceUtil.assertion(!suitValidator.canEdit(suit.getId()),
|
|
|
|
|
"您无权修改ID为%s的套餐", suit.getId());
|
2025-03-21 17:47:51 +08:00
|
|
|
|
// 若不能操作他人的套餐,则不修改用户ID
|
|
|
|
|
if (!userValidator.canView(suit.getUserId())) {
|
2025-03-18 18:05:10 +08:00
|
|
|
|
suit.setUserId(null);
|
|
|
|
|
}
|
2025-03-17 18:08:50 +08:00
|
|
|
|
return toAjax(suitService.updateSuit(suit));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除套餐
|
|
|
|
|
*/
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('bst:suit:remove')")
|
|
|
|
|
@Log(title = "套餐", businessType = BusinessType.DELETE)
|
|
|
|
|
@DeleteMapping("/{ids}")
|
|
|
|
|
public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
|
|
{
|
|
|
|
|
return toAjax(suitService.deleteSuitByIds(ids));
|
|
|
|
|
}
|
2025-04-12 16:15:50 +08:00
|
|
|
|
|
|
|
|
|
// @GetMapping("/test")
|
|
|
|
|
// public AjaxResult test(Long seconds, Long suitId)
|
|
|
|
|
// {
|
|
|
|
|
// SuitVO suit = suitService.selectSuitById(suitId);
|
|
|
|
|
// SuitRentalUnit rentalUnit = SuitRentalUnit.parse(suit.getRentalUnit());
|
|
|
|
|
// if (SuitRidingRule.INTERVAL_FEE.getCode().equals(suit.getRidingRule())) {
|
|
|
|
|
// return success(SuitUtil.calcAmountForIntervalFee(seconds, suit.getIntervalRule(), rentalUnit));
|
|
|
|
|
// } else {
|
|
|
|
|
// return success(SuitUtil.calcAmountForStartFee(seconds, suit.getStartRule(), rentalUnit));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2025-03-17 18:08:50 +08:00
|
|
|
|
}
|