| 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.Segment; | 
| import com.zy.acs.manager.manager.service.SegmentService; | 
| 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 SegmentController extends BaseController { | 
|   | 
|     @Autowired | 
|     private SegmentService segmentService; | 
|   | 
|     @PreAuthorize("hasAuthority('manager:segment:list')") | 
|     @PostMapping("/segment/page") | 
|     public R page(@RequestBody Map<String, Object> map) { | 
|         BaseParam baseParam = buildParam(map, BaseParam.class); | 
|         PageParam<Segment, BaseParam> pageParam = new PageParam<>(baseParam, Segment.class); | 
|         return R.ok().add(segmentService.page(pageParam, pageParam.buildWrapper(false, "update_time"))); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:segment:list')") | 
|     @PostMapping("/segment/list") | 
|     public R list(@RequestBody Map<String, Object> map) { | 
|         return R.ok().add(segmentService.list()); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:segment:list')") | 
|     @PostMapping({"/segment/many/{ids}", "/segments/many/{ids}"}) | 
|     public R many(@PathVariable Long[] ids) { | 
|         return R.ok().add(segmentService.listByIds(Arrays.asList(ids))); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:segment:list')") | 
|     @GetMapping("/segment/{id}") | 
|     public R get(@PathVariable("id") Long id) { | 
|         return R.ok().add(segmentService.getById(id)); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:segment:save')") | 
|     @OperationLog("Create Segment") | 
|     @PostMapping("/segment/save") | 
|     public R save(@RequestBody Segment segment) { | 
|         segment.setCreateBy(getLoginUserId()); | 
|         segment.setCreateTime(new Date()); | 
|         segment.setUpdateBy(getLoginUserId()); | 
|         segment.setUpdateTime(new Date()); | 
|         if (!segmentService.save(segment)) { | 
|             return R.error("Save Fail"); | 
|         } | 
|         return R.ok("Save Success").add(segment); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:segment:update')") | 
|     @OperationLog("Update Segment") | 
|     @PostMapping("/segment/update") | 
|     public R update(@RequestBody Segment segment) { | 
|         segment.setUpdateBy(getLoginUserId()); | 
|         segment.setUpdateTime(new Date()); | 
|         if (!segmentService.updateById(segment)) { | 
|             return R.error("Update Fail"); | 
|         } | 
|         return R.ok("Update Success").add(segment); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:segment:remove')") | 
|     @OperationLog("Delete Segment") | 
|     @PostMapping("/segment/remove/{ids}") | 
|     public R remove(@PathVariable Long[] ids) { | 
|         if (!segmentService.removeByIds(Arrays.asList(ids))) { | 
|             return R.error("Delete Fail"); | 
|         } | 
|         return R.ok("Delete Success").add(ids); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('manager:segment:list')") | 
|     @PostMapping("/segment/query") | 
|     public R query(@RequestParam(required = false) String condition) { | 
|         List<KeyValVo> vos = new ArrayList<>(); | 
|         LambdaQueryWrapper<Segment> wrapper = new LambdaQueryWrapper<>(); | 
|         if (!Cools.isEmpty(condition)) { | 
|             wrapper.like(Segment::getId, condition); | 
|         } | 
|         segmentService.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:segment:list')") | 
|     @PostMapping("/segment/export") | 
|     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
|         ExcelUtil.build(ExcelUtil.create(segmentService.list(), Segment.class), response); | 
|     } | 
|   | 
| } |