123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- 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 getRelatedProducerList(Integer companyId) {
- HttpRespMsg msg = new HttpRespMsg();
- List<AssetCustomCompany> assert_id = assetCustomCompanyMapper.selectList(new QueryWrapper<AssetCustomCompany>().eq("assert_id", companyId));
- if (assert_id.size() > 0) {
- int[] ints = assert_id.stream().mapToInt(AssetCustomCompany::getCustomId).toArray();
- List<Integer> integers = ListUtil.convertFromIntArray(ints);
- msg.data = companyMapper.selectList(new QueryWrapper<Company>().in("id", integers));
- } else {
- msg.data = new ArrayList<>();
- }
- 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 (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));
- }
- }
- msg.data = companies;
- }
- return msg;
- }
- @Override
- public HttpRespMsg detail(Integer id) {
- HttpRespMsg msg = new HttpRespMsg();
- msg.data = companyMapper.getCustomerDetailById(id);
- return msg;
- }
- @Override
- public HttpRespMsg newAdmin(Integer companyId, String username, String account, String roleName) {
- return null;
- }
- @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;
- }
- }
|