From 1c3f11dfd7493a4c4a8d41e2499477840bcc070c Mon Sep 17 00:00:00 2001 From: baizonghao <1719256278@qq.com> Date: 星期五, 19 五月 2023 15:01:46 +0800 Subject: [PATCH] 限制文件大小,用户,报案人审核筛选 --- src/main/java/com/example/jz/controller/WxAppController.java | 304 +++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 275 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/example/jz/controller/WxAppController.java b/src/main/java/com/example/jz/controller/WxAppController.java index 65d5b1b..9a86f93 100644 --- a/src/main/java/com/example/jz/controller/WxAppController.java +++ b/src/main/java/com/example/jz/controller/WxAppController.java @@ -7,15 +7,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.example.jz.auth.TokenJwtManager; import com.example.jz.dao.UserDao; import com.example.jz.modle.R; import com.example.jz.modle.entity.*; -import com.example.jz.modle.vo.CauseVo; -import com.example.jz.modle.vo.MemberVo; -import com.example.jz.modle.vo.ReportVo; +import com.example.jz.modle.vo.*; import com.example.jz.service.*; import com.example.jz.utils.HttpUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; import lombok.SneakyThrows; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -26,11 +28,16 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; +import javax.annotation.Resource; +import java.io.Serializable; +import java.sql.Array; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; @RestController @RequestMapping("/wx") +@Api(tags = "寰俊灏忕▼搴忔帴鍙�") public class WxAppController { private final String wxApp_userCode_verify_url = "https://api.weixin.qq.com/sns/jscode2session"; @@ -70,10 +77,13 @@ GroupUserService groupUserService; @Autowired PublicityService publicityService; + @Autowired + private AnnouncementService announcementService; + @Autowired + private PoliceAnnouncementService policeAnnouncementService; - @GetMapping("/login") - @SneakyThrows - public R login(@RequestParam String code, @RequestParam String phoneNumberCode) { + @GetMapping("/checkIdentity") + public R checkIdentity(@RequestParam String code, @RequestParam String phoneNumberCode) throws Exception { //灏忕▼搴忕櫥褰昽penid Map<String, Object> pathUrl = new HashMap<>(); pathUrl.put("appid", appid); @@ -102,14 +112,92 @@ JSONObject entries = JSONUtil.parseObj(response.getBody()); PhoneInFo phone_info = entries.get("phone_info", PhoneInFo.class); User user = userDao.selectOne(new QueryWrapper<User>().eq("user_mobile", phone_info.getPurePhoneNumber())); + if(Objects.isNull(user)){ + return R.ok(2, phone_info.getPurePhoneNumber()); + }else { + if (user.getRole() == 1){ + return R.ok(1, phone_info.getPurePhoneNumber()); + } else { + return R.ok(0, phone_info.getPurePhoneNumber()); + } + } + } + +// @GetMapping("/login") +// @SneakyThrows +// public R login(@RequestParam String code, @RequestParam String phoneNumberCode) { +// //灏忕▼搴忕櫥褰昽penid +// Map<String, Object> pathUrl = new HashMap<>(); +// pathUrl.put("appid", appid); +// pathUrl.put("secret", secret); +// pathUrl.put("js_code", code); +// pathUrl.put("grant_type", grant_type); +// JSONObject result = JSONUtil.parseObj(HttpUtil.doGet(wxApp_userCode_verify_url, pathUrl)); +// +// //鎵嬫満鍙风爜鐨刟ccess token +// Map<String, Object> accessToken = new HashMap<>(); +// accessToken.put("appid", appid); +// accessToken.put("secret", secret); +// accessToken.put("grant_type", "client_credential"); +// JSONObject accessTokenResult = JSONUtil.parseObj(HttpUtil.doGet(wxApp_accessToken_verify_url, accessToken)); +// +// //鐢佃瘽鍙风爜 +// String url = wxApp_phoneNumber_verify_url + "?access_token=" + accessTokenResult.get("access_token"); +// Map<String, Object> phoneNumber = new HashMap<>(); +// phoneNumber.put("code", phoneNumberCode); +// +// HttpHeaders headers = new HttpHeaders(); +// HttpEntity httpEntity = new HttpEntity<>(phoneNumber, headers); +// System.out.println(httpEntity); +// ResponseEntity response = restTemplate.postForEntity(url, httpEntity, Object.class); +// response.getBody(); +// JSONObject entries = JSONUtil.parseObj(response.getBody()); +// PhoneInFo phone_info = entries.get("phone_info", PhoneInFo.class); +// User user = userDao.selectOne(new QueryWrapper<User>().eq("user_mobile", phone_info.getPurePhoneNumber())); +// String token; +// Integer role; +// Integer id = null; +// if (user == null || user.getId() == null) { +// User newUser = new User(); +// newUser.setUserMobile(phone_info.getPurePhoneNumber()); +// newUser.setUserRegtime(new Date()); +// newUser.setOpenid(result.get("openid").toString()); +// newUser.setStatus(1); +// newUser.setRole(0); +// newUser.setCtime(new Date()); +// userService.save(newUser); +// token = tokenJwtManager.createToken(newUser); +// role = 0; +// id = newUser.getId(); +// } else { +// user.setOpenid(result.get("openid").toString()); +// user.setUserLasttime(new Date()); +// userDao.updateById(user); +// token = tokenJwtManager.createToken(user); +// role = user.getRole(); +// id = user.getId(); +// } +// User user1 = userDao.selectOne(new QueryWrapper<User>().eq("user_mobile", phone_info.getPurePhoneNumber())); +// HashMap<String, Object> loginMessage = new HashMap<>(); +// loginMessage.put("id", id); +// loginMessage.put("token", token); +// loginMessage.put("role", role); +// loginMessage.put("time", user1.getUserIdcard()); +// return R.ok(loginMessage); +// } + + @GetMapping("/login") + @SneakyThrows + public R login(@RequestParam String phone) { + User user = userDao.selectOne(new QueryWrapper<User>().eq("user_mobile", phone)); String token; Integer role; Integer id = null; if (user == null || user.getId() == null) { User newUser = new User(); - newUser.setUserMobile(phone_info.getPurePhoneNumber()); + newUser.setUserMobile(phone); newUser.setUserRegtime(new Date()); - newUser.setOpenid(result.get("openid").toString()); + newUser.setOpenid(phone); newUser.setStatus(1); newUser.setRole(0); newUser.setCtime(new Date()); @@ -118,14 +206,13 @@ role = 0; id = newUser.getId(); } else { - user.setOpenid(result.get("openid").toString()); user.setUserLasttime(new Date()); userDao.updateById(user); token = tokenJwtManager.createToken(user); role = user.getRole(); id = user.getId(); } - User user1 = userDao.selectOne(new QueryWrapper<User>().eq("user_mobile", phone_info.getPurePhoneNumber())); + User user1 = userDao.selectOne(new QueryWrapper<User>().eq("user_mobile", phone)); HashMap<String, Object> loginMessage = new HashMap<>(); loginMessage.put("id", id); loginMessage.put("token", token); @@ -154,18 +241,91 @@ @GetMapping("/user/cause") public R getCause(Integer id) { - return R.ok(reportService.list(new QueryWrapper<Report>().eq("user_id", id))); + List<Report> reports = reportService.list(new QueryWrapper<Report>().eq("user_id", id)); + List<ReportVXVO> res = reports.stream() + .map(item -> { + ReportVXVO res1 = new ReportVXVO(); + BeanUtils.copyProperties(item, res1); + if (!Objects.isNull(causeService.getById(item.getCauseId()))){ + res1.setReportDescription(causeService.getById(item.getCauseId()).getName()); + } + return res1; + }).collect(Collectors.toList()); + return R.ok(res); } @PostMapping("/user/addReport") - public R addReport(@RequestBody Report report) { - User user = userService.getOne(new QueryWrapper<User>().eq("id", report.getUserId())); + public R addReport(@RequestBody ReportVXVO reportVXVO) { + User user = userService.getOne(new QueryWrapper<User>().eq("id", reportVXVO.getUserId())); + user.setRealName(reportVXVO.getRealName()); + user.setSex(reportVXVO.getSex()); + user.setUserIdcard(reportVXVO.getUserIdCard()); + user.setLocation(reportVXVO.getLocation()); + user.setWorkingLocation(reportVXVO.getWorkingLocation()); + + userService.update(user, new LambdaQueryWrapper<User>().eq(User::getId, user.getId())); + Report report = new Report(); + BeanUtils.copyProperties(reportVXVO, report); + report.setAmountInvolved(reportVXVO.getAmountInvolved()); report.setPic(user.getPic()); report.setIsInGroup(0); report.setCtime(new Date()); report.setStatus(0); - report.setReportMethod("鐜板満褰曞叆"); + report.setReportMethod("鎵爜鎶ユ"); return R.ok(reportService.save(report)); + } + + @PostMapping("/user/policeAddReport") + public R policeAddReport(@RequestBody ReportVXVO reportVXVO) { + User one = userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getUserMobile, reportVXVO.getPhone())); + if (Objects.nonNull(one)){ + return R.ok("璇ユ墜鏈哄彿宸茶娉ㄥ唽"); + } + + User user = new User(); + + user.setUserMobile(reportVXVO.getPhone()); + user.setRealName(reportVXVO.getRealName()); + user.setSex(reportVXVO.getSex()); + user.setUserIdcard(reportVXVO.getUserIdCard()); + user.setLocation(reportVXVO.getLocation()); + user.setWorkingLocation(reportVXVO.getWorkingLocation()); + user.setCtime(new Date()); + userService.save(user); + + Report report = new Report(); + BeanUtils.copyProperties(reportVXVO, report); + report.setAmountInvolved(reportVXVO.getAmountInvolved()); + report.setUserId(user.getId()); + report.setPic(user.getPic()); + report.setIsInGroup(0); + report.setCtime(new Date()); + report.setStatus(0); + report.setReportMethod("鎵爜鎶ユ"); + return R.ok(reportService.save(report)); + } + + @PutMapping ("/user/addReport") + public R addReport1(@RequestBody ReportVXVO reportVXVO) { + User user = userService.getOne(new QueryWrapper<User>().eq("id", reportVXVO.getUserId())); + user.setRealName(reportVXVO.getRealName()); + user.setSex(reportVXVO.getSex()); + user.setUserIdcard(reportVXVO.getUserIdCard()); + user.setLocation(reportVXVO.getLocation()); + user.setWorkingLocation(reportVXVO.getWorkingLocation()); + + userService.update(user, new LambdaQueryWrapper<User>().eq(User::getId, user.getId())); + Report report = new Report(); + BeanUtils.copyProperties(reportVXVO, report); + report.setAmountInvolved(reportVXVO.getAmountInvolved()); + report.setPic(user.getPic()); + report.setIsInGroup(0); + report.setCtime(new Date()); + report.setStatus(0); + report.setReportMethod("鎵爜鎶ユ"); + + reportService.update(report, new LambdaQueryWrapper<Report>().eq(Report::getId, report.getId())); + return R.ok("淇敼鎴愬姛"); } @PostMapping("/user/add") @@ -177,18 +337,13 @@ @GetMapping("/manager/group/list") public R getMessage(@RequestParam Integer id, @RequestParam String newDate, @RequestParam String lastDate) { ArrayList<Map<String, Object>> list = new ArrayList<>(); -// List<GroupUser> groupUsers = groupUserService.list(new QueryWrapper<GroupUser>().eq("user_id", id)); List<Group> groupUsers = groupService.list(new QueryWrapper<Group>().eq("user_id", id)); - if (groupUsers != null && groupUsers.size() != 0) { + if (!groupUsers.isEmpty()) { groupUsers.forEach(item -> { HashMap<String, Object> groupMap = new HashMap<>(); - List<Message> message = messageService.list(new QueryWrapper<Message>().eq("group_id", item.getId()).isNotNull("user_id").orderByDesc("ctime")); + List<Message> message = messageService.list(new QueryWrapper<Message>().eq("group_id", item.getId()).orderByDesc("ctime")); groupMap.put("groupName", item.getGroupName()); - if (message != null && message.size() != 0) { - groupMap.put("message", message.get(0).getText()); - groupMap.put("name", message.get(0).getReportName()); - groupMap.put("time", message.get(0).getCtime()); - } + getMessage(groupMap, message); if (StringUtils.isNotBlank(lastDate)) { int count = messageService.count(new QueryWrapper<Message>().eq("group_id", item.getId()).between("ctime", lastDate, newDate)); groupMap.put("count", count); @@ -200,21 +355,51 @@ return R.ok(list); } + @GetMapping("/isExist") + public R isExist(@RequestParam String phone){ + User one = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getUserMobile, phone)); + if(Objects.isNull(one)){ + return R.ok(false, "璇ユ墜鏈哄彿娌℃湁琚敞鍐�"); + }else { + return R.ok(true, "璇ユ墜鏈哄彿宸茶娉ㄥ唽"); + } + } + + /** + * 鏄剧ず鐢ㄦ埛淇℃伅 + */ + @GetMapping("/getGroupUserInfo") + public R getGroupUserInfo(@RequestParam Integer id){ + User one = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getId, id)); + MessageUserInfoVO messageUserInfoVO = new MessageUserInfoVO(); + BeanUtils.copyProperties(messageUserInfoVO, one); + return R.ok(messageUserInfoVO); + } + + private void getMessage(HashMap<String, Object> groupMap, List<Message> message) { + if (!message.isEmpty()) { + groupMap.put("message", message.get(0).getText()); + if (message.get(0).getUserId() == null) { + groupMap.put("name", userDao.selectOne(new QueryWrapper<User>().eq("id", message.get(0).getCopId())).getRealName()); + } else { + groupMap.put("name", message.get(0).getReportName()); + } + groupMap.put("time", message.get(0).getCtime()); + } + } + @GetMapping("/user/group/list") public R getUserMessage(@RequestParam Integer id, @RequestParam String newDate, @RequestParam String lastDate) { ArrayList<Map<String, Object>> list = new ArrayList<>(); - reportService.list((new QueryWrapper<Report>().eq("user_id", id))) + reportService.listGroup(id) .forEach(item -> { GroupUser groupUser = groupUserService.getOne(new QueryWrapper<GroupUser>().eq("user_id", item.getId())); if (groupUser != null) { HashMap<String, Object> groupMap = new HashMap<>(); List<Message> message = messageService.list(new QueryWrapper<Message>().eq("group_id", groupUser.getGroupId()).orderByDesc("ctime")); - if (message != null && message.size() != 0) { - groupMap.put("message", message.get(0).getText()); - groupMap.put("time", message.get(0).getCtime()); - } + getMessage(groupMap, message); Group group = groupService.getOne(new QueryWrapper<Group>().eq("id", groupUser.getGroupId())); groupMap.put("groupName", group.getGroupName()); groupMap.put("id", group.getId()); @@ -240,19 +425,30 @@ HashMap<String, Object> messageMap = new HashMap<>(); messageMap.put("text", item.getText()); messageMap.put("time", item.getCtime()); + messageMap.put("messageId", item.getId()); if (item.getUserId() != null) { Report report = reportService.getOne(new QueryWrapper<Report>().eq("id", item.getUserId())); User user = userService.getOne(new QueryWrapper<User>().eq("id", report.getUserId())); + if (Objects.isNull(user)) { + return; + } messageMap.put("id", user.getId()); messageMap.put("name", item.getReportName()); messageMap.put("mobile", user.getUserMobile()); + messageMap.put("idcard", user.getUserIdcard()); + messageMap.put("sex", user.getSex()); messageMap.put("pic", user.getPic()); messageMap.put("role", 0); + messageMap.put("remark", user.getUserMemo()); } else { messageMap.put("id", item.getCopId()); User user = userService.getOne(new QueryWrapper<User>().eq("id", item.getCopId())); + if (Objects.isNull(user)) { + return; + } messageMap.put("name", user.getRealName()); messageMap.put("mobile", user.getUserMobile()); + messageMap.put("sex", user.getSex()); messageMap.put("role", 1); } message.add(messageMap); @@ -396,10 +592,16 @@ return R.ok(messageService.save(message)); } + + @GetMapping("/group/user/sendMsg") public R sendUserMsg(@RequestParam Integer id, @RequestParam Integer groupId, @RequestParam String msg) { if (StringUtils.isBlank(msg)) { return R.failed("msg is blank"); + } + GroupUser one = groupUserService.getOne(new LambdaQueryWrapper<GroupUser>().eq(GroupUser::getUserId, id).eq(GroupUser::getGroupId, groupId)); + if (one.getBanSpeech() == 1){ + return R.failed("璇ョ敤鎴峰凡缁忚绂佽█"); } Message message = new Message(); message.setUserId(id); @@ -422,20 +624,29 @@ return R.ok(reportVo); } + /** + * + * @param id + * @return + */ @GetMapping("/manager/report") - public R queryReport() { - return R.ok(reportService.list(new LambdaQueryWrapper<Report>().eq(Report::getStatus, 0)) + public R queryReport(@RequestParam Integer id) { + List<Integer> collect = causeService.list(Wrappers.<Cause>lambdaQuery().eq(Cause::getUserId, id)).stream().map(cause -> cause.getId()).collect(Collectors.toList()); + R<List<ReportVo>> ok = R.ok(reportService.list(new LambdaQueryWrapper<Report>().eq(Report::getStatus, 0).in(Report::getCauseId, collect)) .stream() .map(item -> { ReportVo reportVo = new ReportVo(); BeanUtils.copyProperties(item, reportVo); User user = userDao.selectOne(new LambdaQueryWrapper<User>().eq(User::getId, item.getUserId())); + Cause one = causeService.getOne(new LambdaQueryWrapper<Cause>().eq(Cause::getId, item.getCauseId())); + reportVo.setReportDescription(one.getName()); reportVo.setReporterName(user.getRealName()); reportVo.setMobile(user.getUserMobile()); reportVo.setIdcard(user.getUserIdcard()); return reportVo; }) .collect(Collectors.toList())); + return ok; } @GetMapping("/publicity") @@ -446,4 +657,39 @@ } return R.ok(publicityList); } + + @GetMapping("/publicity/{id}") + @ApiOperation("閫氳繃涓婚敭鏌ヨ鍗曟潯鏁版嵁") + public R<Publicity> selectOne(@PathVariable Serializable id) { + return R.ok(publicityService.getById(id)); + } + + @ApiOperation(httpMethod = "POST", value = "缇ゅ叕鍛婃坊鍔�") + @PostMapping("/announcement/add") + public R insert(@RequestParam(value = "groupId") Integer groupId, @RequestParam String announcement) { + Announcement announcement1 = new Announcement(); + announcement1.setText(announcement); + announcement1.setStatus(1); + return R.ok(announcementService.vxAdd(groupId, announcement1)); + } + + @ApiOperation(httpMethod = "DELETE", value = "缇ゅ叕鍛婂垹闄�") + @DeleteMapping("/announcement/delete") + public R delete(@RequestParam(value = "id") Integer id) { + announcementService.removeById(id); + return R.ok(); + } + + @ApiOperation(httpMethod = "GET", value = "鏌ョ湅缇ゅ叕鍛�") + @GetMapping("/getAnnouncements") + public R getAnnouncements(@RequestParam(value = "groupId") Integer groupId) { + return R.ok(announcementService.getAnnouncements(groupId)); + } + + @GetMapping("policeAnnouncement/list") + @ApiOperation(httpMethod = "GET", value = "璀︽柟鍏憡") + public R getPoliceAnnouncement(){ + List<PoliceAnnouncement> list = policeAnnouncementService.list(Wrappers.<PoliceAnnouncement>lambdaQuery().eq(PoliceAnnouncement::getStatus, 1).orderByDesc(PoliceAnnouncement::getCtime)); + return R.ok(list); + } } -- Gitblit v1.8.0