Min 1 year ago
parent
commit
5a02f55d8c

+ 14 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/entity/Product.java

@@ -7,9 +7,12 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import java.time.LocalDateTime;
 import com.baomidou.mybatisplus.annotation.TableField;
 import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
 
 /**
  * <p>
@@ -78,6 +81,8 @@ public class Product extends Model<Product> {
      * 创建时间
      */
     @TableField("create_time")
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
     private LocalDateTime createTime;
 
     /**
@@ -122,6 +127,15 @@ public class Product extends Model<Product> {
     @TableField("descs")
     private String descs;
 
+    @TableField(exist = false)
+    private String inchargerName;
+
+    @TableField(exist = false)
+    private String typeName;
+
+    @TableField(exist = false)
+    private String unitName;
+
 
     @Override
     protected Serializable pkVal() {

+ 123 - 4
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/ProductServiceImpl.java

@@ -6,13 +6,14 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.management.platform.entity.Product;
-import com.management.platform.entity.SysForm;
+import com.management.platform.entity.*;
 import com.management.platform.mapper.ProductMapper;
+import com.management.platform.mapper.SysDictMapper;
 import com.management.platform.mapper.SysFormMapper;
 import com.management.platform.mapper.UserMapper;
 import com.management.platform.service.ProductService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.management.platform.service.WxCorpInfoService;
 import com.management.platform.util.ExcelUtil;
 import com.management.platform.util.HttpRespMsg;
 import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -53,12 +54,19 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
     private SysFormMapper sysFormMapper;
     @Value(value = "${upload.path}")
     private String path;
+    @Resource
+    private WxCorpInfoService wxCorpInfoService;
+    @Resource
+    private SysDictMapper sysDictMapper;
 
     @Override
     public HttpRespMsg getList(Integer companyId,String userId, String productName, String productCode, Integer pageIndex, Integer pageSize) {
         HttpRespMsg msg=new HttpRespMsg();
         LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(Product::getCompanyId,companyId);
+        List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
+        List<SysDict> sysDictOfProductType = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ProductType"));
+        List<SysDict> sysDictOfProductUnit = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ProductUnit"));
         if(!StringUtils.isEmpty(userId)){
             queryWrapper.eq(Product::getCreatorId,userId);
         }
@@ -69,8 +77,23 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
             queryWrapper.like(Product::getProductCode,productCode);
         }
         IPage<Product> productIPage = productMapper.selectPage(new Page<>(pageIndex, pageSize), queryWrapper);
+        List<Product> records = productIPage.getRecords();
+        records.forEach(r->{
+            Optional<User> user = userList.stream().filter(u -> u.getId().equals(r.getCreatorId())).findFirst();
+            if(user.isPresent()){
+                r.setInchargerName(user.get().getName());
+            }
+            Optional<SysDict> unit = sysDictOfProductUnit.stream().filter(u -> u.getId().equals(r.getUnit())).findFirst();
+            if(unit.isPresent()){
+                r.setUnitName(unit.get().getName());
+            }
+            Optional<SysDict> type = sysDictOfProductType.stream().filter(u -> u.getId().equals(r.getCreatorId())).findFirst();
+            if(type.isPresent()){
+                r.setTypeName(type.get().getName());
+            }
+        });
         Map map=new HashMap();
-        map.put("record",productIPage.getRecords());
+        map.put("record",records);
         map.put("total",productIPage.getTotal());
         msg.setData(map);
         return msg;
@@ -81,8 +104,13 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
         HttpRespMsg msg=new HttpRespMsg();
         String fileName = multipartFile.getOriginalFilename();
         File file = new File(fileName == null ? "file" : fileName);
-        Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
+        User user = userMapper.selectById(request.getHeader("token"));
+        Integer companyId = user.getCompanyId();
+        WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, companyId));
         List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>().eq(Product::getCompanyId, companyId));
+        List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
+        List<SysDict> sysDictOfProductType = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ProductType"));
+        List<SysDict> sysDictOfProductUnit = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ProductUnit"));
         InputStream inputStream = null;
         OutputStream outputStream = null;
         try {
@@ -111,6 +139,47 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
             JSONObject configOb = JSON.parseObject(config);
             JSONArray configObJSONArray = configOb.getJSONArray("list");
             List<Product>  importProductList=new ArrayList<>();
+            List<String> userNameList=new ArrayList<>();
+            HttpRespMsg respMsg=new HttpRespMsg();
+            for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
+                HSSFRow row = sheet.getRow(rowIndex);
+                if (row == null) {
+                    continue;
+                }
+                //跳过空行
+                if (ExcelUtil.isRowEmpty(row)) {
+                    continue;
+                }
+                //获取到当前行的列数据
+                int cellNum = row.getLastCellNum();
+                for (int i = 0; i < cellNum; i++) {
+                    JSONObject item = configObJSONArray.getJSONObject(i);
+                    String modelName = item.getString("model");
+                    HSSFCell cell = row.getCell(i);
+                    if(cell!=null){
+                        switch (item.getString("type")){
+                            case "time":cell.setCellType(CellType.NUMERIC);
+                                break;
+                            default:cell.setCellType(CellType.STRING);
+                        }
+                    }
+                    if(modelName.equals("inchargerId")){
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            userNameList.add(cell.getStringCellValue());
+                        }
+                    }
+
+                }
+            }
+            System.out.println("参与搜素的人员列表"+userNameList + userNameList.size());
+            if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1&&userNameList.size()>0){
+                respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, userNameList,null);
+                if(respMsg.code.equals("0")){
+                    msg.setError("姓名为["+String.valueOf(respMsg.data)+"]的人员存在重复,请使用工号!");
+                    return msg;
+                }
+            }
+            List<User> targetUserList= (List<User>) respMsg.data;
             for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
                 HSSFRow row = sheet.getRow(rowIndex);
                 if (row == null) {
@@ -124,6 +193,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
                 int cellNum = row.getLastCellNum();
                 Product product=new Product();
                 product.setCompanyId(companyId);
+                product.setCreatorId(user.getId());
                 for (int i = 0; i < cellNum; i++) {
                     JSONObject item = configObJSONArray.getJSONObject(i);
                     String modelName = item.getString("model");
@@ -160,6 +230,53 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
                             }
                         }
                     }
+                    if(modelName.equals("inchargerId")){
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            String userName = cell.getStringCellValue();
+                            Optional<User> first;
+                            if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
+                                Optional<User> optional = targetUserList.stream().filter(tl -> tl.getName().equals(userName)).findFirst();
+                                first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(userName))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
+                            }else {
+                                first= userList.stream().filter(u -> u.getName().equals(userName)||(u.getJobNumber()!=null&&u.getJobNumber().equals(userName))).findFirst();
+                            }
+                            if (first.isPresent()) {
+                                product.setInchargerId(first.get().getId());
+                            } else {
+                                throw new Exception("["+userName+"]在系统中不存在");
+                            }
+                        }
+                    }
+                    if(modelName.equals("status")){
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            switch (cell.getStringCellValue()){
+                                case "下架":product.setStatus(0);
+                                break;
+                                case "上架":product.setStatus(1);
+                                break;
+                            }
+                        }
+                    }
+                    if(modelName.equals("type")){
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            Optional<SysDict> first = sysDictOfProductType.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
+                            if(first.isPresent()){
+                                product.setType(first.get().getId());
+                            }else {
+                                throw new Exception("产品类型["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
+                            }
+                        }
+                    }
+                    if(modelName.equals("unit")){
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            Optional<SysDict> first = sysDictOfProductUnit.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
+                            if(first.isPresent()){
+                                product.setUnit(first.get().getId());
+                            }else {
+                                throw new Exception("产品单位["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
+                            }
+                        }
+                    }
                     if(!StringUtils.isEmpty(cell.getStringCellValue())){
                         method.invoke(product,cell.getStringCellValue());
                     }
@@ -178,6 +295,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
             e.printStackTrace();
         } catch (InvocationTargetException e) {
             e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
         }
         return msg;
     }

+ 19 - 19
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -4598,7 +4598,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                     first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                     exception=1;
                                 }else {
-                                    first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                    first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                                 }
                             }
                             if (first.isPresent()) {
@@ -4607,7 +4607,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                             } else {
                                 switch (exception){
                                     case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                    case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                    case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                 }
                             }
                         }
@@ -4748,7 +4748,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                     first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                     exception=1;
                                 }else {
-                                    first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                    first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                                 }
                             }
                             Participation p = new Participation();
@@ -4759,7 +4759,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                             } else {
                                 switch (exception){
                                     case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                    case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                    case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                 }
                             }
                         }
@@ -4795,7 +4795,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                         first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                         exception=1;
                                     }else {
-                                        first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                        first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                                     }
                                 }
                                 if (first.isPresent()) {
@@ -4809,7 +4809,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                 } else {
                                     switch (exception){
                                         case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                        case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                        case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                     }
                                 }
                             }
@@ -4862,7 +4862,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                         first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                         exception=1;
                                     }else {
-                                        first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                        first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                                     }
                                 }
                                 if (first.isPresent()) {
@@ -4877,7 +4877,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                 } else {
                                     switch (exception){
                                         case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                        case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                        case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                     }
                                 }
                             }
@@ -4929,7 +4929,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                         first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                         exception=1;
                                     }else {
-                                        first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                        first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                                     }
                                 }
                                 if (first.isPresent()) {
@@ -4944,7 +4944,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                 } else {
                                     switch (exception){
                                         case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                        case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                        case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                     }
                                 }
                             }
@@ -5394,7 +5394,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                             } else {
                                 switch (exception){
                                     case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                    case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                    case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                 }
                             }
                         }
@@ -5987,7 +5987,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                 first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                 exception=1;
                             }else {
-                                first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                             }
                         }
                         Participation p = new Participation();
@@ -5998,7 +5998,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                         } else {
                             switch (exception){
                                 case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                             }
                         }
                     }
@@ -6032,7 +6032,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                         first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                         exception=1;
                                     }else {
-                                        first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                        first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                                     }
                                 }
                                 Participation p = new Participation();
@@ -6047,7 +6047,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                 } else {
                                     switch (exception){
                                         case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                        case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                        case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                     }
                                 }
                             }
@@ -6099,7 +6099,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                         first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                         exception=1;
                                     }else {
-                                        first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                        first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                                     }
                                 }
                                 ProjectAuditor p = new ProjectAuditor();
@@ -6115,7 +6115,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                 } else {
                                     switch (exception){
                                         case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                        case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                        case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                     }
                                 }
                             }
@@ -6167,7 +6167,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                         first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
                                         exception=1;
                                     }else {
-                                        first= userList.stream().filter(u -> u.getName().equals(split[0])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
+                                        first= userList.stream().filter(u -> u.getName().equals(split[1])&&(u.getJobNumber()!=null&&u.getJobNumber().equals(split[1]))).findFirst();
                                     }
                                 }
                                 ProjectCcuser p = new ProjectCcuser();
@@ -6183,7 +6183,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                                 } else {
                                     switch (exception){
                                         case 0:throw new Exception("["+split[0]+"]在系统中不存在");
-                                        case 1:throw new Exception("["+split[0]+"]在系统中不存在");
+                                        case 1:throw new Exception("["+split[1]+"]在系统中不存在");
                                     }
                                 }
                             }

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ProjectMapper.xml

@@ -1902,7 +1902,7 @@
         IFNULL(SUM(te.plan_hours),0) AS planHour
         FROM task_executor te
         LEFT JOIN task t ON t.id=te.task_id
-        LEFT JOIN USER u ON te.executor_id=u.id
+        LEFT JOIN user u ON te.executor_id=u.id
         LEFT JOIN task_group tg ON tg.id=t.group_id
         LEFT JOIN project p ON p.id=tg.project_id
         LEFT JOIN department d ON d.department_id=u.department_id