QyzxAuthController.java 8.71 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
import java.util.ArrayList;
邓实川 committed
11 12
import java.util.Collections;
import java.util.Comparator;
13
import java.util.Date;
邓实川 committed
14
import java.util.HashMap;
邓实川 committed
15
import java.util.List;
16
import java.util.Map;
邓实川 committed
17

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

邓实川 committed
28
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
29 30 31 32 33
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
34 35 36
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.utils.Result;
37
import cn.timer.api.utils.ResultUtil;
邓实川 committed
38 39 40
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

41 42 43 44 45 46 47 48 49 50 51 52
/**
 * <p>
 * Title: QyzxAuthController.java
 * </p>
 * <p>
 * Description:
 * </p>
 * 
 * @author dsc
 * @date 2020年5月19日
 * @version 1.0
 */
邓实川 committed
53 54 55 56 57
@Transactional
@RestController
@Api(tags = "4.2企业中心(账号权限)")
@RequestMapping(value = "/qyzxAuth", produces = { "application/json" })
public class QyzxAuthController {
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 144 145

	@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
146 147
	@GetMapping(value = "/getAll")
	@ApiOperation(value = "获取全部账号信息", httpMethod = "GET", notes = "接口发布说明")
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	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
168 169
		map.put("childAccount", list2);
		list.add(map);
170 171 172

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

邓实川 committed
173
	}
174

邓实川 committed
175 176 177 178 179 180 181 182 183 184 185 186 187
	@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);
邓实川 committed
188 189

		Collections.sort(child, Comparator.comparing(YgglMainEmp::getIsManager));
邓实川 committed
190 191 192
		return ResultUtil.data(child, "查询成功");
	}

邓实川 committed
193
}