QyzxAuthController.java 8.58 KB
Newer Older
邓实川 committed
1 2 3 4 5 6
/**  
* <p>Title: QyzxAuthController.java</p>  
* <p>Description: </p>  
* @author dsc  
* @date 2020年5月19日  
* @version 1.0  
7
*/
邓实川 committed
8 9
package cn.timer.api.controller.qyzx;

10 11
import java.util.ArrayList;
import java.util.Date;
邓实川 committed
12
import java.util.HashMap;
邓实川 committed
13
import java.util.List;
14
import java.util.Map;
邓实川 committed
15

16
import org.apache.commons.collections4.map.HashedMap;
邓实川 committed
17
import org.springframework.transaction.annotation.Transactional;
18
import org.springframework.web.bind.annotation.DeleteMapping;
邓实川 committed
19
import org.springframework.web.bind.annotation.GetMapping;
20 21
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
邓实川 committed
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestParam;
邓实川 committed
24 25
import org.springframework.web.bind.annotation.RestController;

邓实川 committed
26
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
27 28 29 30 31
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.timer.api.bean.qyzx.auth.QyzxAuthAccount;
import cn.timer.api.bean.qyzx.auth.QyzxAuthChild;
import cn.timer.api.bean.yggl.YgglMainEmp;
邓实川 committed
32 33 34
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.utils.Result;
35
import cn.timer.api.utils.ResultUtil;
邓实川 committed
36 37 38
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

39 40 41 42 43 44 45 46 47 48 49 50
/**
 * <p>
 * Title: QyzxAuthController.java
 * </p>
 * <p>
 * Description:
 * </p>
 * 
 * @author dsc
 * @date 2020年5月19日
 * @version 1.0
 */
邓实川 committed
51 52 53 54 55
@Transactional
@RestController
@Api(tags = "4.2企业中心(账号权限)")
@RequestMapping(value = "/qyzxAuth", produces = { "application/json" })
public class QyzxAuthController {
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

	@Transactional
	@PostMapping(value = "/addChildAccount")
	@ApiOperation(value = "新增子账号", httpMethod = "POST", notes = "接口发布说明")
	public Result<QyzxAuthChild> addChildAccount(@CurrentUser UserBean userBean, @RequestParam Integer childEmpNum) {
		Integer orgCode = userBean.getOrgCode();
		Integer empNum = userBean.getEmpNum();
		QyzxAuthAccount qyzxAuthAccount = QyzxAuthAccount.builder().build()
				.selectOne(new QueryWrapper<QyzxAuthAccount>().lambda().eq(QyzxAuthAccount::getOrgCode, orgCode)); // 主账号
		Integer mainEmpNum = qyzxAuthAccount.getEmpNum();
		if (!empNum.equals(mainEmpNum))
			return ResultUtil.error("当前用户没有添加权限");
		Integer max = qyzxAuthAccount.getMaxChildAccount(); // 最大子账号数量
		Integer count = QyzxAuthChild.builder().build().selectCount(new QueryWrapper<QyzxAuthChild>().lambda()
				.eq(QyzxAuthChild::getOrgCode, orgCode).ne(QyzxAuthChild::getIsDel, 1)); // 子账号数量
		if (count >= max)
			return ResultUtil.error("子账号数量达到上限");
		YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda()
				.eq(YgglMainEmp::getEmpNum, childEmpNum).eq(YgglMainEmp::getOrgCode, orgCode));
		if (ygglMainEmp == null)
			return ResultUtil.error("该确认该员工是否存在");

		Integer jobStatus = ygglMainEmp.getJobStatus();
		if (jobStatus == 2 || jobStatus == 3)
			return ResultUtil.error("该员工已离职或离职中");

		QyzxAuthChild oldAuthChild = QyzxAuthChild.builder().build().selectOne(new QueryWrapper<QyzxAuthChild>()
				.lambda().eq(QyzxAuthChild::getOrgCode, orgCode).eq(QyzxAuthChild::getEmpNum, childEmpNum));

		if (mainEmpNum == childEmpNum)
			return ResultUtil.error("添加失败,该账号是主账号");
		if (oldAuthChild != null && oldAuthChild.getIsDel() == 0)
			return ResultUtil.error("添加失败,该账号已是企业子账号");
		else if (oldAuthChild != null && oldAuthChild.getIsDel() == 1) {
			oldAuthChild.setIsDel(0);
			oldAuthChild.setModifiedTime(new Date());
			oldAuthChild.setModifiedUser(empNum);
			oldAuthChild.updateById();

			ygglMainEmp.setIsManager(2);
			ygglMainEmp.updateById();
			return ResultUtil.data(oldAuthChild, "添加企业子账号成功");
		}
		QyzxAuthChild qyzxAuthChild = new QyzxAuthChild();
		qyzxAuthChild.setCreatedUser(empNum);
		qyzxAuthChild.setCreatedTime(new Date());
		qyzxAuthChild.setEmpNum(childEmpNum);
		qyzxAuthChild.setOrgCode(orgCode);
		qyzxAuthChild.setIsDel(0);
//		qyzxAuthChild.setIsOpen(1);
		qyzxAuthChild.insert();

		ygglMainEmp.setIsManager(2);
		ygglMainEmp.updateById();
		return ResultUtil.data(qyzxAuthChild, "添加企业子账号成功");
	}

	@Transactional
	@DeleteMapping(value = "/delChildAccount/{childEmpNum}")
	@ApiOperation(value = "删除子账号", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<String> delChildAccount(@CurrentUser UserBean userBean, @PathVariable Integer childEmpNum) {
		Integer empNum = userBean.getEmpNum();
		QyzxAuthAccount qyzxAuthAccount = QyzxAuthAccount.builder().build().selectOne(
				new QueryWrapper<QyzxAuthAccount>().lambda().eq(QyzxAuthAccount::getOrgCode, userBean.getOrgCode()));
		Integer mainEmpNum = qyzxAuthAccount.getEmpNum();
		if (!empNum.equals(mainEmpNum))
			return ResultUtil.error("没有操作权限");
		if (mainEmpNum.equals(childEmpNum))
			return ResultUtil.error("企业主账号不能被删除");
		boolean result = QyzxAuthChild.builder().isDel(1).build().update(
				new QueryWrapper<QyzxAuthChild>().lambda().eq(QyzxAuthChild::getOrgCode, userBean.getOrgCode()));
		YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>().lambda()
				.eq(YgglMainEmp::getEmpNum, childEmpNum).eq(YgglMainEmp::getOrgCode, userBean.getOrgCode()));
		ygglMainEmp.setIsManager(0);
		if (result && ygglMainEmp.updateById())
			return ResultUtil.success("删除成功");
		return ResultUtil.error("删除失败");
	}

	@PostMapping(value = "/modifyMaxChild")
	@ApiOperation(value = "修改子账号最大数量", httpMethod = "POST", notes = "接口发布说明")
	public Result<QyzxAuthChild> modifyMaxChild(@CurrentUser UserBean userBean, @RequestParam Integer maxNum) {
		if (QyzxAuthAccount.builder().maxChildAccount(maxNum).build().update(
				new QueryWrapper<QyzxAuthAccount>().lambda().eq(QyzxAuthAccount::getOrgCode, userBean.getOrgCode())))
			return ResultUtil.success("修改成功");
		return ResultUtil.error("修改失败");
	}

邓实川 committed
144 145
	@GetMapping(value = "/getAll")
	@ApiOperation(value = "获取全部账号信息", httpMethod = "GET", notes = "接口发布说明")
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	public Result<List<Object>> getAll(@CurrentUser UserBean userBean) {
		List<Object> list = new ArrayList<Object>();

		Map<String, Object> map = new HashedMap<String, Object>();
		QyzxAuthAccount qyzxAuthAccount = QyzxAuthAccount.builder().build().selectOne(
				new QueryWrapper<QyzxAuthAccount>().lambda().eq(QyzxAuthAccount::getOrgCode, userBean.getOrgCode())); // 主账号
		map.put("mainAccount", qyzxAuthAccount);

		List<QyzxAuthChild> childs = QyzxAuthChild.builder().build().selectList(new QueryWrapper<QyzxAuthChild>()
				.lambda().eq(QyzxAuthChild::getOrgCode, userBean.getOrgCode()).ne(QyzxAuthChild::getIsDel, 1)); // 子账号
		System.err.println(childs);
		List<YgglMainEmp> list2 = new ArrayList<YgglMainEmp>();
		for (QyzxAuthChild qyzxAuthChild : childs) {
			Integer empNum = qyzxAuthChild.getEmpNum();
			YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(
					new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getOrgCode, userBean.getOrgCode())
							.eq(YgglMainEmp::getEmpNum, empNum).select(YgglMainEmp::getHeadUrl, YgglMainEmp::getName,
									YgglMainEmp::getPhone, YgglMainEmp::getEmpNum)); // 子账号员工信息
			list2.add(ygglMainEmp);
		}
邓实川 committed
166 167
		map.put("childAccount", list2);
		list.add(map);
168 169 170

		return ResultUtil.data(list, "查询成功");

邓实川 committed
171
	}
172

邓实川 committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
	@GetMapping(value = "/getYgAuth")
	@ApiOperation(value = "获取全部权限信息", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<YgglMainEmp>> getYgAuth(@CurrentUser UserBean userBean) {
		YgglMainEmp main = YgglMainEmp.builder().build()
				.selectOne(new LambdaQueryWrapper<YgglMainEmp>().eq(YgglMainEmp::getOrgCode, userBean.getOrgCode())
						.eq(YgglMainEmp::getIsManager, 1).select(YgglMainEmp::getName, YgglMainEmp::getPhone,
								YgglMainEmp::getEmpNum, YgglMainEmp::getIsManager));

		List<YgglMainEmp> child = YgglMainEmp.builder().build()
				.selectList(new LambdaQueryWrapper<YgglMainEmp>().eq(YgglMainEmp::getOrgCode, userBean.getOrgCode())
						.eq(YgglMainEmp::getIsManager, 2).select(YgglMainEmp::getName, YgglMainEmp::getPhone,
								YgglMainEmp::getEmpNum, YgglMainEmp::getIsManager));
		child.add(main);
		return ResultUtil.data(child, "查询成功");
	}

邓实川 committed
189
}