CompanyService.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. package platform.modules.build.service;
  2. import com.aliyuncs.exceptions.ClientException;
  3. import com.github.pagehelper.PageHelper;
  4. import com.github.pagehelper.PageInfo;
  5. import org.apache.commons.lang3.StringUtils;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import platform.common.Constant;
  12. import platform.common.base.service.BaseService;
  13. import platform.common.base.service.DictionaryItemService;
  14. import platform.common.util.*;
  15. import platform.modules.api.dto.CompanyInfoDto;
  16. import platform.modules.api.service.SkyImageApiService;
  17. import platform.modules.build.DTO.CompanyDto;
  18. import platform.modules.build.DTO.CompanyFeeDto;
  19. import platform.modules.build.dao.CompanyDao;
  20. import platform.modules.build.entity.BuildInfo;
  21. import platform.modules.build.entity.Company;
  22. import platform.modules.build.entity.CompanyContact;
  23. import platform.modules.carrier.dto.CompanyContacts;
  24. import platform.modules.carrier.dto.CustomSearchCondition;
  25. import platform.modules.carrier.dto.SearchCondition;
  26. import platform.modules.company.entity.CompanyBuildingStreet;
  27. import platform.modules.company.entity.ProjectApplication;
  28. import platform.modules.company.entity.ProjectApplicationCompanyInfo;
  29. import platform.modules.company.entity.StockLand;
  30. import platform.modules.company.service.CompanyBuildingStreetService;
  31. import platform.modules.company.service.CompanyContactsService;
  32. import platform.modules.company.service.ProjectApplicationCompanyInfoService;
  33. import platform.modules.government.dto.StreetCompanys;
  34. import platform.modules.government.entity.BuildType;
  35. import platform.modules.government.entity.Street;
  36. import platform.modules.government.entity.User;
  37. import platform.modules.government.service.BuildTypeService;
  38. import platform.modules.government.service.StreetService;
  39. import platform.modules.government.service.UserService;
  40. import platform.modules.sys.entity.Approval;
  41. import platform.modules.sys.entity.Department;
  42. import platform.modules.sys.service.ApprovalService;
  43. import platform.modules.sys.service.DepartmentService;
  44. import platform.modules.sys.service.WaitToDoService;
  45. import platform.modules.sys.web.ResponseMessage;
  46. import tk.mybatis.mapper.entity.Example;
  47. import java.util.ArrayList;
  48. import java.util.Date;
  49. import java.util.List;
  50. import java.util.Objects;
  51. /**
  52. * 企业信息Service
  53. *
  54. * @author lhf
  55. * @version 2017-10-26
  56. */
  57. @Service
  58. @Transactional(readOnly = true)
  59. public class CompanyService extends BaseService<Company> {
  60. private static Logger logger = LoggerFactory.getLogger(CompanyService.class);
  61. @Autowired
  62. private CompanyDao companyDao;
  63. @Autowired
  64. private CompanyContactService companyContactService;
  65. @Autowired
  66. private BuildTypeService buildTypeService;
  67. @Autowired
  68. private DepartmentService departmentService;
  69. @Autowired
  70. private UserService userService;
  71. @Autowired
  72. private ApprovalService approvalService;
  73. @Autowired
  74. CompanyContactsService companyContactsService;
  75. @Autowired
  76. private DictionaryItemService dictionaryItemService;
  77. @Autowired
  78. private BuildInfoService buildInfoService;
  79. @Autowired
  80. private StreetService streeService;
  81. @Autowired
  82. private CompanyBuildingStreetService buildingStreetService;
  83. @Autowired
  84. private WaitToDoService waitToDoService;
  85. @Autowired
  86. private ProjectApplicationCompanyInfoService applicationCompanyInfoService;
  87. @Autowired
  88. private SkyImageApiService skyImageApiService;
  89. public PageInfo<Company> findPage(Integer pageNum, Integer pageSize, String param, CompanyDto companyDto) throws Exception {
  90. /*Example example = new Example(Company.class);
  91. Example.Criteria criteria = example.createCriteria();
  92. Example.Criteria criteria2 = example.createCriteria();
  93. if (StringUtils.isNotBlank(param)) {
  94. criteria.andLike("company_name", "%" + WebUtil.covertData(param) + "%");
  95. //.orLike("phone", "%" + WebUtil.covertData(param) + "%")
  96. //.orLike("contact", "%" + WebUtil.covertData(param) + "%");
  97. }
  98. criteria2.andEqualTo("del_flag", 0);
  99. criteria2.andEqualTo("build_id", ShiroUtils.getUserEntity().getBuild_id());
  100. if (null != companyDto.getIs_start()) {
  101. criteria2.andEqualTo("is_start", companyDto.getIs_start());
  102. }
  103. // 倒序
  104. example.and(criteria2);
  105. example.orderBy("create_time").desc();*/
  106. PageHelper.startPage(pageNum, pageSize);
  107. Integer build_id = ShiroUtils.getUserEntity().getBuild_id();
  108. Integer street_id = ShiroUtils.getUserEntity().getStreet_id();
  109. List<Company> contents = null;
  110. if (StringUtils.isNotBlank(param)) {
  111. String trim = param.trim();
  112. contents = companyDao.selectCompanyByCondition(street_id, build_id, trim);
  113. } else {
  114. contents = companyDao.selectCompanyByCondition(street_id, build_id, param);
  115. }
  116. for (Company company : contents) {
  117. if (null != company.getType_id()) {
  118. BuildType buildType = buildTypeService.findById(company.getType_id());
  119. if (null != buildType) {
  120. company.setType_name(buildType.getType());
  121. }
  122. }
  123. company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
  124. }
  125. return new PageInfo<Company>(contents);
  126. }
  127. @Transactional(readOnly = false)
  128. public Boolean saveCompany(Company company) throws Exception {
  129. company.setBuild_id(ShiroUtils.getUserEntity().getBuild_id());
  130. company.setStreet_id(ShiroUtils.getUserEntity().getStreet_id());
  131. company.setIs_register(1);
  132. company.setIs_start(true);
  133. if (this.insertAndGetId(company) == 1) {
  134. for (CompanyContact companyContact : company.getCompanyContacts()) {
  135. companyContact.setCompany_id(company.getId());
  136. company.setIs_start(true);
  137. companyContactService.saveSelective(companyContact);
  138. }
  139. return true;
  140. }
  141. return false;
  142. }
  143. @Transactional(readOnly = false)
  144. public Boolean updateCompany(Company company) throws Exception {
  145. if (this.updateSelective(company) == 1) {
  146. User user = new User();
  147. user.setBuild_id(company.getBuild_id());
  148. user.setStreet_id(company.getStreet_id());
  149. Street street = streeService.findById(company.getStreet_id());
  150. if (street != null) {
  151. user.setStreet_name(street.getName());
  152. }
  153. if (company.getBuild_id() == null) {
  154. user.setBuild_id(null);
  155. user.setBuild_name("");
  156. } else {
  157. BuildInfo build = buildInfoService.findById(company.getBuild_id());
  158. if (build != null) {
  159. user.setBuild_name(build.getName());
  160. }
  161. }
  162. userService.updateByCompanyId(company.getId().toString(), user);
  163. companyContactService.deleteByCompanyId(company.getId());
  164. for (CompanyContact companyContact : company.getCompanyContacts()) {
  165. if (null != companyContact.getPhone() || null != companyContact.getContact()) {
  166. companyContact.setCompany_id(company.getId());
  167. companyContactService.saveSelective(companyContact);
  168. }
  169. }
  170. //更新厂房所在属地
  171. if (null != company.getBuildingStreets() && company.getBuildingStreets().size() > 0) {
  172. buildingStreetService.deleteByCompanyId(company.getId());
  173. for (CompanyBuildingStreet buildingStreet : company.getBuildingStreets()) {
  174. if (null != buildingStreet.getStreet_id()) {
  175. buildingStreet.setCompany_id(company.getId());
  176. buildingStreetService.saveSelective(buildingStreet);
  177. }
  178. }
  179. }
  180. return true;
  181. }
  182. return false;
  183. }
  184. public Company findByCompanyName(String companyName) throws Exception {
  185. return companyDao.findByCompanyName(companyName);
  186. }
  187. public PageInfo<Company> findPageByName(Integer pageNum, Integer pageSize, String name, List<String> ids) {
  188. PageHelper.startPage(pageNum, pageSize);
  189. List<Company> result = companyDao.findListByCompanyName(name, ids);
  190. return new PageInfo<Company>(result);
  191. }
  192. public List<Company> findListByCompanyIds(List<String> ids) {
  193. List<Company> result = companyDao.findListByCompanyIds(ids);
  194. return result;
  195. }
  196. public List<Company> findCompanyList() {
  197. Example example = new Example(Company.class);
  198. Example.Criteria criteria = example.createCriteria();
  199. criteria.andEqualTo("build_id", ShiroUtils.getUserEntity().getBuild_id());
  200. criteria.andEqualTo("del_flag", 0);
  201. criteria.andEqualTo("is_start", 1);
  202. if (null != ShiroUtils.getUserType() && ShiroUtils.getUserType().equals(Constant.UserType.COMPANY)) {
  203. criteria.andEqualTo("id", ShiroUtils.getCompanyId());
  204. }
  205. example.orderBy("sort").desc();
  206. List<Company> list = companyDao.selectByExample(example);
  207. return list;
  208. }
  209. public List<Company> findCompanies() {
  210. Example example = new Example(Company.class);
  211. Example.Criteria criteria = example.createCriteria();
  212. criteria.andEqualTo("del_flag", 0);
  213. criteria.andEqualTo("is_start", 1);
  214. List<Company> list = companyDao.selectByExample(example);
  215. return list;
  216. }
  217. public Integer findCuntCompanyByBuildId(Integer buildId, String dateFrom, String dateTo) {
  218. return companyDao.findCuntCompanyByBuildId(buildId, dateFrom, dateTo);
  219. }
  220. public PageInfo<Company> findCompanyList(Integer pageNum, Integer pageSize, CompanyDto companyDto) {
  221. Example example = new Example(Company.class);
  222. Example.Criteria criteria = example.createCriteria();
  223. criteria.andEqualTo("del_flag", 0);
  224. criteria.andEqualTo("is_start", 1);
  225. User currUser = ShiroUtils.getUserEntity();
  226. if (currUser.getUser_type().equals(Constant.UserType.STREET)) {
  227. criteria.andEqualTo("street_id", ShiroUtils.getUserEntity().getStreet_id());
  228. } else if (currUser.getUser_type().equals(Constant.UserType.BUILD)) {
  229. criteria.andEqualTo("build_id", ShiroUtils.getUserEntity().getBuild_id());
  230. }
  231. if (StringUtils.isNotBlank(companyDto.getCompany_name())) {
  232. criteria.andLike("company_name", "%" + WebUtil.covertData(companyDto.getCompany_name()) + "%");
  233. }
  234. if (null != companyDto.getType()) {
  235. criteria.andEqualTo("type", companyDto.getType());
  236. }
  237. if (null != companyDto.getIs_product()) {
  238. criteria.andEqualTo("is_product", companyDto.getIs_product());
  239. }
  240. if (StringUtils.isNotBlank(companyDto.getStreet_ids())) {
  241. criteria.andIn("street_id", companyDto.getStreetIdList());
  242. }
  243. if (StringUtils.isNotBlank(companyDto.getBuild_ids())) {
  244. criteria.andIn("build_id", companyDto.getBuildIdList());
  245. }
  246. example.orderBy("sort").desc();
  247. PageHelper.startPage(pageNum, pageSize);
  248. List<Company> list = companyDao.selectByExample(example);
  249. return new PageInfo<Company>(list);
  250. }
  251. /**
  252. * 企业费用查询
  253. *
  254. * @param pageNum
  255. * @param pageSize
  256. * @return
  257. * @throws Exception
  258. */
  259. public PageInfo<CompanyFeeDto> findCompanyFeePage(Integer pageNum, Integer pageSize, String status, String fee_type) throws Exception {
  260. PageHelper.startPage(pageNum, pageSize);
  261. List<CompanyFeeDto> companyFees = companyDao.findCompanyFee(new CompanyFeeDto(ShiroUtils.getUserEntity().getCompany_id(), fee_type, status));
  262. return new PageInfo<CompanyFeeDto>(companyFees);
  263. }
  264. public List<CompanyFeeDto> findLatestCompnayFee(CompanyFeeDto companyFeeDto) {
  265. List<CompanyFeeDto> companyFees = companyDao.findCompanyFee(companyFeeDto);
  266. return companyFees;
  267. }
  268. public Integer findAllCuntCompanyByBuildId(Integer buildId) {
  269. return companyDao.findAllCuntCompanyByBuildId(buildId);
  270. }
  271. public Integer getCompanyCountByStreetName(String name) {
  272. return companyDao.getCompanyCountByStreetName(name);
  273. }
  274. public Integer countByType(Integer typeId) {
  275. return companyDao.countByType(typeId);
  276. }
  277. public Integer countAllCompany() {
  278. platform.modules.government.dto.SearchCondition condition = new platform.modules.government.dto.SearchCondition();
  279. return companyDao.countAllCompany(condition);
  280. }
  281. public Integer countAllCompanyByUserType() {
  282. platform.modules.government.dto.SearchCondition condition = new platform.modules.government.dto.SearchCondition();
  283. if (null != ShiroUtils.getUserType() && ShiroUtils.getUserType().equals(Constant.UserType.STREET)) {
  284. condition.setUser_type(Constant.UserType.STREET);
  285. condition.setStreet_id(ShiroUtils.getStreetId());
  286. }
  287. return companyDao.countAllCompany(condition);
  288. }
  289. //根据id获取企业信息
  290. public Company getCompanyInfo(Integer company_id) {
  291. Company companyInfo = null;
  292. if (null != company_id) {
  293. companyInfo = this.findById(company_id);
  294. }
  295. if (companyInfo != null) {
  296. List<CompanyContact> list = companyContactService.findByCompanyId(company_id);
  297. companyInfo.setCompanyContacts(list);
  298. if (null != list && list.size() > 0) {
  299. companyInfo.setContact(list.get(0).getContact());
  300. companyInfo.setContact_phone((list.get(0).getPhone()));
  301. }
  302. if (null != companyInfo.getStreet_id()) {
  303. try {
  304. companyInfo.setStreet_name(streeService.getStreetName(companyInfo.getStreet_id()));
  305. } catch (Exception e) {
  306. // TODO Auto-generated catch block
  307. e.printStackTrace();
  308. }
  309. }
  310. companyInfo.setBuildingStreets(buildingStreetService.findByCompanyId(company_id));
  311. //是否经营
  312. if (companyInfo.getOperated() != null) {
  313. if (companyInfo.getOperated()) {
  314. companyInfo.setOperatedStr("是");
  315. } else {
  316. companyInfo.setOperatedStr("否");
  317. }
  318. }
  319. }
  320. return companyInfo == null ? new Company() : companyInfo;
  321. }
  322. //根据id获取企业信息
  323. public Company getCompanyInfo(StockLand stockLand) {
  324. Integer company_id = stockLand.getCompany_id();
  325. Company company = null;
  326. if (null != company_id) {
  327. company = this.findById(company_id);
  328. }
  329. if (company != null) {
  330. ProjectApplicationCompanyInfo companyInfo =
  331. applicationCompanyInfoService.findByApplyIdAndType(stockLand.getId(),
  332. Constant.DictionaryType.STOCKLAND);
  333. if (companyInfo != null) {
  334. company.setContact(companyInfo.getContact());
  335. company.setContact_phone(companyInfo.getContact_phone());
  336. }
  337. if (null != company.getStreet_id()) {
  338. try {
  339. company.setStreet_name(streeService.getStreetName(company.getStreet_id()));
  340. } catch (Exception e) {
  341. // TODO Auto-generated catch block
  342. e.printStackTrace();
  343. }
  344. }
  345. company.setBuildingStreets(buildingStreetService.findByCompanyId(company_id));
  346. //是否经营
  347. if (company.getOperated() != null) {
  348. if (company.getOperated()) {
  349. company.setOperatedStr("是");
  350. } else {
  351. company.setOperatedStr("否");
  352. }
  353. }
  354. }
  355. return company == null ? new Company() : company;
  356. }
  357. /**
  358. * 查询企业名称是否存在
  359. */
  360. public boolean isCompanyNameExist(String company_name) {
  361. boolean flag = companyDao.isCompanyNameExist(company_name) > 0 ? true : false;
  362. return flag;
  363. }
  364. /**
  365. * 查询企业统一社会信用代码是否存在
  366. */
  367. public boolean isCompanyUsccExist(String uscc) {
  368. boolean flag = companyDao.isCompanyUsccExist(uscc) > 0 ? true : false;
  369. return flag;
  370. }
  371. /**
  372. * 查询企业组织机构代码是否存在
  373. */
  374. public boolean isCompanyOrganizationCodeExist(String organization_code, String company_id) {
  375. boolean flag = companyDao.isCompanyOrganizationCodeExist(organization_code, company_id) > 0 ? true : false;
  376. return flag;
  377. }
  378. /**
  379. * 根据企业名称和组织机构代码查询唯一企业
  380. */
  381. public boolean isCompanyExist(String company_name, String organization_code) {
  382. boolean flag = companyDao.isCompanyExist(company_name, organization_code) > 0 ? true : false;
  383. return flag;
  384. }
  385. public ResponseMessage approval(Integer type, Integer id, String approval_comment) throws Exception {
  386. Example userexample = new Example(User.class);
  387. Example.Criteria usercriteria = userexample.createCriteria();
  388. usercriteria.andEqualTo("del_flag", "0");
  389. usercriteria.andEqualTo("user_type", Constant.UserType.COMPANY);
  390. usercriteria.andEqualTo("company_id", id);
  391. userexample.orderBy("create_time").asc();
  392. List<User> users = userService.selectByExample(userexample);
  393. List<CompanyContact> companyContacts = companyContactService.findByCompanyId(id);
  394. if (type == 1) {//通过
  395. //查询最近的一条审核记录
  396. Approval approval = approvalService.getLatestApproval(id, Constant.DictionaryType.COMPANY_REGISTER);
  397. if (approval.getOper_type().equals(Constant.OperType.APPROVED) || approval.getOper_type().equals(Constant.OperType.REJECT)) {
  398. return ResponseMessage.error("该单据已审核!");
  399. }
  400. String nextChecker = approval.getNextchecker() == null ? "" : approval.getNextchecker();
  401. Company company = this.findById(id);
  402. User user = userService.findById(company.getCreate_by());
  403. user.setIs_register(1);
  404. user.setIs_start(true);
  405. userService.updateSelective(user);
  406. //userService.updateIsRegist(user.getId() + "", 1 + "");
  407. company.setIs_register(1);
  408. company.setIs_start(true);
  409. //}
  410. this.updateSelective(company);
  411. nextChecker = nextChecker.replace(ShiroUtils.getUserEntity().getId() + ",", "");
  412. Approval approval1 = new Approval();
  413. String department = "";
  414. if (null != userService.findById(ShiroUtils.getUserId()).getDepartment_id()) {
  415. Department dept = departmentService.findById(userService.findById(ShiroUtils.getUserId()).getDepartment_id());
  416. if (null != dept) {
  417. department = dept.getName();
  418. }
  419. }
  420. approval1.setDepartment(department);
  421. approval1.setApply_id(id);
  422. approval1.setType(Constant.DictionaryType.COMPANY_REGISTER);
  423. approval1.setApproval_comment(approval_comment);
  424. approval1.setBefore_approvalstatus("0");
  425. approval1.setAfter_approvalstatus("1");
  426. approval1.setDeal_time(DateUtil.getTimeString(new Date()));
  427. approval1.setChecker(ShiroUtils.getUserId());
  428. approval1.setNextchecker(nextChecker);
  429. approval1.setOper_type(Constant.OperType.APPROVED);
  430. //保存审核记录
  431. approvalService.insertAndGetId(approval1);
  432. if (CommonUtils.isNotNull(users) && users.size() > 0 ) {
  433. sendSMSToRegisteredCompanyUser(users.get(0), true, approval1);
  434. }
  435. } else {//退回
  436. //查询最近的一条审核记录
  437. Approval approval = approvalService.getLatestApproval(id, Constant.DictionaryType.COMPANY_REGISTER);
  438. if (approval.getOper_type().equals(Constant.OperType.APPROVED) || approval.getOper_type().equals(Constant.OperType.REJECT)) {
  439. return ResponseMessage.error("该单据已审核!");
  440. }
  441. Approval approval1 = new Approval();
  442. String department = "";
  443. if (null != userService.findById(ShiroUtils.getUserId()).getDepartment_id()) {
  444. Department dept = departmentService.findById(userService.findById(ShiroUtils.getUserId()).getDepartment_id());
  445. if (null != dept) {
  446. department = dept.getName();
  447. }
  448. }
  449. approval1.setDepartment(department);
  450. approval1.setApply_id(id);
  451. approval1.setType(Constant.DictionaryType.COMPANY_REGISTER);
  452. approval1.setApproval_comment(approval_comment);
  453. approval1.setBefore_approvalstatus("0");
  454. approval1.setAfter_approvalstatus("0");
  455. approval1.setDeal_time(DateUtil.getTimeString(new Date()));
  456. approval1.setChecker(ShiroUtils.getUserId());
  457. approval1.setOper_type(Constant.OperType.REJECT);
  458. //保存审核记录
  459. approvalService.insertAndGetId(approval1);
  460. //退回,把company删掉,否则不能再注册相同名称的企业
  461. Company company = this.findById(id);
  462. company.setDel_flag(true);
  463. this.updateSelective(company);
  464. User user = userService.findById(company.getCreate_by());
  465. user.setIs_register(2);
  466. user.setDel_flag(true);
  467. userService.updateSelective(user);
  468. if (CommonUtils.isNotNull(user) && users.size() > 0) {
  469. sendSMSToRegisteredCompanyUser(users.get(0), false, approval1);
  470. }
  471. //同步信息给天启
  472. // SyncUserDto dto = new SyncUserDto();
  473. // dto.setAction(Constant.METHOD_STATUS.INSERT);
  474. // dto.setOldUserName("");
  475. // dto.setUserName(user.getUser_name());
  476. // dto.setUserLoginName(user.getNick_name());
  477. // dto.setPassword(user.getPassword().trim());
  478. // dto.setCompanyName(user.getCompany_name());
  479. // if (null != user.getStreet_id()) {
  480. // Street street = streeService.findById(user.getStreet_id());
  481. // dto.setStreetName(street.getName());
  482. // }
  483. // dto.setToken(skyImageApiService.accessToken());
  484. // skyImageApiService.syncUserInfo(dto);
  485. }
  486. //完成待办
  487. waitToDoService.completeAllTODO(id, Constant.DictionaryType.COMPANY_REGISTER);
  488. return ResponseMessage.success("审核成功!");
  489. }
  490. //发送短信给企业用户,账号注册成功/失败
  491. // 发送短信 错误修改 wangjiang 2020-1-8
  492. private void sendSMSToRegisteredCompanyUser(User user, Boolean isPassed, Approval approval) {
  493. String templateParam;
  494. String phone = user.getPhone();
  495. logger.info("send msg to register company user which phone is : {}", phone);
  496. if (isPassed) {
  497. //发送短信给企业用户,账号注册成功
  498. //您的企业${company_name}账号注册,审核通过啦! 账号名为${nick_name}。感谢您的支持。
  499. // String phone = user.getPhone();
  500. String nick_name = user.getNick_name();
  501. String company_name = user.getCompany_name();
  502. templateParam = "{\"nick_name\":\"" + nick_name + "\",\"company_name\":\"" + company_name + "\"}";
  503. // AlibabaSMSUtil.sendSMS(phone, Constant.SMS_TemplateCode.COMPANY_USER_REGISTER_PASSED, Constant.SINGNAMW, templateParam);
  504. } else {
  505. //发送短信给企业用户,账号注册失败
  506. //您的企业${company_name}账号注册(账号名为${nick_name}),审核失败。${comment}感谢您的支持。
  507. // String phone = user.getPhone();
  508. String nick_name = user.getNick_name();
  509. String company_name = user.getCompany_name();
  510. String comment = approval.getApproval_comment();
  511. if (null != comment && comment.length() > 20) {
  512. comment = comment.substring(0, 20);
  513. }
  514. templateParam = "{\"nick_name\":\"" + nick_name + "\",\"comment\":\"" + comment + "\",\"company_name\":\"" + company_name + "\"}";
  515. }
  516. try {
  517. AlibabaSMSUtil.sendSMS(phone, Constant.SMS_TemplateCode.COMPANY_USER_REGISTER_REJECT, Constant.SINGNAMW, templateParam);
  518. } catch (ClientException e) {
  519. logger.error("发送阿里巴巴sms错误(ClientException):{}", e.getMessage());
  520. e.printStackTrace();
  521. throw new RuntimeException("发送阿里巴巴sms错误(ClientException):" + e.getMessage());
  522. } catch (InterruptedException e) {
  523. logger.error("发送阿里巴巴sms错误(InterruptedException):{}", e.getMessage());
  524. e.printStackTrace();
  525. throw new RuntimeException("发送阿里巴巴sms错误(InterruptedException):" + e.getMessage());
  526. }
  527. }
  528. public List<Company> findCompanyByCondition(Integer currentStreet_id, Integer currentUserId, String keyword, Company searchCondition) {
  529. return companyDao.findCompanyByCondition(currentStreet_id, currentUserId,
  530. Constant.DictionaryType.COMPANY_REGISTER, keyword, searchCondition);
  531. }
  532. public List<Company> findListByContidion(Integer userId, Integer currentStreet_id, String keyword, Company searchCondition) {
  533. return companyDao.findListByContidion(userId, currentStreet_id, Constant.DictionaryType.COMPANY_REGISTER, keyword, searchCondition);
  534. }
  535. public String getCompanyName(Integer id) {
  536. Company company = this.findById(id);
  537. if (null != company) {
  538. return company.getCompany_name();
  539. }
  540. return "";
  541. }
  542. //获取企业信息,基本信息、联系人
  543. public Company findCompanyInfo(Integer companyId) {
  544. if (null != companyId) {
  545. Company company = this.findById(companyId);
  546. if (null != company.getStreet_id()) {
  547. try {
  548. company.setStreet_name(streeService.getStreetName(company.getStreet_id()));
  549. } catch (Exception e) {
  550. // TODO Auto-generated catch block
  551. e.printStackTrace();
  552. }
  553. }
  554. if (null != company) {
  555. company.setCompanyContacts(companyContactService.findByCompanyId(companyId));
  556. company.setBuildingStreets(buildingStreetService.findByCompanyId(companyId));
  557. return company;
  558. }
  559. }
  560. return new Company();
  561. }
  562. public List<Company> findCompanysByBuildIds(List<String> buildIds, String type_id) {
  563. Example example = new Example(Company.class);
  564. Example.Criteria criteria = example.createCriteria();
  565. Example.Criteria criteria2 = example.createCriteria();
  566. criteria.andEqualTo("del_flag", "0");
  567. if (!Objects.equals("", type_id) && !Objects.equals(null, type_id)) {
  568. criteria.andEqualTo("type_id", type_id);
  569. }
  570. for (String id : buildIds) {
  571. criteria2.orEqualTo("build_id", id);
  572. }
  573. example.and(criteria2);
  574. //倒序
  575. example.orderBy("create_time").desc();
  576. List<Company> companyInfo = this.selectByExample(example);
  577. return companyInfo;
  578. }
  579. /**
  580. * selectCompanyById(由企业id获取企业信息)
  581. *
  582. * @param id
  583. * @return Company
  584. */
  585. public Company selectCompanyById(int id) {
  586. return companyDao.selectCompanyById(id);
  587. }
  588. @SuppressWarnings({"unused", "unused"})
  589. public Company findConpanyInfoById(int id) {
  590. Company company = this.findById(id);
  591. Integer type = company.getType();
  592. //企业性质
  593. if (null != type) {
  594. company.setType_name(dictionaryItemService.findByItemId(type).getName());
  595. } else {
  596. company.setType_name("");
  597. }
  598. //注册资本
  599. Integer currency_unit = company.getCurrency_unit();
  600. if (null != currency_unit) {
  601. company.setCurrency_unit_name(dictionaryItemService.findByItemId(currency_unit).getName());
  602. } else {
  603. company.setCurrency_unit_name("");
  604. }
  605. //街道
  606. Integer street_id = company.getStreet_id();
  607. if (null != street_id) {
  608. company.setStreet_name(streeService.selectById(street_id).getName());
  609. } else {
  610. company.setStreet_name("");
  611. }
  612. //园区
  613. Integer build_id = company.getBuild_id();
  614. if (null != build_id) {
  615. company.setBuild_name(buildInfoService.selectById(build_id).getName());
  616. } else {
  617. company.setBuild_name("");
  618. }
  619. return company;
  620. }
  621. //存量用地街道查询企业,包含厂房在本街道的企业
  622. public PageInfo<Company> findStockLandCompany(Integer pageNum, Integer pageSize, String keyword,
  623. CompanyDto companyDto) {
  624. PageHelper.startPage(pageNum, pageSize);
  625. Integer street_id = ShiroUtils.getUserEntity().getStreet_id();
  626. List<Company> companys = null;
  627. companys = companyDao.selectStockLandCompany(street_id, keyword);
  628. for (Company company : companys) {
  629. if (null != company.getType_id()) {
  630. BuildType buildType = buildTypeService.findById(company.getType_id());
  631. if (null != buildType) {
  632. company.setType_name(buildType.getType());
  633. }
  634. }
  635. company.setCompanyContacts(companyContactService.findByCompanyId(company.getId()));
  636. }
  637. return new PageInfo<Company>(companys);
  638. }
  639. public List<StreetCompanys> getStreetCompanys() {
  640. return companyDao.getStreetCompanys();
  641. }
  642. @Transactional(readOnly = true)
  643. public List<Company> getTotalCompanys() {
  644. Example example = new Example(Company.class);
  645. Example.Criteria criteria = example.createCriteria();
  646. criteria.andEqualTo("del_flag", 0);
  647. criteria.andEqualTo("is_register", 1);
  648. criteria.andEqualTo("is_start", 1);
  649. criteria.andIsNotNull("street_id");
  650. return this.selectByExample(example);
  651. }
  652. public List<Company> getCompanyByCondition(SearchCondition condition) {
  653. return companyDao.getCompanyByCondition(condition);
  654. }
  655. public PageInfo<Company> getCompanyPageByCondition(Integer pageNum, Integer pageSize, CustomSearchCondition condition) {
  656. PageHelper.startPage(pageNum, pageSize);
  657. SearchCondition searchCondition = new SearchCondition();
  658. searchCondition.setCompanyName(condition.getName());
  659. List<Company> list = companyDao.getCompanyByCondition(searchCondition);
  660. return new PageInfo<>(list);
  661. }
  662. public List<Company> getCompanyListByCondition(CustomSearchCondition condition) {
  663. SearchCondition searchCondition = new SearchCondition();
  664. searchCondition.setCompanyName(condition.getName());
  665. List<Company> list = companyDao.getCompanyByCondition(searchCondition);
  666. return list;
  667. }
  668. public Company findByParkIdAndCompanyName(String company_name, Integer id) {
  669. return companyDao.findByParkIdAndCompanyName(company_name, id);
  670. }
  671. /**
  672. * 获取公司信息
  673. *
  674. * @param userId
  675. * @return
  676. */
  677. public CompanyInfoDto findByUserId(Integer userId) {
  678. return companyDao.findByUserId(userId);
  679. }
  680. /**
  681. * 获取公司联系人
  682. *
  683. * @param letter
  684. * @return
  685. */
  686. public List<CompanyContacts> findCompanyListByName(String letter, String companyName) {
  687. return companyContactService.findCompanyContactList(letter, companyName, ShiroUtils.getStreetId(), ShiroUtils.getBuildId());
  688. }
  689. private List<Company> companyContacts(String letter, String searchName) {
  690. List<CompanyContact> companies = companyContactService.findContactList(searchName);
  691. List<Company> companyList = new ArrayList<>();
  692. List<CompanyContact> contactList = new ArrayList<>();
  693. CompanyContacts ccs = new CompanyContacts();
  694. for (LetterEnum anEnum : LetterEnum.values()) {
  695. ccs.setLetter(anEnum.toString());
  696. for (CompanyContact contact : companies) {
  697. if (contact.getLetter().equals(anEnum.toString())){
  698. }
  699. }
  700. }
  701. return null;
  702. }
  703. /**
  704. * 根据社会统一信用代码查找企业
  705. *
  706. * @param uscc
  707. */
  708. public List<Company> findListByUscc(String uscc) {
  709. return companyDao.findListByUscc(uscc);
  710. }
  711. }