package com.ruoyi.web.controller.system; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.List; import java.util.Arrays; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.utils.QRCodeUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.sign.Base64; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.apache.commons.io.IOUtils; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.FastByteArrayOutputStream; import org.springframework.web.bind.annotation.*; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.system.domain.TPersonalPage; import com.ruoyi.system.service.ITPersonalPageService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; import org.springframework.web.multipart.MultipartFile; import javax.imageio.ImageIO; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; /** * 个人页Controller * * @author Alex * @date 2020-09-16 */ @Api(value = "个人页管理", tags = "个人页管理") @RequiredArgsConstructor(onConstructor_ = @Autowired) @RestController @RequestMapping("/system/personal/page" ) public class TPersonalPageController extends BaseController { private final ITPersonalPageService iTPersonalPageService; /** * 查询个人页列表 */ @ApiOperation("个人页列表") @PreAuthorize("@ss.hasPermi('system:personal:page:list')") @GetMapping("/list") public TableDataInfo list(TPersonalPage tPersonalPage) { startPage(); LambdaQueryWrapper lqw = new LambdaQueryWrapper(); if (tPersonalPage.getCustomerId() != null){ lqw.eq(TPersonalPage::getCustomerId ,tPersonalPage.getCustomerId()); } if (StringUtils.isNotBlank(tPersonalPage.getCustomer())){ lqw.eq(TPersonalPage::getCustomer ,tPersonalPage.getCustomer()); } if (StringUtils.isNotBlank(tPersonalPage.getStakeholder())){ lqw.eq(TPersonalPage::getStakeholder ,tPersonalPage.getStakeholder()); } if (tPersonalPage.getStakeholderBirthday() != null){ lqw.eq(TPersonalPage::getStakeholderBirthday ,tPersonalPage.getStakeholderBirthday()); } if (StringUtils.isNotBlank(tPersonalPage.getAvatar())){ lqw.eq(TPersonalPage::getAvatar ,tPersonalPage.getAvatar()); } if (tPersonalPage.getTemplateId() != null){ lqw.eq(TPersonalPage::getTemplateId ,tPersonalPage.getTemplateId()); } if (StringUtils.isNotBlank(tPersonalPage.getContent())){ lqw.eq(TPersonalPage::getContent ,tPersonalPage.getContent()); } if (tPersonalPage.getEnable() != null){ lqw.eq(TPersonalPage::getEnable ,tPersonalPage.getEnable()); } List list = iTPersonalPageService.list(lqw); return getDataTable(list); } /** * 导出个人页列表 */ @PreAuthorize("@ss.hasPermi('system:personal:page:export')" ) @Log(title = "导出个人页" , businessType = BusinessType.EXPORT) @GetMapping("/export" ) public AjaxResult export(TPersonalPage tPersonalPage) { LambdaQueryWrapper lqw = new LambdaQueryWrapper(tPersonalPage); List list = iTPersonalPageService.list(lqw); ExcelUtil util = new ExcelUtil(TPersonalPage. class); return util.exportExcel(list, "page" ); } /** * 获取个人页详细信息 */ @PreAuthorize("@ss.hasPermi('system:personal:page:query')" ) @GetMapping(value = "/{id}" ) public AjaxResult getInfo(@PathVariable("id" ) Long id) { return AjaxResult.success(iTPersonalPageService.getById(id)); } /** * 新增个人页 */ @PreAuthorize("@ss.hasPermi('system:personal:page:add')" ) @Log(title = "新增个人页" , businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody TPersonalPage tPersonalPage) { return toAjax(iTPersonalPageService.save(tPersonalPage) ? 1 : 0); } /** * 修改个人页 */ @PreAuthorize("@ss.hasPermi('system:personal:page:edit')" ) @Log(title = "修改个人页" , businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody TPersonalPage tPersonalPage) { return toAjax(iTPersonalPageService.updateById(tPersonalPage) ? 1 : 0); } /** * 状态修改 */ @PreAuthorize("@ss.hasPermi('system:personal:page:edit')") @PutMapping("/changeEnable") public AjaxResult changeStatus(@RequestBody TPersonalPage tPersonalPage) { if (tPersonalPage == null){ return AjaxResult.error("数据不能为空"); } if (tPersonalPage.getId() <= 0){ return AjaxResult.error("ID不能为空"); } if (!tPersonalPage.getEnable().equals("0") && !tPersonalPage.getEnable().equals("1")){ return AjaxResult.error("修改失败"); } tPersonalPage.setUpdateBy(SecurityUtils.getUsername()); return toAjax(iTPersonalPageService.updateById(tPersonalPage) ? 1 : 0); } /** * 删除个人页 */ @PreAuthorize("@ss.hasPermi('system:personal:page:remove')" ) @Log(title = "个人页" , businessType = BusinessType.DELETE) @DeleteMapping("/{ids}" ) public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(iTPersonalPageService.removeByIds(Arrays.asList(ids)) ? 1 : 0); } @PreAuthorize("@ss.hasPermi('system:personal:page:edit')") @PostMapping("/avatar") public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file, Long id) throws IOException { if (!file.isEmpty()) { String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file); if (iTPersonalPageService.updateAvatar(id, avatar)) { AjaxResult ajax = AjaxResult.success(); ajax.put("imgUrl", avatar); return ajax; } } return AjaxResult.error("上传图片异常,请联系管理员"); } /** * 根据url获取二维码 * @param response * @param url * @return * @throws Exception */ @PreAuthorize("@ss.hasPermi('system:personal:page:query')" ) @GetMapping("/qrcode") public AjaxResult getQrcode(HttpServletResponse response, String url) throws Exception { if (StringUtils.isBlank(url)) { return AjaxResult.error("url为空"); } //二维码图片 BufferedImage image = QRCodeUtils.createImage(url,null,true); // 转换流信息写出 FastByteArrayOutputStream os = new FastByteArrayOutputStream(); try { ImageIO.write(image, "jpg", os); } catch (IOException e) { return AjaxResult.error(e.getMessage()); } AjaxResult ajax = AjaxResult.success(); ajax.put("img", Base64.encode(os.toByteArray())); return ajax; } /** * 根据干系人id获取总数 * @param userId * @return */ @GetMapping("/getCount/{userId}") public AjaxResult getCountByUserID(@PathVariable("userId" ) Long userId) { int count = iTPersonalPageService.count(new LambdaQueryWrapper() .eq(TPersonalPage::getStakeholderId, userId) .eq(TPersonalPage::getEnable,"0") ); AjaxResult result = AjaxResult.success(); result.put("count", count); return result; } }