|
@@ -4,17 +4,20 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.entity.Department;
|
|
|
import com.management.platform.entity.User;
|
|
|
+import com.management.platform.entity.vo.DepartmentMasterVO;
|
|
|
import com.management.platform.entity.vo.DepartmentVO;
|
|
|
import com.management.platform.mapper.DepartmentMapper;
|
|
|
import com.management.platform.mapper.UserMapper;
|
|
|
import com.management.platform.service.DepartmentService;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Stack;
|
|
|
|
|
|
/**
|
|
@@ -47,14 +50,9 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
.setDepartmentName(departmentName)
|
|
|
.setSuperiorId(superiorId)
|
|
|
.setCompanyId(companyId);
|
|
|
- departmentMapper.insert(department);
|
|
|
- //更新最顶级部门
|
|
|
- Integer masterId = department.getDepartmentId();
|
|
|
- while (superiorId != null) {
|
|
|
- masterId = superiorId;
|
|
|
- superiorId = departmentMapper.selectById(masterId).getSuperiorId();
|
|
|
+ if (departmentMapper.insert(department) == 0) {
|
|
|
+ httpRespMsg.setError("修改失败");
|
|
|
}
|
|
|
- departmentMapper.updateById(department.setMasterId(masterId));
|
|
|
} else {
|
|
|
httpRespMsg.setError("无所选父级部门");
|
|
|
}
|
|
@@ -250,4 +248,64 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
.setParentId(department.getSuperiorId());
|
|
|
}
|
|
|
|
|
|
+ //获取某个项目下的统计
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getDepartmentStatistics(HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ List<Department> masterList = departmentMapper.selectList(new QueryWrapper<Department>()
|
|
|
+ .eq("company_id", companyId).isNull("superior_id"));
|
|
|
+ List<DepartmentMasterVO> list = new ArrayList<>();
|
|
|
+ for (Department department : masterList) {
|
|
|
+ DepartmentMasterVO departmentMasterVO = new DepartmentMasterVO();
|
|
|
+ BeanUtils.copyProperties(department, departmentMasterVO);
|
|
|
+ Map<String, Object> map = departmentMapper.getCostByDepartment(
|
|
|
+ getBranchDepartment(department.getDepartmentId(), companyId));
|
|
|
+ departmentMasterVO.setCostTime(map == null ? new Double(0) : (Double) map.get("time"));
|
|
|
+ departmentMasterVO.setCostMoney(map == null ? new Double(0) : (Double) map.get("money"));
|
|
|
+ list.add(departmentMasterVO);
|
|
|
+ }
|
|
|
+ httpRespMsg.data = list;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getUserStatistics(Integer departmentId, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+// Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ Integer companyId = 6;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取某个部门所有子部门id
|
|
|
+ private List<Integer> getBranchDepartment(Integer departmentId, Integer companyId) {
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>()
|
|
|
+ .eq("company_id", companyId));
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ list.add(departmentId);
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Integer targetId = list.get(i);
|
|
|
+ for (int j = 0; j < departmentList.size(); j++) {
|
|
|
+ Integer superiorId = departmentList.get(j).getSuperiorId();
|
|
|
+ if (superiorId == null) {
|
|
|
+ departmentList.remove(j--);
|
|
|
+ } else if (superiorId.equals(targetId)) {
|
|
|
+ list.add(departmentList.get(j).getDepartmentId());
|
|
|
+ departmentList.remove(j--);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|