package com.bofeng.controller; import com.bofeng.dao.UserRoleMapper; import com.bofeng.entity.OwnerLinkman; import com.bofeng.entity.UptownHome; import com.bofeng.entity.UserOpen; import com.bofeng.entity.UserRole; import com.bofeng.service.HomeService; import com.bofeng.service.WxUserOpenService; import com.yvan.Model; import com.yvan.ModelOps; 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 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("用户注册页面点登录") @PostMapping("/userOpen/login") public Model login(JsonWapper jsonWapper) { String code = jsonWapper.asObject(String.class, "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("身份录入之创建角色(家庭用户或业委会成员)") @PostMapping("/userOpen/createRole") public Model 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> 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 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> 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/createYWH") public Model createYWH(JsonWapper jsonWapper) throws Exception { Long uptownId = jsonWapper.asObject(Long.class, "uptownId"); Long userId = jsonWapper.asObject(Long.class, "userId"); List lstOwnerMan = new ArrayList<>(); OwnerLinkman ownerLinkman; if (uptownId == null || uptownId == 0L) { return Model.newFail("请选择所在小区"); } for (int i = 0; i < jsonWapper.asList("lstOwner").size(); i++) { Map 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.createYWH(userId, uptownId, lstOwnerMan)); } catch (Exception e) { return Model.newFail(e.getMessage()); } } }