WxUserOpenController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. package com.bofeng.controller;
  2. import com.bofeng.dao.UserRoleMapper;
  3. import com.bofeng.entity.*;
  4. import com.bofeng.service.HomeService;
  5. import com.bofeng.service.WxUserOpenService;
  6. import com.yvan.Model;
  7. import com.yvan.platform.JsonWapper;
  8. import com.yvan.platform.StringUtils;
  9. import com.yvan.springmvc.HttpParameterParser;
  10. import com.yvan.springmvc.HttpUtils;
  11. import io.swagger.annotations.ApiOperation;
  12. import lombok.val;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import javax.servlet.http.HttpServletRequest;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.Map;
  21. @RestController
  22. public class WxUserOpenController {
  23. @Autowired
  24. private HomeService homeService;
  25. @Autowired
  26. private UserRoleMapper userRoleMapper;
  27. @Autowired
  28. private WxUserOpenService wxUserOpenService;
  29. @GetMapping("/userOpen/loginTest")
  30. public Model<UserOpen> loginTest() {
  31. val parser = HttpParameterParser.newInstance(HttpUtils.currentRequest());
  32. String openId = parser.getString("openId");
  33. String code = parser.getString("code");
  34. if (StringUtils.isNullOrEmpty(code)) {
  35. return Model.newFail("code为空");
  36. }
  37. UserOpen userOpen = homeService.getUserOpenByCode(code);
  38. if (userOpen == null) {
  39. return Model.newFail("微信登录失败");
  40. }
  41. //成功返回用户Id
  42. try {
  43. return Model.newSuccess(userOpen);
  44. } catch (Exception e) {
  45. return Model.newFail(e.getMessage());
  46. }
  47. }
  48. @ApiOperation("用户注册页面点登录")
  49. @GetMapping("/userOpen/login")
  50. public Model<Long> login() {
  51. val parser = HttpParameterParser.newInstance(HttpUtils.currentRequest());
  52. String openId = parser.getString("openId");
  53. String code = parser.getString("code");
  54. // JsonWapper jsonWapper = new JsonWapper(body);
  55. // Map map = jsonWapper.getInnerMap();
  56. // String openId = Conv.NS(map.get("openId"));
  57. // String code = Conv.NS(map.get("code"));
  58. if (StringUtils.isNullOrEmpty(code)) {
  59. return Model.newFail("code为空");
  60. }
  61. UserOpen userOpen = homeService.getUserOpenByCode(code);
  62. if (userOpen == null) {
  63. return Model.newFail("微信登录失败");
  64. }
  65. //成功返回用户Id
  66. try {
  67. return Model.newSuccess(userOpen.getUserId());
  68. } catch (Exception e) {
  69. return Model.newFail(e.getMessage());
  70. }
  71. }
  72. @ApiOperation("身份录入之创建角色(家庭用户或业委会成员)")
  73. @PostMapping("/userOpen/createRole")
  74. public Model<Long> createRole(HttpServletRequest request) throws Exception {
  75. Long isFamily = Long.parseLong(request.getParameter("isFamily"));
  76. Long isYWH = Long.parseLong(request.getParameter("isYWH"));
  77. if (isFamily == 0L && isYWH == 0L) {
  78. return Model.newFail("请至少选择一个角色");
  79. }
  80. //成功返回用户Id
  81. return Model.newSuccess(wxUserOpenService.createRole(isFamily, isYWH));
  82. }
  83. @ApiOperation("获取创建的角色")
  84. @PostMapping("/userOpen/queryUserRoles")
  85. public Model<List<UserRole>> queryUserRoles(JsonWapper jsonWapper) throws Exception {
  86. Long userId = jsonWapper.asObject(Long.class, "userId");
  87. if (userId == null || userId == 0L) {
  88. return Model.newFail("用户不存在");
  89. }
  90. try {
  91. return Model.newSuccess(wxUserOpenService.queryUserRoles(userId));
  92. } catch (Exception e) {
  93. return Model.newFail(e.getMessage());
  94. }
  95. }
  96. @ApiOperation("创建家庭角色,完善家庭及住宅信息")
  97. @PostMapping("/userOpen/createFamily")
  98. public Model<Long> createFamily(JsonWapper jsonWapper) throws Exception {
  99. Long userId = jsonWapper.asObject(Long.class, "userId");
  100. Long unitId = jsonWapper.asObject(Long.class, "unitId");
  101. String doorPlate = jsonWapper.asObject(String.class, "doorPlate");
  102. String linkMan = jsonWapper.asObject(String.class, "linkMan");
  103. Integer helpNum = jsonWapper.asObject(Integer.class, "helpNum");
  104. String phone = jsonWapper.asObject(String.class, "phone");
  105. if (userId == null || userId == 0L) {
  106. return Model.newFail("用户不存在");
  107. }
  108. if (unitId == null || unitId == 0L) {
  109. return Model.newFail("请选择所在单元");
  110. }
  111. if (StringUtils.isNullOrEmpty(doorPlate)) {
  112. return Model.newFail("请填写门牌号");
  113. }
  114. if (StringUtils.isNullOrEmpty(linkMan)) {
  115. return Model.newFail("请填写家庭联系人");
  116. }
  117. if (helpNum == null) {
  118. helpNum = 0;
  119. }
  120. if (StringUtils.isNullOrEmpty(phone)) {
  121. return Model.newFail("请填写家庭联系电话");
  122. }
  123. //成功返回用户Id
  124. try {
  125. return Model.newSuccess(wxUserOpenService.createFamily(userId, unitId, doorPlate, linkMan, helpNum, phone));
  126. } catch (Exception e) {
  127. return Model.newFail(e.getMessage());
  128. }
  129. }
  130. @ApiOperation("获取家庭及住宅信息")
  131. @PostMapping("/userOpen/queryFamily")
  132. public Model<List<UptownHome>> queryFamily(JsonWapper jsonWapper) throws Exception {
  133. Long userId = jsonWapper.asObject(Long.class, "userId");
  134. if (userId == null || userId == 0L) {
  135. return Model.newFail("用户不存在");
  136. }
  137. //成功返回用户Id
  138. return Model.newSuccess(wxUserOpenService.queryFamily(userId));
  139. }
  140. @ApiOperation("创建业委会资格")
  141. @PostMapping("/userOpen/createYWHRule")
  142. public Model<Long> createYWHRule(JsonWapper jsonWapper) throws Exception {
  143. Long userId = jsonWapper.asObject(Long.class, "userId");
  144. if (userId == null || userId == 0L) {
  145. return Model.newFail("用户不存在");
  146. }
  147. //成功返回用户Id
  148. try {
  149. return Model.newSuccess(wxUserOpenService.createYWHRule(userId));
  150. } catch (Exception e) {
  151. return Model.newFail(e.getMessage());
  152. }
  153. }
  154. @ApiOperation("创建业委会角色、成员信息")
  155. @PostMapping("/userOpen/createYWH")
  156. public Model<Long> createYWH(JsonWapper jsonWapper) throws Exception {
  157. Long uptownId = jsonWapper.asObject(Long.class, "uptownId");
  158. Long userId = jsonWapper.asObject(Long.class, "userId");
  159. List<Owner> lstOwner = new ArrayList<>();
  160. Owner owner;
  161. if (uptownId == null || uptownId == 0L) {
  162. return Model.newFail("请选择所在小区");
  163. }
  164. for (int i = 0; i < jsonWapper.asList("lstOwner").size(); i++) {
  165. Map<String, Object> mm = (Map) jsonWapper.asList("lstOwner").get(i);
  166. owner = new Owner();
  167. owner.setLinkman(mm.get("linkman").toString());
  168. owner.setPhone(mm.get("phone").toString());
  169. owner.setType(Long.parseLong(mm.get("type").toString()));
  170. lstOwner.add(owner);
  171. }
  172. if (lstOwner == null || lstOwner.size() == 0) {
  173. return Model.newFail("请增加业委会成员");
  174. }
  175. //成功返回用户Id
  176. try {
  177. return Model.newSuccess(wxUserOpenService.createYWH(userId, uptownId, lstOwner));
  178. } catch (Exception e) {
  179. return Model.newFail(e.getMessage());
  180. }
  181. }
  182. @ApiOperation("修改家庭及住宅信息")
  183. @PostMapping("/userOpen/editFamily")
  184. public Model<Long> editFamily(JsonWapper jsonWapper) throws Exception {
  185. Long userId = jsonWapper.asObject(Long.class, "userId");
  186. Long unitId = jsonWapper.asObject(Long.class, "unitId");
  187. String doorPlate = jsonWapper.asObject(String.class, "doorPlate");
  188. String linkMan = jsonWapper.asObject(String.class, "linkMan");
  189. Integer helpNum = jsonWapper.asObject(Integer.class, "helpNum");
  190. String phone = jsonWapper.asObject(String.class, "phone");
  191. Long urId = jsonWapper.asObject(Long.class, "urId");
  192. if (userId == null || userId == 0L) {
  193. return Model.newFail("用户不存在");
  194. }
  195. if (unitId == null || unitId == 0L) {
  196. return Model.newFail("请选择所在单元");
  197. }
  198. if (StringUtils.isNullOrEmpty(doorPlate)) {
  199. return Model.newFail("请填写门牌号");
  200. }
  201. if (StringUtils.isNullOrEmpty(linkMan)) {
  202. return Model.newFail("请填写家庭联系人");
  203. }
  204. if (helpNum == null) {
  205. helpNum = 0;
  206. }
  207. if (StringUtils.isNullOrEmpty(phone)) {
  208. return Model.newFail("请填写家庭联系电话");
  209. }
  210. //成功返回用户Id
  211. try {
  212. return Model.newSuccess(wxUserOpenService.editFamily(userId, unitId, doorPlate, linkMan, helpNum, phone, urId));
  213. } catch (Exception e) {
  214. return Model.newFail(e.getMessage());
  215. }
  216. }
  217. @ApiOperation("修改业委会成员信息")
  218. @PostMapping("/userOpen/editYWH")
  219. public Model<Long> editYWH(JsonWapper jsonWapper) throws Exception {
  220. Long uptownId = jsonWapper.asObject(Long.class, "uptownId");
  221. Long userId = jsonWapper.asObject(Long.class, "userId");
  222. Long urId = jsonWapper.asObject(Long.class, "urId");
  223. List<OwnerLinkman> lstOwnerMan = new ArrayList<>();
  224. OwnerLinkman ownerLinkman;
  225. if (uptownId == null || uptownId == 0L) {
  226. return Model.newFail("请选择所在小区");
  227. }
  228. for (int i = 0; i < jsonWapper.asList("lstOwner").size(); i++) {
  229. Map<String, Object> mm = (Map) jsonWapper.asList("lstOwner").get(i);
  230. ownerLinkman = new OwnerLinkman();
  231. ownerLinkman.setLinkman(mm.get("linkman").toString());
  232. ownerLinkman.setPhone(mm.get("phone").toString());
  233. ownerLinkman.setType(Long.parseLong(mm.get("type").toString()));
  234. lstOwnerMan.add(ownerLinkman);
  235. }
  236. if (lstOwnerMan == null || lstOwnerMan.size() == 0) {
  237. return Model.newFail("请增加业委会成员");
  238. }
  239. //成功返回用户Id
  240. try {
  241. return Model.newSuccess(wxUserOpenService.editYWH(urId, userId, uptownId, lstOwnerMan));
  242. } catch (Exception e) {
  243. return Model.newFail(e.getMessage());
  244. }
  245. }
  246. }