From 021e5cb3aada949e00470e477c04c7f2cf8ca92a Mon Sep 17 00:00:00 2001 From: ZQN <364596817@qq.com> Date: 星期一, 29 七月 2024 15:58:56 +0800 Subject: [PATCH] 执法申请新增企业 --- project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java | 68 ++++++++++++++++----------------- 1 files changed, 33 insertions(+), 35 deletions(-) diff --git a/project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java b/project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java index b4df7a6..c3f46d2 100644 --- a/project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java +++ b/project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java @@ -62,9 +62,10 @@ SysCompany add = Convert.convert(SysCompany.class, bo); add.setCompanyStatus(1); validEntityBeforeSave(add); - add.setCompanyStatus(0); boolean save = this.save(add); - addCompanyUser(add, 0); + if (isAddUser(bo.getCompanyPhone())){ + addCompanyUser(add, 0); + } return save; } @@ -74,14 +75,18 @@ { SysCompany old = this.getById(bo.getCompanyId()); SysCompany update = Convert.convert(SysCompany.class, bo); - if (!old.getCompanyPhone().equals(update.getCompanyPhone())){ - boolean delUser = delCompanyUser(old.getCompanyId()); - if (!delUser) { - throw new BaseException("鍘熶紒涓氱敤鎴锋竻闄ゅけ璐ワ紝璇疯仈绯荤鐞嗗憳锛�"); - } - this.addCompanyUser(update, update.getCompanyStatus()==0 ? 1 : 0); - } validEntityBeforeSave(update); + if (!old.getCompanyPhone().equals(update.getCompanyPhone())){ + if (this.count(SysCompany::getCompanyPhone, old.getCompanyPhone())==1){ + boolean delUser = delCompanyUser(old.getCompanyPhone()); + if (!delUser) { + throw new BaseException("鍘熶紒涓氱敤鎴锋竻闄ゅけ璐ワ紝璇疯仈绯荤鐞嗗憳锛�"); + } + } + if (isAddUser(update.getCompanyPhone())){ + addCompanyUser(update, update.getCompanyStatus()==0 ? 1 : 0); + } + } return this.updateById(update); } @@ -103,7 +108,7 @@ public Boolean deleteByIds(Collection<Long> ids) { for (Long id : ids) { - boolean b = delCompanyUser(id); + boolean b = delCompanyUser(this.getById(id).getCompanyPhone()); if (!b) { throw new BaseException(String.format("鍘熶紒涓� %1$s 鐢ㄦ埛娓呴櫎澶辫触锛岃鑱旂郴绠$悊鍛橈紒", id)); } @@ -153,7 +158,9 @@ List<SysCompany> companies = Convert.toList(SysCompany.class, resultVo.getVoList()); boolean b = this.saveOrUpdateBatch(companies); for (SysCompany company : companies) { - addCompanyUser(company,1); + if (isAddUser(company.getCompanyPhone())){ + addCompanyUser(company,1); + } } return b; } @@ -168,6 +175,7 @@ private void validEntityBeforeSave(SysCompany entity) { entity.setIsImport(0); + if (StringUtils.isEmpty(entity.getCompanyImg())){ throw new BaseException(String.format("%1$s锛岃涓婁紶钀ヤ笟鎵х収", entity.getCompanyName())); } @@ -195,15 +203,8 @@ if (nameCount>0){ throw new BaseException(String.format("%1$s锛屼紒涓氬悕宸插瓨鍦紒", entity.getCompanyName())); } - int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone())); - if (phoneCount>0){ - throw new BaseException(String.format("%1$s锛屼紒涓氳仈绯荤數璇濆凡瀛樺湪锛�", entity.getCompanyName())); - } SysUser user = new SysUser(); user.setPhonenumber(entity.getCompanyPhone()); - if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { - throw new BaseException(String.format("%1$s锛屼紒涓氳仈绯荤數璇濆凡瀛樺湪锛岃鏇存崲鎵嬫満鍙凤紒", entity.getCompanyName())); - } } else { int codeCount = this.count(lq().eq(SysCompany::getCompanyCode, entity.getCompanyCode()).ne(SysCompany::getCompanyId,entity.getCompanyId())); if (codeCount>0){ @@ -212,10 +213,6 @@ int nameCount = this.count(lq().eq(SysCompany::getCompanyName, entity.getCompanyName()).ne(SysCompany::getCompanyId,entity.getCompanyId())); if (nameCount>0){ throw new BaseException(String.format("%1$s锛屼紒涓氬悕宸插瓨鍦紒", entity.getCompanyName())); - } - int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone()).ne(SysCompany::getCompanyId,entity.getCompanyId())); - if (phoneCount>0){ - throw new BaseException(String.format("%1$s锛屼紒涓氳仈绯荤數璇濆凡瀛樺湪锛�", entity.getCompanyName())); } } } @@ -235,6 +232,10 @@ } if (StringUtils.isEmpty(entity.getCompanyPhone())){ errorList.add(new ImportError(3, "璇峰~鍐欎紒涓氳仈绯讳汉鐢佃瘽锛�")); + } else { + if (entity.getCompanyPhone().length()!=11){ + errorList.add(new ImportError(3, "璇峰~鍐欐纭墜鏈哄彿锛�")); + } } if (StringUtils.isEmpty(entity.getCompanyAddress())){ errorList.add(new ImportError(4, "璇峰~鍐欎紒涓氬湴鍧�锛�")); @@ -247,15 +248,6 @@ if (nameCount>0){ errorList.add(new ImportError(0, "浼佷笟鍚嶅凡瀛樺湪锛�")); } - int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone())); - SysUser user = new SysUser(); - user.setPhonenumber(entity.getCompanyPhone()); - if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { - errorList.add(new ImportError(3, "浼佷笟鑱旂郴鐢佃瘽绯荤粺涓凡瀛樺湪锛岃鏇存崲鐢佃瘽锛�")); - } - if (phoneCount>0){ - errorList.add(new ImportError(3, "浼佷笟鑱旂郴鐢佃瘽宸插瓨鍦紒")); - } entity.setCheckStatus(2); } @@ -264,7 +256,8 @@ * @param entity 浼佷笟淇℃伅 */ @Async - protected void addCompanyUser(SysCompany entity, Integer isImport) + @Override + public void addCompanyUser(SysCompany entity, Integer isImport) { SysUser user = new SysUser(); @@ -308,11 +301,11 @@ /** * 鍒犻櫎浼佷笟鐢ㄦ埛 - * @param companyId 浼佷笟id + * @param companyPhone 浼佷笟id */ - protected boolean delCompanyUser(Long companyId) + protected boolean delCompanyUser(String companyPhone) { - return userService.deleteUserByDeptId(companyId)>0; + return userService.deleteUserByCompanyPhone(companyPhone)>0; } /** @@ -346,4 +339,9 @@ } return qw; } + + private Boolean isAddUser(String phone) + { + return userService.count(userService.lq().eq(SysUser::getUserName, phone).eq(SysUser::getDelFlag,0))==0; + } } -- Gitblit v1.9.1