package com.zt.life.sys.controller;
|
|
import cn.hutool.core.convert.Convert;
|
import com.alibaba.excel.util.StringUtils;
|
import com.zt.common.servlet.Result;
|
import com.zt.core.context.UserContext;
|
import com.zt.core.sys.model.SysDept;
|
import com.zt.life.core.enums.CompanyType;
|
import com.zt.modules.sys.service.SysDeptService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* 维修单位
|
*
|
* @author hehz
|
* @since 1.0.0 2020-09-01
|
*/
|
@RestController
|
@RequestMapping("/sys/repairer")
|
@Api(tags = "维修单位")
|
public class RepairerController {
|
|
@Value("${zt.oss.local-area}")
|
private String localrea;
|
|
@Autowired
|
private SysDeptService sysDeptService;
|
|
@GetMapping("list")
|
@ApiOperation("列表")
|
public Result<List<SysDept>> list() {
|
List<SysDept> list = sysDeptService.getTenantAll();
|
List<SysDept> collect = list
|
.stream()
|
.filter(dept -> (CompanyType.YJS.getValue().equals(dept.getNature()) && dept.isCompany())
|
|| (CompanyType.CJ.getValue().equals(dept.getNature()) && dept.isCompany() && dept.getPid().toString().equals("1271368584383188993"))
|
|| "HBDD".equals(dept.getCode()))
|
.collect(Collectors.toList());
|
return Result.ok(collect);
|
}
|
|
@GetMapping("listRepairerByCriteria")
|
@ApiOperation("列表厂家")
|
public Result<List<SysDept>> listRepairerByCriteria() {
|
List<SysDept> list = sysDeptService.getTenantAll();
|
|
// String factoryId = UserContext.getSessionValue(UserContext.FACTORY_ID);
|
// String shipId = UserContext.getSessionValue(UserContext.SHIP_ID);
|
// String regionFlag = UserContext.getSessionValue(UserContext.REGION_FLAG);
|
//
|
// /*
|
// 如果属于某厂家,就返回此厂家
|
// */
|
// if (!StringUtils.isEmpty(factoryId)) {
|
// List<SysDept> collect = list
|
// .stream()
|
// .filter(dept -> {
|
// return dept.getId().equals(new Long(factoryId));
|
// })
|
// .collect(Collectors.toList());
|
// return Result.ok(collect);
|
// }
|
//
|
// if (!StringUtils.isEmpty(regionFlag)) {
|
// List<SysDept> collectRegion = list
|
// .stream()
|
// .filter(dept -> {
|
// return dept.getCode().equals(regionFlag);
|
// })
|
// .collect(Collectors.toList());
|
//
|
// if(!collectRegion.isEmpty()){
|
// final SysDept regionSysDept=collectRegion.get(0);
|
//
|
// List<SysDept> collect = list
|
// .stream()
|
// .filter(dept -> {
|
// String pids=dept.getPids();
|
// String[] pidsArray=pids.split(",");
|
// for(String pid:pidsArray){
|
// if(pid.equals(regionSysDept.getId().toString()) && CompanyType.CJ.getValue().equals(dept.getNature())){
|
// return true;
|
// }
|
// }
|
//
|
// return false;
|
// })
|
// .collect(Collectors.toList());
|
// return Result.ok(collect);
|
// }
|
//
|
// }
|
|
List<SysDept> collect;
|
// if (!StringUtils.isEmpty(localrea) && !"all".equals(localrea)) {
|
// List<SysDept> collectRegion = list
|
// .stream()
|
// .filter(dept -> {
|
// return dept.getCode().equals(localrea+"cj");
|
// })
|
// .collect(Collectors.toList());
|
// String pid = collectRegion.get(0).getId().toString();
|
// collect = list
|
// .stream()
|
// .filter(dept -> (CompanyType.YJS.getValue().equals(dept.getNature()) && dept.isCompany())
|
// || (CompanyType.CJ.getValue().equals(dept.getNature()) && dept.isCompany() && dept.getPid().toString().equals(pid))
|
// || "HBDD".equals(dept.getCode()))
|
// .collect(Collectors.toList());
|
// }else{
|
// collect = list
|
// .stream()
|
// .filter(dept -> (CompanyType.YJS.getValue().equals(dept.getNature()) && dept.isCompany())
|
// || (CompanyType.CJ.getValue().equals(dept.getNature()) && dept.isCompany() /*&& dept.getPid().toString().equals("1271368584383188993") */)
|
// || "HBDD".equals(dept.getCode()))
|
// .collect(Collectors.toList());
|
// }
|
|
collect = list
|
.stream()
|
.filter(dept -> "cj".equals(dept.getNature()))
|
.collect(Collectors.toList());
|
return Result.ok(collect);
|
}
|
|
|
@GetMapping("listTingTeamByCriteria")
|
@ApiOperation("列表T队")
|
public Result<List<SysDept>> listTingTeamByCriteria() {
|
List<SysDept> list = sysDeptService.getTenantAll();
|
List<SysDept> collect;
|
/*
|
if (!StringUtils.isEmpty(localrea) && !"all".equals(localrea)) {
|
List<SysDept> collectRegion = list
|
.stream()
|
.filter(dept -> {
|
return dept.getCode().equals(localrea+"td");
|
})
|
.collect(Collectors.toList());
|
String pid = collectRegion.get(0).getId().toString();
|
collect = list
|
.stream()
|
.filter(dept -> (
|
(CompanyType.TD.getValue().equals(dept.getNature()) && dept.isCompany() && dept.getPid().toString().equals(pid))
|
))
|
.collect(Collectors.toList());
|
}else{
|
collect = list
|
.stream()
|
.filter(dept -> (
|
(CompanyType.TD.getValue().equals(dept.getNature()) && dept.isCompany() *//*&& dept.getPid().toString().equals("1271368584383188993") *//*)
|
))
|
.collect(Collectors.toList());
|
}*/
|
collect = list
|
.stream()
|
.filter(dept -> "td".equals(dept.getNature()))
|
.collect(Collectors.toList());
|
return Result.ok(collect);
|
}
|
|
@GetMapping("listTingTeamByCriteriaOld")
|
@ApiOperation("列表T队")
|
public Result<List<SysDept>> listTingTeamByCriteriaOld() {
|
List<SysDept> list = sysDeptService.getTenantAll();
|
|
String factoryId = "cj".equals(UserContext.getUser().getUnitType())?UserContext.getUser().getCompanyId().toString():"";
|
String shipId = "t".equals(UserContext.getUser().getUnitType())?UserContext.getUser().getCompanyId().toString():"";
|
String regionFlag = UserContext.getUser().getArea();
|
|
/*
|
如果属于某厂家,就返回空list
|
*/
|
if (!StringUtils.isEmpty(factoryId)) {
|
return Result.ok(new ArrayList<SysDept>());
|
}
|
|
/*
|
如果属于某T,就返回此T下面的TD
|
*/
|
if (!StringUtils.isEmpty(shipId)) {
|
List<SysDept> collectT = list
|
.stream()
|
.filter(dept -> {
|
return dept.getId().equals(new Long(shipId));
|
})
|
.collect(Collectors.toList());
|
|
if(!collectT.isEmpty()){
|
final SysDept tSysDept=collectT.get(0);;
|
|
List<SysDept> collect = list
|
.stream()
|
.filter(dept -> {
|
String pids=dept.getPids();
|
String[] pidsArray=pids.split(",");
|
for(String pid:pidsArray){
|
if(pid.equals(tSysDept.getId().toString()) && CompanyType.TD.getValue().equals(dept.getNature())){
|
return true;
|
}
|
}
|
|
return false;
|
})
|
.collect(Collectors.toList());
|
return Result.ok(collect);
|
}
|
|
}
|
|
if (!StringUtils.isEmpty(regionFlag)) {
|
List<SysDept> collectRegion = list
|
.stream()
|
.filter(dept -> {
|
return dept.getCode().equals(regionFlag);
|
})
|
.collect(Collectors.toList());
|
|
if(!collectRegion.isEmpty()){
|
final SysDept regionSysDept=collectRegion.get(0);;
|
|
List<SysDept> collect = list
|
.stream()
|
.filter(dept -> {
|
String pids=dept.getPids();
|
String[] pidsArray=pids.split(",");
|
for(String pid:pidsArray){
|
if(pid.equals(regionSysDept.getId().toString()) && CompanyType.TD.getValue().equals(dept.getNature())){
|
return true;
|
}
|
}
|
|
return false;
|
})
|
.collect(Collectors.toList());
|
return Result.ok(collect);
|
}
|
|
}
|
|
List<SysDept> collect = list
|
.stream()
|
.filter(dept -> (CompanyType.TD.getValue().equals(dept.getNature()) )
|
)
|
.collect(Collectors.toList());
|
return Result.ok(collect);
|
|
}
|
|
@GetMapping("lists")
|
@ApiOperation("列表")
|
public Result<List<SysDept>> lists() {
|
List<SysDept> list = sysDeptService.getTenantAll();
|
List<SysDept> collect = list
|
.stream()
|
.filter(dept -> CompanyType.YJS.getValue().equals(dept.getNature())
|
|| CompanyType.CJ.getValue().equals(dept.getNature()) || "hbdd".equals(dept.getCode()))
|
.collect(Collectors.toList());
|
return Result.ok(collect);
|
}
|
}
|