145 lines
4.7 KiB
Java
145 lines
4.7 KiB
Java
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));
|
||
}
|
||
}
|