|
@@ -19,6 +19,7 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.DecimalFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -34,9 +35,12 @@ import java.util.stream.Collectors;
|
|
|
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
|
|
|
@Value(value = "${upload.path}")
|
|
|
private String path;
|
|
|
+
|
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
|
@Resource
|
|
|
+ private TimeTypeMapper timeTypeMapper;
|
|
|
+ @Resource
|
|
|
private SysFunctionMapper sysFunctionMapper;
|
|
|
@Resource
|
|
|
private DepartmentMapper departmentMapper;
|
|
@@ -730,6 +734,93 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //获取所有负责的部门id List
|
|
|
+ public List<Integer> getAllManagedDeptIdList(User curUser, List<Department> allDepartmentList) {
|
|
|
+ if (allDepartmentList == null) {
|
|
|
+ allDepartmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", curUser.getCompanyId()));
|
|
|
+ }
|
|
|
+ //负责的部门:先查担任主要负责人的部门
|
|
|
+ List<Department> allMDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", curUser.getId()));
|
|
|
+ //其他负责的部门
|
|
|
+ List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("other_manager_id", curUser.getId()));
|
|
|
+ List<Integer> otherCollect = departmentOtherManagerList.stream().distinct().map(dom -> dom.getDepartmentId()).collect(Collectors.toList());
|
|
|
+ for (Integer integer : otherCollect) {
|
|
|
+ Optional<Department> first = allDepartmentList.stream().filter(ad -> ad.getDepartmentId().equals(integer)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ allMDeptList.add(first.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Department> subDepts = new ArrayList<>();
|
|
|
+ for (Department dp : allMDeptList) {
|
|
|
+ subDepts.addAll(getSubDepts(dp, allDepartmentList));
|
|
|
+ subDepts.add(dp);
|
|
|
+ }
|
|
|
+ List<Integer> collect = subDepts.stream().map(Department::getDepartmentId).collect(Collectors.toList());
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportCustomDataSum(String startDate, String endDate, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ HttpRespMsg msg = getUserCustomDataStatistic(startDate, endDate, null, request);
|
|
|
+ Map<String, Object> map = (Map<String, Object>) msg.data;
|
|
|
+ List<HashMap> itemList = (List<HashMap>) map.get("list");
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
+ List<String> headList = new ArrayList<String>();
|
|
|
+ headList.add("序号");
|
|
|
+ headList.add("姓名");
|
|
|
+ headList.add(timeType.getCustomDataName());
|
|
|
+ List<List<String>> allList = new ArrayList<List<String>>();
|
|
|
+ allList.add(headList);
|
|
|
+ double totalCostTime = 0;
|
|
|
+ int seq=1;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ //计算合计的费用
|
|
|
+ for (Map<String, Object> membMap : itemList) {
|
|
|
+ List<String> membRowData = new ArrayList<String>();
|
|
|
+ membRowData.add(String.valueOf(seq));
|
|
|
+ membRowData.add((String)membMap.get("name"));
|
|
|
+ membRowData.add(((Double)membMap.get("cost")).toString());
|
|
|
+ allList.add(membRowData);
|
|
|
+ totalCostTime += (Double)membMap.get("cost");
|
|
|
+ seq++;
|
|
|
+ }
|
|
|
+ //合计
|
|
|
+ List<String> sumRow = new ArrayList<String>();
|
|
|
+ sumRow.add("合计");
|
|
|
+ sumRow.add("");
|
|
|
+ sumRow.add(""+new BigDecimal(totalCostTime).setScale(1, BigDecimal.ROUND_HALF_UP));
|
|
|
+ allList.add(sumRow);
|
|
|
+ //生成excel文件导出
|
|
|
+ String fileName = timeType.getCustomDataName() + "统计_"+System.currentTimeMillis();
|
|
|
+ String resp = ExcelUtil.exportGeneralExcelByTitleAndList(fileName , allList, path);
|
|
|
+
|
|
|
+ httpRespMsg.data = resp;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<Department> getSubDepts(Department dp, List<Department> list) {
|
|
|
+ List<Department> collect = list.stream().filter(l -> dp.getDepartmentId().equals(l.getSuperiorId())).collect(Collectors.toList());;
|
|
|
+ List<Department> allList = new ArrayList<>();
|
|
|
+ allList.addAll(collect);
|
|
|
+ if (collect.size() > 0) {
|
|
|
+ collect.forEach(c->{
|
|
|
+ allList.addAll(getSubDepts(c, list));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return allList;
|
|
|
+ }
|
|
|
@Override
|
|
|
public HttpRespMsg getUserCustomDataStatistic(String startDate, String endDate, Integer departmentId, HttpServletRequest request) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
@@ -737,18 +828,29 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
|
|
|
List<Integer> deptIds = null;
|
|
|
+ List<Department> allDeptList = null;
|
|
|
//首先校验有无权限
|
|
|
if (departmentId != null) {
|
|
|
if (departmentMapper.selectCount(new QueryWrapper<Department>()
|
|
|
.eq("department_id", departmentId)
|
|
|
.eq("company_id", companyId)) == 1) {
|
|
|
- List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+ allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
deptIds = getBranchDepartment(departmentId, allDeptList);
|
|
|
} else {
|
|
|
httpRespMsg.setError("部门不存在或无查看权限");
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
}
|
|
|
+ //检查是否有查看全公司数值的权限
|
|
|
+ User curUser = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(curUser.getRoleId(), "查看全公司数值");
|
|
|
+ if (functionList.size() == 0) {
|
|
|
+ //检查是否有负责的部门
|
|
|
+ deptIds = getAllManagedDeptIdList(curUser, allDeptList);
|
|
|
+ if (deptIds.size() == 0) {
|
|
|
+ deptIds.add(-1);//没有负责的部门,无权查看
|
|
|
+ }
|
|
|
+ }
|
|
|
List<Map<String, Object>> list = departmentMapper
|
|
|
.getCustomDataByUser(deptIds, startDate, endDate, companyId, null);
|
|
|
Map<String, List<Map<String, Object>>> tempMap = new HashMap<>();
|
|
@@ -882,7 +984,21 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
public HttpRespMsg getDeptCustomDataStatistic(String startDate, String endDate, Integer departmentId, HttpServletRequest request) {
|
|
|
HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
- List<Map<String,Object>> mapList=departmentMapper.getDeptCustomDataStatistic(startDate,endDate,departmentId,companyId);
|
|
|
+
|
|
|
+ List<Integer> deptIds = null;
|
|
|
+ List<Department> allDeptList = null;
|
|
|
+
|
|
|
+ //检查是否有查看全公司数值的权限
|
|
|
+ User curUser = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(curUser.getRoleId(), "查看全公司数值");
|
|
|
+ if (functionList.size() == 0) {
|
|
|
+ //检查是否有负责的部门
|
|
|
+ deptIds = getAllManagedDeptIdList(curUser, allDeptList);
|
|
|
+ if (deptIds.size() == 0) {
|
|
|
+ deptIds.add(-1);//没有负责的部门,无权查看
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Map<String,Object>> mapList=departmentMapper.getDeptCustomDataStatistic(startDate,endDate,deptIds,companyId);
|
|
|
Map<String, List<Map<String, Object>>> tempMap = new HashMap<>();
|
|
|
List<Department> departmentList = new ArrayList<>();
|
|
|
Double totalCost = 0.0;
|