15 changed files with 400 additions and 252 deletions
-
32src/main/java/com/dreamworks/boditech/controller/AccountController.java
-
1src/main/java/com/dreamworks/boditech/controller/DeviceController.java
-
5src/main/java/com/dreamworks/boditech/driver/Device.java
-
3src/main/java/com/dreamworks/boditech/driver/consumable/CsmBufferTubeBox.java
-
70src/main/java/com/dreamworks/boditech/driver/consumable/CsmBufferTubeManager.java
-
9src/main/java/com/dreamworks/boditech/driver/task/Executor.java
-
35src/main/java/com/dreamworks/boditech/driver/task/TaskLoad.java
-
5src/main/java/com/dreamworks/boditech/entity/Account.java
-
33src/main/java/com/dreamworks/boditech/mapper/AccountMapper.java
-
25src/main/java/com/dreamworks/boditech/mapper/UserMapper.java
-
138src/main/java/com/dreamworks/boditech/service/AccountService.java
-
11src/main/java/com/dreamworks/boditech/service/DeviceService.java
-
95src/main/java/com/dreamworks/boditech/service/UserService.java
@ -1,7 +1,10 @@ |
|||
package com.dreamworks.boditech.driver.consumable; |
|||
public class CsmBufferTubeBox { |
|||
public static final String STATUS_NOT_LOADED = "NOT_LOADED"; |
|||
|
|||
public Integer index; |
|||
public Integer projectId; |
|||
public String projectName; |
|||
public Integer tubeAmount; |
|||
public String status; |
|||
} |
@ -1,9 +1,12 @@ |
|||
package com.dreamworks.boditech.entity; |
|||
public class User { |
|||
public class Account { |
|||
public int id; |
|||
public String account; |
|||
public String pin; |
|||
public int isAdmin; |
|||
public long createdAt; |
|||
public int createdBy; |
|||
|
|||
// 上次登录时间 |
|||
public Integer lastLoginTime; |
|||
} |
@ -0,0 +1,33 @@ |
|||
package com.dreamworks.boditech.mapper; |
|||
import com.dreamworks.boditech.entity.Account; |
|||
import org.apache.ibatis.annotations.Delete; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import org.apache.ibatis.annotations.Update; |
|||
import org.apache.ibatis.annotations.Insert; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Mapper |
|||
public interface AccountMapper { |
|||
@Select("SELECT account,isAdmin FROM bdt_accounts ORDER BY isAdmin DESC, lastLoginTime DESC LIMIT #{limit}") |
|||
List<Account> listLoginAccounts(Integer limit); |
|||
|
|||
@Update("UPDATE bdt_accounts SET lastLoginTime=#{lastLoginTime} WHERE id=#{id}") |
|||
void updateLoginTime(Account account); |
|||
|
|||
@Select("SELECT * FROM bdt_accounts WHERE account=#{account} LIMIT 1") |
|||
Account findByAccount(String account); |
|||
|
|||
@Select("SELECT * FROM bdt_accounts WHERE id=#{id}") |
|||
Account findById(int id); |
|||
|
|||
@Update("UPDATE bdt_accounts SET account=#{account}, pin=#{pin}, isAdmin=#{isAdmin} WHERE id=#{id}") |
|||
int update(Account user); |
|||
|
|||
@Delete("DELETE FROM bdt_accounts WHERE id=#{id}") |
|||
int delete(Account user); |
|||
|
|||
@Insert("INSERT INTO bdt_accounts (account, pin, isAdmin, createdAt, createdBy) VALUES (#{account}, #{pin}, #{isAdmin}, #{createdAt}, #{createdBy})") |
|||
int insert(Account user); |
|||
} |
@ -1,25 +0,0 @@ |
|||
package com.dreamworks.boditech.mapper; |
|||
import com.dreamworks.boditech.entity.User; |
|||
import org.apache.ibatis.annotations.Delete; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import org.apache.ibatis.annotations.Update; |
|||
import org.apache.ibatis.annotations.Insert; |
|||
|
|||
@Mapper |
|||
public interface UserMapper { |
|||
@Select("SELECT * FROM bdt_users WHERE account=#{account} LIMIT 1") |
|||
User findByAccount(String account); |
|||
|
|||
@Select("SELECT * FROM bdt_users WHERE id=#{id}") |
|||
User findById(int id); |
|||
|
|||
@Update("UPDATE bdt_users SET account=#{account}, pin=#{pin}, isAdmin=#{isAdmin} WHERE id=#{id}") |
|||
int update(User user); |
|||
|
|||
@Delete("DELETE FROM bdt_users WHERE id=#{id}") |
|||
int delete(User user); |
|||
|
|||
@Insert("INSERT INTO bdt_users (account, pin, isAdmin, createdAt, createdBy) VALUES (#{account}, #{pin}, #{isAdmin}, #{createdAt}, #{createdBy})") |
|||
int insert(User user); |
|||
} |
@ -0,0 +1,138 @@ |
|||
package com.dreamworks.boditech.service; |
|||
import com.dreamworks.boditech.entity.ParamUserLogin; |
|||
import com.dreamworks.boditech.entity.Account; |
|||
import com.dreamworks.boditech.mapper.AccountMapper; |
|||
import jakarta.annotation.Resource; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.DigestUtils; |
|||
import java.util.List; |
|||
@Service |
|||
public class AccountService { |
|||
private static final Logger LOG = LoggerFactory.getLogger(AccountService.class); |
|||
@Resource |
|||
private AccountMapper userMapper; |
|||
@Resource |
|||
private ActionLogService actionLog; |
|||
@Resource |
|||
private DeviceService deviceService; |
|||
// current user |
|||
private Account curAccount = null; |
|||
|
|||
// list-login-accounts |
|||
public List<Account> listLoginAccounts(Integer limit) { |
|||
return this.userMapper.listLoginAccounts(limit); |
|||
} |
|||
|
|||
// login |
|||
public Account login(ParamUserLogin param) { |
|||
Account account = userMapper.findByAccount(param.account); |
|||
String hashPin = DigestUtils.md5DigestAsHex(param.pin.getBytes()); |
|||
if ( null == account || !account.pin.equals(hashPin) ) { |
|||
throw new RuntimeException("ACCOUNT_LOGIN_INVALID_ACCOUNT_OR_PIN_CODE"); |
|||
} |
|||
|
|||
account.lastLoginTime = (int)(System.currentTimeMillis() / 1000); |
|||
this.userMapper.updateLoginTime(account); |
|||
|
|||
this.curAccount = account; |
|||
this.curAccount.pin = "****"; |
|||
this.actionLog.setUserId(account.id); |
|||
this.actionLog.log("account.login", param.account); |
|||
return account; |
|||
} |
|||
|
|||
// logout |
|||
public void logout() { |
|||
if ( this.deviceService.isExecutorRunning() ) { |
|||
throw new RuntimeException("ACCOUNT_LOGOUT_EXECUTOR_RUNNING"); |
|||
} |
|||
|
|||
this.actionLog.log("account.logout"); |
|||
this.actionLog.setUserId(0); |
|||
this.curAccount = null; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
// create |
|||
public Account create(String account, String pin) { |
|||
if ( null == this.curAccount || 0 == this.curAccount.isAdmin) { |
|||
throw new RuntimeException("无权限创建用户"); |
|||
} |
|||
|
|||
Account user = userMapper.findByAccount(account); |
|||
if ( null != user ) { |
|||
throw new RuntimeException("用户名已存在"); |
|||
} |
|||
|
|||
user = new Account(); |
|||
user.account = account; |
|||
user.pin = pin; |
|||
user.isAdmin = 0; |
|||
user.createdAt = System.currentTimeMillis(); |
|||
user.createdBy = this.curAccount.id; |
|||
userMapper.insert(user); |
|||
|
|||
user = this.userMapper.findByAccount(account); |
|||
LOG.info("user create success, user id : {}", user.id); |
|||
return user; |
|||
} |
|||
|
|||
// pin-update |
|||
public void pinUpdate(String pin) { |
|||
if ( null == this.curAccount) { |
|||
throw new RuntimeException("请先登录"); |
|||
} |
|||
|
|||
this.curAccount.pin = pin; |
|||
int changeCount = userMapper.update(this.curAccount); |
|||
if ( 1 != changeCount ) { |
|||
throw new RuntimeException("数据更新异常"); |
|||
} |
|||
} |
|||
|
|||
// delete |
|||
public void delete(int id) { |
|||
if ( null == this.curAccount || 0 == this.curAccount.isAdmin) { |
|||
throw new RuntimeException("无权限删除用户"); |
|||
} |
|||
|
|||
Account user = this.userMapper.findById(id); |
|||
if ( null == user ) { |
|||
throw new RuntimeException("无效的用户id : " + id); |
|||
} |
|||
|
|||
int deleteCount = this.userMapper.delete(user); |
|||
if ( 1 != deleteCount ) { |
|||
throw new RuntimeException("数据删除异常"); |
|||
} |
|||
} |
|||
} |
@ -1,95 +0,0 @@ |
|||
package com.dreamworks.boditech.service; |
|||
import com.dreamworks.boditech.entity.ParamUserLogin; |
|||
import com.dreamworks.boditech.entity.User; |
|||
import com.dreamworks.boditech.mapper.UserMapper; |
|||
import jakarta.annotation.Resource; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.DigestUtils; |
|||
@Service |
|||
public class UserService { |
|||
private static final Logger LOG = LoggerFactory.getLogger(UserService.class); |
|||
@Resource |
|||
private UserMapper userMapper; |
|||
@Resource |
|||
private ActionLogService actionLog; |
|||
// current user |
|||
private User curUser = null; |
|||
|
|||
// login |
|||
public User login(ParamUserLogin param) { |
|||
User user = userMapper.findByAccount(param.account); |
|||
String hashPin = DigestUtils.md5DigestAsHex(param.pin.getBytes()); |
|||
if ( null == user || !user.pin.equals(hashPin) ) { |
|||
throw new RuntimeException("USER_LOGIN_INVALID_ACCOUNT_OR_PIN_CODE"); |
|||
} |
|||
|
|||
this.curUser = user; |
|||
this.curUser.pin = "****"; |
|||
this.actionLog.setUserId(user.id); |
|||
this.actionLog.log("user.login", param.account); |
|||
return user; |
|||
} |
|||
|
|||
// logout |
|||
public void logout() { |
|||
this.actionLog.log("user.logout"); |
|||
this.actionLog.setUserId(0); |
|||
this.curUser = null; |
|||
} |
|||
|
|||
// create |
|||
public User create(String account, String pin) { |
|||
if ( null == this.curUser || 0 == this.curUser.isAdmin) { |
|||
throw new RuntimeException("无权限创建用户"); |
|||
} |
|||
|
|||
User user = userMapper.findByAccount(account); |
|||
if ( null != user ) { |
|||
throw new RuntimeException("用户名已存在"); |
|||
} |
|||
|
|||
user = new User(); |
|||
user.account = account; |
|||
user.pin = pin; |
|||
user.isAdmin = 0; |
|||
user.createdAt = System.currentTimeMillis(); |
|||
user.createdBy = this.curUser.id; |
|||
userMapper.insert(user); |
|||
|
|||
user = this.userMapper.findByAccount(account); |
|||
LOG.info("user create success, user id : {}", user.id); |
|||
return user; |
|||
} |
|||
|
|||
// pin-update |
|||
public void pinUpdate(String pin) { |
|||
if ( null == this.curUser ) { |
|||
throw new RuntimeException("请先登录"); |
|||
} |
|||
|
|||
this.curUser.pin = pin; |
|||
int changeCount = userMapper.update(this.curUser); |
|||
if ( 1 != changeCount ) { |
|||
throw new RuntimeException("数据更新异常"); |
|||
} |
|||
} |
|||
|
|||
// delete |
|||
public void delete(int id) { |
|||
if ( null == this.curUser || 0 == this.curUser.isAdmin) { |
|||
throw new RuntimeException("无权限删除用户"); |
|||
} |
|||
|
|||
User user = this.userMapper.findById(id); |
|||
if ( null == user ) { |
|||
throw new RuntimeException("无效的用户id : " + id); |
|||
} |
|||
|
|||
int deleteCount = this.userMapper.delete(user); |
|||
if ( 1 != deleteCount ) { |
|||
throw new RuntimeException("数据删除异常"); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue