| | |
| | | package com.panzhihua.sangeshenbian.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.redis.RedisUtils; |
| | | import com.panzhihua.sangeshenbian.model.entity.Banner; |
| | | import com.panzhihua.sangeshenbian.model.entity.Department; |
| | | import com.panzhihua.sangeshenbian.model.entity.PartyMember; |
| | | import com.panzhihua.sangeshenbian.model.entity.SystemUser; |
| | | import com.panzhihua.sangeshenbian.model.query.BasePage; |
| | | import com.panzhihua.sangeshenbian.model.vo.ComplaintTodoVO; |
| | | import com.panzhihua.sangeshenbian.model.vo.MessageNotificationVO; |
| | | 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.service.*; |
| | | import com.panzhihua.sangeshenbian.utils.BaiduMapUtil; |
| | | import com.panzhihua.sangeshenbian.warpper.IdentityInformationVO; |
| | | import com.panzhihua.sangeshenbian.warpper.PermissionsVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author mitao |
| | |
| | | private final IMessageNotificationService messageNotificationService; |
| | | private final IComplaintService complaintService; |
| | | private final ISystemUserService systemUserService; |
| | | private final UserService userService; |
| | | private final IDepartmentService departmentService; |
| | | private final IPartyMemberService partyMemberService; |
| | | private final RedisUtils redisUtils; |
| | | |
| | | @ApiOperation("获取banner列表") |
| | | @GetMapping("/banner-list") |
| | |
| | | @ApiOperation("获取党员证信息") |
| | | public R<PartyCardInfoVO> getPartyCardInfo() { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | // 获取党员信息 |
| | | PartyMember partyMember = partyMemberService.getOne(new LambdaQueryWrapper<PartyMember>() |
| | | .eq(PartyMember::getPhone, loginUserInfo.getPhone()) |
| | | .eq(PartyMember::getDelFlag, 0)); |
| | | |
| | | 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.setName(partyMember.getName()); |
| | | partyCardInfoVO.setIdCard(partyMember.getIdNumber()); |
| | | partyCardInfoVO.setDistricts(partyMember.getDistricts()); |
| | | partyCardInfoVO.setStreet(partyMember.getStreet()); |
| | | partyCardInfoVO.setCommunity(partyMember.getCommunity()); |
| | | partyCardInfoVO.setPartyOrganization(partyMember.getPartyOrganization()); |
| | | return R.ok(partyCardInfoVO); |
| | | } |
| | | |
| | |
| | | public R<JSONArray> searchLocation(String query, String location) { |
| | | return R.ok(BaiduMapUtil.searchLocation(query, location)); |
| | | } |
| | | |
| | | /** |
| | | * 获取身份信息 |
| | | */ |
| | | @GetMapping("/identity-info") |
| | | @ApiOperation("获取身份信息") |
| | | public R<IdentityInformationVO> getIdentityInfo() { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | // 获取党员信息 |
| | | PartyMember partyMember = partyMemberService.getOne(new LambdaQueryWrapper<PartyMember>() |
| | | .eq(PartyMember::getPhone, loginUserInfo.getPhone()) |
| | | .eq(PartyMember::getDelFlag, 0)); |
| | | |
| | | // 获取管理员信息 |
| | | SystemUser systemUser = systemUserService.getSystemUserAdminByPhone(getLoginUserInfo().getPhone()).orElse(null); |
| | | // 获取身份 |
| | | Integer identity = (Integer) redisUtils.get("identity:" + loginUserInfo.getPhone()); |
| | | // 获取提示内容是否确认 |
| | | Integer isConfirm = (Integer) redisUtils.get("confirmContent:" + loginUserInfo.getPhone()); |
| | | List<PermissionsVO> permissions = new ArrayList<>(); |
| | | IdentityInformationVO identityInformationVO = new IdentityInformationVO(); |
| | | identityInformationVO.setIsConfirmContent(isConfirm !=null && isConfirm == 1); |
| | | if (partyMember != null) { |
| | | identityInformationVO.setIsFrozen(partyMember.getFreezeStatus() == 1); |
| | | } |
| | | if (systemUser != null) { |
| | | identityInformationVO.setIsFrozen(systemUser.getStatus() == 2); |
| | | } |
| | | |
| | | if (identity == null && systemUser != null) { |
| | | identityInformationVO.setIdentity(2); |
| | | redisUtils.set("identity:" + loginUserInfo.getPhone(), 2); |
| | | }else if (identity == null && partyMember != null){ |
| | | identityInformationVO.setIdentity(1); |
| | | redisUtils.set("identity:" + loginUserInfo.getPhone(), 1); |
| | | } |
| | | else { |
| | | identityInformationVO.setIdentity(identity); |
| | | } |
| | | |
| | | if (identityInformationVO.getIdentity() != null){ |
| | | if (identityInformationVO.getIdentity() == 1){ |
| | | identityInformationVO.setIsFrozen(partyMember !=null && partyMember.getFreezeStatus() == 1); |
| | | }else if (identityInformationVO.getIdentity() == 2){ |
| | | identityInformationVO.setIsFrozen(systemUser != null &&systemUser.getStatus() == 2); |
| | | } |
| | | }else { |
| | | identityInformationVO.setIsFrozen(false); |
| | | } |
| | | |
| | | |
| | | |
| | | identityInformationVO.setIsPartymember(partyMember != null && partyMember.getAuditStatus().equals(1)); |
| | | identityInformationVO.setIsConfirm(partyMember != null && partyMember.getIsConfirm() == 1); |
| | | identityInformationVO.setAuditStatus(partyMember == null ? null : partyMember.getAuditStatus()); |
| | | if (partyMember != null) { |
| | | PermissionsVO partyMemberPermissions = new PermissionsVO(); |
| | | partyMemberPermissions.setIdentity(1); |
| | | partyMemberPermissions.setName(String.format("%s%s", partyMember.getCommunity(), "党员")); |
| | | partyMemberPermissions.setIsFrozen(partyMember.getFreezeStatus() == 1); |
| | | permissions.add(partyMemberPermissions); |
| | | } |
| | | if (systemUser != null) { |
| | | Integer accountLevel = systemUser.getAccountLevel(); |
| | | String districts = systemUser.getDistricts(); |
| | | String street = systemUser.getStreet(); |
| | | String community = systemUser.getCommunity(); |
| | | PermissionsVO adminPermissions = new PermissionsVO(); |
| | | adminPermissions.setIdentity(2); |
| | | adminPermissions.setIsFrozen(systemUser.getStatus() == 2); |
| | | if (accountLevel == 1){ |
| | | adminPermissions.setName(String.format("%s%s%s%s%s", "攀枝花市",districts, street, community, "管理员")); |
| | | }if (accountLevel == 2) { |
| | | adminPermissions.setIdentity(2); |
| | | } else if (accountLevel == 3) { |
| | | adminPermissions.setIdentity(2); |
| | | } else if (accountLevel == 4) { |
| | | adminPermissions.setIdentity(2); |
| | | } |
| | | permissions.add(adminPermissions); |
| | | } |
| | | identityInformationVO.setPermissions(permissions); |
| | | return R.ok(identityInformationVO); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 切换身份 |
| | | */ |
| | | @GetMapping("/change-identity") |
| | | @ApiOperation("切换身份") |
| | | public R<?> changeIdentity(Integer identity) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | redisUtils.set("identity:" + loginUserInfo.getPhone(), identity); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 提示内容确认 |
| | | */ |
| | | @GetMapping("/confirm-content") |
| | | @ApiOperation("提示内容确认") |
| | | public R<?> confirmContent() { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | redisUtils.set("confirmContent:" + loginUserInfo.getPhone(), 1); |
| | | return R.ok(); |
| | | } |
| | | } |