|
@@ -0,0 +1,143 @@
|
|
|
+package com.persagy.dmp.rwd.edit.service;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import com.persagy.common.criteria.CriteriaUtils;
|
|
|
+import com.persagy.common.criteria.JacksonCriteria;
|
|
|
+import com.persagy.common.security.MD5Utils;
|
|
|
+import com.persagy.common.web.MapResponse;
|
|
|
+import com.persagy.common.web.PagedResponse;
|
|
|
+import com.persagy.dmp.rwd.edit.config.web.UserUtils;
|
|
|
+import com.persagy.dmp.rwd.edit.entity.AdminRole;
|
|
|
+import com.persagy.dmp.rwd.edit.entity.AdminUser;
|
|
|
+import com.persagy.dmp.rwd.edit.entity.AdminUserProject;
|
|
|
+import com.persagy.dmp.rwd.edit.entity.QAdminUser;
|
|
|
+import com.persagy.dmp.rwd.edit.repository.AdminUserRepository;
|
|
|
+import com.querydsl.core.types.dsl.BooleanExpression;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.transaction.Transactional;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class AdminUserService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AdminUserRepository adminUserRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CriteriaUtils criteriaUtils;
|
|
|
+
|
|
|
+ private List<BooleanExpression> parse(ObjectNode criteria) {
|
|
|
+ // TODO
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagedResponse<AdminUser> query(JacksonCriteria criteria) {
|
|
|
+ PagedResponse<AdminUser> query = criteriaUtils.query(QAdminUser.adminUser, this::parse, criteria);
|
|
|
+ PagedResponse<AdminUser> resp = new PagedResponse<>();
|
|
|
+ resp.setCount(query.getCount());
|
|
|
+ List<AdminUser> data = query.getData();
|
|
|
+ if (data != null && data.size() > 0) {
|
|
|
+ Set<String> withColumns = criteria.getWithColumns();
|
|
|
+ List<AdminUser> list = new ArrayList<>(data.size());
|
|
|
+ boolean withRoles = withColumns != null && withColumns.contains("roles");
|
|
|
+ boolean withProjects = withColumns != null && withColumns.contains("projects");
|
|
|
+ for (AdminUser user : data) {
|
|
|
+ AdminUser model = new AdminUser();
|
|
|
+ BeanUtils.copyProperties(user, model, "password", "roles", "projects");
|
|
|
+ if (withRoles) {
|
|
|
+ model.setRoles(user.getRoles());
|
|
|
+ }
|
|
|
+ if (withProjects) {
|
|
|
+ model.setProjects(user.getProjects());
|
|
|
+ }
|
|
|
+ list.add(model);
|
|
|
+ }
|
|
|
+ resp.setData(list);
|
|
|
+ }
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public MapResponse create(AdminUser param) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+ // TODO
|
|
|
+ String username = param.getUsername();
|
|
|
+ if (username == null) {
|
|
|
+ response.setFail("账号不可为空!");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ long count = adminUserRepository.count(QAdminUser.adminUser.username.eq(username));
|
|
|
+ if (count > 0) {
|
|
|
+ response.setFail("账号已存在!");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ AdminUser entity = new AdminUser();
|
|
|
+ entity.setUsername(username);
|
|
|
+ entity.setRealname(param.getRealname());
|
|
|
+ entity.setPassword(MD5Utils.getSign(username + "123456"));
|
|
|
+ entity.setCreateUser(UserUtils.currentUserId());
|
|
|
+ entity.setStatus(1);
|
|
|
+ adminUserRepository.save(entity);
|
|
|
+ response.add("id", entity.getId());
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public MapResponse update(AdminUser param) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+ // TODO
|
|
|
+ Integer userId = param.getId();
|
|
|
+ AdminUser user = adminUserRepository.findById(userId).get();
|
|
|
+ String realname = param.getRealname();
|
|
|
+ if (realname != null) {
|
|
|
+ user.setRealname(realname);
|
|
|
+ }
|
|
|
+ String phone = param.getPhone();
|
|
|
+ if (phone != null) {
|
|
|
+ user.setPhone(phone);
|
|
|
+ }
|
|
|
+ String remark = param.getRemark();
|
|
|
+ if (remark != null) {
|
|
|
+ user.setRemark(remark);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AdminRole> roles = param.getRoles();
|
|
|
+ if (roles != null) {
|
|
|
+ user.getRoles().clear();
|
|
|
+ user.getRoles().addAll(roles);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AdminUserProject> projects = param.getProjects();
|
|
|
+ if (projects != null) {
|
|
|
+ user.getProjects().clear();
|
|
|
+ for (AdminUserProject project : projects) {
|
|
|
+ project.setUser(user);
|
|
|
+ }
|
|
|
+ user.getProjects().addAll(projects);
|
|
|
+ }
|
|
|
+
|
|
|
+ adminUserRepository.save(user);
|
|
|
+ response.add("id", userId);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public MapResponse delete(AdminUser param) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+ // TODO
|
|
|
+
|
|
|
+ Integer id = param.getId();
|
|
|
+ AdminUser user = adminUserRepository.findById(id).get();
|
|
|
+ user.setStatus(0);
|
|
|
+ user.setUpdateUser(UserUtils.currentUserId());
|
|
|
+ adminUserRepository.save(user);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|