88e030b7
王彪总
init project
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
|
package com.java110.common.cmd.machineAuth;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.machine.MachineAuthDto;
import com.java110.dto.user.UserDto;
import com.java110.intf.common.IMachineAuthInnerServiceSMO;
import com.java110.intf.user.IUserInnerServiceSMO;
import com.java110.po.machine.MachineAuthPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* 修改员工门禁授权
*
* @author fqz
* @date 2022-10-29
*/
@Java110Cmd(serviceCode = "machineAuth.updateMachineAuth")
public class UpdateMachineAuth extends Cmd {
@Autowired
private IMachineAuthInnerServiceSMO machineAuthInnerServiceSMOImpl;
@Autowired
private IUserInnerServiceSMO userInnerServiceSMOImpl;
private static Logger logger = LoggerFactory.getLogger(UpdateMachineAuth.class);
@Override
public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
Assert.jsonObjectHaveKey(reqJson, "authId", "请求报文中未包含授权ID");
Assert.jsonObjectHaveKey(reqJson, "communityId", "请求报文中未包含小区信息");
Assert.jsonObjectHaveKey(reqJson, "startTime", "请求报文中未包含开始时间");
Assert.jsonObjectHaveKey(reqJson, "endTime", "请求报文中未包含结束时间");
Assert.jsonObjectHaveKey(reqJson, "personId", "请求报文中未包含员工ID");
Assert.jsonObjectHaveKey(reqJson, "machineId", "请求报文中未包含设备ID");
MachineAuthDto machineAuthDto = new MachineAuthDto();
machineAuthDto.setMachineId(reqJson.getString("machineId"));
machineAuthDto.setPersonId(reqJson.getString("personId"));
List<MachineAuthDto> machineAuthDtos = machineAuthInnerServiceSMOImpl.queryMachineAuths(machineAuthDto);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (machineAuthDtos != null && machineAuthDtos.size() > 0) {
for (MachineAuthDto machineAuth : machineAuthDtos) {
if (machineAuth.getAuthId().equals(reqJson.getString("authId"))) {
continue;
} else {
//获取结束时间
Date endTime = simpleDateFormat.parse(machineAuth.getEndTime());
//开始时间
Date newStartTime = simpleDateFormat.parse(reqJson.getString("startTime"));
int i = newStartTime.compareTo(endTime);
if (i < 0) { //上次结束时间大于本次开始时间
throw new IllegalArgumentException("该时间段内该员工已经授权过该设备,无法再次进行授权!");
}
}
}
}
}
@Override
@Java110Transactional
public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
MachineAuthPo machineAuthPo = BeanConvertUtil.covertBean(reqJson, MachineAuthPo.class);
UserDto userDto = new UserDto();
userDto.setUserId(reqJson.getString("personId"));
List<UserDto> users = userInnerServiceSMOImpl.getUsers(userDto);
Assert.listOnlyOne(users, "查询员工错误!");
machineAuthPo.setPersonName(users.get(0).getName());
int flag = machineAuthInnerServiceSMOImpl.updateMachineAuth(machineAuthPo);
if (flag < 1) {
throw new CmdException("修改员工门禁授权失败");
}
context.setResponseEntity(ResultVo.success());
}
}
|