package com.ruoyi.web.controller.zhang;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ZSelfNote;
import com.ruoyi.service.ZSelfNoteDownloadService;
import com.ruoyi.service.ZSelfNoteService;
import com.ruoyi.service.ZSelfNoteShareService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM;
import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE;
/**
*
* 前端控制器
*
*
* @author ojq
* @since 2023-03-14
*/
@RestController
@RequestMapping("/zSelfNote")
@Slf4j
public class ZSelfNoteController extends BaseController {
@Autowired
private ZSelfNoteService zSelfNoteService;
@Autowired
private ZSelfNoteShareService zSelfNoteShareService;
@Autowired
private ZSelfNoteDownloadService zSelfNoteDownloadService;
/**
* 查询所有记录
*/
@GetMapping("/all")
public AjaxResult listAll(ZSelfNote zSelfNote){
Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1);
Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10);
return zSelfNoteService.selectDataList(zSelfNote,pageNum,pageSize);
}
/**
* 根据id查询
*/
@GetMapping()
public AjaxResult listById(@PathParam("id") Long id){
return AjaxResult.success(zSelfNoteService.getById(id));
}
/**
* 模板
*/
@PostMapping("/model")
public void getModel(HttpServletResponse response){
ZSelfNote zSelfNote = new ZSelfNote();
List emptyList = Collections.singletonList(zSelfNote);
ExcelUtil util = new ExcelUtil<>(ZSelfNote.class);
util.exportExcel(response, emptyList, "个人记事本记录数据");
}
/**
* 导出个人记事本记录列表
*/
// @PreAuthorize("@ss.hasPermi('system:property:export')")
@Log(title = "个人记事本记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response)
{
List list = zSelfNoteService.selectByCondition();
log.info("导出记录为:{}",list);
log.info("导出记录为:{}",list);
ExcelUtil util = new ExcelUtil<>(ZSelfNote.class);
util.exportExcel(response, list, "个人记事本记录数据");
}
@Log(title = "个人记事本记录", businessType = BusinessType.EXPORT)
@PostMapping("/export1/{ids}")
public void export1(HttpServletResponse response,@PathVariable Long[] ids)
{
List list = zSelfNoteService.selectByIds(ids);
log.info("导出记录为:{}",list);
ExcelUtil util = new ExcelUtil<>(ZSelfNote.class);
util.exportExcel(response, list, "个人记事本记录数据");
}
/**
* 导入个人记事本记录列表
*/
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
@PostMapping("/importData")
public AjaxResult importData(@RequestParam("excelImport") MultipartFile file) throws Exception
{
return zSelfNoteService.importExcel(file);
}
/**
* 新增个人记事本记录
*/
// @PreAuthorize("@ss.hasPermi('system:property:add')")
@Log(title = "个人记事本记录", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ZSelfNote zSelfNote)
{
return zSelfNoteService.mySave(zSelfNote);
}
/**
* 修改个人记事本记录
*/
// @PreAuthorize("@ss.hasPermi('system:property:edit')")
@Log(title = "个人记事本记录", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ZSelfNote zSelfNote)
{
return toAjax(zSelfNoteService.updateById(zSelfNote));
}
//
/**
* 批量删除个人记事本记录
*/
// @PreAuthorize("@ss.hasPermi('system:property:remove')")
@Log(title = "个人记事本记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
if (! (zSelfNoteDownloadService.deleteData(ids) && zSelfNoteShareService.deleteByContentId(ids) ) ){
return AjaxResult.error();
}
return toAjax(zSelfNoteService.removeByIds(Arrays.asList(ids)));
}
}