| | |
| | | package com.panzhihua.sangeshenbian.api; |
| | | |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.interfaces.OperLog; |
| | |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo; |
| | | import com.panzhihua.common.service.auth.TokenService; |
| | | import com.panzhihua.common.utlis.HttpClientUtil; |
| | | import com.panzhihua.common.utlis.ServletUtils; |
| | | import com.panzhihua.sangeshenbian.model.entity.SystemMenu; |
| | | import com.panzhihua.sangeshenbian.model.entity.SystemRoleMenu; |
| | | import com.panzhihua.sangeshenbian.model.entity.SystemUser; |
| | | import com.panzhihua.sangeshenbian.annotation.SysLog; |
| | | import com.panzhihua.sangeshenbian.model.entity.*; |
| | | import com.panzhihua.sangeshenbian.model.vo.RegionVO; |
| | | import com.panzhihua.sangeshenbian.service.ISystemMenuService; |
| | | import com.panzhihua.sangeshenbian.service.ISystemRoleMenuService; |
| | | import com.panzhihua.sangeshenbian.service.ISystemUserService; |
| | | import com.panzhihua.sangeshenbian.service.*; |
| | | import com.panzhihua.sangeshenbian.utils.SignatureUtil; |
| | | import com.panzhihua.sangeshenbian.warpper.*; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.security.MessageDigest; |
| | | import java.text.MessageFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | @Resource |
| | | private ISystemMenuService systemMenuService; |
| | | |
| | | @Resource |
| | | private IBcRegionService bcRegionService; |
| | | @Resource |
| | | private IComStreetService comStreetService; |
| | | @Resource |
| | | private IComActService comActService; |
| | | |
| | | @Resource |
| | | private ISystemLogService systemLogService; |
| | | |
| | | @Resource |
| | | private ISystemUserLevelService systemUserLevelService; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @PostMapping("/login") |
| | | @ApiOperation(value = "登录", tags = {"三个身边后台-登录"}) |
| | | @OperLog(operModul = "三个身边后台",operType = 0,businessType = "登录") |
| | | @SysLog(operatorCategory = "登录",operId = 1) |
| | | public R<TokenVo> login(@RequestBody LoginVo vo){ |
| | | String key = "login:" + vo.getPhone(); |
| | | Integer size = (Integer) redisTemplate.opsForValue().get(key); |
| | |
| | | LoginReturnVO loginReturnVO = reult.getData(); |
| | | TokenVo tokenVo = new TokenVo(); |
| | | BeanUtils.copyProperties(loginReturnVO, tokenVo); |
| | | tokenVo.setUserId(Long.valueOf(systemUser.getId())); |
| | | |
| | | List<SystemRoleMenu> list = systemRoleMenuService.list(new LambdaQueryWrapper<SystemRoleMenu>().eq(SystemRoleMenu::getSystemRoleId, systemUser.getSystemRoleId())); |
| | | List<Integer> collect = list.stream().map(SystemRoleMenu::getSystemMenuId).collect(Collectors.toList()); |
| | |
| | | |
| | | @PostMapping("/add") |
| | | @ApiOperation(value = "添加人员", tags = {"三个身边管理后台-人员管理"}) |
| | | @OperLog(operModul = "三个身边后台",operType = 1,businessType = "添加人员") |
| | | @SysLog(operatorCategory = "添加账号",operId = 4) |
| | | public R add(@RequestBody SystemUser systemUser){ |
| | | Integer id = this.getLoginUserInfoSanGeShenBian().getId(); |
| | | SystemUser user = systemUserService.getById(id); |
| | | List<SystemUserLevel> systemUserLevels = systemUser.getSystemUserLevels(); |
| | | if(systemUserLevels==null || systemUserLevels.isEmpty()){ |
| | | return R.fail("请选择账号层级"); |
| | | } |
| | | // 获取最高层级的用于原来的判断 |
| | | systemUserLevels.sort(Comparator.comparing(SystemUserLevel::getLevel)); |
| | | Integer level = systemUserLevels.get(0).getLevel(); |
| | | user.setAccountLevel(level); |
| | | |
| | | |
| | | if(2 == user.getAccountLevel() && 1 == systemUser.getAccountLevel()){ |
| | | return R.fail("不能添加市级账号"); |
| | | } |
| | |
| | | if(0 < count){ |
| | | return R.fail("手机号重复。"); |
| | | } |
| | | |
| | | String districtsCode = systemUser.getDistrictsCode(); |
| | | if (!StringUtils.isEmpty(districtsCode)){ |
| | | BcRegion bcRegion = bcRegionService.getOne(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getRegionCode, districtsCode)); |
| | | systemUser.setDistricts(bcRegion.getRegionName()); |
| | | } |
| | | |
| | | String streetId = systemUser.getStreetId(); |
| | | if (!StringUtils.isEmpty(streetId)){ |
| | | ComStreet comStreet = comStreetService.getById(streetId); |
| | | systemUser.setStreet(comStreet.getName()); |
| | | } |
| | | Long communityId = systemUser.getCommunityId(); |
| | | if (communityId != null){ |
| | | ComAct act = comActService.getById(communityId); |
| | | systemUser.setCommunity(act.getName()); |
| | | } |
| | | |
| | | systemUser.setStatus(1); |
| | | systemUser.setCreateTime(LocalDateTime.now()); |
| | | // 2.0.1 默认管理员 |
| | | systemUser.setIsAdmin(1); |
| | | systemUserService.save(systemUser); |
| | | |
| | | // 2.0.1添加账号层级 |
| | | systemUserLevels.forEach(e->{ |
| | | e.setSystemUserId(systemUser.getId()); |
| | | e.setStatus(1); |
| | | }); |
| | | systemUserLevelService.saveBatch(systemUserLevels); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/edit") |
| | | @ApiOperation(value = "编辑人员", tags = {"三个身边后台-人员管理"}) |
| | | @OperLog(operModul = "三个身边后台",operType = 2,businessType = "编辑人员") |
| | | @SysLog(operatorCategory = "编辑账号",operId = 4) |
| | | public R edit(@RequestBody SystemUser systemUser){ |
| | | List<SystemUserLevel> systemUserLevels = systemUser.getSystemUserLevels(); |
| | | if(systemUserLevels==null || systemUserLevels.isEmpty()){ |
| | | return R.fail("请选择账号层级"); |
| | | } |
| | | long count = systemUserService.count(new LambdaQueryWrapper<SystemUser>().eq(SystemUser::getPhone, systemUser.getPhone()) |
| | | .ne(SystemUser::getStatus, 3).ne(SystemUser::getId, systemUser.getId())); |
| | | if(0 < count){ |
| | | return R.fail("手机号重复。"); |
| | | } |
| | | |
| | | String districtsCode = systemUser.getDistrictsCode(); |
| | | if (!StringUtils.isEmpty(districtsCode)){ |
| | | BcRegion bcRegion = bcRegionService.getOne(new LambdaQueryWrapper<BcRegion>().eq(BcRegion::getRegionCode, districtsCode)); |
| | | systemUser.setDistricts(bcRegion.getRegionName()); |
| | | } |
| | | |
| | | String streetId = systemUser.getStreetId(); |
| | | if (!StringUtils.isEmpty(streetId)){ |
| | | ComStreet comStreet = comStreetService.getById(streetId); |
| | | systemUser.setStreet(comStreet.getName()); |
| | | } |
| | | Long communityId = systemUser.getCommunityId(); |
| | | if (communityId != null){ |
| | | ComAct act = comActService.getById(communityId); |
| | | systemUser.setCommunity(act.getName()); |
| | | } |
| | | |
| | | |
| | | systemUser.setStatus(1); |
| | | systemUser.setCreateTime(LocalDateTime.now()); |
| | | systemUserService.updateById(systemUser); |
| | | // 移除原来层级 在添加新层级 |
| | | systemUserLevelService.remove(new LambdaQueryWrapper<SystemUserLevel>().eq(SystemUserLevel::getSystemUserId, systemUser.getId())); |
| | | systemUserLevels.forEach(e->{ |
| | | e.setSystemUserId(systemUser.getId()); |
| | | e.setStatus(1); |
| | | }); |
| | | systemUserLevelService.saveBatch(systemUserLevels); |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @DeleteMapping("/delete/{id}") |
| | | @ApiOperation(value = "删除人员", tags = {"三个身边后台-人员管理"}) |
| | | @OperLog(operModul = "三个身边后台",operType = 3,businessType = "删除人员") |
| | | @SysLog(operatorCategory = "删除账号",operId = 4) |
| | | public R delete(@PathVariable("id") Integer id){ |
| | | SystemUser systemUser = systemUserService.getById(id); |
| | | systemUser.setStatus(3); |
| | | systemUserService.updateById(systemUser); |
| | | return R.ok(); |
| | | systemUserLevelService.update(new LambdaUpdateWrapper<SystemUserLevel>().eq(SystemUserLevel::getSystemUserId, id).set(SystemUserLevel::getStatus,3)); |
| | | return R.ok(systemUser.getName()); |
| | | } |
| | | |
| | | |
| | |
| | | @OperLog(operModul = "三个身边后台",operType = 0,businessType = "查询人员详情") |
| | | public R<SystemUser> getSystemUserInfo(@PathVariable("id") Integer id){ |
| | | SystemUser systemUser = systemUserService.getById(id); |
| | | List<SystemUserLevel> listBySystemUserId = systemUserLevelService.getListBySystemUserId(id); |
| | | listBySystemUserId.sort(Comparator.comparing(SystemUserLevel::getLevel)); |
| | | systemUser.setSystemUserLevels(listBySystemUserId); |
| | | return R.ok(systemUser); |
| | | } |
| | | |