package com.vincent.rsf.server.manager.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.vincent.rsf.framework.common.Cools;
|
import com.vincent.rsf.framework.common.R;
|
import com.vincent.rsf.framework.exception.CoolException;
|
import com.vincent.rsf.server.common.utils.ExcelUtil;
|
import com.vincent.rsf.server.common.annotation.OperationLog;
|
import com.vincent.rsf.server.common.domain.BaseParam;
|
import com.vincent.rsf.server.common.domain.KeyValVo;
|
import com.vincent.rsf.server.common.domain.PageParam;
|
import com.vincent.rsf.server.manager.controller.params.IsptItemsParams;
|
import com.vincent.rsf.server.manager.controller.params.QlyInspectAndItem;
|
import com.vincent.rsf.server.manager.entity.QlyIsptItem;
|
import com.vincent.rsf.server.manager.service.QlyIsptItemService;
|
import com.vincent.rsf.server.system.controller.BaseController;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
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.*;
|
|
@Api(tags = "质检明细")
|
@RestController
|
public class QlyIsptItemController extends BaseController {
|
|
@Autowired
|
private QlyIsptItemService qlyIsptItemService;
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:list')")
|
@PostMapping("/qlyIsptItem/page")
|
public R page(@RequestBody Map<String, Object> map) {
|
BaseParam baseParam = buildParam(map, BaseParam.class);
|
PageParam<QlyIsptItem, BaseParam> pageParam = new PageParam<>(baseParam, QlyIsptItem.class);
|
return R.ok().add(qlyIsptItemService.page(pageParam, pageParam.buildWrapper(true)));
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:list')")
|
@PostMapping("/qlyIsptItem/list")
|
public R list(@RequestBody Map<String, Object> map) {
|
return R.ok().add(qlyIsptItemService.list());
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:list')")
|
@PostMapping({"/qlyIsptItem/many/{ids}", "/qlyIsptItems/many/{ids}"})
|
public R many(@PathVariable Long[] ids) {
|
return R.ok().add(qlyIsptItemService.listByIds(Arrays.asList(ids)));
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:list')")
|
@GetMapping("/qlyIsptItem/{id}")
|
public R get(@PathVariable("id") Long id) {
|
return R.ok().add(qlyIsptItemService.getById(id));
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:save')")
|
@OperationLog("Create 质检信息")
|
@PostMapping("/qlyIsptItem/save")
|
public R save(@RequestBody QlyIsptItem qlyIsptItem) {
|
qlyIsptItem.setCreateBy(getLoginUserId());
|
qlyIsptItem.setCreateTime(new Date());
|
qlyIsptItem.setUpdateBy(getLoginUserId());
|
qlyIsptItem.setUpdateTime(new Date());
|
if (!qlyIsptItemService.save(qlyIsptItem)) {
|
return R.error("Save Fail");
|
}
|
return R.ok("Save Success").add(qlyIsptItem);
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:update')")
|
@OperationLog("Update 质检信息")
|
@PostMapping("/qlyIsptItem/update")
|
public R update(@RequestBody QlyIsptItem qlyIsptItem) {
|
qlyIsptItem.setUpdateBy(getLoginUserId());
|
qlyIsptItem.setUpdateTime(new Date());
|
if (!qlyIsptItemService.updateById(qlyIsptItem)) {
|
return R.error("Update Fail");
|
}
|
return R.ok("Update Success").add(qlyIsptItem);
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:remove')")
|
@OperationLog("Delete 质检信息")
|
@PostMapping("/qlyIsptItem/remove/{ids}")
|
public R remove(@PathVariable Long[] ids) {
|
if (!qlyIsptItemService.removeByIds(Arrays.asList(ids))) {
|
return R.error("Delete Fail");
|
}
|
return R.ok("Delete Success").add(ids);
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:list')")
|
@PostMapping("/qlyIsptItem/query")
|
public R query(@RequestParam(required = false) String condition) {
|
List<KeyValVo> vos = new ArrayList<>();
|
LambdaQueryWrapper<QlyIsptItem> wrapper = new LambdaQueryWrapper<>();
|
if (!Cools.isEmpty(condition)) {
|
wrapper.like(QlyIsptItem::getId, condition);
|
}
|
qlyIsptItemService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
|
item -> vos.add(new KeyValVo(item.getId(), item.getId()))
|
);
|
return R.ok().add(vos);
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:list')")
|
@PostMapping("/qlyIsptItem/export")
|
public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
|
ExcelUtil.build(ExcelUtil.create(qlyIsptItemService.list(), QlyIsptItem.class), response);
|
}
|
|
@PreAuthorize("hasAuthority('manager:qlyIsptItem:update')")
|
@ApiOperation("快速质检")
|
@PostMapping("/qlyIsptItem/batch/update")
|
public R batchUpdate(@RequestBody IsptItemsParams params) {
|
if (Objects.isNull(params)) {
|
throw new CoolException("参数不能为空!!");
|
}
|
if (qlyIsptItemService.batchUpdate(params)) {
|
return R.ok("修改成功!!");
|
} else {
|
return R.error("修改失败!!");
|
}
|
}
|
|
}
|