TPersonalPageController.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package com.ruoyi.web.controller.system;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import java.awt.image.BufferedImage;
  4. import java.io.IOException;
  5. import java.util.List;
  6. import java.util.Arrays;
  7. import com.ruoyi.common.config.RuoYiConfig;
  8. import com.ruoyi.common.utils.QRCodeUtils;
  9. import com.ruoyi.common.utils.SecurityUtils;
  10. import com.ruoyi.common.utils.StringUtils;
  11. import com.ruoyi.common.utils.file.FileUploadUtils;
  12. import com.ruoyi.common.utils.sign.Base64;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import lombok.RequiredArgsConstructor;
  16. import org.apache.commons.io.IOUtils;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.util.FastByteArrayOutputStream;
  20. import org.springframework.web.bind.annotation.*;
  21. import com.ruoyi.common.annotation.Log;
  22. import com.ruoyi.common.core.controller.BaseController;
  23. import com.ruoyi.common.core.domain.AjaxResult;
  24. import com.ruoyi.common.enums.BusinessType;
  25. import com.ruoyi.system.domain.TPersonalPage;
  26. import com.ruoyi.system.service.ITPersonalPageService;
  27. import com.ruoyi.common.utils.poi.ExcelUtil;
  28. import com.ruoyi.common.core.page.TableDataInfo;
  29. import org.springframework.web.multipart.MultipartFile;
  30. import javax.imageio.ImageIO;
  31. import javax.servlet.ServletOutputStream;
  32. import javax.servlet.http.HttpServletResponse;
  33. /**
  34. * 个人页Controller
  35. *
  36. * @author Alex
  37. * @date 2020-09-16
  38. */
  39. @Api(value = "个人页管理", tags = "个人页管理")
  40. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  41. @RestController
  42. @RequestMapping("/system/personal/page" )
  43. public class TPersonalPageController extends BaseController {
  44. private final ITPersonalPageService iTPersonalPageService;
  45. /**
  46. * 查询个人页列表
  47. */
  48. @ApiOperation("个人页列表")
  49. @PreAuthorize("@ss.hasPermi('system:personal:page:list')")
  50. @GetMapping("/list")
  51. public TableDataInfo list(TPersonalPage tPersonalPage)
  52. {
  53. startPage();
  54. LambdaQueryWrapper<TPersonalPage> lqw = new LambdaQueryWrapper<TPersonalPage>();
  55. if (tPersonalPage.getCustomerId() != null){
  56. lqw.eq(TPersonalPage::getCustomerId ,tPersonalPage.getCustomerId());
  57. }
  58. if (StringUtils.isNotBlank(tPersonalPage.getCustomer())){
  59. lqw.eq(TPersonalPage::getCustomer ,tPersonalPage.getCustomer());
  60. }
  61. if (StringUtils.isNotBlank(tPersonalPage.getStakeholder())){
  62. lqw.eq(TPersonalPage::getStakeholder ,tPersonalPage.getStakeholder());
  63. }
  64. if (tPersonalPage.getStakeholderBirthday() != null){
  65. lqw.eq(TPersonalPage::getStakeholderBirthday ,tPersonalPage.getStakeholderBirthday());
  66. }
  67. if (StringUtils.isNotBlank(tPersonalPage.getAvatar())){
  68. lqw.eq(TPersonalPage::getAvatar ,tPersonalPage.getAvatar());
  69. }
  70. if (tPersonalPage.getTemplateId() != null){
  71. lqw.eq(TPersonalPage::getTemplateId ,tPersonalPage.getTemplateId());
  72. }
  73. if (StringUtils.isNotBlank(tPersonalPage.getContent())){
  74. lqw.eq(TPersonalPage::getContent ,tPersonalPage.getContent());
  75. }
  76. if (tPersonalPage.getEnable() != null){
  77. lqw.eq(TPersonalPage::getEnable ,tPersonalPage.getEnable());
  78. }
  79. List<TPersonalPage> list = iTPersonalPageService.list(lqw);
  80. return getDataTable(list);
  81. }
  82. /**
  83. * 导出个人页列表
  84. */
  85. @PreAuthorize("@ss.hasPermi('system:personal:page:export')" )
  86. @Log(title = "导出个人页" , businessType = BusinessType.EXPORT)
  87. @GetMapping("/export" )
  88. public AjaxResult export(TPersonalPage tPersonalPage) {
  89. LambdaQueryWrapper<TPersonalPage> lqw = new LambdaQueryWrapper<TPersonalPage>(tPersonalPage);
  90. List<TPersonalPage> list = iTPersonalPageService.list(lqw);
  91. ExcelUtil<TPersonalPage> util = new ExcelUtil<TPersonalPage>(TPersonalPage. class);
  92. return util.exportExcel(list, "page" );
  93. }
  94. /**
  95. * 获取个人页详细信息
  96. */
  97. @PreAuthorize("@ss.hasPermi('system:personal:page:query')" )
  98. @GetMapping(value = "/{id}" )
  99. public AjaxResult getInfo(@PathVariable("id" ) Long id) {
  100. return AjaxResult.success(iTPersonalPageService.getById(id));
  101. }
  102. /**
  103. * 新增个人页
  104. */
  105. @PreAuthorize("@ss.hasPermi('system:personal:page:add')" )
  106. @Log(title = "新增个人页" , businessType = BusinessType.INSERT)
  107. @PostMapping
  108. public AjaxResult add(@RequestBody TPersonalPage tPersonalPage) {
  109. return toAjax(iTPersonalPageService.save(tPersonalPage) ? 1 : 0);
  110. }
  111. /**
  112. * 修改个人页
  113. */
  114. @PreAuthorize("@ss.hasPermi('system:personal:page:edit')" )
  115. @Log(title = "修改个人页" , businessType = BusinessType.UPDATE)
  116. @PutMapping
  117. public AjaxResult edit(@RequestBody TPersonalPage tPersonalPage) {
  118. return toAjax(iTPersonalPageService.updateById(tPersonalPage) ? 1 : 0);
  119. }
  120. /**
  121. * 状态修改
  122. */
  123. @PreAuthorize("@ss.hasPermi('system:personal:page:edit')")
  124. @PutMapping("/changeEnable")
  125. public AjaxResult changeStatus(@RequestBody TPersonalPage tPersonalPage)
  126. {
  127. if (tPersonalPage == null){
  128. return AjaxResult.error("数据不能为空");
  129. }
  130. if (tPersonalPage.getId() <= 0){
  131. return AjaxResult.error("ID不能为空");
  132. }
  133. if (!tPersonalPage.getEnable().equals("0") && !tPersonalPage.getEnable().equals("1")){
  134. return AjaxResult.error("修改失败");
  135. }
  136. tPersonalPage.setUpdateBy(SecurityUtils.getUsername());
  137. return toAjax(iTPersonalPageService.updateById(tPersonalPage) ? 1 : 0);
  138. }
  139. /**
  140. * 删除个人页
  141. */
  142. @PreAuthorize("@ss.hasPermi('system:personal:page:remove')" )
  143. @Log(title = "个人页" , businessType = BusinessType.DELETE)
  144. @DeleteMapping("/{ids}" )
  145. public AjaxResult remove(@PathVariable Long[] ids) {
  146. return toAjax(iTPersonalPageService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
  147. }
  148. @PreAuthorize("@ss.hasPermi('system:personal:page:edit')")
  149. @PostMapping("/avatar")
  150. public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file, Long id) throws IOException {
  151. if (!file.isEmpty()) {
  152. String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file);
  153. if (iTPersonalPageService.updateAvatar(id, avatar)) {
  154. AjaxResult ajax = AjaxResult.success();
  155. ajax.put("imgUrl", avatar);
  156. return ajax;
  157. }
  158. }
  159. return AjaxResult.error("上传图片异常,请联系管理员");
  160. }
  161. /**
  162. * 根据url获取二维码
  163. * @param response
  164. * @param url
  165. * @return
  166. * @throws Exception
  167. */
  168. @PreAuthorize("@ss.hasPermi('system:personal:page:query')" )
  169. @GetMapping("/qrcode")
  170. public AjaxResult getQrcode(HttpServletResponse response, String url) throws Exception {
  171. if (StringUtils.isBlank(url)) {
  172. return AjaxResult.error("url为空");
  173. }
  174. //二维码图片
  175. BufferedImage image = QRCodeUtils.createImage(url,null,true);
  176. // 转换流信息写出
  177. FastByteArrayOutputStream os = new FastByteArrayOutputStream();
  178. try {
  179. ImageIO.write(image, "jpg", os);
  180. }
  181. catch (IOException e) {
  182. return AjaxResult.error(e.getMessage());
  183. }
  184. AjaxResult ajax = AjaxResult.success();
  185. ajax.put("img", Base64.encode(os.toByteArray()));
  186. return ajax;
  187. }
  188. /**
  189. * 根据干系人id获取总数
  190. * @param userId
  191. * @return
  192. */
  193. @GetMapping("/getCount/{userId}")
  194. public AjaxResult getCountByUserID(@PathVariable("userId" ) Long userId) {
  195. int count = iTPersonalPageService.count(new LambdaQueryWrapper<TPersonalPage>()
  196. .eq(TPersonalPage::getStakeholderId, userId)
  197. .eq(TPersonalPage::getEnable,"0")
  198. );
  199. AjaxResult result = AjaxResult.success();
  200. result.put("count", count);
  201. return result;
  202. }
  203. }