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.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 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 */ @Slf4j @RestController @RequestMapping("/self/user") 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 list = zInfoUserService.selectByCondition(zInfoUser); log.info("导出记录为:{}",list); ExcelUtil 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 util = new ExcelUtil<>(ZInfoUser.class); List 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 success(zInfoUserService.getById(userId)); } // /** * 新增、修改个人详细信息记录 */ // @PreAuthorize("@ss.hasPermi('system:property:add')") @Log(title = "个人详细信息记录", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody ZInfoUser zInfoUser) { 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); } }