springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/HomeController.java
@@ -5,10 +5,9 @@ import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.model.vos.LoginUserInfoVO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo; import com.panzhihua.common.service.sangeshenbian.SystemUserService; import com.panzhihua.common.service.user.UserService; import com.panzhihua.sangeshenbian.model.entity.Banner; import com.panzhihua.sangeshenbian.model.entity.Department; import com.panzhihua.sangeshenbian.model.entity.SystemUser; import com.panzhihua.sangeshenbian.model.query.BasePage; import com.panzhihua.sangeshenbian.model.vo.ComplaintTodoVO; @@ -16,6 +15,7 @@ import com.panzhihua.sangeshenbian.model.vo.PartyCardInfoVO; import com.panzhihua.sangeshenbian.service.IBannerService; import com.panzhihua.sangeshenbian.service.IComplaintService; import com.panzhihua.sangeshenbian.service.IDepartmentService; import com.panzhihua.sangeshenbian.service.IMessageNotificationService; import com.panzhihua.sangeshenbian.service.ISystemUserService; import com.panzhihua.sangeshenbian.utils.BaiduMapUtil; @@ -29,7 +29,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; /** * @author mitao @@ -37,7 +41,7 @@ */ @RestController @RequestMapping("/applet/home") @RequiredArgsConstructor(onConstructor_=@Lazy) @RequiredArgsConstructor(onConstructor_ = @Lazy) @Api(tags = "首页相关接口") public class HomeController extends BaseController { private final IBannerService bannerService; @@ -45,11 +49,14 @@ private final IComplaintService complaintService; private final ISystemUserService systemUserService; private final UserService userService; private final IDepartmentService departmentService; @ApiOperation("获取banner列表") @GetMapping("/banner-list") public R<List<Banner>> getBannerList() { return R.ok(bannerService.list()); } @GetMapping("/party-card-info") @ApiOperation("获取党员证信息") public R<PartyCardInfoVO> getPartyCardInfo() { @@ -57,43 +64,71 @@ PartyCardInfoVO partyCardInfoVO = new PartyCardInfoVO(); partyCardInfoVO.setName(loginUserInfo.getName()); partyCardInfoVO.setIdCard(loginUserInfo.getIdCard()); Optional<SystemUser> systemUserOpt = systemUserService.getSystemUserByPhone(loginUserInfo.getPhone()); systemUserOpt.ifPresent(systemUser -> { // 使用Optional链式调用简化部门ID获取逻辑 Integer lastDepartmentId = Optional.ofNullable(systemUser.getFourDepartmentId()) .orElseGet(() -> Optional.ofNullable(systemUser.getThreeDepartmentId()) .orElseGet(systemUser::getTwoDepartmentId)); // 缓存部门查询结果避免重复查询 Map<Integer, Department> departmentCache = new HashMap<>(); Department first = departmentCache.computeIfAbsent(systemUser.getOneDepartmentId(), departmentService::getById); Department last = null; if (Objects.nonNull(lastDepartmentId)) { last = departmentCache.computeIfAbsent(lastDepartmentId, departmentService::getById); } // 使用Objects.toString简化字符串拼接 partyCardInfoVO.setPartyOrganization( Objects.isNull(last) ? Objects.toString(first.getName(), "") : Objects.toString(first.getName(), "") + "-" + Objects.toString(last.getName(), "")); }); partyCardInfoVO.setPartyOrganization(loginUserInfo.getCommunityName()); return R.ok(partyCardInfoVO); } @PostMapping("/message") @ApiOperation("获取消息列表") public R<Page<MessageNotificationVO>> getMessageList(@RequestBody BasePage page) { return R.ok(messageNotificationService.getMessageList(page,getUserId())); return R.ok(messageNotificationService.getMessageList(page, getUserId())); } @PostMapping("/todo-list") @ApiOperation("获取待办诉求") public R<Page<ComplaintTodoVO>> getTodoList(@RequestBody BasePage page) { return R.ok(complaintService.getTodoList(page,getLoginUserInfo())); return R.ok(complaintService.getTodoList(page, getLoginUserInfo())); } @GetMapping("/current-user-info") @ApiOperation("获取三个身边当前用户信息 用于判断用户是否是上级") public R<SystemUser> getCurrentUserInfo() { return R.ok(systemUserService.getSystemUserByPhone(getLoginUserInfo().getPhone()).orElse(null)); return R.ok(systemUserService.getSystemUserAdminByPhone(getLoginUserInfo().getPhone()).orElse(null)); } /** * 标记已读 */ @PostMapping("/read") @ApiOperation("标记已读") public R<?> read(){ public R<?> read() { messageNotificationService.read(getLoginUserInfo()); return R.ok(); } /** * 百度地图圆形区域检索 * * @param query * @param location * @return */ @GetMapping("/search-location") @ApiOperation("百度地图圆形区域检索") public R<JSONArray> searchLocation(String query,String location){ return R.ok(BaiduMapUtil.searchLocation(query,location)); public R<JSONArray> searchLocation(String query, String location) { return R.ok(BaiduMapUtil.searchLocation(query, location)); } } springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/ISystemUserService.java
@@ -26,9 +26,12 @@ /** * 根据手机号码查询小程序用户在三个身边的上级角色用户 */ Optional<SystemUser> getSystemUserAdminByPhone(String phone); /** * 根据手机号码查询小程序用户在三个身边的用户 */ Optional<SystemUser> getSystemUserByPhone(String phone); /** * 获取行政区划数据 * springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java
@@ -1,7 +1,6 @@ package com.panzhihua.sangeshenbian.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -30,7 +29,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.panzhihua.sangeshenbian.model.vo.ComplaintVO; import com.panzhihua.sangeshenbian.service.ISystemUserService; import io.jsonwebtoken.lang.Collections; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; @@ -92,7 +90,7 @@ // 设置流水号 complaint.setSerialNumber(serialNumber); Optional<SystemUser> systemUserOpt = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone()); Optional<SystemUser> systemUserOpt = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone()); Integer accountLevel = 5; Long superiorId = null; if (systemUserOpt.isPresent()) { @@ -166,7 +164,7 @@ public Page<ComplaintVO> complaintList(ComplaintQuery query, LoginUserInfoVO loginUserInfoVO) { Page<ComplaintVO> page = new Page<>(query.getPageNum(), query.getPageSize()); //判断当前登录用户级别,查询对应工单 Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone()); Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone()); String targetId = ""; int isSuperior = 0; Integer accountLevel = 5; @@ -215,7 +213,7 @@ */ @Override public ComplaintVO detail(Long id, LoginUserInfoVO loginUserInfoVO) { Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone()); Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone()); String targetId = ""; int isSuperior = 0; Integer accountLevel = 5; @@ -479,7 +477,7 @@ @Override @Transactional(rollbackFor = Exception.class) public void reportAudit(ComplaintReporAuditDTO complaintReporAuditDTO, LoginUserInfoVO loginUserInfoVO) { Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone()); Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone()); if (!systemUserByPhone.isPresent()) { throw new ServiceException("无权审核"); } @@ -592,7 +590,7 @@ @Override @Transactional(rollbackFor = Exception.class) public void saveDelay(ComplaintDelayDTO dto, LoginUserInfoVO loginUserInfoVO) { SystemUser systemUser = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone()).orElse(null); SystemUser systemUser = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone()).orElse(null); Long superiorId; Long currentId; int reportType; @@ -678,7 +676,7 @@ @Override public void delayAudit(ComplaintDelayAuditDTO dto, LoginUserInfoVO loginUserInfoVO) { SystemUser systemUser = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone()).orElse(null); SystemUser systemUser = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone()).orElse(null); int accountLevel = systemUser.getAccountLevel(); // 改为基本类型 Long cunrrentId; @@ -804,7 +802,7 @@ */ @Override public Page<ComplaintTodoVO> getTodoList(BasePage basePage, LoginUserInfoVO loginUserInfo) { Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserByPhone(loginUserInfo.getPhone()); Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserAdminByPhone(loginUserInfo.getPhone()); String targetId = ""; int isSuperior = 0; //上级 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/MessageNotificationServiceImpl.java
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.panzhihua.common.model.vos.LoginUserInfoVO; import com.panzhihua.common.service.sangeshenbian.SystemUserService; import com.panzhihua.sangeshenbian.dao.MessageNotificationMapper; import com.panzhihua.sangeshenbian.model.entity.MessageNotification; import com.panzhihua.sangeshenbian.model.entity.SystemUser; @@ -18,7 +17,6 @@ import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import java.util.Objects; import java.util.Optional; /** @@ -53,7 +51,7 @@ @Override public void read(LoginUserInfoVO loginUserInfoVO) { String undertakerUserId = ""; Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone()); Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserAdminByPhone(loginUserInfoVO.getPhone()); if (systemUserByPhone.isPresent()) { SystemUser systemUser = systemUserByPhone.get(); if (systemUser.getIsAdmin().equals(1)){ springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/SystemUserServiceImpl.java
@@ -42,7 +42,7 @@ * @return */ @Override public Optional<SystemUser> getSystemUserByPhone(String phone) { public Optional<SystemUser> getSystemUserAdminByPhone(String phone) { if (StringUtils.isBlank(phone)) { return Optional.empty(); } @@ -50,10 +50,16 @@ .eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3) .eq(SystemUser::getIsAdmin, 1).last("LIMIT 1").oneOpt(); } @Override public Optional<SystemUser> getSystemUserByPhone(String phone) { if (StringUtils.isBlank(phone)) { return Optional.empty(); } return this.lambdaQuery() .eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3).last("LIMIT 1").oneOpt(); } /** * 获取行政区划数据 *