electripper-v2/ruoyi-web/src/main/java/com/ruoyi/web/bst/ModelController.java

145 lines
4.7 KiB
Java
Raw Normal View History

2025-03-18 18:05:10 +08:00
package com.ruoyi.web.bst;
2025-03-21 17:47:51 +08:00
import java.util.Collections;
2025-03-18 18:05:10 +08:00
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;
2025-03-21 17:47:51 +08:00
import com.ruoyi.bst.model.domain.Model;
2025-03-18 18:05:10 +08:00
import com.ruoyi.bst.model.domain.ModelQuery;
import com.ruoyi.bst.model.domain.ModelVO;
2025-03-21 17:47:51 +08:00
import com.ruoyi.bst.model.service.ModelAssembler;
2025-03-18 18:05:10 +08:00
import com.ruoyi.bst.model.service.ModelService;
2025-03-21 17:47:51 +08:00
import com.ruoyi.bst.model.service.ModelValidator;
2025-03-18 18:05:10 +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;
import com.ruoyi.common.core.validate.ValidGroup;
import com.ruoyi.common.enums.BusinessType;
2025-03-21 17:47:51 +08:00
import com.ruoyi.common.utils.ServiceUtil;
2025-03-18 18:05:10 +08:00
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;
2025-03-21 17:47:51 +08:00
@Autowired
private ModelAssembler modelAssembler;
@Autowired
private ModelValidator modelValidator;
2025-03-18 18:05:10 +08:00
/**
* 查询车辆型号列表
*/
@PreAuthorize("@ss.hasPermi('bst:model:list')")
@GetMapping("/list")
public TableDataInfo list(ModelQuery query)
{
startPage();
startOrderBy();
2025-03-21 17:47:51 +08:00
query.setScope(true);
2025-03-18 18:05:10 +08:00
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)
{
2025-03-21 17:47:51 +08:00
query.setScope(true);
2025-03-18 18:05:10 +08:00
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)
{
2025-03-21 17:47:51 +08:00
ModelVO model = modelService.selectModelById(id, true);
List<ModelVO> list = Collections.singletonList(model);
modelAssembler.assembleSuitList(list);
return success(model);
2025-03-18 18:05:10 +08:00
}
/**
* 新增车辆型号
*/
@PreAuthorize("@ss.hasPermi('bst:model:add')")
@Log(title = "车辆型号", businessType = BusinessType.INSERT)
@PostMapping
2025-03-21 17:47:51 +08:00
public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Model data)
2025-03-18 18:05:10 +08:00
{
2025-03-21 17:47:51 +08:00
// 若不能操作他人,则设置为当前用户
if (!userValidator.canView(data.getUserId())) {
data.setUserId(getUserId());
}
return toAjax(modelService.insertModel(data));
2025-03-18 18:05:10 +08:00
}
/**
* 修改车辆型号
*/
@PreAuthorize("@ss.hasPermi('bst:model:edit')")
@Log(title = "车辆型号", businessType = BusinessType.UPDATE)
@PutMapping
2025-03-21 17:47:51 +08:00
public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) Model data)
2025-03-18 18:05:10 +08:00
{
2025-03-21 17:47:51 +08:00
ServiceUtil.assertion(!modelValidator.canEdit(data.getId()),
"当前用户无权限修改ID为%s的型号", data.getId());
// 若不能操作他人则不修改用户ID
if (!userValidator.canView(data.getUserId())) {
data.setUserId(null);
}
return toAjax(modelService.updateModel(data));
2025-03-18 18:05:10 +08:00
}
/**
* 删除车辆型号
*/
@PreAuthorize("@ss.hasPermi('bst:model:remove')")
@Log(title = "车辆型号", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
2025-03-21 17:47:51 +08:00
public AjaxResult remove(@PathVariable List<Long> ids)
2025-03-18 18:05:10 +08:00
{
2025-03-21 17:47:51 +08:00
ServiceUtil.assertion(!modelValidator.canDeleteAll(ids),
"当前用户无权限删除ID为%s的型号", ids);
return toAjax(modelService.logicDel(ids));
2025-03-18 18:05:10 +08:00
}
}