ZzglController.java 28.7 KB
Newer Older
1 2 3 4
package cn.timer.api.controller.zzgl;

import java.util.ArrayList;
import java.util.List;
5
import java.util.stream.Collectors;
6 7 8

import javax.transaction.Transactional;

284718418@qq.com committed
9
import cn.timer.api.bean.kqmk.KqglAssoMonthPunchSummary;
翁国栋 committed
10 11
import cn.timer.api.bean.zzgl.*;
import com.google.common.collect.Lists;
284718418@qq.com committed
12 13
import freemarker.template.utility.StringUtil;
import io.swagger.annotations.ApiParam;
14
import org.springframework.beans.factory.annotation.Autowired;
284718418@qq.com committed
15
import org.springframework.util.StringUtils;
16
import org.springframework.validation.annotation.Validated;
284718418@qq.com committed
17
import org.springframework.web.bind.annotation.*;
18 19 20 21 22

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
23
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
24
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
25
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
26

lal committed
27
import cn.hutool.core.bean.BeanUtil;
28
import cn.hutool.core.collection.CollectionUtil;
29 30 31 32
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
33
import cn.hutool.core.util.StrUtil;
34 35
import cn.timer.api.aspect.lang.annotation.Log;
import cn.timer.api.aspect.lang.enums.BusinessType;
ilal committed
36 37
import cn.timer.api.bean.admin.AdminMenuTemplate;
import cn.timer.api.bean.qyzx.QyzxAdminMenu;
38 39 40
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
41
import cn.timer.api.config.enuminterface.YgEnumInterface;
ilal committed
42
import cn.timer.api.controller.kqgl.ClockInTool;
43
import cn.timer.api.controller.zzgl.service.ZzglBmgwMService;
44
import cn.timer.api.dao.yggl.YgglMainEmpMapper;
45 46
import cn.timer.api.dao.zzgl.ZzglBmgwMMapper;
import cn.timer.api.dao.zzgl.ZzglLogDgjlMapper;
47 48
import cn.timer.api.dao.zzgl.ZzglMenuMapper;
import cn.timer.api.dao.zzgl.ZzglPostMenuMapper;
ilal committed
49
import cn.timer.api.dto.qyzx.MenuStructureDto;
lal committed
50
import cn.timer.api.dto.zzgl.DepartmentStaffDto;
51 52
import cn.timer.api.dto.zzgl.LogDgjlsDto;
import cn.timer.api.dto.zzgl.LogDgjlsQueryDto;
lal committed
53
import cn.timer.api.dto.zzgl.ObtainDepartmentDto;
54
import cn.timer.api.dto.zzgl.UpEmpDeptDto;
55
import cn.timer.api.dto.zzgl.ZzglPostMenuDto;
56 57 58 59 60 61 62 63 64 65 66 67
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "2.组织管理")
@RestController
@Transactional
@RequestMapping(value = "/zzgl", produces = { "application/json" })
public class ZzglController {

	@Autowired
68
	ZzglBmgwMService zzglBmgwMService;
69

70
	@Autowired
71
	ZzglBmgwMMapper zzglBmgwMMapper;
72

73 74
	@Autowired
	ZzglPostMenuMapper zzglPostMenuMapper;
75 76

	@Autowired
77
	ZzglLogDgjlMapper zzglLogDgjlMapper;
78

79 80
	@Autowired
	YgglMainEmpMapper ygglMainEmpMapper;
81 82 83

	/**
	 * 架构树/架构图/导出
84
	 *
85 86 87 88 89 90 91 92 93 94 95
	 * @param
	 * @return
	 */
	@GetMapping(value = "/deptlist")
	@ApiOperation(value = "获取部门岗位", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<ZzglBmgwM>> selectlistdept(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();
		List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
				.eq(ZzglBmgwM::getOrgCode, orgCode).list();
		return ResultUtil.data(zzglBmgwMs);
	}
96

97
	/**
98
	 * 获取部门岗位-升级版
99
	 *
100 101 102
	 * @param
	 * @return
	 */
103
	@GetMapping(value = "/deptlist_plus")
104 105
	@ApiOperation(value = "1.获取部门岗位-升级版", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 1)
106
	public Result<List<Tree<String>>> deptlistPlus(@CurrentUser UserBean userBean) {
107 108 109
		Integer orgCode = userBean.getOrgCode();
		List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
				.eq(ZzglBmgwM::getOrgCode, orgCode).list();
110

111
		// 构建node列表
112 113 114 115
//		List<TreeNode<String>> nodeList = CollUtil.newArrayList();
//		zzglBmgwMs.forEach(z -> {
//			nodeList.add(new TreeNode<>(Convert.toStr(z.getId()), Convert.toStr(z.getUpId()), z.getName(), 0));
//		});
116

117 118 119 120 121 122 123 124 125
		//配置
		TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
		// 自定义属性名 都要默认值的
		treeNodeConfig.setIdKey("id");
		treeNodeConfig.setParentIdKey("upId");
		// 最大递归深度
//		treeNodeConfig.setDeep(10);

		//转换器
126
		List<Tree<String>> treeNodes = TreeUtil.build(zzglBmgwMs, "0", treeNodeConfig,
127
		        (treeNode, tree) -> {
128 129 130
		            tree.setId(Convert.toStr(treeNode.getId()));
		            tree.setParentId(Convert.toStr(treeNode.getUpId()));
//		            tree.setWeight(treeNode.getWeight());
131 132
		            tree.setName(treeNode.getName());
		            // 扩展属性 ...
133
		            tree.putExtra("leader", treeNode.getLeader());
tangzhaoqian committed
134
		            tree.putExtra("type", treeNode.getType());
135 136
//		            tree.putExtra("other", new Object());
		        });
137 138 139



tangzhaoqian committed
140 141 142
//		System.out.println(treeNodes);
//		System.out.println(treeNodes.size());
//		System.out.println(deep2(treeNodes));
143

144 145
		return ResultUtil.data(treeNodes);
	}
146 147 148 149 150 151 152 153 154 155 156 157 158 159

	@GetMapping(value = "/deptlist_ultra")
	@ApiOperation(value = "获取部门岗位", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<ZzglBmgwM>> deptlist_plusUltra(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();
		List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
				.eq(ZzglBmgwM::getOrgCode, orgCode).list();
		zzglBmgwMs.forEach(z->{
			if(z.getType()==1){
				z.setUserList(new LambdaQueryChainWrapper<YgglMainEmp>(ygglMainEmpMapper).eq(YgglMainEmp::getBmgwId,z.getId()).list());
			}
		});
		return ResultUtil.data(zzglBmgwMs);
	}
tangzhaoqian committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
	// 非递归,利用树的层次遍历
//	public static int deep2(List<Tree<String>> treeNodes) {
//		if(treeNodes == null)
//			return 0;
//		int depth = 0;
//		for (Tree<String> tree : treeNodes) {
//			if (tree.getChildren() == null) {
//				depth = tree.size()-1 > depth ? tree.size()-1 : depth;
//				if (Convert.toInt(tree.get("type")) == 1) {
//					depth = depth > 1 ? depth - 1 : depth;
//				}
//				System.out.println("depth = "+ depth);
//			}else {
//				int temp = deep2(tree.getChildren());
//				depth = temp > depth ? temp : depth;
//				System.out.println("temp = "+ temp);
//			}
//		}
178
//
tangzhaoqian committed
179 180
//		return depth;
//	}
181

182 183
	/**
	 * 获取部门
184
	 *
185 186 187 188 189 190 191 192 193 194 195 196
	 * @param
	 * @return
	 */
	@GetMapping(value = "/depts_tree")
	@ApiOperation(value = "2.获取部门", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 1)
	public Result<List<Tree<String>>> deptsOnlyone(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();
		List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
				.eq(ZzglBmgwM::getOrgCode, orgCode).list();
		if (CollectionUtil.isNotEmpty(zzglBmgwMs)) {
			zzglBmgwMs = zzglBmgwMs.stream().filter(z -> z.getType() == 0).collect(Collectors.toList());
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
			if (CollectionUtil.isNotEmpty(zzglBmgwMs)) {
				//配置
				TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
				// 自定义属性名 都要默认值的
				treeNodeConfig.setIdKey("id");
				treeNodeConfig.setParentIdKey("upId");

				//转换器
				List<Tree<String>> treeNodes = TreeUtil.build(zzglBmgwMs, "0", treeNodeConfig,
			        (treeNode, tree) -> {
			            tree.setId(Convert.toStr(treeNode.getId()));
			            tree.setParentId(Convert.toStr(treeNode.getUpId()));
			            tree.setName(treeNode.getName());
			            // 扩展属性 ...
			            tree.putExtra("leader", treeNode.getLeader());
			            tree.putExtra("type", treeNode.getType());
214

215
				});
216

217 218
				return ResultUtil.data(treeNodes);
			}
219

220
		}
221

222 223
		return ResultUtil.success();
	}
224

225
	@GetMapping(value = "/depts")
226 227
	@ApiOperation(value = "2.获取部门", httpMethod = "GET", notes = "接口发布说明")
	@ApiOperationSupport(order = 2)
228 229 230
	public Result<List<ZzglBmgwM>> selectdepts(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();
		List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
231 232 233
				.eq(ZzglBmgwM::getOrgCode, orgCode)
				.eq(ZzglBmgwM::getType, YgEnumInterface.OrgType.DEPARTMENT)
				.list();
234 235
		return ResultUtil.data(zzglBmgwMs);
	}
236 237 238

	/**
	 * 岗位成员
239
	 *
240 241 242 243 244
	 * @param 部门岗位id
	 * @return
	 */
	@GetMapping(value = "/otherlistent/{id}")
	@ApiOperation(value = "获取岗位成员列表", httpMethod = "GET", notes = "接口发布说明")
284718418@qq.com committed
245
	public Result<List<YgglMainEmp>> selectOtherlistent(@CurrentUser UserBean userBean, @PathVariable Integer id, @ApiParam("过滤参数") @RequestParam(value = "param", required = false, defaultValue = "") String param) {
246 247 248 249 250 251 252
		Integer orgCode = userBean.getOrgCode();
		ArrayList<Integer> list = new ArrayList<Integer>();
		List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
				.eq(ZzglBmgwM::getOrgCode, orgCode).list();
		list.add(id);
		ZzglBmgwM.getDepts(list, id, zzglBmgwMs);

253 254 255
		ZzglBmgwM messsage = ZzglBmgwM.builder().build().selectOne(new QueryWrapper<ZzglBmgwM>().eq("id", id));
		Integer lead = messsage.getLeader(); // 获取部门或岗位领导id

256 257 258 259 260 261
		if (list == null || list.size() == 0) {
			return ResultUtil.error("部门信息不存在,请先添加部门!");
		} else {
			LambdaQueryWrapper<YgglMainEmp> ygglMainEmpsLambdaQueryWrapper = new LambdaQueryWrapper<>();
			ygglMainEmpsLambdaQueryWrapper
					.select(YgglMainEmp::getId, YgglMainEmp::getEmpNum, YgglMainEmp::getName, YgglMainEmp::getPhone,
284718418@qq.com committed
262 263 264 265
							YgglMainEmp::getBmgwId,YgglMainEmp::getCustomNum)
					.eq(YgglMainEmp::getOrgCode, orgCode)
					.and(i -> i.in(YgglMainEmp::getBmgwId, list.toArray()))
					.and(!StrUtil.hasBlank(param),w -> w.like(YgglMainEmp::getName, param).or().like(YgglMainEmp::getEmpNum, param).or().eq(YgglMainEmp::getPhone, param).or().like(YgglMainEmp::getCustomNum, param))
266
					.last(lead != null, "order by if (emp_num='" + lead + "',0,1)");
267 268 269 270 271 272 273
			List<YgglMainEmp> ygglMainEmps = YgglMainEmp.builder().build().selectList(ygglMainEmpsLambdaQueryWrapper);
			return ResultUtil.data(ygglMainEmps);
		}
	}

	/**
	 * 获取调岗记录(weng)
274
	 *
275 276 277 278 279
	 * @param 部门岗位id
	 * @return
	 */
	@PostMapping(value = "/listdgjl")
	@ApiOperation(value = "获取调岗记录(weng)", httpMethod = "POST", notes = "接口发布说明")
280 281
	public Result<Object> selectlistdgjl(@CurrentUser UserBean userBean,
			@RequestBody LogDgjlsQueryDto logDgjlsQueryDto) {
282 283 284 285 286 287 288 289 290 291
		Integer orgCode = userBean.getOrgCode();
		ArrayList<Integer> list = new ArrayList<Integer>();
		List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
				.eq(ZzglBmgwM::getOrgCode, orgCode).list();
		list.add(logDgjlsQueryDto.getDeptId());
		ZzglBmgwM.getDepts(list, logDgjlsQueryDto.getDeptId(), zzglBmgwMs);

		if (list == null || list.size() == 0) {
			return ResultUtil.error("部门信息不存在,请先添加部门!");
		} else {
292

293 294
			logDgjlsQueryDto.setDeptIdList(list);
			logDgjlsQueryDto.setOrgCode(orgCode);
295

296 297 298 299 300 301 302 303 304 305
			IPage<LogDgjlsDto> page = new Page<LogDgjlsDto>(
					logDgjlsQueryDto.getCurrentPage() == null ? 1 : logDgjlsQueryDto.getCurrentPage(),
					logDgjlsQueryDto.getTotalPage() == null ? 10 : logDgjlsQueryDto.getTotalPage());
			List<LogDgjlsDto> logDgjlDtos = zzglLogDgjlMapper.selectListdgjls(page, logDgjlsQueryDto);
			return ResultUtil.data(page, logDgjlDtos, "查询成功");
		}
	}

	/**
	 * 未设置岗位的成员
306
	 *
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
	 * @return
	 */
	@GetMapping(value = "/listent")
	@ApiOperation(value = "未设置岗位的成员", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<YgglMainEmp>> selectlistent(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();

		LambdaQueryWrapper<YgglMainEmp> ygglMainEmpsLambdaQueryWrapper = new LambdaQueryWrapper<>();
		ygglMainEmpsLambdaQueryWrapper
				.select(YgglMainEmp::getId, YgglMainEmp::getEmpNum, YgglMainEmp::getName, YgglMainEmp::getPhone)
				.eq(YgglMainEmp::getOrgCode, orgCode)
				.and(i -> i.isNull(YgglMainEmp::getBmgwId).or().eq(YgglMainEmp::getBmgwId, 0));
		// .and(lqw -> lqw.notIn(id != null,
		// YgglMainEmp::getBmgwId,Arrays.asList(id)).or().isNull(YgglMainEmp::getBmgwId))
		List<YgglMainEmp> ygglMainEmps = YgglMainEmp.builder().build().selectList(ygglMainEmpsLambdaQueryWrapper);
		// List<ZzglBmgwMEmpDto> zzglBmgwMEmpDtos =
		// zzglBmgwMMapper.selectOtherListByOrgCode(orgCode,id);
		return ResultUtil.data(ygglMainEmps);
	}

	/**
tangzhaoqian committed
328
	 * 添加/修改部门岗位
329
	 *
330 331 332 333
	 * @param
	 * @return
	 */
	@PostMapping(value = "/dept")
334 335
	@ApiOperation(value = "添加/修改部门", httpMethod = "POST", notes = "接口发布说明")
	@Log(title = "添加/修改-部门", businessType = BusinessType.INSERT_UPDATE)
336
	public Result<ZzglBmgwM> adddept(@CurrentUser UserBean userBean, @RequestBody ZzglBmgwM zzglBmgwM) {
337

338 339 340 341 342 343
		Integer count = zzglBmgwMMapper.selectCount(new QueryWrapper<ZzglBmgwM>().lambda()
				.eq(ZzglBmgwM::getOrgCode, userBean.getOrgCode()));
		if (count <= 0) {
			// 根部门upId 默认为0
			zzglBmgwM.setUpId(0);
		}
344
		ZzglBmgwM bmgwM = zzglBmgwMMapper.selectById(zzglBmgwM.getUpId());
345
		if(bmgwM !=null) {
346
			if (bmgwM.getType() != 0) {
347 348
				return ResultUtil.error("部门名称上级不能为岗位");
			}
349
		}
350
		if (zzglBmgwM.getLeader() == null && StrUtil.length(StrUtil.trim(zzglBmgwM.getName())) == 0)
351
			return ResultUtil.error("部门名称不能为空");
352

353 354
		Boolean notId = zzglBmgwM.getId() == null;
		if (notId && zzglBmgwM.getType() == null)
355
			zzglBmgwM.setType((Integer) 0);
356 357
			zzglBmgwM.setOrgCode(userBean.getOrgCode());
			zzglBmgwM.insertOrUpdate();
358

359
		return notId ? ResultUtil.data(zzglBmgwM) : ResultUtil.success();
360
	}
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
	/**
	 * 添加/修改部门岗位
	 *
	 * @param
	 * @return
	 */
	@PostMapping(value = "/job")
	@ApiOperation(value = "添加/修改部门", httpMethod = "POST", notes = "接口发布说明")
	@Log(title = "添加/修改-部门", businessType = BusinessType.INSERT_UPDATE)
	public Result<ZzglBmgwM> addjob
	(@CurrentUser UserBean userBean, @RequestBody ZzglBmgwM zzglBmgwM) {



		if (zzglBmgwM.getLeader() == null && StrUtil.length(StrUtil.trim(zzglBmgwM.getName())) == 0)
			return ResultUtil.error("岗位名称不能为空");

		Boolean notId = zzglBmgwM.getId() == null;
		if (notId && zzglBmgwM.getType() == null)
			zzglBmgwM.setType((Integer) 1);
		zzglBmgwM.setOrgCode(userBean.getOrgCode());
		zzglBmgwM.insertOrUpdate();

		return notId ? ResultUtil.data(zzglBmgwM) : ResultUtil.success();
	}



389 390
	/**
	 * 删除部门岗位
391
	 *
392 393 394 395 396
	 * @param 部门岗位ids [1,2,3,4]
	 * @return
	 */
	@DeleteMapping(value = "/dept")
	@ApiOperation(value = "删除部门岗位", httpMethod = "DELETE", notes = "接口发布说明")
tangzhaoqian committed
397
	@Log(title = "删除-部门岗位", businessType = BusinessType.DELETE)
398 399
	public Result<Integer> deldepts(@CurrentUser UserBean userBean, @RequestBody List<Integer> ids) {
		YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build();
400

401
		zzglLogDgjlMapper.insertbydeldept(ids, userBean.getEmpNum());
402 403 404
		ygglMainEmp.update(new UpdateWrapper<YgglMainEmp>().lambda()
				.set(YgglMainEmp::getBmgwId, null)
				.in(YgglMainEmp::getBmgwId, ids));
405 406 407 408 409 410 411
		zzglBmgwMMapper.deleteBatchIds(ids);

		return ResultUtil.success();
	}

	/**
	 * 批量修改/删除员工部门
412
	 *
413 414 415 416 417 418 419 420 421
	 * @param 部门岗位id
	 * @return
	 */
	@PostMapping(value = "/empdept")
	@ApiOperation(value = "批量修改/删除员工部门", httpMethod = "POST", notes = "接口发布说明")
	public Result<Void> updatelistempdept(@CurrentUser UserBean userBean, @RequestBody UpEmpDeptDto upEmpDeptDto) {
		Integer dpetId = upEmpDeptDto.getDpetId();
		List<Integer> empNums = upEmpDeptDto.getEmpNum();
		YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build();
284718418@qq.com committed
422
		KqglAssoMonthPunchSummary kqglAssoMonthPunchSummary = KqglAssoMonthPunchSummary.builder().build();
翁国栋 committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
		String comm=null;
		Integer type=null;
		if(dpetId == null || dpetId == 0 ){
			comm="岗位删除员工";
			type=4;
		}else if(upEmpDeptDto.getIsdg() == null){
			comm="岗位添加员工";
			type=5;
		}else{
			if(upEmpDeptDto.getIsdg()==1) {
				comm = "员工调岗";
				type = 2;
			}
			if(upEmpDeptDto.getIsdg()==6) {
				comm = upEmpDeptDto.getRemake();
				type = 6;
			}
			if(upEmpDeptDto.getIsdg()==7) {
				comm = upEmpDeptDto.getRemake();;
				type = 7;
			}
		}
//		zzglLogDgjlMapper.insertbyaddemp(empNums, userBean.getEmpNum(), dpetId,null, userBean.getOrgCode(),comm,type);
tangzhaoqian committed
446 447 448 449 450 451 452
		// 清楚 leader 主管标记
		if ((dpetId == null || dpetId == 0) || upEmpDeptDto.getIsdg() == null) {
			ZzglBmgwM.builder().leader(null).build()
				.update(new UpdateWrapper<ZzglBmgwM>().lambda()
						.eq(ZzglBmgwM::getOrgCode, userBean.getOrgCode())
						.in(ZzglBmgwM::getLeader, empNums));
		}
453

翁国栋 committed
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
//		ygglMainEmp.update(new UpdateWrapper<YgglMainEmp>().lambda()
//				.set(YgglMainEmp::getBmgwId, dpetId).set(YgglMainEmp::getBmgwName, upEmpDeptDto.getDept())
//				.eq(YgglMainEmp::getOrgCode, userBean.getOrgCode()).in(YgglMainEmp::getEmpNum, empNums));

		List<YgglMainEmp> ygglMainEmpList=YgglMainEmp.builder().build().selectList(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getOrgCode,userBean.getOrgCode()).in(YgglMainEmp::getEmpNum,empNums));
		Integer oId=null;
			for(YgglMainEmp y:ygglMainEmpList) {
				if (upEmpDeptDto.getZpglCompanyId() != null) {
					y.setZpglCompanyId(upEmpDeptDto.getZpglCompanyId());
				}
				if (upEmpDeptDto.getZpglCompanyId() != null) {
					y.setZpglGzddId(upEmpDeptDto.getZpglGzddId());
				}
				if (upEmpDeptDto.getZpglCompanyId() != null) {
					y.setZpglZjId(upEmpDeptDto.getZpglZjId());
				}
				if (dpetId != null) {
					oId = y.getBmgwId();
					y.setBmgwId(dpetId);
				}
				y.updateById();
				zzglLogDgjlMapper.insertbyaddemp(empNums, userBean.getEmpNum(), dpetId, oId, userBean.getOrgCode(),
						comm, type);
			}
284718418@qq.com committed
478 479 480 481 482 483 484
		// 调岗 同步部门 和 岗位信息 打卡月汇总
		if(!StringUtils.isEmpty(upEmpDeptDto.getIsdg()) && upEmpDeptDto.getIsdg().intValue()==1){
			kqglAssoMonthPunchSummary.update(new UpdateWrapper<KqglAssoMonthPunchSummary>().lambda()
					.set(KqglAssoMonthPunchSummary::getDept, upEmpDeptDto.getDept()).set(KqglAssoMonthPunchSummary::getPost, upEmpDeptDto.getPost())
					.eq(KqglAssoMonthPunchSummary::getOrgCode, userBean.getOrgCode()).in(KqglAssoMonthPunchSummary::getNum, empNums)
			);
		}
翁国栋 committed
485

486 487
		return ResultUtil.success();
	}
488

489 490
	/**
	 * 岗位权限
491
	 *
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
	 * @param 部门岗位id
	 * @return
	 */
	@GetMapping(value = "/auth/{id}")
	@ApiOperation(value = "获取岗位岗位权限", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<ZzglAuth>> auth(@CurrentUser UserBean userBean, @PathVariable Integer id) {
		Integer orgCode = userBean.getOrgCode();
		ArrayList<Integer> list = new ArrayList<Integer>();
		List<ZzglBmgwM> zzglBmgwMs = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
				.eq(ZzglBmgwM::getOrgCode, orgCode).list();
				ZzglBmgwM.getupDepts(list, id, zzglBmgwMs);
		if (list == null || list.size() == 0) {
			return ResultUtil.error("部门信息不存在,请先添加部门!");
		} else {
			LambdaQueryWrapper<ZzglAuth> wp = new LambdaQueryWrapper<>();
			wp.select(ZzglAuth::getMenuId, ZzglAuth::getBmgwId).eq(ZzglAuth::getOrgCode, orgCode)
					.and(i -> i.in(ZzglAuth::getBmgwId, list.toArray()));
			List<ZzglAuth> zas = ZzglAuth.builder().build().selectList(wp);
510 511 512



ilal committed
513 514 515 516 517 518 519 520 521 522 523 524 525 526
			List<MenuStructureDto> mestrs = new ArrayList<MenuStructureDto>();
			List<QyzxAdminMenu> qyme = QyzxAdminMenu.builder().build().selectList(new QueryWrapper<QyzxAdminMenu>().lambda().eq(QyzxAdminMenu::getOrgCode, userBean.getOrgCode()).orderByAsc(QyzxAdminMenu::getSortNumber));
			String[] zdy = new String[qyme.size()];
			int i  = 0;
			for(QyzxAdminMenu me : qyme) {
				MenuStructureDto metr = MenuStructureDto.builder().build();
				metr.setMenuCode(me.getMenuCode());
				metr.setMenuName(me.getMenuName());
				metr.setSortNumber(me.getSortNumber());
				AdminMenuTemplate adte = AdminMenuTemplate.builder().build().selectOne(new QueryWrapper<AdminMenuTemplate>().lambda().eq(AdminMenuTemplate::getMenuCode, me.getMenuCode()));
				metr.setPath(adte.getPath());
				mestrs.add(metr);
				zdy[i] = me.getMenuCode();
				i++;
527
			}
ilal committed
528 529 530
			//
			List<AdminMenuTemplate> adtes = AdminMenuTemplate.builder().build().selectList(new QueryWrapper<AdminMenuTemplate>().lambda().eq(AdminMenuTemplate::getEnable, 1).orderByAsc(AdminMenuTemplate::getSortNumber));
			for(AdminMenuTemplate adm : adtes) {
531

ilal committed
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
				if(!ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(zdy), adm.getMenuCode())) {
					if(adm.getDistribution() == 0 && userBean.getOrgCode() == 3) {
						MenuStructureDto metr = MenuStructureDto.builder().build();
						metr.setMenuCode(adm.getMenuCode());
						metr.setMenuName(adm.getMenuName());
						metr.setSortNumber(adm.getSortNumber());
						metr.setPath(adm.getPath());
						mestrs.add(metr);
					}else if(adm.getDistribution() == 1) {
						MenuStructureDto metr = MenuStructureDto.builder().build();
						metr.setMenuCode(adm.getMenuCode());
						metr.setMenuName(adm.getMenuName());
						metr.setSortNumber(adm.getSortNumber());
						metr.setPath(adm.getPath());
						mestrs.add(metr);
					}
				}
			}
550

ilal committed
551 552 553 554 555 556 557 558 559 560 561 562
			List<ZzglAuth> zas_ = new ArrayList<ZzglAuth>();
			String[] qhf = new String[mestrs.size()];
			int y = 0;
			for(MenuStructureDto metu : mestrs) {
				ZzglAuth zd = ZzglAuth.builder().build();
				 for(ZzglAuth zg : zas) {
					if(metu.getPath().equals(zg.getMenuId())) {
						zd.setBmgwId(zg.getBmgwId());
						zd.setMenuId(zg.getMenuId());
						zas_.add(zd);
						qhf[y] = zg.getMenuId();
						y++;
563
						break;
ilal committed
564 565 566
					}
				}
			}
567

ilal committed
568 569 570 571 572 573 574 575
			for(ZzglAuth zg : zas) {
				if(!ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull2(qhf), zg.getMenuId())) {
					ZzglAuth zd = ZzglAuth.builder().build();
					zd.setBmgwId(zg.getBmgwId());
					zd.setMenuId(zg.getMenuId());
					zas_.add(zd);
				}
			}
576 577


ilal committed
578
			return ResultUtil.data(zas_);
579 580 581 582 583
		}
	}

	/**
	 * 批量修改/删除岗位权限
584
	 *
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
	 * @param 部门岗位id
	 * @param 菜单ids
	 * @return
	 */
	@PostMapping(value = "/auth/{id}")
	@ApiOperation(value = "批量修改/删除岗位权限", httpMethod = "POST", notes = "接口发布说明")
	public Result<Void> auth(@CurrentUser UserBean userBean, @PathVariable Integer id, @RequestBody List<String> ids) {
		Integer orgCode = userBean.getOrgCode();
		ZzglAuth.builder().build().delete(
				new QueryWrapper<ZzglAuth>().lambda().eq(ZzglAuth::getOrgCode, orgCode).eq(ZzglAuth::getBmgwId, id));
		ids.forEach(o -> {
			ZzglAuth za = ZzglAuth.builder().build();
			za.setBmgwId(id);
			za.setOrgCode(orgCode);
			za.setMenuId(o);
			za.insert();
		});
		return ResultUtil.success();
	}
604

605 606
	@Autowired
	private ZzglMenuMapper zzglMenuMapper;
607

608 609
	/**
	 * 获取-菜单权限列表
610
	 *
611 612 613 614 615
	 * @return
	 */
	@GetMapping(value = "/menu")
	@ApiOperation(value = "获取-菜单权限列表", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<ZzglMenu>> selectMenu(@CurrentUser UserBean userBean) {
616

617
		List<ZzglMenu> list = zzglMenuMapper.selectList(null);
618

619 620
		return ResultUtil.data(list);
	}
621

622 623
	/**
	 * 获取-菜单权限-搜索
624
	 *
625 626 627 628 629
	 * @return
	 */
//	@PostMapping(value = "/querymenu")
//	@ApiOperation(value = "获取-菜单权限-搜索", httpMethod = "POST", notes = "接口发布说明")
//	public Result<List<Tree<String>>> queryMenu(@CurrentUser UserBean userBean,@RequestBody ZzglMenuQueryDto zzglMenuQueryDto) {
630
//
631
//		List<ZzglMenu> list = zzglMenuMapper.queryList(zzglMenuQueryDto);
632
//
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
//		//配置
//		TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
//		// 自定义属性名 都要默认值的
////		treeNodeConfig.setIdKey("id");
////		treeNodeConfig.setParentIdKey("upId");
//		treeNodeConfig.setNameKey("menuName");
//		// 最大递归深度
////		treeNodeConfig.setDeep(10);
//
//		//转换器
//		List<Tree<String>> treeNodes = TreeUtil.build(list, "0", treeNodeConfig,
//		        (treeNode, tree) -> {
//		            tree.setId(Convert.toStr(treeNode.getMenuId()));
//		            tree.setParentId(Convert.toStr(treeNode.getParentId()));
////				            tree.setWeight(treeNode.getWeight());
//		            tree.setName(treeNode.getMenuName());
//		            // 扩展属性 ...
//		            tree.putExtra("icon", treeNode.getIcon());
//		            tree.putExtra("isFrame", treeNode.getIsFrame());
//		            tree.putExtra("menuType", treeNode.getMenuType());
//		            tree.putExtra("orderNum", treeNode.getOrderNum());
//		            tree.putExtra("path", treeNode.getPath());
//		            tree.putExtra("perms", treeNode.getPerms());
//		            tree.putExtra("remark", treeNode.getRemark());
//		            tree.putExtra("visible", treeNode.getVisible());
////				    tree.putExtra("other", new Object());
//		        });
660
//
661 662
//		return ResultUtil.data(treeNodes);
//	}
663

664 665
	/**
	 * 新增-菜单权限
666
	 *
667 668 669 670 671 672
	 * @param 部门岗位id
	 * @return
	 */
	@PostMapping(value = "/menu")
	@ApiOperation(value = "新增-菜单权限", httpMethod = "POST", notes = "接口发布说明")
	public Result<List<ZzglMenu>> insertPostMenus(@Validated @RequestBody ZzglMenu zzglMenu) {
673

674 675 676 677 678
		Integer conut = zzglMenuMapper.selectCount(new QueryWrapper<ZzglMenu>().lambda()
				.eq(ZzglMenu::getMenuId, zzglMenu.getParentId()));
		if (conut <= 0) {
			return ResultUtil.error("上级权限不存在!");
		}
679

680 681
		return zzglMenu.insert() ? ResultUtil.success() : ResultUtil.error();
	}
682

683 684
	/**
	 * 删除-菜单权限
685
	 *
686 687 688 689 690 691
	 * @param 部门岗位id
	 * @return
	 */
	@DeleteMapping(value = "/menu/{id}")
	@ApiOperation(value = "删除-菜单权限", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<List<ZzglMenu>> deletePostMenus(@Validated @RequestBody Integer id) {
692

693 694
		return zzglMenuMapper.deleteById(id) > 0 ? ResultUtil.success() : ResultUtil.error();
	}
695

696 697
	/**
	 * 修改-菜单权限
698
	 *
699 700 701 702 703 704
	 * @param 部门岗位id
	 * @return
	 */
	@PutMapping(value = "/menu/{id}")
	@ApiOperation(value = "修改-菜单权限", httpMethod = "PUT", notes = "接口发布说明")
	public Result<List<ZzglMenu>> updatePostMenus(@Validated @RequestBody ZzglMenu zzglMenu) {
705

706 707
		return zzglMenu.updateById() ? ResultUtil.success() : ResultUtil.error();
	}
708

709 710
	/**
	 * 获取-该岗位的菜单权限
711
	 *
712 713 714 715 716 717
	 * @param 部门岗位id
	 * @return
	 */
	@GetMapping(value = "/menu/{id}")
	@ApiOperation(value = "获取-该岗位的菜单权限", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<Integer>> selectMenuByPostId(@CurrentUser UserBean userBean,@PathVariable Integer id) {
718

719 720
		return ResultUtil.data(zzglBmgwMService.selectMenuByPostId(id));
	}
721

722 723
	/**
	 * 修改-该岗位的菜单权限
724
	 *
725 726 727 728 729 730
	 * @param 部门岗位id
	 * @return
	 */
	@PutMapping(value = "/post_menu")
	@ApiOperation(value = "修改-该岗位的菜单权限", httpMethod = "PUT", notes = "接口发布说明")
	public Result<List<ZzglMenu>> updatePostMenus(@CurrentUser UserBean userBean,@RequestBody ZzglPostMenuDto zzglPostMenuDto) {
731

732 733 734
		Integer delCount = zzglPostMenuMapper.delete(new QueryWrapper<ZzglPostMenu>().lambda()
				.eq(ZzglPostMenu::getBmgwId, zzglPostMenuDto.getId()));
		Integer updateCount = zzglPostMenuMapper.insertPostMenus(zzglPostMenuDto.getId(),zzglPostMenuDto.getMenus());
735

736 737
		return ResultUtil.success();
	}
738 739


lal committed
740 741 742 743 744
	@GetMapping(value = "/appdeptlist")
	@ApiOperation(value = "APP获取部门岗位", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> selectapplistdept(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();
		List<ObtainDepartmentDto> tmen = new ArrayList<ObtainDepartmentDto>();
745

lal committed
746 747 748 749 750
		List<ZzglBmgwM> zzglbmgwms = new LambdaQueryChainWrapper<ZzglBmgwM>(zzglBmgwMMapper)
				.eq(ZzglBmgwM::getOrgCode, userBean.getOrgCode()).eq(ZzglBmgwM::getType, 0).list();
		for(ZzglBmgwM gw : zzglbmgwms) {
			ObtainDepartmentDto tm = ObtainDepartmentDto.builder().build();
			BeanUtil.copyProperties(gw, tm);
751

lal committed
752 753
			List<DepartmentStaffDto> destff = ygglMainEmpMapper.DepartmentStaff(orgCode,gw.getId());
			tm.setUser(destff);
754

lal committed
755 756
			tmen.add(tm);
		}
757

lal committed
758 759
		return ResultUtil.data(tmen);
	}
翁国栋 committed
760 761 762 763 764 765
	@GetMapping(value = "/dgListByUser")
	@ApiOperation(value = "获取异动记录", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> dgListByUser(@CurrentUser UserBean userBean,@RequestParam(value = "empNum", required = false, defaultValue = "") Integer empNum) {
		List<ZzglLogDgjl> zzglLogDgjlList=zzglLogDgjlMapper.selectListByUser(userBean.getOrgCode(),empNum);
		return ResultUtil.data(zzglLogDgjlList);
	}
766
}