Browse Source

组织机构,增加修改时判断组织机构代码重复性

周箭河 5 years ago
parent
commit
f87b962e95

+ 8 - 0
mec-web/src/main/java/com/ym/mec/web/controller/OrganizationController.java

@@ -29,6 +29,10 @@ public class OrganizationController extends BaseController {
     @ApiOperation(value = "新增机构")
     @PostMapping("/add")
     public Object add(Organization organization){
+        Organization organizationByCode = organizationService.findByCode(organization.getCode());
+        if(organizationByCode != null){
+            return failed("组织机构代码已经存在,请更改");
+        }
         Date date = new Date();
         organization.setCreateTime(date);
         organization.setUpdateTime(date);
@@ -44,6 +48,10 @@ public class OrganizationController extends BaseController {
     @ApiOperation(value = "修改机构信息")
     @PutMapping("/update")
     public Object update(Organization organization){
+        Organization organizationByCode = organizationService.findByCode(organization.getCode());
+        if(organizationByCode != null && !organizationByCode.getId().equals(organization.getId())){
+            return failed("组织机构代码已存在,请更改");
+        }
         organization.setUpdateTime(new Date());
         return succeed(organizationService.update(organization));
     }

+ 7 - 0
mec-web/src/main/java/com/ym/mec/web/dal/dao/OrganizationDao.java

@@ -15,4 +15,11 @@ public interface OrganizationDao extends BaseDAO<Integer, Organization> {
      * @return
      */
     List<Organization> findByParentId(@Param("parentId") Integer parentId, @Param("delFlag") String delFlag);
+
+    /**
+     * 根据机构编码查机构
+     * @param code
+     * @return
+     */
+    Organization findByCode(@Param("code") int code);
 }

+ 9 - 0
mec-web/src/main/java/com/ym/mec/web/service/OrganizationService.java

@@ -4,6 +4,7 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.web.dal.entity.Organization;
 import com.ym.mec.web.dal.page.OrganizationQueryInfo;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -16,4 +17,12 @@ public interface OrganizationService extends BaseService<Integer, Organization>
      */
     PageInfo<Organization> queryTreePage(OrganizationQueryInfo queryInfo);
 
+    /**
+     * 根据机构编码查机构
+     * @param code
+     * @return
+     */
+    Organization findByCode(@Param("code") int code);
+
+
 }

+ 4 - 0
mec-web/src/main/java/com/ym/mec/web/service/impl/OrganizationServiceImpl.java

@@ -51,5 +51,9 @@ public class OrganizationServiceImpl extends BaseServiceImpl<Integer, Organizati
 		}
 			return org;
 	}
+
+	public Organization findByCode(int code){
+		return organizationDao.findByCode(code);
+	}
 	
 }

+ 4 - 0
mec-web/src/main/resources/config/mybatis/OrganizationMapper.xml

@@ -99,4 +99,8 @@
     <select id="findByParentId" resultMap="Organization">
         SELECT * FROM organization <include refid="queryPageSql"/>
     </select>
+
+    <select id="findByCode" resultMap="Organization">
+        SELECT * FROM organization WHERE code = #{code}
+    </select>
 </mapper>