package com.vincent.rsf.server.system.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.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.system.entity.TaskPathTemplate; import com.vincent.rsf.server.system.service.TaskPathTemplateService; import com.vincent.rsf.server.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 public class TaskPathTemplateController extends BaseController { @Autowired private TaskPathTemplateService taskPathTemplateService; @PreAuthorize("hasAuthority('system:taskPathTemplate:list')") @PostMapping("/taskPathTemplate/page") public R page(@RequestBody Map map) { BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, TaskPathTemplate.class); return R.ok().add(taskPathTemplateService.page(pageParam, pageParam.buildWrapper(true))); } @PreAuthorize("hasAuthority('system:taskPathTemplate:list')") @PostMapping("/taskPathTemplate/list") public R list(@RequestBody Map map) { return R.ok().add(taskPathTemplateService.list()); } @PreAuthorize("hasAuthority('system:taskPathTemplate:list')") @PostMapping({"/taskPathTemplate/many/{ids}", "/taskPathTemplates/many/{ids}"}) public R many(@PathVariable Long[] ids) { return R.ok().add(taskPathTemplateService.listByIds(Arrays.asList(ids))); } @PreAuthorize("hasAuthority('system:taskPathTemplate:list')") @GetMapping("/taskPathTemplate/{id}") public R get(@PathVariable("id") Long id) { return R.ok().add(taskPathTemplateService.getById(id)); } @PreAuthorize("hasAuthority('system:taskPathTemplate:save')") @OperationLog("Create 物料权限") @PostMapping("/taskPathTemplate/save") public R save(@RequestBody TaskPathTemplate taskPathTemplate) { taskPathTemplate.setCreateBy(getLoginUserId()); taskPathTemplate.setCreateTime(new Date()); taskPathTemplate.setUpdateBy(getLoginUserId()); taskPathTemplate.setUpdateTime(new Date()); if (!taskPathTemplateService.save(taskPathTemplate)) { return R.error("Save Fail"); } return R.ok("Save Success").add(taskPathTemplate); } @PreAuthorize("hasAuthority('system:taskPathTemplate:update')") @OperationLog("Update 物料权限") @PostMapping("/taskPathTemplate/update") public R update(@RequestBody TaskPathTemplate taskPathTemplate) { taskPathTemplate.setUpdateBy(getLoginUserId()); taskPathTemplate.setUpdateTime(new Date()); if (!taskPathTemplateService.updateById(taskPathTemplate)) { return R.error("Update Fail"); } return R.ok("Update Success").add(taskPathTemplate); } @PreAuthorize("hasAuthority('system:taskPathTemplate:remove')") @OperationLog("Delete 物料权限") @PostMapping("/taskPathTemplate/remove/{ids}") public R remove(@PathVariable Long[] ids) { if (!taskPathTemplateService.removeByIds(Arrays.asList(ids))) { return R.error("Delete Fail"); } return R.ok("Delete Success").add(ids); } @PreAuthorize("hasAuthority('system:taskPathTemplate:list')") @PostMapping("/taskPathTemplate/query") public R query(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!Cools.isEmpty(condition)) { wrapper.like(TaskPathTemplate::getId, condition); } taskPathTemplateService.page(new Page<>(1, 30), wrapper).getRecords().forEach( item -> vos.add(new KeyValVo(item.getId(), item.getId())) ); return R.ok().add(vos); } @PreAuthorize("hasAuthority('system:taskPathTemplate:list')") @PostMapping("/taskPathTemplate/export") public void export(@RequestBody Map map, HttpServletResponse response) throws Exception { ExcelUtil.build(ExcelUtil.create(taskPathTemplateService.list(), TaskPathTemplate.class), response); } }