From def06893b9706ac62cd56ad9da989f688f94cb64 Mon Sep 17 00:00:00 2001 From: Jinquan_Ou <Jinquan@gdut.com> Date: 星期四, 06 四月 2023 22:17:17 +0800 Subject: [PATCH] 8888 --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java | 140 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 135 insertions(+), 5 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java index c83c026..7b630a1 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java @@ -1,28 +1,158 @@ 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 org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.domain.ZInfoUser; +import com.ruoyi.service.ZInfoUserService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM; +import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE; /** * <p> - * 鍓嶇鎺у埗鍣� + * 鍓嶇鎺у埗鍣� * </p> * * @author ojq * @since 2023-03-14 */ +@Slf4j @RestController @RequestMapping("/self/user") -public class ZInfoUserController { +public class ZInfoUserController extends BaseController { + + @Resource + private ZInfoUserService zInfoUserService; + +// @GetMapping("/all") +// public AjaxResult listAll(ZInfoUser zInfoUser){ +// Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1); +// Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10); +// return zInfoUserService.selectInfoList(zInfoUser, pageNum, pageSize); +// } + /** + * 瀵煎嚭涓汉璇︾粏淇℃伅璁板綍鍒楄〃 + */ +// @PreAuthorize("@ss.hasPermi('system:property:export')") + @Log(title = "涓汉璇︾粏淇℃伅璁板綍", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, ZInfoUser zInfoUser) { + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + zInfoUser.setUserId(userId); + List<ZInfoUser> list = zInfoUserService.selectByCondition(zInfoUser); + log.info("瀵煎嚭璁板綍涓�:{}", list); + ExcelUtil<ZInfoUser> util = new ExcelUtil<>(ZInfoUser.class); + util.exportExcel(response, list, "涓汉璇︾粏淇℃伅璁板綍鏁版嵁"); + } + + /** + * 瀵煎叆涓汉璇︾粏淇℃伅璁板綍鍒楄〃 + */ + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.IMPORT) + @PostMapping("/importData") + public AjaxResult importData(@RequestParam("excelImport") MultipartFile file) throws Exception { + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + ExcelUtil<ZInfoUser> util = new ExcelUtil<>(ZInfoUser.class); + List<ZInfoUser> eventList = util.importExcel(file.getInputStream()); + log.info("涓汉璇︾粏淇℃伅鍒楄〃涓猴細{}", eventList); + if (eventList.size() > 1) { + return AjaxResult.error("瀵煎叆涓汉淇℃伅鍙兘鏈変竴鏉¤褰�"); + } + + ZInfoUser zInfoUser = eventList.get(0); + zInfoUser.setUserId(userId); + + if (zInfoUserService.updateById(zInfoUser)) { + return AjaxResult.success("瀵煎叆鏁版嵁鎴愬姛"); + } + return AjaxResult.error("瀵煎叆鏁版嵁澶辫触"); + + } + + /** + * 鑾峰彇涓汉璇︾粏淇℃伅璁板綍璇︾粏淇℃伅 + */ +// @PreAuthorize("@ss.hasPermi('system:property:query')") + @GetMapping() + public AjaxResult getInfo() { + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + return AjaxResult.success(zInfoUserService.getById(userId)); + } +// + + /** + * 鏂板銆佷慨鏀逛釜浜鸿缁嗕俊鎭褰� + */ +// @PreAuthorize("@ss.hasPermi('system:property:add')") + @Log(title = "涓汉璇︾粏淇℃伅璁板綍", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody ZInfoUser zInfoUser) { + if (!Pattern.matches("^[\\d]+(?:,[\\d]+)*$",zInfoUser.getFamilyId())) { + throw new RuntimeException("璇疯緭鍏ュ彧鏈夋暟瀛楀拰鑻辨枃閫楀彿鐨勫瓧绗︿覆锛屼笖鏁板瓧鍜岄�楀彿蹇呴』浜ゆ浛鍑虹幇"); + } + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + zInfoUser.setUserId(userId); + return toAjax(zInfoUserService.saveOrUpdate(zInfoUser)); + } + +// /** +// * 淇敼涓汉璇︾粏淇℃伅璁板綍 +// */ +//// @PreAuthorize("@ss.hasPermi('system:property:edit')") +// @Log(title = "涓汉璇︾粏淇℃伅璁板綍", businessType = BusinessType.UPDATE) +// @PutMapping +// public AjaxResult edit(@RequestBody ZInfoUser zInfoUser) +// { +// return toAjax(zInfoUserService.updateById(zInfoUser)); +// } +// + + /** + * 鍒犻櫎涓汉璇︾粏淇℃伅璁板綍 + */ +// @PreAuthorize("@ss.hasPermi('system:property:remove')") + @Log(title = "涓汉璇︾粏淇℃伅璁板綍", businessType = BusinessType.DELETE) + @DeleteMapping() + public AjaxResult remove() { + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + return toAjax(zInfoUserService.removeById(userId)); + } + /** + * 鏌ヨ瀹跺涵涓昏鎴愬憳鍙婂叧绯� + */ + + @GetMapping("/relation") + public AjaxResult listMyRelation() { + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + return zInfoUserService.searchMyRelation(userId); + } } -- Gitblit v1.9.1