|
|
@@ -0,0 +1,340 @@
|
|
|
+package com.idea.pro.wx.web;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.idea.pro.wx.jwt.LoginCheck;
|
|
|
+import com.idea.pro.wx.pojo.MyInfo;
|
|
|
+import com.idea.pro.wx.pojo.PasswordModel;
|
|
|
+import com.idea.pro.wx.vo.TreeUserModel;
|
|
|
+import com.rockstar.frame.model.FrameRole;
|
|
|
+import com.rockstar.frame.model.FrameUser;
|
|
|
+import com.rockstar.frame.model.FrameUserExample;
|
|
|
+import com.rockstar.frame.service.FrameRoleService;
|
|
|
+import com.rockstar.frame.service.FrameUserService;
|
|
|
+import com.rockstar.system.model.SysDept;
|
|
|
+import com.rockstar.system.model.SysDeptExample;
|
|
|
+import com.rockstar.system.service.SysDeptService;
|
|
|
+import com.rockstar.user.model.UserAccount;
|
|
|
+import com.rockstar.user.model.UserAccountExample;
|
|
|
+import com.rockstar.user.service.UserAccountService;
|
|
|
+import com.rockstar.util.MD5Util;
|
|
|
+import com.rockstar.util.ResponseUtil;
|
|
|
+import com.rockstar.util.SnowflakeIdWorker;
|
|
|
+import com.rockstar.util.StringUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = "/wx/frameUser")
|
|
|
+@Api(tags = "用户")
|
|
|
+public class WxFrameUserController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FrameUserService frameUserService;
|
|
|
+ @Autowired
|
|
|
+ private SysDeptService sysDeptService;
|
|
|
+ @Autowired
|
|
|
+ private FrameRoleService frameRoleService;
|
|
|
+ @Autowired
|
|
|
+ private UserAccountService userAccountService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改登录密码
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/editPassword", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+ @LoginCheck
|
|
|
+ public Object editPassword(PasswordModel model){
|
|
|
+ FrameUser frameUser = frameUserService.selectByPrimaryKey(model.getUserId());
|
|
|
+ if (!StringUtils.equals(frameUser.getPassword(), MD5Util.encode(MD5Util.encode(model.getOldPassword().trim())))) {
|
|
|
+ return ResponseUtil.fail(202,"原密码输入不正确");
|
|
|
+ }
|
|
|
+ frameUser.setPassword(MD5Util.encode(MD5Util.encode(model.getNewPassword().trim())));
|
|
|
+ frameUser.setUpdatedat(new Date());
|
|
|
+ int userHome = frameUserService.updateByPrimaryKeySelective(frameUser);
|
|
|
+ if(userHome ==0){
|
|
|
+ return ResponseUtil.fail(203,"修改失败");
|
|
|
+ }
|
|
|
+ return ResponseUtil.ok("修改成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/getMyInfo", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+ @LoginCheck
|
|
|
+ public Object getMyInfo(String userId){
|
|
|
+ if(StringUtils.isEmpty(userId)){
|
|
|
+ return ResponseUtil.fail(202,"参数有误");
|
|
|
+ }
|
|
|
+ FrameUser frameUser = frameUserService.selectByPrimaryKey(userId);
|
|
|
+ if (null==frameUser) {
|
|
|
+ return ResponseUtil.fail(202,"用户不存在");
|
|
|
+ }
|
|
|
+ MyInfo myInfo = new MyInfo();
|
|
|
+ myInfo.setUserName(frameUser.getUsername());
|
|
|
+ myInfo.setPhone(frameUser.getPhone());
|
|
|
+ myInfo.setEmail(frameUser.getEmail());
|
|
|
+ if(StringUtils.isNotEmpty(frameUser.getDepartment())){
|
|
|
+ SysDept sysDept = sysDeptService.selectByPrimaryKey(frameUser.getDepartment());
|
|
|
+ myInfo.setDeptName(null!=sysDept?sysDept.getDeptName():"");
|
|
|
+ }
|
|
|
+ List<FrameRole> roleList = frameRoleService.queryUserRole(userId);
|
|
|
+ if(CollectionUtils.isNotEmpty(roleList)){
|
|
|
+ myInfo.setRoleName(roleList.stream().map(FrameRole::getName).collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ return ResponseUtil.ok(myInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/getSelectUser", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+ @LoginCheck
|
|
|
+ public Object getSelectUser(String searchName){
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ SysDept sysDept = sysDeptService.selectByPrimaryKey("0");
|
|
|
+ if(null!=sysDept){
|
|
|
+ jsonObject.put("id", sysDept.getId());
|
|
|
+ jsonObject.put("name", sysDept.getDeptName());
|
|
|
+ FrameUserExample frameUserExample = new FrameUserExample();
|
|
|
+ FrameUserExample.Criteria criteria = frameUserExample.createCriteria();
|
|
|
+ criteria.andDepartmentEqualTo(sysDept.getId()).andStatusEqualTo("1")
|
|
|
+ .andIdNotEqualTo("1");
|
|
|
+ if(StringUtils.isNotEmpty(searchName)){
|
|
|
+ criteria.andTruenameLike("%"+searchName+"%");
|
|
|
+ }
|
|
|
+ List<FrameUser> frameUserList = frameUserService.selectByExample(frameUserExample);
|
|
|
+ if(CollectionUtils.isNotEmpty(frameUserList)){
|
|
|
+ JSONArray objects = new JSONArray();
|
|
|
+ for (FrameUser frameUser : frameUserList) {
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("id", frameUser.getId());
|
|
|
+ jsonObject1.put("name", frameUser.getTruename());
|
|
|
+ objects.add(jsonObject1);
|
|
|
+ }
|
|
|
+ jsonObject.put("deptUser", objects);
|
|
|
+ }else{
|
|
|
+ jsonObject.put("deptUser", new JSONArray());
|
|
|
+ }
|
|
|
+ jsonObject.put("children", getChildDeptAndUser(sysDept.getId(), searchName));
|
|
|
+ }
|
|
|
+ return ResponseUtil.ok(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/getSelectUserTwo", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+// @LoginCheck
|
|
|
+ public Object getSelectUserTwo(String searchName){
|
|
|
+ List<SysDept> deptList = sysDeptService.listAll(new SysDept());
|
|
|
+ FrameUserExample userExample = new FrameUserExample();
|
|
|
+ FrameUserExample.Criteria criteria = userExample.createCriteria();
|
|
|
+// andDelFlagEqualTo("0")
|
|
|
+ criteria.andStatusEqualTo("1").andDepartmentIsNotNull();
|
|
|
+ if(StringUtils.isNotEmpty(searchName))
|
|
|
+ criteria.andTruenameLike("%"+searchName+"%");
|
|
|
+ List<FrameUser> userList = frameUserService.selectByExample(userExample);
|
|
|
+ List<TreeUserModel> resltList = new ArrayList<>();
|
|
|
+ deptList.stream().forEach(dept -> {
|
|
|
+ TreeUserModel dtree = new TreeUserModel();
|
|
|
+ dtree.setType("d");
|
|
|
+ dtree.setId(dept.getId());
|
|
|
+ dtree.setParentid(dept.getParentId());
|
|
|
+ dtree.setName(dept.getDeptName());
|
|
|
+ dtree.setUsername(dept.getDeptName());
|
|
|
+ resltList.add(dtree);
|
|
|
+ });
|
|
|
+ userList.stream().forEach(user -> {
|
|
|
+ TreeUserModel utree = new TreeUserModel();
|
|
|
+ utree.setType("u");
|
|
|
+ utree.setId(user.getId());
|
|
|
+ utree.setParentid(user.getDepartment());
|
|
|
+ utree.setName(user.getTruename());
|
|
|
+ utree.setUsername(user.getTruename());
|
|
|
+ resltList.add(utree);
|
|
|
+ });
|
|
|
+ return ResponseUtil.ok(resltList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONArray getChildDeptAndUser(String id, String searchName) {
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ SysDeptExample sysDeptExample = new SysDeptExample();
|
|
|
+ sysDeptExample.createCriteria().andParentIdEqualTo(id);
|
|
|
+ List<SysDept> sysDeptList = sysDeptService.selectByExample(sysDeptExample);
|
|
|
+ if(CollectionUtils.isNotEmpty(sysDeptList)){
|
|
|
+ for (SysDept sysDept : sysDeptList) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("id", sysDept.getId());
|
|
|
+ jsonObject.put("name", sysDept.getDeptName());
|
|
|
+ FrameUserExample frameUserExample = new FrameUserExample();
|
|
|
+ FrameUserExample.Criteria criteria = frameUserExample.createCriteria();
|
|
|
+ criteria.andDepartmentEqualTo(sysDept.getId()).andStatusEqualTo("1")
|
|
|
+ .andIdNotEqualTo("1");
|
|
|
+ if(StringUtils.isNotEmpty(searchName)){
|
|
|
+ criteria.andTruenameLike("%"+searchName+"%");
|
|
|
+ }
|
|
|
+ List<FrameUser> frameUserList = frameUserService.selectByExample(frameUserExample);
|
|
|
+ if(CollectionUtils.isNotEmpty(frameUserList)){
|
|
|
+ JSONArray objects = new JSONArray();
|
|
|
+ for (FrameUser frameUser : frameUserList) {
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("id", frameUser.getId());
|
|
|
+ jsonObject1.put("name", frameUser.getTruename());
|
|
|
+ objects.add(jsonObject1);
|
|
|
+ }
|
|
|
+ jsonObject.put("deptUser", objects);
|
|
|
+ }else{
|
|
|
+ jsonObject.put("deptUser", new JSONArray());
|
|
|
+ }
|
|
|
+ jsonObject.put("children", getChildDeptAndUser(sysDept.getId(), searchName));
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return jsonArray;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/getSelectDept", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+ @LoginCheck
|
|
|
+ public Object getSelectDept(String deptName){
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ SysDeptExample example = new SysDeptExample();
|
|
|
+ SysDeptExample.Criteria criteria = example.createCriteria();
|
|
|
+ if(StringUtils.isNotEmpty(deptName)){
|
|
|
+ criteria.andDeptNameLike("%"+deptName+"%");
|
|
|
+ }
|
|
|
+ List<SysDept> sysDeptList = sysDeptService.selectByExample(example);
|
|
|
+ if(CollectionUtils.isNotEmpty(sysDeptList)){
|
|
|
+ for (SysDept sysDept : sysDeptList) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("id", sysDept.getId());
|
|
|
+ jsonObject.put("name", sysDept.getDeptName());
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseUtil.ok(jsonArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/getSelectDeptTwo", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+// @LoginCheck
|
|
|
+ public Object getSelectDeptTwo(String deptName){
|
|
|
+ List<TreeUserModel> resltList = new ArrayList<>();
|
|
|
+ SysDeptExample example = new SysDeptExample();
|
|
|
+ SysDeptExample.Criteria criteria = example.createCriteria();
|
|
|
+ if(StringUtils.isNotEmpty(deptName)){
|
|
|
+ criteria.andDeptNameLike("%"+deptName+"%");
|
|
|
+ }
|
|
|
+ List<SysDept> sysDeptList = sysDeptService.selectByExample(example);
|
|
|
+ sysDeptList.stream().forEach(dept -> {
|
|
|
+ TreeUserModel dtree = new TreeUserModel();
|
|
|
+ dtree.setType("d");
|
|
|
+ dtree.setId(dept.getId());
|
|
|
+ dtree.setParentid(dept.getParentId());
|
|
|
+ dtree.setName(dept.getDeptName());
|
|
|
+ dtree.setUsername(dept.getDeptName());
|
|
|
+ resltList.add(dtree);
|
|
|
+ });
|
|
|
+ return ResponseUtil.ok(resltList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/userList", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+ public Object getSelectDeptTwo(FrameUser user){
|
|
|
+ FrameUserExample example = new FrameUserExample();
|
|
|
+ FrameUserExample.Criteria criteria = example.createCriteria();
|
|
|
+ criteria.andIdNotEqualTo("1");
|
|
|
+ if(null!=user&&StringUtils.isNotEmpty(user.getTruename())){
|
|
|
+ criteria.andTruenameLike("%"+user.getTruename()+"%");
|
|
|
+ }
|
|
|
+ if(null!=user&&StringUtils.isNotEmpty(user.getDepartment())){
|
|
|
+ criteria.andDepartmentEqualTo(user.getDepartment());
|
|
|
+ }
|
|
|
+ List<FrameUser> frameUsers = frameUserService.selectByExample(example);
|
|
|
+ return frameUsers;
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 微信用户绑定山水城用户
|
|
|
+// * @param code
|
|
|
+// * @param userId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @RequestMapping(value="/bindWxOpenId", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+// public Object bindWxOpenId(String code, String userId) {
|
|
|
+//
|
|
|
+// // 获取openId
|
|
|
+// String openId = WeixinPushUtool.getWeixinUserOpenId(code);
|
|
|
+//
|
|
|
+// // 判断用户是否已绑定
|
|
|
+// UserAccountExample userAccountExample = new UserAccountExample();
|
|
|
+// userAccountExample.createCriteria().andUserIdEqualTo(userId);
|
|
|
+// List<UserAccount> userAccounts = userAccountService.selectByExample(userAccountExample);
|
|
|
+// if(CollectionUtils.isNotEmpty(userAccounts)){
|
|
|
+// return ResponseUtil.fail(-1,"此账号已绑定,请勿重复操作");
|
|
|
+// }
|
|
|
+// // 判断openId是否已绑定
|
|
|
+// userAccountExample = new UserAccountExample();
|
|
|
+// userAccountExample.createCriteria().andOpenIdEqualTo(openId);
|
|
|
+// userAccounts = userAccountService.selectByExample(userAccountExample);
|
|
|
+// if(CollectionUtils.isNotEmpty(userAccounts)){
|
|
|
+// return ResponseUtil.fail(-1,"此微信号已绑定,请勿重复操作");
|
|
|
+// }
|
|
|
+//
|
|
|
+// FrameUser frameUser = frameUserService.selectByPrimaryKey(userId);
|
|
|
+//
|
|
|
+// UserAccount userAccount = new UserAccount();
|
|
|
+// userAccount.setId(SnowflakeIdWorker.getUUID());
|
|
|
+// userAccount.setUserId(userId);
|
|
|
+// userAccount.setOpenId(openId);
|
|
|
+// userAccount.setAccount(frameUser.getUsername());
|
|
|
+// userAccount.setCreatedAt(new Date());
|
|
|
+//
|
|
|
+// userAccountService.insert(userAccount);
|
|
|
+// return ResponseUtil.ok();
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 微信用户解绑山水城用户
|
|
|
+// * @param userId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @RequestMapping(value="/unbindWxOpenId", method= RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+// public Object unbindWxOpenId(String userId) {
|
|
|
+//
|
|
|
+// UserAccountExample userAccountExample = new UserAccountExample();
|
|
|
+// userAccountExample.createCriteria().andUserIdEqualTo(userId);
|
|
|
+// List<UserAccount> userAccounts = userAccountService.selectByExample(userAccountExample);
|
|
|
+// if(CollectionUtils.isEmpty(userAccounts)){
|
|
|
+// return ResponseUtil.fail(-1,"此账号未绑定,无需解绑");
|
|
|
+// }
|
|
|
+// UserAccount userAccount = userAccounts.get(0);
|
|
|
+// userAccountService.deleteByPrimaryKey(userAccount.getId());
|
|
|
+// return ResponseUtil.ok();
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户id获取用户
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/getWxUserById", method= RequestMethod.GET,produces = {MediaType.APPLICATION_JSON_VALUE})
|
|
|
+ public Object getWxUserById(String userId) {
|
|
|
+
|
|
|
+ FrameUser frameUser = frameUserService.selectByPrimaryKey(userId);
|
|
|
+ JSONObject newJSONObject = JSONObject.parseObject(JSONObject.toJSONString(frameUser));
|
|
|
+ UserAccountExample userAccountExample = new UserAccountExample();
|
|
|
+ userAccountExample.createCriteria().andUserIdEqualTo(frameUser.getId());
|
|
|
+ List<UserAccount> userAccounts = userAccountService.selectByExample(userAccountExample);
|
|
|
+ if(CollectionUtils.isNotEmpty(userAccounts)){
|
|
|
+ newJSONObject.put("bindFlag","1");
|
|
|
+ }
|
|
|
+ return ResponseUtil.ok(newJSONObject);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|