|
@@ -1,12 +1,29 @@
|
|
|
package com.huimv.receive.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.huimv.receive.common.utils.IDCardValidator;
|
|
|
+import com.huimv.receive.common.utils.PhoneNumberValidator;
|
|
|
+import com.huimv.receive.common.utils.Result;
|
|
|
+import com.huimv.receive.common.utils.ResultCode;
|
|
|
+import com.huimv.receive.entity.SysAccountMultilevel;
|
|
|
+import com.huimv.receive.entity.SysUser;
|
|
|
+import com.huimv.receive.service.ISysAccountMultilevelService;
|
|
|
+import com.huimv.receive.service.ISysUserService;
|
|
|
import com.huimv.receive.service.IUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/admin/user")
|
|
@@ -15,21 +32,12 @@ public class SysUserController {
|
|
|
@Autowired
|
|
|
private IUserService iUserService;
|
|
|
|
|
|
-// @PostMapping("/add")
|
|
|
-// public Result addUser(@RequestBody User user){
|
|
|
-// return iUserService.addUser(user);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @PostMapping("/edit")
|
|
|
-// public Result updateUser(@RequestBody User user){
|
|
|
-// return iUserService.updateUser(user);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @RequestMapping("/remove")
|
|
|
-// public Result removeUser(@RequestParam("userIds") List<Integer> userIds) {
|
|
|
-//
|
|
|
-// return iUserService.removeUser(userIds);
|
|
|
-// }
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysAccountMultilevelService accountMultilevelService;
|
|
|
+
|
|
|
|
|
|
@PostMapping("/list")
|
|
|
public JSONObject listUser(@RequestBody Map map) {
|
|
@@ -39,5 +47,88 @@ public class SysUserController {
|
|
|
String searchStr = (String)map.get("searchStr");
|
|
|
return iUserService.findUserAccount(searchStr,pageNum,pageSize);
|
|
|
}
|
|
|
+ //员工分页查询
|
|
|
+ @PostMapping("/page")
|
|
|
+ public Result page(@RequestBody Map map) {
|
|
|
+ return sysUserService.pageAll(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ //员工新增
|
|
|
+ @PostMapping("/add")
|
|
|
+ public Result add(@RequestBody SysUser sysUser) {
|
|
|
+ String cardType = sysUser.getCardType();
|
|
|
+ String cardNum = sysUser.getCardNum();
|
|
|
+ if ("身份证".equals(cardType) && !IDCardValidator.isValidIDCard(cardNum))
|
|
|
+ return new Result(10001,"身份证格式不正确",false);
|
|
|
+
|
|
|
+ String userPhone = sysUser.getUserPhone();
|
|
|
+ if (!PhoneNumberValidator.isValidPhoneNumber(userPhone))
|
|
|
+ return new Result(10001,"手机号格式不正确",false);
|
|
|
+
|
|
|
+ int count = sysUserService.count(new QueryWrapper<SysUser>().eq("card_type", cardType).eq("card_num", cardNum));
|
|
|
+ if (count >0)
|
|
|
+ return new Result(10001,"身份证已存在",false);
|
|
|
+
|
|
|
+ int countUserPhone = sysUserService.count(new QueryWrapper<SysUser>().eq("user_phone", userPhone));
|
|
|
+ if (countUserPhone >0)
|
|
|
+ return new Result(10001,"身份证已存在",false);
|
|
|
+ if (ObjectUtil.isNotEmpty(sysUser.getBirthday())){
|
|
|
+ sysUser.setAge(DateUtil.ageOfNow(sysUser.getBirthday()));
|
|
|
+ }
|
|
|
+ sysUserService.save(sysUser);
|
|
|
+ return new Result(10000,"保存成功",true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询工作地点
|
|
|
+ @PostMapping("/listWorkLocation")
|
|
|
+ public Result listWorkLocation(@RequestBody Map map) {
|
|
|
+ return sysUserService.listWorkLocation(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ public Result update(@RequestBody SysUser sysUser) {
|
|
|
+ String cardType = sysUser.getCardType();
|
|
|
+ String cardNum = sysUser.getCardNum();
|
|
|
+ if ("身份证".equals(cardType) && !IDCardValidator.isValidIDCard(cardNum))
|
|
|
+ return new Result(10001,"身份证格式不正确",false);
|
|
|
+
|
|
|
+ String userPhone = sysUser.getUserPhone();
|
|
|
+ if (!PhoneNumberValidator.isValidPhoneNumber(userPhone))
|
|
|
+ return new Result(10001,"手机号格式不正确",false);
|
|
|
+
|
|
|
+ int count = sysUserService.count(new QueryWrapper<SysUser>().eq("card_type", cardType).eq("card_num", cardNum));
|
|
|
+ if (count >1)
|
|
|
+ return new Result(10001,"身份证已存在",false);
|
|
|
+
|
|
|
+ int countUserPhone = sysUserService.count(new QueryWrapper<SysUser>().eq("user_phone", userPhone));
|
|
|
+ if (countUserPhone >1)
|
|
|
+ return new Result(10001,"身份证已存在",false);
|
|
|
+ if (ObjectUtil.isNotEmpty(sysUser.getBirthday())){
|
|
|
+ sysUser.setAge(DateUtil.ageOfNow(sysUser.getBirthday()));
|
|
|
+ }
|
|
|
+ sysUserService.save(sysUser);
|
|
|
+ return new Result(10000,"保存成功",true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/remove")
|
|
|
+ @Transactional
|
|
|
+ public Result remove(@RequestBody Map<String,String> map) {
|
|
|
+ String ids = map.get("ids");
|
|
|
+ if (StringUtils.isBlank(ids))
|
|
|
+ return new Result(10001,"所选用户不存在",false);
|
|
|
+ List<String> collection = Arrays.stream(ids.split(","))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ sysUserService.removeByIds(collection);
|
|
|
+ //删除账号
|
|
|
+ accountMultilevelService.remove(new QueryWrapper<SysAccountMultilevel>().in("user_id",collection));
|
|
|
+ return new Result(10000,"删除成功",true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //账号查询
|
|
|
+ @PostMapping("/pageAccount")
|
|
|
+ public Result pageAccount(@RequestBody Map<String,Object> map) {
|
|
|
+ return sysUserService.pageAccount(map);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|