123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- 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<TPersonalPage> lqw = new LambdaQueryWrapper<TPersonalPage>();
- 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<TPersonalPage> 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<TPersonalPage> lqw = new LambdaQueryWrapper<TPersonalPage>(tPersonalPage);
- List<TPersonalPage> list = iTPersonalPageService.list(lqw);
- ExcelUtil<TPersonalPage> util = new ExcelUtil<TPersonalPage>(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<TPersonalPage>()
- .eq(TPersonalPage::getStakeholderId, userId)
- .eq(TPersonalPage::getEnable,"0")
- );
- AjaxResult result = AjaxResult.success();
- result.put("count", count);
- return result;
- }
- }
|