取货点和社区添加验证重复

This commit is contained in:
2023-03-25 15:02:58 +08:00
parent 1639e0ec9a
commit f302bb372e
10 changed files with 86 additions and 10 deletions

View File

@@ -63,6 +63,11 @@ public class BuildWuyeCompanyController {
@PreAuthorize("hasAuthority('build:wuyeCompany:create')") @PreAuthorize("hasAuthority('build:wuyeCompany:create')")
public Object saveBuildWuyeCompany(@RequestBody BuildWuyeCompany entity) { public Object saveBuildWuyeCompany(@RequestBody BuildWuyeCompany entity) {
try { try {
//查询是否存在该社区
int count = IBuildWuyeCompanyService.selectByName(entity.getName());
if(count>0){
return new CommonResult().failed("该社区已存在");
}
entity.setStatus(StatusEnum.AuditType.SUCESS.code()); entity.setStatus(StatusEnum.AuditType.SUCESS.code());
if (IBuildWuyeCompanyService.saveCompany(entity)) { if (IBuildWuyeCompanyService.saveCompany(entity)) {
return new CommonResult().success(); return new CommonResult().success();
@@ -80,6 +85,11 @@ public class BuildWuyeCompanyController {
@PreAuthorize("hasAuthority('build:wuyeCompany:update')") @PreAuthorize("hasAuthority('build:wuyeCompany:update')")
public Object updateBuildWuyeCompany(@RequestBody BuildWuyeCompany entity) { public Object updateBuildWuyeCompany(@RequestBody BuildWuyeCompany entity) {
try { try {
//查询是否存在该社区
int count = IBuildWuyeCompanyService.selectByNameAndId(entity.getName(),entity.getId());
if(count>0){
return new CommonResult().failed("该社区已存在");
}
if (IBuildWuyeCompanyService.updateById(entity)) { if (IBuildWuyeCompanyService.updateById(entity)) {
return new CommonResult().success(); return new CommonResult().success();
} }

View File

@@ -70,10 +70,12 @@ public class BuildingCommunityController {
entity.setCreateTime(new Date()); entity.setCreateTime(new Date());
entity.setStatus(StatusEnum.AuditType.SUCESS.code()); entity.setStatus(StatusEnum.AuditType.SUCESS.code());
if (ValidatorUtils.empty(entity.getCompanyId())) { if (ValidatorUtils.empty(entity.getCompanyId())) {
// entity.setCompanyId(UserUtils.getCurrentMember().getStoreId()); return new CommonResult().failed("请选择物业啊");
} }
if (ValidatorUtils.empty(entity.getCompanyId())) { //判断该物业是否存在相同小区的名称
return new CommonResult().failed("请选择物业攻啊"); int count = IBuildingCommunityService.selectByNameAndCompanyId(entity.getName(),entity.getCompanyId());
if(count > 0){
return new CommonResult().failed("该取货点已存在");
} }
if (IBuildingCommunityService.saveCommunity(entity)) { if (IBuildingCommunityService.saveCommunity(entity)) {
return new CommonResult().success(); return new CommonResult().success();
@@ -91,6 +93,11 @@ public class BuildingCommunityController {
public Object updateBuildingCommunity(@RequestBody BuildingCommunity entity) { public Object updateBuildingCommunity(@RequestBody BuildingCommunity entity) {
try { try {
//判断该物业是否存在相同小区的名称
int count = IBuildingCommunityService.selectByNameAndCompanyIdAndId(entity.getName(),entity.getCompanyId(),entity.getId());
if(count > 0){
return new CommonResult().failed("该取货点已存在");
}
if (IBuildingCommunityService.updateById(entity)) { if (IBuildingCommunityService.updateById(entity)) {
return new CommonResult().success(); return new CommonResult().success();
} }

View File

@@ -14,4 +14,8 @@ import com.zscat.mallplus.build.entity.BuildWuyeCompany;
public interface IBuildWuyeCompanyService extends IService<BuildWuyeCompany> { public interface IBuildWuyeCompanyService extends IService<BuildWuyeCompany> {
boolean saveCompany(BuildWuyeCompany entity); boolean saveCompany(BuildWuyeCompany entity);
int selectByName(String name);
int selectByNameAndId(String name, Long id);
} }

View File

@@ -19,4 +19,8 @@ public interface IBuildingCommunityService extends IService<BuildingCommunity> {
boolean saveCommunity(BuildingCommunity entity); boolean saveCommunity(BuildingCommunity entity);
IPage<BuildingCommunity> pagerList(Page<BuildingCommunity> buildingCommunityPage, QueryWrapper<BuildingCommunity> buildingCommunityQueryWrapper); IPage<BuildingCommunity> pagerList(Page<BuildingCommunity> buildingCommunityPage, QueryWrapper<BuildingCommunity> buildingCommunityQueryWrapper);
int selectByNameAndCompanyId(String name, Long companyId);
int selectByNameAndCompanyIdAndId(String name, Long companyId, Long id);
} }

View File

@@ -67,4 +67,14 @@ public class BuildWuyeCompanyServiceImpl extends ServiceImpl<BuildWuyeCompanyMap
// userRoleMapper.insert(userRole); // userRoleMapper.insert(userRole);
return true; return true;
} }
@Override
public int selectByName(String name) {
return baseMapper.selectByName(name);
}
@Override
public int selectByNameAndId(String name, Long id) {
return baseMapper.selectByNameAndId(name,id);
}
} }

View File

@@ -44,26 +44,25 @@ public class BuildingCommunityServiceImpl extends ServiceImpl<BuildingCommunityM
entity.setCreateTime(new Date()); entity.setCreateTime(new Date());
communityMapper.insert(entity); communityMapper.insert(entity);
// 2 创建物业公司账号 // 2 创建物业公司账号
SysUser user = new SysUser(); /* SysUser user = new SysUser();
user.setUsername(entity.getName()); user.setUsername(entity.getName());
SysUser umsAdminList = userMapper.selectByUserName(entity.getName()); SysUser umsAdminList = userMapper.selectByUserName(entity.getName());
if (umsAdminList != null) { if (umsAdminList != null) {
throw new ApiMallPlusException("此小区已存在"); throw new ApiMallPlusException("此小区已存在");
} }
user.setStatus(1); user.setStatus(1);
// user.setStoreId(entity.getId());
user.setPassword(passwordEncoder.encode("123456")); user.setPassword(passwordEncoder.encode("123456"));
user.setCreateTime(new Date()); user.setCreateTime(new Date());
user.setSupplyId(0L); user.setSupplyId(0L);
user.setNote("小区账户小区ID=" + entity.getName() + "," + entity.getId()); user.setNote("小区账户小区ID=" + entity.getName() + "," + entity.getId());
user.setNickName(entity.getName()); user.setNickName(entity.getName());
userMapper.insert(user); userMapper.insert(user);*/
// 3 分配物业公司角色 // 3 分配物业公司角色
SysUserRole userRole = new SysUserRole(); /* SysUserRole userRole = new SysUserRole();
userRole.setAdminId(user.getId()); userRole.setAdminId(user.getId());
userRole.setRoleId(5L); userRole.setRoleId(5L);
userRoleMapper.insert(userRole); userRoleMapper.insert(userRole);*/
return true; return true;
} }
@@ -72,4 +71,14 @@ public class BuildingCommunityServiceImpl extends ServiceImpl<BuildingCommunityM
IPage<BuildingCommunity> page = baseMapper.pagerList(buildingCommunityPage,buildingCommunityQueryWrapper); IPage<BuildingCommunity> page = baseMapper.pagerList(buildingCommunityPage,buildingCommunityQueryWrapper);
return page; return page;
} }
@Override
public int selectByNameAndCompanyId(String name, Long companyId) {
return baseMapper.selectByNameAndCompanyId(name,companyId);
}
@Override
public int selectByNameAndCompanyIdAndId(String name, Long companyId, Long id) {
return baseMapper.selectByNameAndCompanyIdAndId(name,companyId,id);
}
} }

View File

@@ -2,6 +2,7 @@ package com.zscat.mallplus.build.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zscat.mallplus.build.entity.BuildWuyeCompany; import com.zscat.mallplus.build.entity.BuildWuyeCompany;
import org.apache.ibatis.annotations.Param;
/** /**
* <p> * <p>
@@ -13,4 +14,7 @@ import com.zscat.mallplus.build.entity.BuildWuyeCompany;
*/ */
public interface BuildWuyeCompanyMapper extends BaseMapper<BuildWuyeCompany> { public interface BuildWuyeCompanyMapper extends BaseMapper<BuildWuyeCompany> {
int selectByName(String name);
int selectByNameAndId(@Param("name") String name, @Param("id") Long id);
} }

View File

@@ -31,4 +31,8 @@ public interface BuildingCommunityMapper extends BaseMapper<BuildingCommunity> {
@Param("pageSize") Integer pageSize); @Param("pageSize") Integer pageSize);
IPage<BuildingCommunity> pagerList(Page<BuildingCommunity> buildingCommunityPage, @Param(Constants.WRAPPER)QueryWrapper<BuildingCommunity> buildingCommunityQueryWrapper); IPage<BuildingCommunity> pagerList(Page<BuildingCommunity> buildingCommunityPage, @Param(Constants.WRAPPER)QueryWrapper<BuildingCommunity> buildingCommunityQueryWrapper);
int selectByNameAndCompanyId(@Param("name") String name, @Param("companyId") Long companyId);
int selectByNameAndCompanyIdAndId(@Param("name") String name, @Param("companyId") Long companyId, @Param("id") Long id);
} }

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.zscat.mallplus.build.mapper.BuildWuyeCompanyMapper">
<select id="selectByName" resultType="int">
select count(*)
from build_wuye_company
where name = #{name}
</select>
<select id="selectByNameAndId" resultType="int">
select count(*)
from build_wuye_company
where name = #{name}
and id &lt;&gt; #{id}
</select>
</mapper>

View File

@@ -45,4 +45,12 @@
${ew.sqlSegment} ${ew.sqlSegment}
</where> </where>
</select> </select>
<select id="selectByNameAndCompanyId" resultType="int">
select count(*) from building_community where name = #{name} and company_id = #{companyId}
</select>
<select id="selectByNameAndCompanyIdAndId" resultType="int">
select count(*) from building_community where name = #{name} and company_id = #{companyId} and id &lt;&gt; #{id}
</select>
</mapper> </mapper>