WxUserOpenController.java 10 KB

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