| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package com.izouma.nineth.web.netease;
- import com.izouma.nineth.web.BaseController;
- import com.izouma.nineth.domain.netease.NeteaseMessage;
- import com.izouma.nineth.service.netease.NeteaseMessageService;
- import com.izouma.nineth.dto.PageQuery;
- import com.izouma.nineth.exception.BusinessException;
- import com.izouma.nineth.repo.netease.NeteaseMessageRepo;
- import com.izouma.nineth.utils.ObjUtils;
- import com.izouma.nineth.utils.excel.ExcelUtils;
- import lombok.AllArgsConstructor;
- import org.apache.commons.validator.Msg;
- import org.springframework.data.domain.Page;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.util.List;
- @RestController
- @RequestMapping("/neteaseMessage")
- @AllArgsConstructor
- public class NeteaseMessageController extends BaseController {
- private NeteaseMessageService neteaseMessageService;
- private NeteaseMessageRepo neteaseMessageRepo;
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/save")
- public NeteaseMessage save(@RequestBody NeteaseMessage record) {
- if (record.getId() != null) {
- NeteaseMessage orig = neteaseMessageRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
- ObjUtils.merge(orig, record);
- return neteaseMessageRepo.save(orig);
- }
- return neteaseMessageRepo.save(record);
- }
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/all")
- public Page<NeteaseMessage> all(@RequestBody PageQuery pageQuery) {
- return neteaseMessageService.all(pageQuery);
- }
- @GetMapping("/get/{id}")
- public NeteaseMessage get(@PathVariable Long id) {
- return neteaseMessageRepo.findById(id).orElseThrow(new BusinessException("无记录"));
- }
- @PostMapping("/del/{id}")
- public void del(@PathVariable Long id) {
- neteaseMessageRepo.softDelete(id);
- }
- @GetMapping("/excel")
- @ResponseBody
- public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
- List<NeteaseMessage> data = all(pageQuery).getContent();
- ExcelUtils.export(response, data);
- }
- @PostMapping("/sendMsg")
- public NeteaseMessage sendMsg(@RequestBody NeteaseMessage msg) {
- return neteaseMessageService.sendMessage(msg);
- }
- }
|