From 4a5879a5454a5b396a13ab0b3c7386cdc0779ea7 Mon Sep 17 00:00:00 2001
From: baizonghao <1719256278@qq.com>
Date: 星期一, 17 四月 2023 13:54:39 +0800
Subject: [PATCH] 一系列修改,主要包括添加,警方通告

---
 src/main/java/com/example/jz/controller/WxAppController.java |  336 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 310 insertions(+), 26 deletions(-)

diff --git a/src/main/java/com/example/jz/controller/WxAppController.java b/src/main/java/com/example/jz/controller/WxAppController.java
index 2c7afe6..4b74b69 100644
--- a/src/main/java/com/example/jz/controller/WxAppController.java
+++ b/src/main/java/com/example/jz/controller/WxAppController.java
@@ -3,17 +3,21 @@
 
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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.*;
 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;
@@ -24,11 +28,15 @@
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.client.RestTemplate;
 
+import javax.annotation.Resource;
+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";
@@ -38,7 +46,7 @@
     private final String wxApp_accessToken_verify_url = "https://api.weixin.qq.com/cgi-bin/token";
 
     @Value("${wx.appid}")
-    private  String appid;
+    private String appid;
 
     @Value("${wx.secret}")
     private String secret;
@@ -66,10 +74,15 @@
     MessageService messageService;
     @Autowired
     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);
@@ -98,14 +111,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());
@@ -114,17 +205,18 @@
             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));
         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);
     }
 
@@ -148,18 +240,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")
@@ -171,18 +336,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);
@@ -194,21 +354,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());
@@ -234,19 +424,29 @@
                     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);
                     } 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);
@@ -390,8 +590,17 @@
         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);
         message.setText(msg);
@@ -400,4 +609,79 @@
         message.setReportName(userService.getOne(new QueryWrapper<User>().eq("id", reportService.getOne(new QueryWrapper<Report>().eq("id", id)).getUserId())).getRealName());
         return R.ok(messageService.save(message));
     }
+
+    @GetMapping("/group/member/detail")
+    public R getMemberDetail(@RequestParam Integer id) {
+        Report report = reportService.getOne(new LambdaQueryWrapper<Report>().eq(Report::getId, id));
+        ReportVo reportVo = new ReportVo();
+        BeanUtils.copyProperties(report, reportVo);
+        User user = userDao.selectOne(new LambdaQueryWrapper<User>().eq(User::getId, report.getUserId()));
+        reportVo.setReporterName(user.getRealName());
+        reportVo.setMobile(user.getUserMobile());
+        reportVo.setIdcard(user.getUserIdcard());
+        return R.ok(reportVo);
+    }
+
+    /**
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping("/manager/report")
+    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")
+    public R queryPublicity(@RequestParam(required = false) Integer size) {
+        List<Publicity> publicityList = publicityService.list(new LambdaQueryWrapper<Publicity>().eq(Publicity::getStatus, 1));
+        if (size != null) {
+            return R.ok(publicityList.stream().limit(size));
+        }
+        return R.ok(publicityList);
+    }
+
+    @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