123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- package com.hz.employmentsite.services.impl.companyService;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.hz.employmentsite.filter.exception.BaseException;
- import com.hz.employmentsite.mapper.*;
- import com.hz.employmentsite.mapper.cquery.CompanyCQuery;
- import com.hz.employmentsite.mapper.cquery.LabelCQuery;
- import com.hz.employmentsite.model.*;
- import com.hz.employmentsite.services.service.companyService.CompanyService;
- import com.hz.employmentsite.services.service.companyService.FirmService;
- import com.hz.employmentsite.services.service.companyService.IndustryService;
- import com.hz.employmentsite.services.service.system.DictionaryService;
- import com.hz.employmentsite.util.StringUtils;
- import com.hz.employmentsite.vo.companyService.AppCompanyPostVo;
- import com.hz.employmentsite.vo.companyService.CompanyVo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service("CompanyService")
- public class CompanyServiceImpl implements CompanyService {
- @Autowired
- private CompanyCQuery companyCQuery;
- @Autowired
- private StringUtils stringUtils;
- @Autowired
- private DictionaryService dictionaryService;
- @Autowired
- private PcCompanyMapper pcCompanyMapper;
- @Autowired
- private AreaCodeMapper areaCodeMapper;
- @Autowired
- private PcSiteMapper siteMapper;
- @Autowired
- private PcPostMapper pcPostMapper;
- @Autowired
- private PcSiteUserMapper pcSiteUserMapper;
- @Autowired
- private FirmService firmService;
- @Autowired
- private IndustryService industryService;
- @Autowired
- private PcLabelCompanyMapper pcLabelCompanyMapper;
- @Autowired
- private LabelCQuery labelCQuery;
- @Override
- public PageInfo<CompanyVo> getList(Integer pageIndex, Integer pageSize,
- List<String> companyIDList, String companyName,
- String companyCode, String recordStatus,
- String regionCode, String streetCode,
- String createUserId, String workTime, String loginUserID,
- String siteID, Date startDate, Date endDate) {
- String curLoginUserSiteID = "";
- if (!stringUtils.IsNullOrEmpty(loginUserID)) {
- PcSiteUserExample siteUserExp = new PcSiteUserExample();
- siteUserExp.or().andUserIDEqualTo(loginUserID);
- curLoginUserSiteID = pcSiteUserMapper.selectByExample(siteUserExp).get(0).getSiteID();
- }
- PageHelper.startPage(pageIndex, pageSize);
- List<CompanyVo> dataList = companyCQuery.getList(stringUtils.ListToInSql(companyIDList), companyName, companyCode, recordStatus, regionCode, streetCode, createUserId, workTime, curLoginUserSiteID, siteID, startDate, endDate);
- PageInfo<CompanyVo> result = new PageInfo(dataList);
- return result;
- }
- @Override
- public List<PcCompany> getCompanyBySiteIDList(String siteID) {
- PcCompanyExample exp = new PcCompanyExample();
- exp.or().andSiteIDEqualTo(siteID);
- return pcCompanyMapper.selectByExample(exp);
- }
- private int ifHadRepeatData(CompanyVo data){
- var result = 0;
- PcCompanyExample companyExp1 = new PcCompanyExample();
- companyExp1.or().andCompanyNameEqualTo(data.getCompanyName()).andCompanyIDNotEqualTo(data.getCompanyID());
- var ifRepeatName = pcCompanyMapper.selectByExample(companyExp1).size()>0;
- PcCompanyExample companyExp2 = new PcCompanyExample();
- companyExp2.or().andCompanyCodeEqualTo(data.getCompanyCode()).andCompanyIDNotEqualTo(data.getCompanyID());
- var ifRepeatCode = pcCompanyMapper.selectByExample(companyExp2).size()>0;
- result += ifRepeatName? 1:0;
- result += ifRepeatCode? 2:0;
- return result;
- }
- @Override
- public Integer save(CompanyVo data, String userId) {
- Integer result = 0;
- Boolean isExist = data.getCompanyID() != null;
- PcCompanyWithBLOBs dbData = null;
- PcCompanyExample exp = new PcCompanyExample();
- PcCompanyExample.Criteria cro = exp.createCriteria();
- if (isExist) {
- cro.andCompanyIDEqualTo(data.getCompanyID());
- dbData = pcCompanyMapper.selectByExampleWithBLOBs(exp).stream().findFirst().orElse(null);
- }
- var repeatResult = ifHadRepeatData(data);
- switch (repeatResult){
- default:
- case 0:
- break;
- case 1:
- throw new BaseException("1004","企业名称已存在!");
- case 2:
- throw new BaseException("1004","统一社会信用代码已存在!");
- case 3:
- throw new BaseException("1004","信用代码、企业名称重复!");
- }
- if (dbData == null) {
- exp = new PcCompanyExample();
- dbData = new PcCompanyWithBLOBs();
- // dbData.setCompanyID(UUID.randomUUID().toString());
- dbData.setCompanyID(data.getCompanyID());
- dbData.setCompanyName(data.getCompanyName());
- dbData.setIsShortage(data.getIsShortage());
- dbData.setCompanyCode(data.getCompanyCode());
- dbData.setSiteID(data.getSiteID());
- dbData.setRegionCode(data.getRegionCode());
- dbData.setStreetCode(data.getStreetCode());
- dbData.setCompanyAddress(data.getCompanyAddress());
- dbData.setWorkSituation(data.getWorkSituation());
- dbData.setCompanyModel(data.getCompanyModel());
- dbData.setCompanyType(data.getCompanyType());
- dbData.setUserName(data.getUserName());
- dbData.setUserMobile(data.getUserMobile());
- dbData.setCompanyEmail(data.getCompanyEmail());
- dbData.setFrName(data.getFrName());
- dbData.setValidDate(data.getValidDate());
- dbData.setRecordStatus(data.getRecordStatus());
- dbData.setBusinScope(data.getBusinScope());
- dbData.setCompanyDesc(data.getCompanyDesc());
- dbData.setInsuredCount(data.getInsuredCount());
- dbData.setLongitude(data.getLongitude());
- dbData.setLatitude(data.getLatitude());
- dbData.setOpenId(data.getOpenId());
- dbData.setCreateTime(new Date());
- dbData.setCreateUserID(userId);
- dbData.setModifyTime(new Date());
- dbData.setModifyUserID(userId);
- dbData.setEstablishmentTime(data.getEstablishmentTime());
- dbData.setRegisteredCapital(data.getRegisteredCapital());
- dbData.setSignInPoliticalArea(data.getSignInPoliticalArea());
- dbData.setWebsite(data.getWebsite());
- dbData.setBonus(data.getBonus());
- dbData.setIndustryID(data.getIndustryID());
- dbData.setEstateCategoryID(data.getEstateCategoryID());
- dbData.setTagID(data.getTagID());
- result = pcCompanyMapper.insert(dbData);
- } else {
- dbData.setCompanyName(data.getCompanyName());
- dbData.setCompanyCode(data.getCompanyCode());
- dbData.setIsShortage(data.getIsShortage());
- dbData.setSiteID(data.getSiteID());
- dbData.setRegionCode(data.getRegionCode());
- dbData.setStreetCode(data.getStreetCode());
- dbData.setCompanyAddress(data.getCompanyAddress());
- dbData.setWorkSituation(data.getWorkSituation());
- dbData.setCompanyModel(data.getCompanyModel());
- dbData.setCompanyType(data.getCompanyType());
- dbData.setUserName(data.getUserName());
- dbData.setUserMobile(data.getUserMobile());
- dbData.setCompanyEmail(data.getCompanyEmail());
- dbData.setFrName(data.getFrName());
- dbData.setValidDate(data.getValidDate());
- dbData.setRecordStatus(data.getRecordStatus());
- dbData.setBusinScope(data.getBusinScope());
- dbData.setCompanyDesc(data.getCompanyDesc());
- dbData.setInsuredCount(data.getInsuredCount());
- dbData.setLongitude(data.getLongitude());
- dbData.setLatitude(data.getLatitude());
- dbData.setOpenId(data.getOpenId());
- dbData.setModifyTime(new Date());
- dbData.setModifyUserID(userId);
- dbData.setEstablishmentTime(data.getEstablishmentTime());
- dbData.setRegisteredCapital(data.getRegisteredCapital());
- dbData.setSignInPoliticalArea(data.getSignInPoliticalArea());
- dbData.setWebsite(data.getWebsite());
- dbData.setBonus(data.getBonus());
- dbData.setIndustryID(data.getIndustryID());
- dbData.setEstateCategoryID(data.getEstateCategoryID());
- dbData.setTagID(data.getTagID());
- result = pcCompanyMapper.updateByPrimaryKeySelective(dbData);
- }
- if(data.listLabel!=null && data.listLabel.size()>0){
- PcLabelCompanyExample labelEmp = new PcLabelCompanyExample();
- labelEmp.or().andCompanyIDEqualTo(data.getCompanyID());
- pcLabelCompanyMapper.deleteByExample(labelEmp);
- data.listLabel.forEach(x->{
- PcLabelCompany labelModel = new PcLabelCompany();
- labelModel.setCompanyID(data.getCompanyID());
- labelModel.setLabelID(x.getLabelID());
- pcLabelCompanyMapper.insert(labelModel);
- });
- }
- return result;
- }
- @Override
- public Integer delete(List<String> ids) {
- int result = 0;
- for(String curCompanyID : ids){
- PcPostExample pcPostExp = new PcPostExample();
- pcPostExp.or().andCompanyIDEqualTo(curCompanyID);
- var curCompanyPostList = pcPostMapper.selectByExample(pcPostExp).stream().toList();
- if( curCompanyPostList != null && curCompanyPostList.size() > 0){
- throw new BaseException("10004","所选企业已有关联岗位信息,不允许删除!");
- }else{
- int count = pcCompanyMapper.deleteByPrimaryKey(curCompanyID);
- if(count>0){
- PcLabelCompanyExample labelEmp = new PcLabelCompanyExample();
- labelEmp.or().andCompanyIDEqualTo(curCompanyID);
- pcLabelCompanyMapper.deleteByExample(labelEmp);
- }
- result+=count;
- }
- }
- return result;
- }
- @Override
- public CompanyVo getDataById(String id) {
- if (stringUtils.IsNullOrEmpty(id)) {
- return null;
- }
- CompanyVo data = companyCQuery.getList(stringUtils.ListToInSql(Arrays.asList(id)), null, null, null, null, null, null, null, null, null, null, null).stream().findFirst().orElse(null);
- if(data!=null){
- data.listLabel = labelCQuery.getCompanyLabelList(id);
- }
- return data;
- }
- @Override
- public List<CompanyVo> importCompany(List<CompanyVo> dataList, String userID) {
- if (dataList.size() <= 0)
- throw new BaseException("1004", "请添加导入数据!");
- //所属驿站
- List<PcSite> siteList = siteMapper.selectByExample(null);
- //所属县区
- AreaCodeExample reginExp = new AreaCodeExample();
- reginExp.or().andLvEqualTo("3");
- List<AreaCode> regionList = areaCodeMapper.selectByExample(reginExp);
- //所属街道
- AreaCodeExample streetExp = new AreaCodeExample();
- reginExp.or().andLvEqualTo("4");
- List<AreaCode> streetList = areaCodeMapper.selectByExample(streetExp);
- List<CompanyVo> resultList = new ArrayList<>();
- //企业规模
- List<SysDictionaryItem> dicCompanyModelList = dictionaryService.getDictionaryItemList("CompanyModel");
- List<SysDictionaryItem> dicCompanyTypeList = dictionaryService.getDictionaryItemList("CompanyType");
- dataList.forEach(item -> {
- String errorInfo = "";
- item.companyID = UUID.randomUUID().toString();
- if (stringUtils.IsNullOrEmpty(item.companyCode))
- errorInfo += "请填写统一信用代码!";
- if (stringUtils.IsNullOrEmpty(item.companyName))
- errorInfo += "请填写企业名称!";
- if (stringUtils.IsNullOrEmpty(item.SiteName))
- errorInfo += "请填写所属驿站!";
- else {
- item.siteID = siteList.stream().filter(it -> it.getSiteName().equals(item.getSiteName().trim()))
- .findFirst().orElse(new PcSite()).getSiteID();
- if (stringUtils.IsNullOrEmpty(item.siteID)) {
- errorInfo += "驿站不存在!";
- }
- }
- if (stringUtils.IsNullOrEmpty(item.companyAddress))
- errorInfo += "请填写企业办公地址!";
- if (stringUtils.IsNullOrEmpty(item.userName))
- errorInfo += "请填写企业联系人!";
- if (stringUtils.IsNullOrEmpty(item.userMobile))
- errorInfo += "请填写企业联系电话!";
- if (stringUtils.IsNullOrEmpty(item.recordStatusName))
- errorInfo += "请填写企业状态!";
- else {
- if (item.recordStatusName.equals("在营"))
- item.recordStatus = 1;
- else
- item.recordStatus = 0;
- }
- if (stringUtils.IsNullOrEmpty(item.isShortageName))
- errorInfo += "请填写是否缺工!";
- else {
- if (item.isShortageName.equals("是")) item.isShortage = 1;
- else item.isShortage = 0;
- }
- if (stringUtils.IsNullOrEmpty(errorInfo)) {
- resultList.add(item);
- } else {
- item.setErrorMessage(errorInfo);
- }
- if (!stringUtils.IsNullOrEmpty(item.regionName))
- {
- item.regionCode = regionList.stream().filter(it -> it.getName().equals(item.regionName.trim()))
- .findFirst().orElse(new AreaCode()).getCode();
- if (stringUtils.IsNullOrEmpty(item.regionCode))
- errorInfo += "县区名称不存在!";
- }
- if (!stringUtils.IsNullOrEmpty(item.streetName))
- {
- item.streetCode = streetList.stream().filter(it -> it.getName().equals(item.streetName.trim()))
- .findFirst().orElse(new AreaCode()).getCode();
- if (stringUtils.IsNullOrEmpty(item.streetCode))
- errorInfo += "街道名称不存在!";
- }
- if (!stringUtils.IsNullOrEmpty(item.companyTypeStr))
- {
- item.companyType = dicCompanyTypeList.stream().filter(it -> it.getName().equals(item.companyTypeStr.trim()))
- .findFirst().orElse(new SysDictionaryItem()).getValue();
- if (item.companyType == null || item.companyType == 0)
- errorInfo += "企业分类不存在!";
- }
- if (!stringUtils.IsNullOrEmpty(item.companyModelStr))
- {
- item.companyModel = dicCompanyModelList.stream().filter(it -> it.getName().equals(item.companyModelStr.trim()))
- .findFirst().orElse(new SysDictionaryItem()).getValue();
- if (item.companyModel == null || item.companyModel == 0)
- errorInfo += "企业规模不存在!";
- }
- });
- if (dataList.stream().filter(it -> !stringUtils.IsNullOrEmpty(it.errorMessage)).collect(Collectors.toList()).size() > 0)
- return dataList;
- resultList.forEach(item -> {
- save(item, userID);
- });
- return null;
- }
- @Override
- public List<PcSite> getSiteList() {
- //所属驿站
- List<PcSite> siteList = siteMapper.selectByExample(null);
- return siteList;
- }
- @Override
- public Integer saveAppCompanyPost(AppCompanyPostVo data, String userId) {
- String pattern = "yyyy-MM-dd"; // 日期字符串的格式
- SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
- var companyID = UUID.randomUUID().toString();
- if (stringUtils.IsNullOrEmpty(data.getCompanyID())) {
- data.setCompanyID(companyID);
- }
- Integer rows = save(data, userId);
- final int[] postRows = {0};
- if (rows > 0) {
- PcPostExample expPost = new PcPostExample();
- PcPostExample.Criteria cro = expPost.or();
- cro.andCompanyIDEqualTo(data.getCompanyID());
- int delRows=pcPostMapper.deleteByExample(expPost);
- data.getPostData().stream().forEach(x -> {
- PcPost post = new PcPost();
- post.setRecordStatus(1);
- post.setPostID(UUID.randomUUID().toString());
- post.setCompanyID(data.getCompanyID());
- post.setPostName(x.get("postName").toString());
- post.setRecruitCount(Integer.parseInt(x.get("recruitCount").toString()));
- post.setValidDay(Integer.parseInt(x.get("validDay").toString()));
- try {
- post.setValidTime(dateFormat.parse(x.get("validTime").toString()));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- int r = pcPostMapper.insert(post);
- postRows[0] += r;
- });
- return postRows[0];
- }
- return null;
- }
- @Override
- public CompanyVo normalByCompanyName(String companyName) {
- PcFirmWithBLOBs pcFirm = firmService.selectByCompanyName(companyName);
- if (pcFirm == null) {
- return null;
- }
- CompanyVo companyVo = new CompanyVo();
- // 匹配数据
- companyVo.setFrName(pcFirm.getDbrName());
- companyVo.setRegisteredCapital(Double.valueOf(pcFirm.getRegisteredCapital()));
- companyVo.setCompanyCode(pcFirm.getCompanyCode());
- companyVo.setInsuredCount(Integer.valueOf(pcFirm.getInsuredCount()));
- companyVo.setUserMobile(pcFirm.getLxMobile());
- companyVo.setCompanyEmail(pcFirm.getEmail());
- companyVo.setCompanyAddress(pcFirm.getLatestAddress());
- companyVo.setBusinScope(pcFirm.getBusinessScope());
- if (pcFirm.getIndustry() != null && !pcFirm.getIndustry().isBlank()) {
- // 获取行业数据
- List<PcIndustry> allList = industryService.getAllList();
- PcIndustry pcIndustry = allList.stream().filter(item -> item.getIndustryName().equals(pcFirm.getIndustry())).findFirst().orElse(new PcIndustry());
- companyVo.setIndustryID(pcIndustry.getIndustryId());
- companyVo.setIndustryName(pcIndustry.getIndustryName());
- }
- return companyVo;
- }
- }
|