| package com.zy.acs.manager.manager.controller; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| 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.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.common.utils.BusinessSortService; | 
| import com.zy.acs.manager.common.utils.ExcelUtil; | 
| import com.zy.acs.manager.manager.entity.Task; | 
| import com.zy.acs.manager.manager.service.TaskService; | 
| 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 TaskController extends BaseController { | 
|   | 
|     @Autowired | 
|     private TaskService taskService; | 
|     @Autowired | 
|     private BusinessSortService businessSortService; | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:list')") | 
|     @PostMapping("/task/page") | 
|     public R page(@RequestBody Map<String, Object> map) { | 
|         BaseParam baseParam = buildParam(map, BaseParam.class); | 
|         PageParam<Task, BaseParam> pageParam = new PageParam<>(baseParam, Task.class); | 
|         QueryWrapper<Task> wrapper = pageParam.buildWrapper(false, "io_time"); | 
|         if (hasCreateTimeDesc(pageParam.getOrders())) { | 
| //            wrapper.last(businessSortService.getOrderBySql(TaskStsType.class, "task_sts")); | 
|         } | 
|         return R.ok().add(taskService.page(pageParam, wrapper)); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:list')") | 
|     @PostMapping("/task/list") | 
|     public R list(@RequestBody Map<String, Object> map) { | 
|         return R.ok().add(taskService.list()); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:list')") | 
|     @PostMapping({"/task/many/{ids}", "/tasks/many/{ids}"}) | 
|     public R many(@PathVariable Long[] ids) { | 
|         return R.ok().add(taskService.listByIds(Arrays.asList(ids))); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:list')") | 
|     @GetMapping("/task/{id}") | 
|     public R get(@PathVariable("id") Long id) { | 
|         return R.ok().add(taskService.getById(id)); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:save')") | 
|     @OperationLog("Create Task") | 
|     @PostMapping("/task/save") | 
|     public R save(@RequestBody Task task) { | 
|         task.setCreateBy(getLoginUserId()); | 
|         task.setCreateTime(new Date()); | 
|         task.setUpdateBy(getLoginUserId()); | 
|         task.setUpdateTime(new Date()); | 
|         if (!taskService.save(task)) { | 
|             return R.error("Save Fail"); | 
|         } | 
|         return R.ok("Save Success").add(task); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:update')") | 
|     @OperationLog("Update Task") | 
|     @PostMapping("/task/update") | 
|     public R update(@RequestBody Task task) { | 
|         task.setUpdateBy(getLoginUserId()); | 
|         task.setUpdateTime(new Date()); | 
|         if (!taskService.updateById(task)) { | 
|             return R.error("Update Fail"); | 
|         } | 
|         return R.ok("Update Success").add(task); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:remove')") | 
|     @OperationLog("Delete Task") | 
|     @PostMapping("/task/remove/{ids}") | 
|     public R remove(@PathVariable Long[] ids) { | 
|         if (!taskService.removeByIds(Arrays.asList(ids))) { | 
|             return R.error("Delete Fail"); | 
|         } | 
|         return R.ok("Delete Success").add(ids); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:list')") | 
|     @PostMapping("/task/query") | 
|     public R query(@RequestParam(required = false) String condition) { | 
|         List<KeyValVo> vos = new ArrayList<>(); | 
|         LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>(); | 
|         if (!Cools.isEmpty(condition)) { | 
|             wrapper.like(Task::getSeqNum, condition); | 
|         } | 
|         taskService.page(new Page<>(1, 30), wrapper).getRecords().forEach( | 
|                 item -> vos.add(new KeyValVo(item.getId(), item.getSeqNum())) | 
|         ); | 
|         return R.ok().add(vos); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:list')") | 
|     @PostMapping("/task/export") | 
|     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
|         ExcelUtil.build(ExcelUtil.create(taskService.list(), Task.class), response); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:update')") | 
|     @OperationLog("Complete Task") | 
|     @GetMapping("/task/complete/{id}") | 
|     public R complete(@PathVariable Long id) { | 
|         return taskService.complete(id, getLoginUserId()) ? R.ok("Complete Success") : R.error("Complete Fail"); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:task:update')") | 
|     @OperationLog("Cancel Task") | 
|     @GetMapping("/task/cancel/{id}") | 
|     public R cancel(@PathVariable Long id) { | 
|         return taskService.cancel(id, getLoginUserId()) ? R.ok("Cancel Success") : R.error("Cancel Fail"); | 
|     } | 
|   | 
| } |