package com.zy.acs.manager.manager.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.zy.acs.framework.common.Cools;
|
import com.zy.acs.framework.common.R;
|
import com.zy.acs.manager.common.utils.ExcelUtil;
|
import com.zy.acs.manager.common.annotation.OperationLog;
|
import com.zy.acs.manager.common.domain.BaseParam;
|
import com.zy.acs.manager.common.domain.KeyValVo;
|
import com.zy.acs.manager.common.domain.PageParam;
|
import com.zy.acs.manager.manager.entity.StaType;
|
import com.zy.acs.manager.manager.service.StaTypeService;
|
import com.zy.acs.manager.system.controller.BaseController;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.*;
|
|
@RestController
|
@RequestMapping("/api")
|
public class StaTypeController extends BaseController {
|
|
@Autowired
|
private StaTypeService staTypeService;
|
|
@PreAuthorize("hasAuthority('manager:staType:list')")
|
@PostMapping("/staType/page")
|
public R page(@RequestBody Map<String, Object> map) {
|
BaseParam baseParam = buildParam(map, BaseParam.class);
|
PageParam<StaType, BaseParam> pageParam = new PageParam<>(baseParam, StaType.class);
|
return R.ok().add(staTypeService.page(pageParam, pageParam.buildWrapper(true)));
|
}
|
|
@PreAuthorize("hasAuthority('manager:staType:list')")
|
@PostMapping("/staType/list")
|
public R list(@RequestBody Map<String, Object> map) {
|
return R.ok().add(staTypeService.list());
|
}
|
|
@PreAuthorize("hasAuthority('system:staType:list')")
|
@PostMapping({"/staType/many/{ids}", "/staTypes/many/{ids}"})
|
public R many(@PathVariable Long[] ids) {
|
return R.ok().add(staTypeService.listByIds(Arrays.asList(ids)));
|
}
|
|
@PreAuthorize("hasAuthority('manager:staType:list')")
|
@GetMapping("/staType/{id}")
|
public R get(@PathVariable("id") Long id) {
|
return R.ok().add(staTypeService.getById(id));
|
}
|
|
@PreAuthorize("hasAuthority('manager:staType:save')")
|
@OperationLog("Create StaType")
|
@PostMapping("/staType/save")
|
public R save(@RequestBody StaType staType) {
|
staType.setCreateBy(getLoginUserId());
|
staType.setCreateTime(new Date());
|
staType.setUpdateBy(getLoginUserId());
|
staType.setUpdateTime(new Date());
|
if (!staTypeService.save(staType)) {
|
return R.error("Save Fail");
|
}
|
return R.ok("Save Success").add(staType);
|
}
|
|
@PreAuthorize("hasAuthority('manager:staType:update')")
|
@OperationLog("Update StaType")
|
@PostMapping("/staType/update")
|
public R update(@RequestBody StaType staType) {
|
staType.setUpdateBy(getLoginUserId());
|
staType.setUpdateTime(new Date());
|
if (!staTypeService.updateById(staType)) {
|
return R.error("Update Fail");
|
}
|
return R.ok("Update Success").add(staType);
|
}
|
|
@PreAuthorize("hasAuthority('manager:staType:remove')")
|
@OperationLog("Delete StaType")
|
@PostMapping("/staType/remove/{ids}")
|
public R remove(@PathVariable Long[] ids) {
|
if (!staTypeService.removeByIds(Arrays.asList(ids))) {
|
return R.error("Delete Fail");
|
}
|
return R.ok("Delete Success").add(ids);
|
}
|
|
@PreAuthorize("hasAuthority('manager:staType:list')")
|
@PostMapping("/staType/query")
|
public R query(@RequestParam(required = false) String condition) {
|
List<KeyValVo> vos = new ArrayList<>();
|
LambdaQueryWrapper<StaType> wrapper = new LambdaQueryWrapper<>();
|
if (!Cools.isEmpty(condition)) {
|
wrapper.like(StaType::getName, condition);
|
}
|
staTypeService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
|
item -> vos.add(new KeyValVo(item.getId(), item.getName()))
|
);
|
return R.ok().add(vos);
|
}
|
|
@PreAuthorize("hasAuthority('manager:staType:list')")
|
@PostMapping("/staType/export")
|
public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
|
ExcelUtil.build(ExcelUtil.create(staTypeService.list(), StaType.class), response);
|
}
|
|
}
|