| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- package com.template.controller;
- import com.template.api.SmartIdentityControllerAPI;
- import com.template.common.utils.paramUtils;
- import com.template.model.pojo.SmartApply;
- import com.template.model.pojo.SmartIdentity;
- import com.template.model.pojo.SmartScreenshot;
- import com.template.model.request.insertIdentityRequest;
- import com.template.model.request.updateIdentityRequest;
- import com.template.model.result.CommonResult;
- import com.template.model.result.PageUtils;
- import com.template.model.vo.ApplysVo;
- import com.template.model.vo.IdentityApplyVo;
- import com.template.model.vo.SemesterVo;
- import com.template.services.SmartApplyService;
- import com.template.services.SmartIdentityService;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Optional;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author ceshi
- * @since 2023-12-04
- */
- @RestController
- public class SmartIdentityController implements SmartIdentityControllerAPI {
- @Autowired
- private SmartApplyService smartApplyService;
- @Autowired
- private SmartIdentityService smartIdentityService;
- /**
- * 新增身份
- *
- * @param smartIdentity 身份数据
- * @param bindingResult
- * @return
- */
- @Override
- public CommonResult insertSmartIdentity(insertIdentityRequest smartIdentity, BindingResult bindingResult) {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- SmartIdentity data = smartIdentityService.queryIdentityByName(smartIdentity.getName());
- if (data != null) {
- return CommonResult.fail("该身份已存在");
- }
- SmartIdentity identity = new SmartIdentity();
- identity.setName(smartIdentity.getName());
- identity.setApplyId(StringUtils.join(smartIdentity.getApplyIds(), ','));
- int result = smartIdentityService.insertSmartIdentity(identity);
- return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
- }
- /**
- * 更新身份
- *
- * @param sa 身份数据
- * @param bindingResult
- * @return
- */
- @Override
- public CommonResult updateSmartIdentityById(updateIdentityRequest sa, BindingResult bindingResult) {
- if (bindingResult.hasErrors()) {
- String st = paramUtils.getParamError(bindingResult);
- return CommonResult.fail(st);
- }
- SmartIdentity oldData = smartIdentityService.getSmartById(sa.getId());
- if (oldData == null) {
- return CommonResult.fail("身份数据无效,修改失败");
- }
- if (sa.getName() != null && !sa.getName().equals(oldData.getName())) {
- //查看是否存在相同身份的数据
- SmartIdentity data = smartIdentityService.queryIdentityByName(sa.getName());
- if (data != null) {
- return CommonResult.fail("该身份已存在");
- }
- }
- SmartIdentity identity = new SmartIdentity();
- identity.setId(sa.getId());
- identity.setName(sa.getName());
- identity.setApplyId(StringUtils.join(sa.getApplyIds(), ','));
- int result = smartIdentityService.updateSmartIdentity(identity);
- return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
- }
- /**
- * 身份分页数据查询
- *
- * @param currentPage 当前页数
- * @param pageCount 一页数据条数
- * @param name 查询名称
- * @return
- */
- @Override
- public CommonResult queryPageSmartIdentitys(int currentPage, int pageCount, String name) {
- PageUtils<SmartIdentity> result = smartIdentityService.queryPageSmartIdentitys(currentPage, pageCount, name);
- for (SmartIdentity data : result.getList()) {
- List<String> lists = Arrays.asList(data.getApplyId().split(","));
- data.setApplyIds(lists);
- }
- return CommonResult.ok(result);
- }
- @Override
- public CommonResult deleteSmartIdentityById(int id) {
- SmartIdentity data = smartIdentityService.getSmartById(id);
- if (data == null) {
- return CommonResult.fail("当前数据不存在,删除失败!");
- }
- int result = smartIdentityService.deleteSmartIdentityById(id);
- return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
- }
- @Override
- public CommonResult querySmartIdentitys() {
- List<SmartIdentity> datas = smartIdentityService.list(null);
- List<SemesterVo> result = new ArrayList<>();
- for (SmartIdentity data : datas) {
- SemesterVo model = new SemesterVo();
- model.setId(data.getId());
- model.setName(data.getName());
- result.add(model);
- }
- return CommonResult.ok(result);
- }
- @Override
- public CommonResult queryIdentityApplyById(int id) {
- List<ApplysVo> result = new ArrayList<>();
- SmartIdentity identity = smartIdentityService.getSmartById(id);
- if (identity == null) {
- return CommonResult.fail("当前身份不合法,无应用权限");
- }
- if (identity.getApplyId() == null) {
- return CommonResult.fail("当前身份信息无应用权限");
- }
- List<SmartApply> applys = smartApplyService.queryAppletApplys();
- if(applys == null){
- return CommonResult.fail("应用管理数据为空");
- }
- List<String> applyIds = Arrays.asList(identity.getApplyId().split(","));
- for (String applyId : applyIds) {
- Optional<SmartApply> applyData = applys.stream().filter(e -> e.getId().equals(Integer.valueOf(applyId))).findFirst();
- if(applyData != null && applyData.isPresent()){
- ApplysVo data = new ApplysVo();
- data.setId(applyData.get().getId());
- data.setPath(applyData.get().getRoute());
- data.setTitle(applyData.get().getName());
- data.setUrl(applyData.get().getLogo());
- result.add(data);
- }
- }
- return CommonResult.ok(result);
- }
- }
|