QyzxAuthController.java 7.65 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.List;
13
import java.util.Map;
邓实川 committed
14

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

25 26 27 28 29
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
30 31 32
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.utils.Result;
33
import cn.timer.api.utils.ResultUtil;
邓实川 committed
34 35 36
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

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

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

		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);
		}
		Map<String, Object> map2 = new HashedMap<String, Object>();
		map2.put("childAccount", list2);
		list.add(map2);

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

邓实川 committed
171
	}
172

邓实川 committed
173
}