|
@@ -1,450 +1,455 @@
|
|
-package com.hssx.cloudmodel.service.impl;
|
|
|
|
-
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
|
-import com.github.pagehelper.PageInfo;
|
|
|
|
-import com.hssx.cloudmodel.constant.Constant;
|
|
|
|
-import com.hssx.cloudmodel.entity.*;
|
|
|
|
-import com.hssx.cloudmodel.entity.vo.CompanyVO;
|
|
|
|
-import com.hssx.cloudmodel.entity.vo.ProjectVO;
|
|
|
|
-import com.hssx.cloudmodel.entity.vo.UserVO;
|
|
|
|
-import com.hssx.cloudmodel.mapper.*;
|
|
|
|
-import com.hssx.cloudmodel.service.CompanyService;
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
-import com.hssx.cloudmodel.util.HttpRespMsg;
|
|
|
|
-import com.hssx.cloudmodel.util.ListUtil;
|
|
|
|
-import com.hssx.cloudmodel.util.PageUtil;
|
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-import java.util.stream.Stream;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * <p>
|
|
|
|
- * 服务实现类
|
|
|
|
- * </p>
|
|
|
|
- *
|
|
|
|
- * @author 吴涛涛
|
|
|
|
- * @since 2019-07-26
|
|
|
|
- */
|
|
|
|
-@Service
|
|
|
|
-public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {
|
|
|
|
- @Resource
|
|
|
|
- CompanyMapper companyMapper;
|
|
|
|
- @Resource
|
|
|
|
- UserMapper userMapper;
|
|
|
|
- @Resource
|
|
|
|
- LngLatCompanyMapper lngLatCompanyMapper;
|
|
|
|
- @Resource
|
|
|
|
- ProjectMapper projectMapper;
|
|
|
|
- @Resource
|
|
|
|
- MouldMapper mouldMapper;
|
|
|
|
- @Resource
|
|
|
|
- ProjectUserMapper projectUserMapper;
|
|
|
|
- @Resource
|
|
|
|
- ProjectApproveMapper projectApproveMapper;
|
|
|
|
- @Resource
|
|
|
|
- AssetCustomCompanyMapper assetCustomCompanyMapper;
|
|
|
|
- @Resource
|
|
|
|
- CustomCompanyMapper customCompanyMapper;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg addAndUpdateRole(CompanyVO companyVO, Integer flag, String companyIds) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
- Company company = new Company();
|
|
|
|
- if (flag == 0) {
|
|
|
|
- //添加公司
|
|
|
|
- QueryWrapper<Company> qw = new QueryWrapper<>();
|
|
|
|
- qw.eq("company_name", companyVO.getCompanyName());
|
|
|
|
- int count = companyMapper.selectCount(qw);
|
|
|
|
- if (count > 0) {
|
|
|
|
- msg.setError("公司已存在,请勿重复添加");
|
|
|
|
- return msg;
|
|
|
|
- } else {
|
|
|
|
- if (companyVO.getCompanyType() == 0) {
|
|
|
|
- //资产方直接添加
|
|
|
|
- BeanUtils.copyProperties(companyVO, company);
|
|
|
|
- companyMapper.insert(company);
|
|
|
|
- if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
- List<Integer> ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
- for (Integer ide : ides) {
|
|
|
|
- if (assetCustomCompanyMapper.selectCount(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()).eq("custom_id", ide)) == 0) {
|
|
|
|
- AssetCustomCompany assetCustomCompany = new AssetCustomCompany();
|
|
|
|
- assetCustomCompany.setAssertId(company.getId());
|
|
|
|
- assetCustomCompany.setCustomId(ide);
|
|
|
|
- assetCustomCompanyMapper.insert(assetCustomCompany);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else if (companyVO.getCompanyType() == 1) {
|
|
|
|
- //生产方
|
|
|
|
- BeanUtils.copyProperties(companyVO, company);
|
|
|
|
- companyMapper.insert(company);
|
|
|
|
- if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
- List<Integer> ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
- for (Integer ide : ides) {
|
|
|
|
- if (assetCustomCompanyMapper.selectCount(new QueryWrapper<AssetCustomCompany>().eq("assert_id", ide).eq("custom_id", company.getId())) == 0) {
|
|
|
|
- AssetCustomCompany assetCustomCompany = new AssetCustomCompany();
|
|
|
|
- assetCustomCompany.setAssertId(ide);
|
|
|
|
- assetCustomCompany.setCustomId(company.getId());
|
|
|
|
- assetCustomCompanyMapper.insert(assetCustomCompany);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- LngLatCompany factory = new LngLatCompany();
|
|
|
|
- factory.setxLat(companyVO.getXLat());
|
|
|
|
- factory.setyLng(companyVO.getYLng());
|
|
|
|
- factory.setCompanyId(company.getId());
|
|
|
|
- lngLatCompanyMapper.insert(factory);
|
|
|
|
- }
|
|
|
|
- msg.data = company;
|
|
|
|
- }
|
|
|
|
- } else if (flag == 1) {
|
|
|
|
- //更新公司信息
|
|
|
|
- BeanUtils.copyProperties(companyVO, company);
|
|
|
|
- if (companyVO.getCompanyType() == 0) {
|
|
|
|
- //修改资产方
|
|
|
|
- BeanUtils.copyProperties(companyVO, company);
|
|
|
|
- List<AssetCustomCompany> list = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()));
|
|
|
|
- //判断所关联的生产方是否已被应用到项目
|
|
|
|
- List<Integer> cousIds = list.stream().map(AssetCustomCompany::getCustomId).collect(Collectors.toList());
|
|
|
|
- cousIds.add(-1);
|
|
|
|
- List<Integer> noMouldCompanyIds = new ArrayList<>();
|
|
|
|
- noMouldCompanyIds = mouldMapper.selectList(new QueryWrapper<Mould>().in("produce_company_id", cousIds).eq("company_id", company.getId())).stream().map(Mould::getProduceCompanyId).collect(Collectors.toList());
|
|
|
|
- noMouldCompanyIds.add(-1);
|
|
|
|
- List<Integer> ides = new ArrayList<>();
|
|
|
|
- if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
- ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
- }
|
|
|
|
- ides.add(-1);
|
|
|
|
- if (!ides.containsAll(noMouldCompanyIds)) {
|
|
|
|
- msg.setError("当前公司所关联的生产方公司中已被用用到项目,不可执行修改操作。");
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
- //删除之前的关联公司
|
|
|
|
- assetCustomCompanyMapper.delete(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()));
|
|
|
|
- if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
- ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
- for (Integer ide : ides) {
|
|
|
|
- if (assetCustomCompanyMapper.selectCount(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()).eq("custom_id", ide)) == 0) {
|
|
|
|
- AssetCustomCompany assetCustomCompany = new AssetCustomCompany();
|
|
|
|
- assetCustomCompany.setAssertId(company.getId());
|
|
|
|
- assetCustomCompany.setCustomId(ide);
|
|
|
|
- assetCustomCompanyMapper.insert(assetCustomCompany);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- companyMapper.updateById(company);
|
|
|
|
- } else if (companyVO.getCompanyType() == 1) {
|
|
|
|
- //生产方
|
|
|
|
- BeanUtils.copyProperties(companyVO, company);
|
|
|
|
- QueryWrapper<LngLatCompany> qw = new QueryWrapper<>();
|
|
|
|
- qw.eq("company_id", companyVO.getId());
|
|
|
|
- LngLatCompany lngLatCompany = lngLatCompanyMapper.selectOne(qw);
|
|
|
|
- LngLatCompany factory = new LngLatCompany();
|
|
|
|
- factory.setxLat(companyVO.getXLat());
|
|
|
|
- factory.setyLng(companyVO.getYLng());
|
|
|
|
- factory.setCompanyId(company.getId());
|
|
|
|
- factory.setId(lngLatCompany.getId());
|
|
|
|
- lngLatCompanyMapper.updateById(factory);
|
|
|
|
- List<AssetCustomCompany> list = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("custom_id", company.getId()));
|
|
|
|
- //判断所关联的生产方是否已被应用到项目
|
|
|
|
- List<Integer> cousIds = list.stream().map(AssetCustomCompany::getAssertId).collect(Collectors.toList());
|
|
|
|
- cousIds.add(-1);
|
|
|
|
- List<Integer> noMouldCompanyIds = new ArrayList<>();
|
|
|
|
- noMouldCompanyIds = mouldMapper.selectList(new QueryWrapper<Mould>().eq("produce_company_id", company.getId()).in("company_id", cousIds)).stream().map(Mould::getCompanyId).collect(Collectors.toList());
|
|
|
|
- noMouldCompanyIds.add(-1);
|
|
|
|
- List<Integer> ides = new ArrayList<>();
|
|
|
|
- if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
- ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
- }
|
|
|
|
- ides.add(-1);
|
|
|
|
- if (!ides.containsAll(noMouldCompanyIds)) {
|
|
|
|
- msg.setError("当前公司所关联的资产方公司已被用用到项目,不可执行修改操作。");
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
- //删除之前的关联公司
|
|
|
|
- assetCustomCompanyMapper.delete(new QueryWrapper<AssetCustomCompany>().eq("custom_id", companyVO.getId()));
|
|
|
|
- if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
- ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
- for (Integer ide : ides) {
|
|
|
|
- if (assetCustomCompanyMapper.selectCount(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()).eq("custom_id", ide)) == 0) {
|
|
|
|
- AssetCustomCompany assetCustomCompany = new AssetCustomCompany();
|
|
|
|
- assetCustomCompany.setAssertId(ide);
|
|
|
|
- assetCustomCompany.setCustomId(company.getId());
|
|
|
|
- assetCustomCompanyMapper.insert(assetCustomCompany);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- companyMapper.updateById(company);
|
|
|
|
- }
|
|
|
|
- msg.data = company;
|
|
|
|
- }
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg pageList(PageUtil page, String keyName, Integer companyType) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
- List<CompanyVO> list = new ArrayList<>();
|
|
|
|
- PageHelper.startPage(page.getPageNum(), page.getPageSize());
|
|
|
|
- list = companyMapper.getCustomerListByKeyName(keyName, companyType);
|
|
|
|
- PageInfo<CompanyVO> pageInfos = new PageInfo<>(list);
|
|
|
|
- msg.data = pageInfos;
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<Company> getIdAndNamelist(User user) {
|
|
|
|
- QueryWrapper<Company> qw = new QueryWrapper<>();
|
|
|
|
- qw.select("id", "company_name", "company_type");
|
|
|
|
- List<Integer> ides = new ArrayList<>();
|
|
|
|
- if (Constant.SYS_ID.equals(user.getParentId())) {
|
|
|
|
- //此时是admin创建用户,返回可选的生产方公司,查询出当前admin的信息并获取他的公司id
|
|
|
|
- User admin = userMapper.selectOne(new QueryWrapper<User>().eq("id", user.getId()));
|
|
|
|
- ides = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>()
|
|
|
|
- .eq("assert_id", admin.getCompanyId()))
|
|
|
|
- .stream()
|
|
|
|
- .map(AssetCustomCompany::getCustomId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- ides.add(admin.getCompanyId());
|
|
|
|
- ides.add(-1);
|
|
|
|
- qw.in("id", ides);
|
|
|
|
- } else if (Constant.SYS_PARENT_ID.equals(user.getParentId())) {
|
|
|
|
- //系统管理员创建admin,返回资产方公司
|
|
|
|
- qw.eq("company_type", Constant.ASSETS_COMPANY);
|
|
|
|
- } else {
|
|
|
|
- //此时是项目经理创建其他用户
|
|
|
|
- User admin = userMapper.selectOne(new QueryWrapper<User>().eq("id", user.getParentId()));
|
|
|
|
- //获取创建他的资产方管理员公司所关联的生产方
|
|
|
|
- ides = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>()
|
|
|
|
- .eq("assert_id", admin.getCompanyId()))
|
|
|
|
- .stream()
|
|
|
|
- .map(AssetCustomCompany::getCustomId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- ides.add(admin.getCompanyId());
|
|
|
|
- ides.add(-1);
|
|
|
|
- qw.in("id", ides);
|
|
|
|
- }
|
|
|
|
- return companyMapper.selectList(qw);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<Company> addCompanyListToProject(User user) {
|
|
|
|
- QueryWrapper<Company> qw = new QueryWrapper<>();
|
|
|
|
- qw.eq("company_type", Constant.PRODUCER_COMPANY);
|
|
|
|
- return companyMapper.selectList(qw);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg getCoutomCompanyAndMouldsByUser(UserVO userVO) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
- List<CompanyVO> companyVOS = new ArrayList<>();
|
|
|
|
- List<Integer> mouldIds = new ArrayList<>();
|
|
|
|
- mouldIds.add(-1);
|
|
|
|
- User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
|
- if (Constant.SYS_ID.equals(currentUser.getParentId())) {
|
|
|
|
- //此时是admin,可看到自己公司下的模具和交于生产的公司
|
|
|
|
- QueryWrapper<Mould> qw = new QueryWrapper<>();
|
|
|
|
- List<Mould> moulds = mouldMapper.selectList(qw.eq("company_id", currentUser.getCompanyId()));
|
|
|
|
- for (Mould mould : moulds) {
|
|
|
|
- mouldIds.add(mould.getId());
|
|
|
|
- }
|
|
|
|
- companyVOS = companyMapper.getListMould(mouldIds);
|
|
|
|
- } else if (Constant.SYS_PARENT_ID.equals(currentUser.getParentId())) {
|
|
|
|
- //系统管理员创建admin,返回资产方公司
|
|
|
|
- List<Mould> moulds = mouldMapper.selectList(new QueryWrapper<Mould>());
|
|
|
|
- for (Mould mould : moulds) {
|
|
|
|
- mouldIds.add(mould.getId());
|
|
|
|
- }
|
|
|
|
- companyVOS = companyMapper.getListMould(mouldIds);
|
|
|
|
- } else {
|
|
|
|
- //此时是项目经理
|
|
|
|
- QueryWrapper<Project> qw = new QueryWrapper<>();
|
|
|
|
- qw.eq("manager_id", currentUser.getId());
|
|
|
|
- List<Integer> set = new ArrayList<>();
|
|
|
|
- set.add(-1);
|
|
|
|
- List<Project> projects = projectMapper.selectList(qw);
|
|
|
|
- if (projects.size() > 0) {
|
|
|
|
- for (Project project : projects) {
|
|
|
|
- set.add(project.getId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-// //充当普通人员参与的项目
|
|
|
|
- List<ProjectUser> projectUsers = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().eq("user_id", currentUser.getId()));
|
|
|
|
- if (projectUsers.size() > 0) {
|
|
|
|
- for (ProjectUser projectUser : projectUsers) {
|
|
|
|
- set.add(projectUser.getProjectId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //充当审批人员参与的项目
|
|
|
|
- List<ProjectApprove> projectss = projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>().eq("approver_id", currentUser.getId()));
|
|
|
|
- if (projectss.size() > 0) {
|
|
|
|
- for (ProjectApprove projectUser : projectss) {
|
|
|
|
- set.add(projectUser.getProjectId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- List<Mould> moulds = mouldMapper.selectList(new QueryWrapper<Mould>().in("project_id", set));
|
|
|
|
- for (Mould mould : moulds) {
|
|
|
|
- mouldIds.add(mould.getId());
|
|
|
|
- }
|
|
|
|
- companyVOS = companyMapper.getListMould(mouldIds);
|
|
|
|
- }
|
|
|
|
- msg.data = companyVOS;
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg relationList(Integer companyType) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
- msg.data = companyMapper.selectList(new QueryWrapper<Company>().eq("company_type", companyType));
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg detail(UserVO userVO) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
-// Company company = companyMapper.selectById(userVO.getCompanyId());
|
|
|
|
-// if (company != null) {
|
|
|
|
-// if (0 == company.getCompanyType()) {
|
|
|
|
-// //资产方
|
|
|
|
-// CompanyVO
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-// } else {
|
|
|
|
-// msg.setError("公司不存在");
|
|
|
|
-// }
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg getOwnerRelateCompany(CompanyVO companyVO) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
- User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", companyVO.getToken()));
|
|
|
|
- List<Integer> ides = new ArrayList<>();
|
|
|
|
- ides.add(-1);
|
|
|
|
- if (null == currentUser) {
|
|
|
|
- msg.setError("用户不存在或者未登录");
|
|
|
|
- return msg;
|
|
|
|
- } else {
|
|
|
|
- Company company = companyMapper.selectById(companyVO.getId());
|
|
|
|
- if (Constant.PRODUCER_COMPANY .equals(company.getCompanyType())) {
|
|
|
|
- //生产方公司,返回关联的资产方公司列表
|
|
|
|
- ides = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>()
|
|
|
|
- .eq("custom_id", company.getId()))
|
|
|
|
- .stream()
|
|
|
|
- .map(AssetCustomCompany::getAssertId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- msg.data = companyMapper.selectList(new QueryWrapper<Company>().in("id", ides));
|
|
|
|
- } else if (Constant.ASSETS_COMPANY .equals(company.getCompanyType())) {
|
|
|
|
- //资产方公司,返回关联的生产方公司列表
|
|
|
|
- ides = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>()
|
|
|
|
- .eq("assert_id", company.getId()))
|
|
|
|
- .stream()
|
|
|
|
- .map(AssetCustomCompany::getCustomId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- msg.data = companyMapper.selectList(new QueryWrapper<Company>().in("id", ides));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg getProduceCompany(UserVO userVO) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
- User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
|
- if (null == currentUser) {
|
|
|
|
- msg.setError("用户不存在或者未登录");
|
|
|
|
- return msg;
|
|
|
|
- } else {
|
|
|
|
- Integer ownerCompany = projectMapper.selectById(userVO.getProjectId()).getOwnerCompany();
|
|
|
|
- List<Integer> companyIds = customCompanyMapper.selectList(new QueryWrapper<CustomCompany>()
|
|
|
|
- .eq("project_id", userVO.getProjectId()))
|
|
|
|
- .stream()
|
|
|
|
- .map(CustomCompany::getCompanyId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- companyIds.add(ownerCompany);
|
|
|
|
- List<Company> list = companyMapper.selectList(new QueryWrapper<Company>().in("id", companyIds));
|
|
|
|
- msg.data = list;
|
|
|
|
- }
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg getProduceCompanyByCurrentUser(UserVO userVO) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
- User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
|
- List<Company> companies = new ArrayList<>();
|
|
|
|
- if (null == currentUser) {
|
|
|
|
- msg.setError("用户不存在或者未登录");
|
|
|
|
- return msg;
|
|
|
|
- } else {
|
|
|
|
- if (Constant.SYS_PARENT_ID .equals(currentUser.getParentId())) {
|
|
|
|
- companies = companyMapper.selectList(new QueryWrapper<Company>());
|
|
|
|
- } else if (Constant.SYS_ID .equals(currentUser.getParentId())) {
|
|
|
|
- if (currentUser.getSubordinateType() == 0) {
|
|
|
|
- List<Integer> customCompanyIds = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("assert_id", currentUser.getCompanyId())).stream().map(AssetCustomCompany::getCustomId).collect(Collectors.toList());
|
|
|
|
- customCompanyIds.add(currentUser.getCompanyId());
|
|
|
|
- companies = companyMapper.selectList(new QueryWrapper<Company>().in("id", customCompanyIds));
|
|
|
|
- } else if (currentUser.getSubordinateType() == 1) {
|
|
|
|
- List<Integer> assetCompanyIds = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("custom_id", currentUser.getCompanyId())).stream().map(AssetCustomCompany::getAssertId).collect(Collectors.toList());
|
|
|
|
- assetCompanyIds.add(currentUser.getCompanyId());
|
|
|
|
- companies = companyMapper.selectList(new QueryWrapper<Company>().in("id", assetCompanyIds));
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- List<Integer> projectIds = new ArrayList<>();
|
|
|
|
- QueryWrapper<Project> qwPro = new QueryWrapper<>();
|
|
|
|
- qwPro.eq("manager_id", currentUser.getId());
|
|
|
|
- projectIds = projectMapper.selectList(qwPro).stream().map(Project::getId).collect(Collectors.toList());
|
|
|
|
- projectIds.add(-1);
|
|
|
|
- //项目经理或者普通用户
|
|
|
|
- projectIds.addAll(projectUserMapper.selectList(new QueryWrapper<ProjectUser>()
|
|
|
|
- .eq("user_id", currentUser.getId()))
|
|
|
|
- .stream()
|
|
|
|
- .map(ProjectUser::getProjectId)
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
- //作为审批人
|
|
|
|
- projectIds.addAll(projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>()
|
|
|
|
- .eq("approver_id", currentUser.getId()))
|
|
|
|
- .stream()
|
|
|
|
- .map(ProjectApprove::getProjectId)
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
- String keyName = null;
|
|
|
|
- List<ProjectVO> projects = projectMapper.getProjectListByUidInProjectIds(keyName, projectIds);
|
|
|
|
- List<Integer> ids = projects.stream().map(Project::getOwnerCompany).collect(Collectors.toList());
|
|
|
|
- ids.add(-1);
|
|
|
|
- companies = companyMapper.selectList(new QueryWrapper<Company>().in("id", ids));
|
|
|
|
- }
|
|
|
|
- msg.data = companies;
|
|
|
|
- }
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public HttpRespMsg deleteById(Integer id) {
|
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
- Integer count = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", id));
|
|
|
|
- if (count > 0) {
|
|
|
|
- msg.setError("该公司已被应用到用户中,暂不提供删除操作");
|
|
|
|
- return msg;
|
|
|
|
- } else {
|
|
|
|
- Company company = companyMapper.selectById(id);
|
|
|
|
- companyMapper.deleteById(id);
|
|
|
|
- if (company.getCompanyType() == 0) {
|
|
|
|
- //删除资产方关联的生产方公司
|
|
|
|
- assetCustomCompanyMapper.delete(new QueryWrapper<AssetCustomCompany>().eq("assert_id", id));
|
|
|
|
- } else if (company.getCompanyType() == 1) {
|
|
|
|
- assetCustomCompanyMapper.delete(new QueryWrapper<AssetCustomCompany>().eq("custom_id", id));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+package com.hssx.cloudmodel.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
+import com.hssx.cloudmodel.constant.Constant;
|
|
|
|
+import com.hssx.cloudmodel.entity.*;
|
|
|
|
+import com.hssx.cloudmodel.entity.vo.CompanyVO;
|
|
|
|
+import com.hssx.cloudmodel.entity.vo.ProjectVO;
|
|
|
|
+import com.hssx.cloudmodel.entity.vo.UserVO;
|
|
|
|
+import com.hssx.cloudmodel.mapper.*;
|
|
|
|
+import com.hssx.cloudmodel.service.CompanyService;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.hssx.cloudmodel.util.HttpRespMsg;
|
|
|
|
+import com.hssx.cloudmodel.util.ListUtil;
|
|
|
|
+import com.hssx.cloudmodel.util.PageUtil;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author 吴涛涛
|
|
|
|
+ * @since 2019-07-26
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {
|
|
|
|
+ @Resource
|
|
|
|
+ CompanyMapper companyMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ UserMapper userMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ LngLatCompanyMapper lngLatCompanyMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ ProjectMapper projectMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ MouldMapper mouldMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ ProjectUserMapper projectUserMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ ProjectApproveMapper projectApproveMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ AssetCustomCompanyMapper assetCustomCompanyMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ CustomCompanyMapper customCompanyMapper;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg addAndUpdateRole(CompanyVO companyVO, Integer flag, String companyIds) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ Company company = new Company();
|
|
|
|
+ if (flag == 0) {
|
|
|
|
+ //添加公司
|
|
|
|
+ QueryWrapper<Company> qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("company_name", companyVO.getCompanyName());
|
|
|
|
+ int count = companyMapper.selectCount(qw);
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ msg.setError("公司已存在,请勿重复添加");
|
|
|
|
+ return msg;
|
|
|
|
+ } else {
|
|
|
|
+ if (companyVO.getCompanyType() == 0) {
|
|
|
|
+ //资产方直接添加
|
|
|
|
+ BeanUtils.copyProperties(companyVO, company);
|
|
|
|
+ companyMapper.insert(company);
|
|
|
|
+ if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
+ List<Integer> ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
+ for (Integer ide : ides) {
|
|
|
|
+ if (assetCustomCompanyMapper.selectCount(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()).eq("custom_id", ide)) == 0) {
|
|
|
|
+ AssetCustomCompany assetCustomCompany = new AssetCustomCompany();
|
|
|
|
+ assetCustomCompany.setAssertId(company.getId());
|
|
|
|
+ assetCustomCompany.setCustomId(ide);
|
|
|
|
+ assetCustomCompanyMapper.insert(assetCustomCompany);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (companyVO.getCompanyType() == 1) {
|
|
|
|
+ //生产方
|
|
|
|
+ BeanUtils.copyProperties(companyVO, company);
|
|
|
|
+ companyMapper.insert(company);
|
|
|
|
+ if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
+ List<Integer> ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
+ for (Integer ide : ides) {
|
|
|
|
+ if (assetCustomCompanyMapper.selectCount(new QueryWrapper<AssetCustomCompany>().eq("assert_id", ide).eq("custom_id", company.getId())) == 0) {
|
|
|
|
+ AssetCustomCompany assetCustomCompany = new AssetCustomCompany();
|
|
|
|
+ assetCustomCompany.setAssertId(ide);
|
|
|
|
+ assetCustomCompany.setCustomId(company.getId());
|
|
|
|
+ assetCustomCompanyMapper.insert(assetCustomCompany);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ LngLatCompany factory = new LngLatCompany();
|
|
|
|
+ factory.setxLat(companyVO.getXLat());
|
|
|
|
+ factory.setyLng(companyVO.getYLng());
|
|
|
|
+ factory.setCompanyId(company.getId());
|
|
|
|
+ lngLatCompanyMapper.insert(factory);
|
|
|
|
+ }
|
|
|
|
+ msg.data = company;
|
|
|
|
+ }
|
|
|
|
+ } else if (flag == 1) {
|
|
|
|
+ //更新公司信息
|
|
|
|
+ BeanUtils.copyProperties(companyVO, company);
|
|
|
|
+ if (companyVO.getCompanyType() == 0) {
|
|
|
|
+ //修改资产方
|
|
|
|
+ BeanUtils.copyProperties(companyVO, company);
|
|
|
|
+ List<AssetCustomCompany> list = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()));
|
|
|
|
+ //判断所关联的生产方是否已被应用到项目
|
|
|
|
+ List<Integer> cousIds = list.stream().map(AssetCustomCompany::getCustomId).collect(Collectors.toList());
|
|
|
|
+ cousIds.add(-1);
|
|
|
|
+ List<Integer> noMouldCompanyIds = new ArrayList<>();
|
|
|
|
+ noMouldCompanyIds = mouldMapper.selectList(new QueryWrapper<Mould>().in("produce_company_id", cousIds).eq("company_id", company.getId())).stream().map(Mould::getProduceCompanyId).collect(Collectors.toList());
|
|
|
|
+ noMouldCompanyIds.add(-1);
|
|
|
|
+ List<Integer> ides = new ArrayList<>();
|
|
|
|
+ if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
+ ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
+ }
|
|
|
|
+ ides.add(-1);
|
|
|
|
+ if (!ides.containsAll(noMouldCompanyIds)) {
|
|
|
|
+ msg.setError("当前公司所关联的生产方公司中已被用用到项目,不可执行修改操作。");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ //删除之前的关联公司
|
|
|
|
+ assetCustomCompanyMapper.delete(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()));
|
|
|
|
+ if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
+ ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
+ for (Integer ide : ides) {
|
|
|
|
+ if (assetCustomCompanyMapper.selectCount(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()).eq("custom_id", ide)) == 0) {
|
|
|
|
+ AssetCustomCompany assetCustomCompany = new AssetCustomCompany();
|
|
|
|
+ assetCustomCompany.setAssertId(company.getId());
|
|
|
|
+ assetCustomCompany.setCustomId(ide);
|
|
|
|
+ assetCustomCompanyMapper.insert(assetCustomCompany);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ companyMapper.updateById(company);
|
|
|
|
+ } else if (companyVO.getCompanyType() == 1) {
|
|
|
|
+ //生产方
|
|
|
|
+ BeanUtils.copyProperties(companyVO, company);
|
|
|
|
+ QueryWrapper<LngLatCompany> qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("company_id", companyVO.getId());
|
|
|
|
+ LngLatCompany lngLatCompany = lngLatCompanyMapper.selectOne(qw);
|
|
|
|
+ LngLatCompany factory = new LngLatCompany();
|
|
|
|
+ factory.setxLat(companyVO.getXLat());
|
|
|
|
+ factory.setyLng(companyVO.getYLng());
|
|
|
|
+ factory.setCompanyId(company.getId());
|
|
|
|
+ factory.setId(lngLatCompany.getId());
|
|
|
|
+ lngLatCompanyMapper.updateById(factory);
|
|
|
|
+ List<AssetCustomCompany> list = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("custom_id", company.getId()));
|
|
|
|
+ //判断所关联的生产方是否已被应用到项目
|
|
|
|
+ List<Integer> cousIds = list.stream().map(AssetCustomCompany::getAssertId).collect(Collectors.toList());
|
|
|
|
+ cousIds.add(-1);
|
|
|
|
+ List<Integer> noMouldCompanyIds = new ArrayList<>();
|
|
|
|
+ noMouldCompanyIds = mouldMapper.selectList(new QueryWrapper<Mould>().eq("produce_company_id", company.getId()).in("company_id", cousIds)).stream().map(Mould::getCompanyId).collect(Collectors.toList());
|
|
|
|
+ noMouldCompanyIds.add(-1);
|
|
|
|
+ List<Integer> ides = new ArrayList<>();
|
|
|
|
+ if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
+ ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
+ }
|
|
|
|
+ ides.add(-1);
|
|
|
|
+ if (!ides.containsAll(noMouldCompanyIds)) {
|
|
|
|
+ msg.setError("当前公司所关联的资产方公司已被用用到项目,不可执行修改操作。");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ //删除之前的关联公司
|
|
|
|
+ assetCustomCompanyMapper.delete(new QueryWrapper<AssetCustomCompany>().eq("custom_id", companyVO.getId()));
|
|
|
|
+ if (companyIds != null && !"".equals(companyIds)) {
|
|
|
|
+ ides = ListUtil.convertIntegerIdsArrayToList(companyIds);
|
|
|
|
+ for (Integer ide : ides) {
|
|
|
|
+ if (assetCustomCompanyMapper.selectCount(new QueryWrapper<AssetCustomCompany>().eq("assert_id", company.getId()).eq("custom_id", ide)) == 0) {
|
|
|
|
+ AssetCustomCompany assetCustomCompany = new AssetCustomCompany();
|
|
|
|
+ assetCustomCompany.setAssertId(ide);
|
|
|
|
+ assetCustomCompany.setCustomId(company.getId());
|
|
|
|
+ assetCustomCompanyMapper.insert(assetCustomCompany);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ companyMapper.updateById(company);
|
|
|
|
+ //修改项目关联的生产方公司表信息(以防止后续查询修改后公司名字与之前库里存的公司名不一样的问题)
|
|
|
|
+ CustomCompany customCompany = new CustomCompany();
|
|
|
|
+ customCompany.setCompanyId(company.getId());
|
|
|
|
+ customCompany.setCompanyName(company.getCompanyName());
|
|
|
|
+ customCompanyMapper.update(customCompany,new QueryWrapper<CustomCompany>().eq("company_id",company.getId()));
|
|
|
|
+ }
|
|
|
|
+ msg.data = company;
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg pageList(PageUtil page, String keyName, Integer companyType) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ List<CompanyVO> list = new ArrayList<>();
|
|
|
|
+ PageHelper.startPage(page.getPageNum(), page.getPageSize());
|
|
|
|
+ list = companyMapper.getCustomerListByKeyName(keyName, companyType);
|
|
|
|
+ PageInfo<CompanyVO> pageInfos = new PageInfo<>(list);
|
|
|
|
+ msg.data = pageInfos;
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Company> getIdAndNamelist(User user) {
|
|
|
|
+ QueryWrapper<Company> qw = new QueryWrapper<>();
|
|
|
|
+ qw.select("id", "company_name", "company_type");
|
|
|
|
+ List<Integer> ides = new ArrayList<>();
|
|
|
|
+ if (Constant.SYS_ID.equals(user.getParentId())) {
|
|
|
|
+ //此时是admin创建用户,返回可选的生产方公司,查询出当前admin的信息并获取他的公司id
|
|
|
|
+ User admin = userMapper.selectOne(new QueryWrapper<User>().eq("id", user.getId()));
|
|
|
|
+ ides = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>()
|
|
|
|
+ .eq("assert_id", admin.getCompanyId()))
|
|
|
|
+ .stream()
|
|
|
|
+ .map(AssetCustomCompany::getCustomId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ ides.add(admin.getCompanyId());
|
|
|
|
+ ides.add(-1);
|
|
|
|
+ qw.in("id", ides);
|
|
|
|
+ } else if (Constant.SYS_PARENT_ID.equals(user.getParentId())) {
|
|
|
|
+ //系统管理员创建admin,返回资产方公司
|
|
|
|
+ qw.eq("company_type", Constant.ASSETS_COMPANY);
|
|
|
|
+ } else {
|
|
|
|
+ //此时是项目经理创建其他用户
|
|
|
|
+ User admin = userMapper.selectOne(new QueryWrapper<User>().eq("id", user.getParentId()));
|
|
|
|
+ //获取创建他的资产方管理员公司所关联的生产方
|
|
|
|
+ ides = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>()
|
|
|
|
+ .eq("assert_id", admin.getCompanyId()))
|
|
|
|
+ .stream()
|
|
|
|
+ .map(AssetCustomCompany::getCustomId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ ides.add(admin.getCompanyId());
|
|
|
|
+ ides.add(-1);
|
|
|
|
+ qw.in("id", ides);
|
|
|
|
+ }
|
|
|
|
+ return companyMapper.selectList(qw);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Company> addCompanyListToProject(User user) {
|
|
|
|
+ QueryWrapper<Company> qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("company_type", Constant.PRODUCER_COMPANY);
|
|
|
|
+ return companyMapper.selectList(qw);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getCoutomCompanyAndMouldsByUser(UserVO userVO) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ List<CompanyVO> companyVOS = new ArrayList<>();
|
|
|
|
+ List<Integer> mouldIds = new ArrayList<>();
|
|
|
|
+ mouldIds.add(-1);
|
|
|
|
+ User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
|
+ if (Constant.SYS_ID.equals(currentUser.getParentId())) {
|
|
|
|
+ //此时是admin,可看到自己公司下的模具和交于生产的公司
|
|
|
|
+ QueryWrapper<Mould> qw = new QueryWrapper<>();
|
|
|
|
+ List<Mould> moulds = mouldMapper.selectList(qw.eq("company_id", currentUser.getCompanyId()));
|
|
|
|
+ for (Mould mould : moulds) {
|
|
|
|
+ mouldIds.add(mould.getId());
|
|
|
|
+ }
|
|
|
|
+ companyVOS = companyMapper.getListMould(mouldIds);
|
|
|
|
+ } else if (Constant.SYS_PARENT_ID.equals(currentUser.getParentId())) {
|
|
|
|
+ //系统管理员创建admin,返回资产方公司
|
|
|
|
+ List<Mould> moulds = mouldMapper.selectList(new QueryWrapper<Mould>());
|
|
|
|
+ for (Mould mould : moulds) {
|
|
|
|
+ mouldIds.add(mould.getId());
|
|
|
|
+ }
|
|
|
|
+ companyVOS = companyMapper.getListMould(mouldIds);
|
|
|
|
+ } else {
|
|
|
|
+ //此时是项目经理
|
|
|
|
+ QueryWrapper<Project> qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("manager_id", currentUser.getId());
|
|
|
|
+ List<Integer> set = new ArrayList<>();
|
|
|
|
+ set.add(-1);
|
|
|
|
+ List<Project> projects = projectMapper.selectList(qw);
|
|
|
|
+ if (projects.size() > 0) {
|
|
|
|
+ for (Project project : projects) {
|
|
|
|
+ set.add(project.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+// //充当普通人员参与的项目
|
|
|
|
+ List<ProjectUser> projectUsers = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().eq("user_id", currentUser.getId()));
|
|
|
|
+ if (projectUsers.size() > 0) {
|
|
|
|
+ for (ProjectUser projectUser : projectUsers) {
|
|
|
|
+ set.add(projectUser.getProjectId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //充当审批人员参与的项目
|
|
|
|
+ List<ProjectApprove> projectss = projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>().eq("approver_id", currentUser.getId()));
|
|
|
|
+ if (projectss.size() > 0) {
|
|
|
|
+ for (ProjectApprove projectUser : projectss) {
|
|
|
|
+ set.add(projectUser.getProjectId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<Mould> moulds = mouldMapper.selectList(new QueryWrapper<Mould>().in("project_id", set));
|
|
|
|
+ for (Mould mould : moulds) {
|
|
|
|
+ mouldIds.add(mould.getId());
|
|
|
|
+ }
|
|
|
|
+ companyVOS = companyMapper.getListMould(mouldIds);
|
|
|
|
+ }
|
|
|
|
+ msg.data = companyVOS;
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg relationList(Integer companyType) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.data = companyMapper.selectList(new QueryWrapper<Company>().eq("company_type", companyType));
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg detail(UserVO userVO) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+// Company company = companyMapper.selectById(userVO.getCompanyId());
|
|
|
|
+// if (company != null) {
|
|
|
|
+// if (0 == company.getCompanyType()) {
|
|
|
|
+// //资产方
|
|
|
|
+// CompanyVO
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// } else {
|
|
|
|
+// msg.setError("公司不存在");
|
|
|
|
+// }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getOwnerRelateCompany(CompanyVO companyVO) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", companyVO.getToken()));
|
|
|
|
+ List<Integer> ides = new ArrayList<>();
|
|
|
|
+ ides.add(-1);
|
|
|
|
+ if (null == currentUser) {
|
|
|
|
+ msg.setError("用户不存在或者未登录");
|
|
|
|
+ return msg;
|
|
|
|
+ } else {
|
|
|
|
+ Company company = companyMapper.selectById(companyVO.getId());
|
|
|
|
+ if (Constant.PRODUCER_COMPANY .equals(company.getCompanyType())) {
|
|
|
|
+ //生产方公司,返回关联的资产方公司列表
|
|
|
|
+ ides = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>()
|
|
|
|
+ .eq("custom_id", company.getId()))
|
|
|
|
+ .stream()
|
|
|
|
+ .map(AssetCustomCompany::getAssertId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ msg.data = companyMapper.selectList(new QueryWrapper<Company>().in("id", ides));
|
|
|
|
+ } else if (Constant.ASSETS_COMPANY .equals(company.getCompanyType())) {
|
|
|
|
+ //资产方公司,返回关联的生产方公司列表
|
|
|
|
+ ides = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>()
|
|
|
|
+ .eq("assert_id", company.getId()))
|
|
|
|
+ .stream()
|
|
|
|
+ .map(AssetCustomCompany::getCustomId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ msg.data = companyMapper.selectList(new QueryWrapper<Company>().in("id", ides));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getProduceCompany(UserVO userVO) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
|
+ if (null == currentUser) {
|
|
|
|
+ msg.setError("用户不存在或者未登录");
|
|
|
|
+ return msg;
|
|
|
|
+ } else {
|
|
|
|
+ Integer ownerCompany = projectMapper.selectById(userVO.getProjectId()).getOwnerCompany();
|
|
|
|
+ List<Integer> companyIds = customCompanyMapper.selectList(new QueryWrapper<CustomCompany>()
|
|
|
|
+ .eq("project_id", userVO.getProjectId()))
|
|
|
|
+ .stream()
|
|
|
|
+ .map(CustomCompany::getCompanyId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ companyIds.add(ownerCompany);
|
|
|
|
+ List<Company> list = companyMapper.selectList(new QueryWrapper<Company>().in("id", companyIds));
|
|
|
|
+ msg.data = list;
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getProduceCompanyByCurrentUser(UserVO userVO) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
|
+ List<Company> companies = new ArrayList<>();
|
|
|
|
+ if (null == currentUser) {
|
|
|
|
+ msg.setError("用户不存在或者未登录");
|
|
|
|
+ return msg;
|
|
|
|
+ } else {
|
|
|
|
+ if (Constant.SYS_PARENT_ID .equals(currentUser.getParentId())) {
|
|
|
|
+ companies = companyMapper.selectList(new QueryWrapper<Company>());
|
|
|
|
+ } else if (Constant.SYS_ID .equals(currentUser.getParentId())) {
|
|
|
|
+ if (currentUser.getSubordinateType() == 0) {
|
|
|
|
+ List<Integer> customCompanyIds = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("assert_id", currentUser.getCompanyId())).stream().map(AssetCustomCompany::getCustomId).collect(Collectors.toList());
|
|
|
|
+ customCompanyIds.add(currentUser.getCompanyId());
|
|
|
|
+ companies = companyMapper.selectList(new QueryWrapper<Company>().in("id", customCompanyIds));
|
|
|
|
+ } else if (currentUser.getSubordinateType() == 1) {
|
|
|
|
+ List<Integer> assetCompanyIds = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("custom_id", currentUser.getCompanyId())).stream().map(AssetCustomCompany::getAssertId).collect(Collectors.toList());
|
|
|
|
+ assetCompanyIds.add(currentUser.getCompanyId());
|
|
|
|
+ companies = companyMapper.selectList(new QueryWrapper<Company>().in("id", assetCompanyIds));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ List<Integer> projectIds = new ArrayList<>();
|
|
|
|
+ QueryWrapper<Project> qwPro = new QueryWrapper<>();
|
|
|
|
+ qwPro.eq("manager_id", currentUser.getId());
|
|
|
|
+ projectIds = projectMapper.selectList(qwPro).stream().map(Project::getId).collect(Collectors.toList());
|
|
|
|
+ projectIds.add(-1);
|
|
|
|
+ //项目经理或者普通用户
|
|
|
|
+ projectIds.addAll(projectUserMapper.selectList(new QueryWrapper<ProjectUser>()
|
|
|
|
+ .eq("user_id", currentUser.getId()))
|
|
|
|
+ .stream()
|
|
|
|
+ .map(ProjectUser::getProjectId)
|
|
|
|
+ .collect(Collectors.toList()));
|
|
|
|
+ //作为审批人
|
|
|
|
+ projectIds.addAll(projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>()
|
|
|
|
+ .eq("approver_id", currentUser.getId()))
|
|
|
|
+ .stream()
|
|
|
|
+ .map(ProjectApprove::getProjectId)
|
|
|
|
+ .collect(Collectors.toList()));
|
|
|
|
+ String keyName = null;
|
|
|
|
+ List<ProjectVO> projects = projectMapper.getProjectListByUidInProjectIds(keyName, projectIds);
|
|
|
|
+ List<Integer> ids = projects.stream().map(Project::getOwnerCompany).collect(Collectors.toList());
|
|
|
|
+ ids.add(-1);
|
|
|
|
+ companies = companyMapper.selectList(new QueryWrapper<Company>().in("id", ids));
|
|
|
|
+ }
|
|
|
|
+ msg.data = companies;
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg deleteById(Integer id) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ Integer count = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", id));
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ msg.setError("该公司已被应用到用户中,暂不提供删除操作");
|
|
|
|
+ return msg;
|
|
|
|
+ } else {
|
|
|
|
+ Company company = companyMapper.selectById(id);
|
|
|
|
+ companyMapper.deleteById(id);
|
|
|
|
+ if (company.getCompanyType() == 0) {
|
|
|
|
+ //删除资产方关联的生产方公司
|
|
|
|
+ assetCustomCompanyMapper.delete(new QueryWrapper<AssetCustomCompany>().eq("assert_id", id));
|
|
|
|
+ } else if (company.getCompanyType() == 1) {
|
|
|
|
+ assetCustomCompanyMapper.delete(new QueryWrapper<AssetCustomCompany>().eq("custom_id", id));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|