123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- package com.bofeng.controller;
- import com.bofeng.dao.UserRoleMapper;
- import com.bofeng.entity.*;
- import com.bofeng.service.HomeService;
- import com.bofeng.service.WxUserOpenService;
- import com.yvan.Model;
- import com.yvan.platform.JsonWapper;
- import com.yvan.platform.StringUtils;
- import com.yvan.springmvc.HttpParameterParser;
- import com.yvan.springmvc.HttpUtils;
- import io.swagger.annotations.ApiOperation;
- import lombok.val;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletRequest;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- @RestController
- public class WxUserOpenController {
- @Autowired
- private HomeService homeService;
- @Autowired
- private UserRoleMapper userRoleMapper;
- @Autowired
- private WxUserOpenService wxUserOpenService;
- @GetMapping("/userOpen/loginTest")
- public Model<UserOpen> loginTest() {
- val parser = HttpParameterParser.newInstance(HttpUtils.currentRequest());
- String openId = parser.getString("openId");
- String code = parser.getString("code");
- if (StringUtils.isNullOrEmpty(code)) {
- return Model.newFail("code为空");
- }
- UserOpen userOpen = homeService.getUserOpenByCode(code);
- if (userOpen == null) {
- return Model.newFail("微信登录失败");
- }
- //成功返回用户Id
- try {
- return Model.newSuccess(userOpen);
- } catch (Exception e) {
- return Model.newFail(e.getMessage());
- }
- }
- @ApiOperation("用户注册页面点登录")
- @GetMapping("/userOpen/login")
- public Model<Long> login() {
- val parser = HttpParameterParser.newInstance(HttpUtils.currentRequest());
- String openId = parser.getString("openId");
- String code = parser.getString("code");
- // JsonWapper jsonWapper = new JsonWapper(body);
- // Map map = jsonWapper.getInnerMap();
- // String openId = Conv.NS(map.get("openId"));
- // String code = Conv.NS(map.get("code"));
- if (StringUtils.isNullOrEmpty(code)) {
- return Model.newFail("code为空");
- }
- UserOpen userOpen = homeService.getUserOpenByCode(code);
- if (userOpen == null) {
- return Model.newFail("微信登录失败");
- }
- //成功返回用户Id
- try {
- return Model.newSuccess(userOpen.getUserId());
- } catch (Exception e) {
- return Model.newFail(e.getMessage());
- }
- }
- @ApiOperation("身份录入之创建角色(家庭用户或业委会成员)")
- @PostMapping("/userOpen/createRole")
- public Model<Long> createRole(HttpServletRequest request) throws Exception {
- Long isFamily = Long.parseLong(request.getParameter("isFamily"));
- Long isYWH = Long.parseLong(request.getParameter("isYWH"));
- if (isFamily == 0L && isYWH == 0L) {
- return Model.newFail("请至少选择一个角色");
- }
- //成功返回用户Id
- return Model.newSuccess(wxUserOpenService.createRole(isFamily, isYWH));
- }
- @ApiOperation("获取创建的角色")
- @PostMapping("/userOpen/queryUserRoles")
- public Model<List<UserRole>> queryUserRoles(JsonWapper jsonWapper) throws Exception {
- Long userId = jsonWapper.asObject(Long.class, "userId");
- if (userId == null || userId == 0L) {
- return Model.newFail("用户不存在");
- }
- try {
- return Model.newSuccess(wxUserOpenService.queryUserRoles(userId));
- } catch (Exception e) {
- return Model.newFail(e.getMessage());
- }
- }
- @ApiOperation("创建家庭角色,完善家庭及住宅信息")
- @PostMapping("/userOpen/createFamily")
- public Model<Long> createFamily(JsonWapper jsonWapper) throws Exception {
- Long userId = jsonWapper.asObject(Long.class, "userId");
- Long unitId = jsonWapper.asObject(Long.class, "unitId");
- String doorPlate = jsonWapper.asObject(String.class, "doorPlate");
- String linkMan = jsonWapper.asObject(String.class, "linkMan");
- Integer helpNum = jsonWapper.asObject(Integer.class, "helpNum");
- String phone = jsonWapper.asObject(String.class, "phone");
- if (userId == null || userId == 0L) {
- return Model.newFail("用户不存在");
- }
- if (unitId == null || unitId == 0L) {
- return Model.newFail("请选择所在单元");
- }
- if (StringUtils.isNullOrEmpty(doorPlate)) {
- return Model.newFail("请填写门牌号");
- }
- if (StringUtils.isNullOrEmpty(linkMan)) {
- return Model.newFail("请填写家庭联系人");
- }
- if (helpNum == null) {
- helpNum = 0;
- }
- if (StringUtils.isNullOrEmpty(phone)) {
- return Model.newFail("请填写家庭联系电话");
- }
- //成功返回用户Id
- try {
- return Model.newSuccess(wxUserOpenService.createFamily(userId, unitId, doorPlate, linkMan, helpNum, phone));
- } catch (Exception e) {
- return Model.newFail(e.getMessage());
- }
- }
- @ApiOperation("获取家庭及住宅信息")
- @PostMapping("/userOpen/queryFamily")
- public Model<List<UptownHome>> queryFamily(JsonWapper jsonWapper) throws Exception {
- Long userId = jsonWapper.asObject(Long.class, "userId");
- if (userId == null || userId == 0L) {
- return Model.newFail("用户不存在");
- }
- //成功返回用户Id
- return Model.newSuccess(wxUserOpenService.queryFamily(userId));
- }
- @ApiOperation("创建业委会资格")
- @PostMapping("/userOpen/createYWHRule")
- public Model<Long> createYWHRule(JsonWapper jsonWapper) throws Exception {
- Long userId = jsonWapper.asObject(Long.class, "userId");
- if (userId == null || userId == 0L) {
- return Model.newFail("用户不存在");
- }
- //成功返回用户Id
- try {
- return Model.newSuccess(wxUserOpenService.createYWHRule(userId));
- } catch (Exception e) {
- return Model.newFail(e.getMessage());
- }
- }
- @ApiOperation("创建业委会角色、成员信息")
- @PostMapping("/userOpen/createYWH")
- public Model<Long> createYWH(JsonWapper jsonWapper) throws Exception {
- Long uptownId = jsonWapper.asObject(Long.class, "uptownId");
- Long userId = jsonWapper.asObject(Long.class, "userId");
- List<Owner> lstOwner = new ArrayList<>();
- Owner owner;
- if (uptownId == null || uptownId == 0L) {
- return Model.newFail("请选择所在小区");
- }
- for (int i = 0; i < jsonWapper.asList("lstOwner").size(); i++) {
- Map<String, Object> mm = (Map) jsonWapper.asList("lstOwner").get(i);
- owner = new Owner();
- owner.setLinkman(mm.get("linkman").toString());
- owner.setPhone(mm.get("phone").toString());
- owner.setType(Long.parseLong(mm.get("type").toString()));
- lstOwner.add(owner);
- }
- if (lstOwner == null || lstOwner.size() == 0) {
- return Model.newFail("请增加业委会成员");
- }
- //成功返回用户Id
- try {
- return Model.newSuccess(wxUserOpenService.createYWH(userId, uptownId, lstOwner));
- } catch (Exception e) {
- return Model.newFail(e.getMessage());
- }
- }
- @ApiOperation("修改家庭及住宅信息")
- @PostMapping("/userOpen/editFamily")
- public Model<Long> editFamily(JsonWapper jsonWapper) throws Exception {
- Long userId = jsonWapper.asObject(Long.class, "userId");
- Long unitId = jsonWapper.asObject(Long.class, "unitId");
- String doorPlate = jsonWapper.asObject(String.class, "doorPlate");
- String linkMan = jsonWapper.asObject(String.class, "linkMan");
- Integer helpNum = jsonWapper.asObject(Integer.class, "helpNum");
- String phone = jsonWapper.asObject(String.class, "phone");
- Long urId = jsonWapper.asObject(Long.class, "urId");
- if (userId == null || userId == 0L) {
- return Model.newFail("用户不存在");
- }
- if (unitId == null || unitId == 0L) {
- return Model.newFail("请选择所在单元");
- }
- if (StringUtils.isNullOrEmpty(doorPlate)) {
- return Model.newFail("请填写门牌号");
- }
- if (StringUtils.isNullOrEmpty(linkMan)) {
- return Model.newFail("请填写家庭联系人");
- }
- if (helpNum == null) {
- helpNum = 0;
- }
- if (StringUtils.isNullOrEmpty(phone)) {
- return Model.newFail("请填写家庭联系电话");
- }
- //成功返回用户Id
- try {
- return Model.newSuccess(wxUserOpenService.editFamily(userId, unitId, doorPlate, linkMan, helpNum, phone, urId));
- } catch (Exception e) {
- return Model.newFail(e.getMessage());
- }
- }
- @ApiOperation("修改业委会成员信息")
- @PostMapping("/userOpen/editYWH")
- public Model<Long> editYWH(JsonWapper jsonWapper) throws Exception {
- Long uptownId = jsonWapper.asObject(Long.class, "uptownId");
- Long userId = jsonWapper.asObject(Long.class, "userId");
- Long urId = jsonWapper.asObject(Long.class, "urId");
- List<OwnerLinkman> lstOwnerMan = new ArrayList<>();
- OwnerLinkman ownerLinkman;
- if (uptownId == null || uptownId == 0L) {
- return Model.newFail("请选择所在小区");
- }
- for (int i = 0; i < jsonWapper.asList("lstOwner").size(); i++) {
- Map<String, Object> mm = (Map) jsonWapper.asList("lstOwner").get(i);
- ownerLinkman = new OwnerLinkman();
- ownerLinkman.setLinkman(mm.get("linkman").toString());
- ownerLinkman.setPhone(mm.get("phone").toString());
- ownerLinkman.setType(Long.parseLong(mm.get("type").toString()));
- lstOwnerMan.add(ownerLinkman);
- }
- if (lstOwnerMan == null || lstOwnerMan.size() == 0) {
- return Model.newFail("请增加业委会成员");
- }
- //成功返回用户Id
- try {
- return Model.newSuccess(wxUserOpenService.editYWH(urId, userId, uptownId, lstOwnerMan));
- } catch (Exception e) {
- return Model.newFail(e.getMessage());
- }
- }
- }
|