electripper-v2/ruoyi-web/src/main/java/com/ruoyi/web/bst/ModelController.java
2025-03-21 17:47:51 +08:00

145 lines
4.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.ruoyi.web.bst;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
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.model.domain.Model;
import com.ruoyi.bst.model.domain.ModelQuery;
import com.ruoyi.bst.model.domain.ModelVO;
import com.ruoyi.bst.model.service.ModelAssembler;
import com.ruoyi.bst.model.service.ModelService;
import com.ruoyi.bst.model.service.ModelValidator;
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;
import com.ruoyi.common.core.validate.ValidGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.user.service.UserValidator;
/**
* 车辆型号Controller
*
* @author ruoyi
* @date 2025-03-18
*/
@RestController
@RequestMapping("/bst/model")
public class ModelController extends BaseController
{
@Autowired
private ModelService modelService;
@Autowired
private UserValidator userValidator;
@Autowired
private ModelAssembler modelAssembler;
@Autowired
private ModelValidator modelValidator;
/**
* 查询车辆型号列表
*/
@PreAuthorize("@ss.hasPermi('bst:model:list')")
@GetMapping("/list")
public TableDataInfo list(ModelQuery query)
{
startPage();
startOrderBy();
query.setScope(true);
List<ModelVO> list = modelService.selectModelList(query);
return getDataTable(list);
}
/**
* 导出车辆型号列表
*/
@PreAuthorize("@ss.hasPermi('bst:model:export')")
@Log(title = "车辆型号", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, ModelQuery query)
{
query.setScope(true);
List<ModelVO> list = modelService.selectModelList(query);
ExcelUtil<ModelVO> util = new ExcelUtil<ModelVO>(ModelVO.class);
util.exportExcel(response, list, "车辆型号数据");
}
/**
* 获取车辆型号详细信息
*/
@PreAuthorize("@ss.hasPermi('bst:model:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
ModelVO model = modelService.selectModelById(id, true);
List<ModelVO> list = Collections.singletonList(model);
modelAssembler.assembleSuitList(list);
return success(model);
}
/**
* 新增车辆型号
*/
@PreAuthorize("@ss.hasPermi('bst:model:add')")
@Log(title = "车辆型号", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Model data)
{
// 若不能操作他人,则设置为当前用户
if (!userValidator.canView(data.getUserId())) {
data.setUserId(getUserId());
}
return toAjax(modelService.insertModel(data));
}
/**
* 修改车辆型号
*/
@PreAuthorize("@ss.hasPermi('bst:model:edit')")
@Log(title = "车辆型号", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) Model data)
{
ServiceUtil.assertion(!modelValidator.canEdit(data.getId()),
"当前用户无权限修改ID为%s的型号", data.getId());
// 若不能操作他人则不修改用户ID
if (!userValidator.canView(data.getUserId())) {
data.setUserId(null);
}
return toAjax(modelService.updateModel(data));
}
/**
* 删除车辆型号
*/
@PreAuthorize("@ss.hasPermi('bst:model:remove')")
@Log(title = "车辆型号", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable List<Long> ids)
{
ServiceUtil.assertion(!modelValidator.canDeleteAll(ids),
"当前用户无权限删除ID为%s的型号", ids);
return toAjax(modelService.logicDel(ids));
}
}