|
@ -7,6 +7,7 @@ import awesome.group.game.dao.mapper.MatrixAdminMapper; |
|
|
import awesome.group.game.dao.mapper.MatrixAdvRecordMapper; |
|
|
import awesome.group.game.dao.mapper.MatrixAdvRecordMapper; |
|
|
import awesome.group.game.dao.mapper.MatrixAppMapper; |
|
|
import awesome.group.game.dao.mapper.MatrixAppMapper; |
|
|
import awesome.group.game.service.bo.AdvRecordQuery; |
|
|
import awesome.group.game.service.bo.AdvRecordQuery; |
|
|
|
|
|
import awesome.group.game.service.bo.MatrixAdminBo; |
|
|
import awesome.group.game.service.bo.MatrixAdvRecordBo; |
|
|
import awesome.group.game.service.bo.MatrixAdvRecordBo; |
|
|
import awesome.group.game.service.bo.PageResult; |
|
|
import awesome.group.game.service.bo.PageResult; |
|
|
import awesome.group.game.service.common.exception.PaganiException; |
|
|
import awesome.group.game.service.common.exception.PaganiException; |
|
@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
import com.google.common.base.Joiner; |
|
|
|
|
|
|
|
|
import java.sql.Timestamp; |
|
|
import java.sql.Timestamp; |
|
|
import java.text.ParseException; |
|
|
import java.text.ParseException; |
|
@ -40,7 +42,11 @@ public class AdminService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private MatrixAppMapper appMapper; |
|
|
private MatrixAppMapper appMapper; |
|
|
|
|
|
|
|
|
public MatrixAdmin login(String name, String pwd) { |
|
|
public static final int SUPER_ADMIN = 1;//超级管理员
|
|
|
|
|
|
public static final int NORMAL_ADMIN = 2;//普通管理员
|
|
|
|
|
|
public static final int OTHER = 3;//普通账号
|
|
|
|
|
|
|
|
|
|
|
|
public MatrixAdmin login(String name, String pwd, String channel) { |
|
|
MatrixAdmin admin = adminMapper.query(name); |
|
|
MatrixAdmin admin = adminMapper.query(name); |
|
|
if (admin == null) { |
|
|
if (admin == null) { |
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "用户名或密码不正确"); |
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "用户名或密码不正确"); |
|
@ -49,6 +55,9 @@ public class AdminService { |
|
|
if (!password.equals(admin.getPassword())) { |
|
|
if (!password.equals(admin.getPassword())) { |
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "用户名或密码不正确"); |
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "用户名或密码不正确"); |
|
|
} |
|
|
} |
|
|
|
|
|
if (admin.getRole() != SUPER_ADMIN && !admin.getChannel().equalsIgnoreCase(channel)) { |
|
|
|
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "用户名或密码不正确"); |
|
|
|
|
|
} |
|
|
return admin; |
|
|
return admin; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -56,7 +65,8 @@ public class AdminService { |
|
|
return adminMapper.selectById(id); |
|
|
return adminMapper.selectById(id); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public PageResult<MatrixAdvRecordBo> advList(AdvRecordQuery param, int ownerId) { |
|
|
public PageResult<MatrixAdvRecordBo> advList(AdvRecordQuery param, Integer ownerId) { |
|
|
|
|
|
MatrixAdmin admin = adminMapper.selectById(ownerId); |
|
|
List<MatrixApp> appList = appMapper.selectList(null); |
|
|
List<MatrixApp> appList = appMapper.selectList(null); |
|
|
LambdaQueryWrapper<MatrixAdvRecord> wrapper = Wrappers.lambdaQuery(); |
|
|
LambdaQueryWrapper<MatrixAdvRecord> wrapper = Wrappers.lambdaQuery(); |
|
|
|
|
|
|
|
@ -86,8 +96,8 @@ public class AdminService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
wrapper.orderByDesc(MatrixAdvRecord::getId); |
|
|
wrapper.orderByDesc(MatrixAdvRecord::getId); |
|
|
if (ownerId != 1) { |
|
|
if (admin.getRole() != SUPER_ADMIN) { |
|
|
List<Integer> appIds = appList.stream().filter(x -> x.getOwnerId() != null && x.getOwnerId() == ownerId).map(MatrixApp::getId).toList(); |
|
|
List<Integer> appIds = Arrays.stream(admin.getAppIds().split(",")).map(Integer::parseInt).toList(); |
|
|
if (CollectionUtils.isEmpty(appIds)) { |
|
|
if (CollectionUtils.isEmpty(appIds)) { |
|
|
return new PageResult<>(new ArrayList<>(), 0); |
|
|
return new PageResult<>(new ArrayList<>(), 0); |
|
|
} |
|
|
} |
|
@ -108,11 +118,55 @@ public class AdminService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public List<MatrixApp> appList(Integer adminId) { |
|
|
public List<MatrixApp> appList(Integer adminId) { |
|
|
if (adminId == 1) { |
|
|
MatrixAdmin admin = adminMapper.selectById(adminId); |
|
|
|
|
|
if (adminId == SUPER_ADMIN) { |
|
|
return appMapper.selectList(null); |
|
|
return appMapper.selectList(null); |
|
|
} |
|
|
} |
|
|
LambdaQueryWrapper<MatrixApp> query = Wrappers.lambdaQuery(); |
|
|
LambdaQueryWrapper<MatrixApp> query = Wrappers.lambdaQuery(); |
|
|
query.eq(MatrixApp::getOwnerId, adminId); |
|
|
query.in(MatrixApp::getId, Arrays.stream(admin.getAppIds().split(",")).map(Integer::parseInt).toList()); |
|
|
return appMapper.selectList(query); |
|
|
return appMapper.selectList(query); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void grantApp(String appIds, int adminId, Integer currentAdminId) { |
|
|
|
|
|
List<Integer> legalAppIds = new ArrayList<>(appList(currentAdminId).stream().map(MatrixApp::getId).toList()); |
|
|
|
|
|
List<Integer> paramIds = Arrays.stream(appIds.split(",")).map(Integer::parseInt).toList(); |
|
|
|
|
|
legalAppIds.retainAll(paramIds); |
|
|
|
|
|
String str = Joiner.on(",").join(legalAppIds); |
|
|
|
|
|
adminMapper.updateAppIds(str, adminId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<MatrixAdminBo> adminList(String channel) { |
|
|
|
|
|
LambdaQueryWrapper<MatrixAdmin> query = Wrappers.lambdaQuery(); |
|
|
|
|
|
query.eq(MatrixAdmin::getChannel, channel); |
|
|
|
|
|
List<MatrixAdmin> res = adminMapper.selectList(query); |
|
|
|
|
|
|
|
|
|
|
|
return res.stream().map(MatrixAdminBo::new).toList(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void saveAdmin(MatrixAdminBo bo, String channel) { |
|
|
|
|
|
MatrixAdmin admin = new MatrixAdmin(); |
|
|
|
|
|
BeanUtils.copyProperties(bo, admin); |
|
|
|
|
|
if (!CollectionUtils.isEmpty(bo.getAppIds())) { |
|
|
|
|
|
admin.setAppIds(Joiner.on(",").join(bo.getAppIds())); |
|
|
|
|
|
} |
|
|
|
|
|
admin.setChannel(channel); |
|
|
|
|
|
if (admin.getId() != null) { |
|
|
|
|
|
if (StringUtils.hasText(admin.getPassword())) { |
|
|
|
|
|
admin.setPassword(EncryptUtil.sha1(admin.getPassword())); |
|
|
|
|
|
} else { |
|
|
|
|
|
MatrixAdmin origin = adminMapper.selectById(admin.getId()); |
|
|
|
|
|
admin.setPassword(origin.getPassword()); |
|
|
|
|
|
} |
|
|
|
|
|
adminMapper.updateById(admin); |
|
|
|
|
|
} else { |
|
|
|
|
|
if(adminMapper.query(bo.getName()) != null) { |
|
|
|
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "用户名重复"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!StringUtils.hasText(bo.getPassword())) { |
|
|
|
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "密码不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
admin.setPassword(EncryptUtil.sha1(bo.getPassword())); |
|
|
|
|
|
adminMapper.insert(admin); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|