|
@@ -0,0 +1,97 @@
|
|
|
+package com.management.platform.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.entity.BonusExcludeProject;
|
|
|
+import com.management.platform.entity.Project;
|
|
|
+import com.management.platform.entity.User;
|
|
|
+import com.management.platform.entity.bo.AddOrUpdateBonusExcludeProjectBO;
|
|
|
+import com.management.platform.mapper.BonusExcludeProjectMapper;
|
|
|
+import com.management.platform.mapper.ProjectMapper;
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
|
+import com.management.platform.service.BonusExcludeProjectService;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class BonusExcludeProjectServiceImpl extends ServiceImpl<BonusExcludeProjectMapper, BonusExcludeProject> implements BonusExcludeProjectService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BonusExcludeProjectMapper bonusExcludeProjectMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg addOrUpdateProjects(AddOrUpdateBonusExcludeProjectBO addBO, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ if(null ==user){
|
|
|
+ httpRespMsg.setError("登录凭证有误,请联系管理员");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ List<BonusExcludeProject> resList = new ArrayList<BonusExcludeProject>();
|
|
|
+ if(1==addBO.getIsAll()){
|
|
|
+ List<Project> allProjects = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", user.getCompanyId()));
|
|
|
+ List<BonusExcludeProject> collect = allProjects.stream().map(t -> {
|
|
|
+ BonusExcludeProject project = new BonusExcludeProject();
|
|
|
+ project.setProjectId(t.getId());
|
|
|
+ project.setCreateBy(user.getId());
|
|
|
+ return project;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ resList = collect;
|
|
|
+ }else {
|
|
|
+ for (int i = 0; i < addBO.getProjects().length; i++) {
|
|
|
+ BonusExcludeProject project = new BonusExcludeProject();
|
|
|
+ project.setProjectId(Integer.parseInt(addBO.getProjects()[i]));
|
|
|
+ project.setCreateBy(user.getId());
|
|
|
+ resList.add(project);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bonusExcludeProjectMapper.delete(new LambdaQueryWrapper<BonusExcludeProject>()
|
|
|
+ .eq(BonusExcludeProject::getCompanyId,user.getCompanyId()));
|
|
|
+ if(CollectionUtils.isNotEmpty(resList)){
|
|
|
+ bonusExcludeProjectMapper.bacthInsert(resList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getProjects(HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ if(null ==user){
|
|
|
+ httpRespMsg.setError("登录凭证有误,请联系管理员");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ Integer projectCount = projectMapper.selectCount(new LambdaQueryWrapper<Project>()
|
|
|
+ .eq(Project::getCompanyId, user.getCompanyId()));
|
|
|
+
|
|
|
+ List<BonusExcludeProject> resList = bonusExcludeProjectMapper
|
|
|
+ .selectList(new LambdaQueryWrapper<BonusExcludeProject>()
|
|
|
+ .eq(BonusExcludeProject::getCompanyId,user.getCompanyId()));
|
|
|
+ if(projectCount == resList.size()){
|
|
|
+ map.put("isAll",1);
|
|
|
+ }else{
|
|
|
+ map.put("isAll",0);
|
|
|
+ }
|
|
|
+ map.put("projectList",resList);
|
|
|
+ httpRespMsg.setData(map);
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+}
|