CompanyServiceImpl.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. package com.hz.employmentsite.services.impl.companyService;
  2. import com.github.pagehelper.PageHelper;
  3. import com.github.pagehelper.PageInfo;
  4. import com.hz.employmentsite.filter.exception.BaseException;
  5. import com.hz.employmentsite.mapper.*;
  6. import com.hz.employmentsite.mapper.cquery.CompanyCQuery;
  7. import com.hz.employmentsite.mapper.cquery.LabelCQuery;
  8. import com.hz.employmentsite.model.*;
  9. import com.hz.employmentsite.services.service.companyService.CompanyService;
  10. import com.hz.employmentsite.services.service.companyService.FirmService;
  11. import com.hz.employmentsite.services.service.companyService.IndustryService;
  12. import com.hz.employmentsite.services.service.system.DictionaryService;
  13. import com.hz.employmentsite.util.StringUtils;
  14. import com.hz.employmentsite.vo.companyService.AppCompanyPostVo;
  15. import com.hz.employmentsite.vo.companyService.CompanyVo;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import java.text.ParseException;
  19. import java.text.SimpleDateFormat;
  20. import java.util.*;
  21. import java.util.stream.Collectors;
  22. @Service("CompanyService")
  23. public class CompanyServiceImpl implements CompanyService {
  24. @Autowired
  25. private CompanyCQuery companyCQuery;
  26. @Autowired
  27. private StringUtils stringUtils;
  28. @Autowired
  29. private DictionaryService dictionaryService;
  30. @Autowired
  31. private PcCompanyMapper pcCompanyMapper;
  32. @Autowired
  33. private AreaCodeMapper areaCodeMapper;
  34. @Autowired
  35. private PcSiteMapper siteMapper;
  36. @Autowired
  37. private PcPostMapper pcPostMapper;
  38. @Autowired
  39. private PcSiteUserMapper pcSiteUserMapper;
  40. @Autowired
  41. private FirmService firmService;
  42. @Autowired
  43. private IndustryService industryService;
  44. @Autowired
  45. private PcLabelCompanyMapper pcLabelCompanyMapper;
  46. @Autowired
  47. private LabelCQuery labelCQuery;
  48. @Override
  49. public PageInfo<CompanyVo> getList(Integer pageIndex, Integer pageSize,
  50. List<String> companyIDList, String companyName,
  51. String companyCode, String recordStatus,
  52. String regionCode, String streetCode,
  53. String createUserId, String workTime, String loginUserID,
  54. String siteID, Date startDate, Date endDate) {
  55. String curLoginUserSiteID = "";
  56. if (!stringUtils.IsNullOrEmpty(loginUserID)) {
  57. PcSiteUserExample siteUserExp = new PcSiteUserExample();
  58. siteUserExp.or().andUserIDEqualTo(loginUserID);
  59. curLoginUserSiteID = pcSiteUserMapper.selectByExample(siteUserExp).get(0).getSiteID();
  60. }
  61. PageHelper.startPage(pageIndex, pageSize);
  62. List<CompanyVo> dataList = companyCQuery.getList(stringUtils.ListToInSql(companyIDList), companyName, companyCode, recordStatus, regionCode, streetCode, createUserId, workTime, curLoginUserSiteID, siteID, startDate, endDate);
  63. PageInfo<CompanyVo> result = new PageInfo(dataList);
  64. return result;
  65. }
  66. @Override
  67. public List<PcCompany> getCompanyBySiteIDList(String siteID) {
  68. PcCompanyExample exp = new PcCompanyExample();
  69. exp.or().andSiteIDEqualTo(siteID);
  70. return pcCompanyMapper.selectByExample(exp);
  71. }
  72. private int ifHadRepeatData(CompanyVo data){
  73. var result = 0;
  74. PcCompanyExample companyExp1 = new PcCompanyExample();
  75. companyExp1.or().andCompanyNameEqualTo(data.getCompanyName()).andCompanyIDNotEqualTo(data.getCompanyID());
  76. var ifRepeatName = pcCompanyMapper.selectByExample(companyExp1).size()>0;
  77. PcCompanyExample companyExp2 = new PcCompanyExample();
  78. companyExp2.or().andCompanyCodeEqualTo(data.getCompanyCode()).andCompanyIDNotEqualTo(data.getCompanyID());
  79. var ifRepeatCode = pcCompanyMapper.selectByExample(companyExp2).size()>0;
  80. result += ifRepeatName? 1:0;
  81. result += ifRepeatCode? 2:0;
  82. return result;
  83. }
  84. @Override
  85. public Integer save(CompanyVo data, String userId) {
  86. Integer result = 0;
  87. Boolean isExist = data.getCompanyID() != null;
  88. PcCompanyWithBLOBs dbData = null;
  89. PcCompanyExample exp = new PcCompanyExample();
  90. PcCompanyExample.Criteria cro = exp.createCriteria();
  91. if (isExist) {
  92. cro.andCompanyIDEqualTo(data.getCompanyID());
  93. dbData = pcCompanyMapper.selectByExampleWithBLOBs(exp).stream().findFirst().orElse(null);
  94. }
  95. var repeatResult = ifHadRepeatData(data);
  96. switch (repeatResult){
  97. default:
  98. case 0:
  99. break;
  100. case 1:
  101. throw new BaseException("1004","企业名称已存在!");
  102. case 2:
  103. throw new BaseException("1004","统一社会信用代码已存在!");
  104. case 3:
  105. throw new BaseException("1004","信用代码、企业名称重复!");
  106. }
  107. if (dbData == null) {
  108. exp = new PcCompanyExample();
  109. dbData = new PcCompanyWithBLOBs();
  110. // dbData.setCompanyID(UUID.randomUUID().toString());
  111. dbData.setCompanyID(data.getCompanyID());
  112. dbData.setCompanyName(data.getCompanyName());
  113. dbData.setIsShortage(data.getIsShortage());
  114. dbData.setCompanyCode(data.getCompanyCode());
  115. dbData.setSiteID(data.getSiteID());
  116. dbData.setRegionCode(data.getRegionCode());
  117. dbData.setStreetCode(data.getStreetCode());
  118. dbData.setCompanyAddress(data.getCompanyAddress());
  119. dbData.setWorkSituation(data.getWorkSituation());
  120. dbData.setCompanyModel(data.getCompanyModel());
  121. dbData.setCompanyType(data.getCompanyType());
  122. dbData.setUserName(data.getUserName());
  123. dbData.setUserMobile(data.getUserMobile());
  124. dbData.setCompanyEmail(data.getCompanyEmail());
  125. dbData.setFrName(data.getFrName());
  126. dbData.setValidDate(data.getValidDate());
  127. dbData.setRecordStatus(data.getRecordStatus());
  128. dbData.setBusinScope(data.getBusinScope());
  129. dbData.setCompanyDesc(data.getCompanyDesc());
  130. dbData.setInsuredCount(data.getInsuredCount());
  131. dbData.setLongitude(data.getLongitude());
  132. dbData.setLatitude(data.getLatitude());
  133. dbData.setOpenId(data.getOpenId());
  134. dbData.setCreateTime(new Date());
  135. dbData.setCreateUserID(userId);
  136. dbData.setModifyTime(new Date());
  137. dbData.setModifyUserID(userId);
  138. dbData.setEstablishmentTime(data.getEstablishmentTime());
  139. dbData.setRegisteredCapital(data.getRegisteredCapital());
  140. dbData.setSignInPoliticalArea(data.getSignInPoliticalArea());
  141. dbData.setWebsite(data.getWebsite());
  142. dbData.setBonus(data.getBonus());
  143. dbData.setIndustryID(data.getIndustryID());
  144. dbData.setEstateCategoryID(data.getEstateCategoryID());
  145. dbData.setTagID(data.getTagID());
  146. result = pcCompanyMapper.insert(dbData);
  147. } else {
  148. dbData.setCompanyName(data.getCompanyName());
  149. dbData.setCompanyCode(data.getCompanyCode());
  150. dbData.setIsShortage(data.getIsShortage());
  151. dbData.setSiteID(data.getSiteID());
  152. dbData.setRegionCode(data.getRegionCode());
  153. dbData.setStreetCode(data.getStreetCode());
  154. dbData.setCompanyAddress(data.getCompanyAddress());
  155. dbData.setWorkSituation(data.getWorkSituation());
  156. dbData.setCompanyModel(data.getCompanyModel());
  157. dbData.setCompanyType(data.getCompanyType());
  158. dbData.setUserName(data.getUserName());
  159. dbData.setUserMobile(data.getUserMobile());
  160. dbData.setCompanyEmail(data.getCompanyEmail());
  161. dbData.setFrName(data.getFrName());
  162. dbData.setValidDate(data.getValidDate());
  163. dbData.setRecordStatus(data.getRecordStatus());
  164. dbData.setBusinScope(data.getBusinScope());
  165. dbData.setCompanyDesc(data.getCompanyDesc());
  166. dbData.setInsuredCount(data.getInsuredCount());
  167. dbData.setLongitude(data.getLongitude());
  168. dbData.setLatitude(data.getLatitude());
  169. dbData.setOpenId(data.getOpenId());
  170. dbData.setModifyTime(new Date());
  171. dbData.setModifyUserID(userId);
  172. dbData.setEstablishmentTime(data.getEstablishmentTime());
  173. dbData.setRegisteredCapital(data.getRegisteredCapital());
  174. dbData.setSignInPoliticalArea(data.getSignInPoliticalArea());
  175. dbData.setWebsite(data.getWebsite());
  176. dbData.setBonus(data.getBonus());
  177. dbData.setIndustryID(data.getIndustryID());
  178. dbData.setEstateCategoryID(data.getEstateCategoryID());
  179. dbData.setTagID(data.getTagID());
  180. result = pcCompanyMapper.updateByPrimaryKeySelective(dbData);
  181. }
  182. if(data.listLabel!=null && data.listLabel.size()>0){
  183. PcLabelCompanyExample labelEmp = new PcLabelCompanyExample();
  184. labelEmp.or().andCompanyIDEqualTo(data.getCompanyID());
  185. pcLabelCompanyMapper.deleteByExample(labelEmp);
  186. data.listLabel.forEach(x->{
  187. PcLabelCompany labelModel = new PcLabelCompany();
  188. labelModel.setCompanyID(data.getCompanyID());
  189. labelModel.setLabelID(x.getLabelID());
  190. pcLabelCompanyMapper.insert(labelModel);
  191. });
  192. }
  193. return result;
  194. }
  195. @Override
  196. public Integer delete(List<String> ids) {
  197. int result = 0;
  198. for(String curCompanyID : ids){
  199. PcPostExample pcPostExp = new PcPostExample();
  200. pcPostExp.or().andCompanyIDEqualTo(curCompanyID);
  201. var curCompanyPostList = pcPostMapper.selectByExample(pcPostExp).stream().toList();
  202. if( curCompanyPostList != null && curCompanyPostList.size() > 0){
  203. throw new BaseException("10004","所选企业已有关联岗位信息,不允许删除!");
  204. }else{
  205. int count = pcCompanyMapper.deleteByPrimaryKey(curCompanyID);
  206. if(count>0){
  207. PcLabelCompanyExample labelEmp = new PcLabelCompanyExample();
  208. labelEmp.or().andCompanyIDEqualTo(curCompanyID);
  209. pcLabelCompanyMapper.deleteByExample(labelEmp);
  210. }
  211. result+=count;
  212. }
  213. }
  214. return result;
  215. }
  216. @Override
  217. public CompanyVo getDataById(String id) {
  218. if (stringUtils.IsNullOrEmpty(id)) {
  219. return null;
  220. }
  221. CompanyVo data = companyCQuery.getList(stringUtils.ListToInSql(Arrays.asList(id)), null, null, null, null, null, null, null, null, null, null, null).stream().findFirst().orElse(null);
  222. if(data!=null){
  223. data.listLabel = labelCQuery.getCompanyLabelList(id);
  224. }
  225. return data;
  226. }
  227. @Override
  228. public List<CompanyVo> importCompany(List<CompanyVo> dataList, String userID) {
  229. if (dataList.size() <= 0)
  230. throw new BaseException("1004", "请添加导入数据!");
  231. //所属驿站
  232. List<PcSite> siteList = siteMapper.selectByExample(null);
  233. //所属县区
  234. AreaCodeExample reginExp = new AreaCodeExample();
  235. reginExp.or().andLvEqualTo("3");
  236. List<AreaCode> regionList = areaCodeMapper.selectByExample(reginExp);
  237. //所属街道
  238. AreaCodeExample streetExp = new AreaCodeExample();
  239. reginExp.or().andLvEqualTo("4");
  240. List<AreaCode> streetList = areaCodeMapper.selectByExample(streetExp);
  241. List<CompanyVo> resultList = new ArrayList<>();
  242. //企业规模
  243. List<SysDictionaryItem> dicCompanyModelList = dictionaryService.getDictionaryItemList("CompanyModel");
  244. List<SysDictionaryItem> dicCompanyTypeList = dictionaryService.getDictionaryItemList("CompanyType");
  245. dataList.forEach(item -> {
  246. String errorInfo = "";
  247. item.companyID = UUID.randomUUID().toString();
  248. if (stringUtils.IsNullOrEmpty(item.companyCode))
  249. errorInfo += "请填写统一信用代码!";
  250. if (stringUtils.IsNullOrEmpty(item.companyName))
  251. errorInfo += "请填写企业名称!";
  252. if (stringUtils.IsNullOrEmpty(item.SiteName))
  253. errorInfo += "请填写所属驿站!";
  254. else {
  255. item.siteID = siteList.stream().filter(it -> it.getSiteName().equals(item.getSiteName().trim()))
  256. .findFirst().orElse(new PcSite()).getSiteID();
  257. if (stringUtils.IsNullOrEmpty(item.siteID)) {
  258. errorInfo += "驿站不存在!";
  259. }
  260. }
  261. if (stringUtils.IsNullOrEmpty(item.companyAddress))
  262. errorInfo += "请填写企业办公地址!";
  263. if (stringUtils.IsNullOrEmpty(item.userName))
  264. errorInfo += "请填写企业联系人!";
  265. if (stringUtils.IsNullOrEmpty(item.userMobile))
  266. errorInfo += "请填写企业联系电话!";
  267. if (stringUtils.IsNullOrEmpty(item.recordStatusName))
  268. errorInfo += "请填写企业状态!";
  269. else {
  270. if (item.recordStatusName.equals("在营"))
  271. item.recordStatus = 1;
  272. else
  273. item.recordStatus = 0;
  274. }
  275. if (stringUtils.IsNullOrEmpty(item.isShortageName))
  276. errorInfo += "请填写是否缺工!";
  277. else {
  278. if (item.isShortageName.equals("是")) item.isShortage = 1;
  279. else item.isShortage = 0;
  280. }
  281. if (stringUtils.IsNullOrEmpty(errorInfo)) {
  282. resultList.add(item);
  283. } else {
  284. item.setErrorMessage(errorInfo);
  285. }
  286. if (!stringUtils.IsNullOrEmpty(item.regionName))
  287. {
  288. item.regionCode = regionList.stream().filter(it -> it.getName().equals(item.regionName.trim()))
  289. .findFirst().orElse(new AreaCode()).getCode();
  290. if (stringUtils.IsNullOrEmpty(item.regionCode))
  291. errorInfo += "县区名称不存在!";
  292. }
  293. if (!stringUtils.IsNullOrEmpty(item.streetName))
  294. {
  295. item.streetCode = streetList.stream().filter(it -> it.getName().equals(item.streetName.trim()))
  296. .findFirst().orElse(new AreaCode()).getCode();
  297. if (stringUtils.IsNullOrEmpty(item.streetCode))
  298. errorInfo += "街道名称不存在!";
  299. }
  300. if (!stringUtils.IsNullOrEmpty(item.companyTypeStr))
  301. {
  302. item.companyType = dicCompanyTypeList.stream().filter(it -> it.getName().equals(item.companyTypeStr.trim()))
  303. .findFirst().orElse(new SysDictionaryItem()).getValue();
  304. if (item.companyType == null || item.companyType == 0)
  305. errorInfo += "企业分类不存在!";
  306. }
  307. if (!stringUtils.IsNullOrEmpty(item.companyModelStr))
  308. {
  309. item.companyModel = dicCompanyModelList.stream().filter(it -> it.getName().equals(item.companyModelStr.trim()))
  310. .findFirst().orElse(new SysDictionaryItem()).getValue();
  311. if (item.companyModel == null || item.companyModel == 0)
  312. errorInfo += "企业规模不存在!";
  313. }
  314. });
  315. if (dataList.stream().filter(it -> !stringUtils.IsNullOrEmpty(it.errorMessage)).collect(Collectors.toList()).size() > 0)
  316. return dataList;
  317. resultList.forEach(item -> {
  318. save(item, userID);
  319. });
  320. return null;
  321. }
  322. @Override
  323. public List<PcSite> getSiteList() {
  324. //所属驿站
  325. List<PcSite> siteList = siteMapper.selectByExample(null);
  326. return siteList;
  327. }
  328. @Override
  329. public Integer saveAppCompanyPost(AppCompanyPostVo data, String userId) {
  330. String pattern = "yyyy-MM-dd"; // 日期字符串的格式
  331. SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
  332. var companyID = UUID.randomUUID().toString();
  333. if (stringUtils.IsNullOrEmpty(data.getCompanyID())) {
  334. data.setCompanyID(companyID);
  335. }
  336. Integer rows = save(data, userId);
  337. final int[] postRows = {0};
  338. if (rows > 0) {
  339. PcPostExample expPost = new PcPostExample();
  340. PcPostExample.Criteria cro = expPost.or();
  341. cro.andCompanyIDEqualTo(data.getCompanyID());
  342. int delRows=pcPostMapper.deleteByExample(expPost);
  343. data.getPostData().stream().forEach(x -> {
  344. PcPost post = new PcPost();
  345. post.setRecordStatus(1);
  346. post.setPostID(UUID.randomUUID().toString());
  347. post.setCompanyID(data.getCompanyID());
  348. post.setPostName(x.get("postName").toString());
  349. post.setRecruitCount(Integer.parseInt(x.get("recruitCount").toString()));
  350. post.setValidDay(Integer.parseInt(x.get("validDay").toString()));
  351. try {
  352. post.setValidTime(dateFormat.parse(x.get("validTime").toString()));
  353. } catch (ParseException e) {
  354. e.printStackTrace();
  355. }
  356. int r = pcPostMapper.insert(post);
  357. postRows[0] += r;
  358. });
  359. return postRows[0];
  360. }
  361. return null;
  362. }
  363. @Override
  364. public CompanyVo normalByCompanyName(String companyName) {
  365. PcFirmWithBLOBs pcFirm = firmService.selectByCompanyName(companyName);
  366. if (pcFirm == null) {
  367. return null;
  368. }
  369. CompanyVo companyVo = new CompanyVo();
  370. // 匹配数据
  371. companyVo.setFrName(pcFirm.getDbrName());
  372. companyVo.setRegisteredCapital(Double.valueOf(pcFirm.getRegisteredCapital()));
  373. companyVo.setCompanyCode(pcFirm.getCompanyCode());
  374. companyVo.setInsuredCount(Integer.valueOf(pcFirm.getInsuredCount()));
  375. companyVo.setUserMobile(pcFirm.getLxMobile());
  376. companyVo.setCompanyEmail(pcFirm.getEmail());
  377. companyVo.setCompanyAddress(pcFirm.getLatestAddress());
  378. companyVo.setBusinScope(pcFirm.getBusinessScope());
  379. if (pcFirm.getIndustry() != null && !pcFirm.getIndustry().isBlank()) {
  380. // 获取行业数据
  381. List<PcIndustry> allList = industryService.getAllList();
  382. PcIndustry pcIndustry = allList.stream().filter(item -> item.getIndustryName().equals(pcFirm.getIndustry())).findFirst().orElse(new PcIndustry());
  383. companyVo.setIndustryID(pcIndustry.getIndustryId());
  384. companyVo.setIndustryName(pcIndustry.getIndustryName());
  385. }
  386. return companyVo;
  387. }
  388. }