35 changed files with 773 additions and 78 deletions
@ -0,0 +1,152 @@ |
|||
package com.model2d3d.viewer.back.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.model2d3d.viewer.back.common.response.PageResponse; |
|||
import com.model2d3d.viewer.back.common.response.ResponseCode; |
|||
import com.model2d3d.viewer.back.common.response.SimpleDataResponse; |
|||
import com.model2d3d.viewer.back.configurator.interceptor.AccessRequired; |
|||
import com.model2d3d.viewer.back.dto.building.BuildingSearchParams; |
|||
import com.model2d3d.viewer.back.dto.building.DeleteBuildingParams; |
|||
import com.model2d3d.viewer.back.dto.building.OptBuildingParams; |
|||
import com.model2d3d.viewer.back.service.BuildingService; |
|||
import com.model2d3d.viewer.back.vo.building.BuildingPageVO; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.Parameter; |
|||
|
|||
import java.io.FileNotFoundException; |
|||
|
|||
import jakarta.servlet.http.HttpServletResponse; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
|
|||
/** |
|||
* |
|||
* @author jwy-style |
|||
* |
|||
*/ |
|||
/** |
|||
* Controller for managing buildings. |
|||
* Handles JSON formatted data and requires authentication token verification for all methods in the class. |
|||
* Request mapping for HTTP requests is "/building". |
|||
*/ |
|||
@RestController |
|||
@AccessRequired |
|||
// Indicates whether login token verification is required. Placing it here means all methods in this class require authentication.
|
|||
@RequestMapping("/building") // HTTP request path mapping
|
|||
@Tag(name = "BuildingController", description = "Building Management Module - APIs for managing buildings") |
|||
@SuppressWarnings("unchecked") |
|||
public class BuildingController { |
|||
|
|||
private static final Logger logger = LoggerFactory.getLogger(BuildingController.class); |
|||
|
|||
@Autowired |
|||
private BuildingService buildingService; |
|||
|
|||
/** |
|||
* Add a building. |
|||
* |
|||
* @param optBuildingParams parameters for building operation |
|||
* @param LoginName login name |
|||
* @param AccessToken authentication token |
|||
* @param UserId user ID |
|||
* @param CompanyId user's company ID (optional) |
|||
* @param LanguageType language type (0: Chinese, 1: English, 2: Japanese) |
|||
* @return a SimpleDataResponse indicating the result of the add operation |
|||
*/ |
|||
@AccessRequired |
|||
@Operation(summary = "Add a building") |
|||
@RequestMapping(value = "/add", method = RequestMethod.POST) |
|||
public SimpleDataResponse add( |
|||
@RequestBody @Validated OptBuildingParams optBuildingParams, |
|||
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required = true) String LoginName, |
|||
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required = true) String AccessToken, |
|||
@Parameter(name="UserId",description="用户ID",required=true,schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) String UserId, |
|||
@Parameter(name="CompanyId",description="所属企业ID",required=false,schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) String CompanyId, |
|||
@Parameter(name = "LanguageType", description = "Language type", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required = true) Integer LanguageType) { |
|||
return buildingService.add(optBuildingParams, UserId, CompanyId, LanguageType); |
|||
} |
|||
|
|||
/** |
|||
* Edit a building. |
|||
* |
|||
* @param optBuildingParams parameters for building operation |
|||
* @param LoginName login name |
|||
* @param AccessToken authentication token |
|||
* @param UserId user ID |
|||
* @param CompanyId user's company ID (optional) |
|||
* @param LanguageType language type (0: Chinese, 1: English, 2: Japanese) |
|||
* @return a SimpleDataResponse indicating the result of the edit operation |
|||
*/ |
|||
@Operation(summary = "Edit a building") |
|||
@RequestMapping(value = "/edit", method = RequestMethod.POST) |
|||
public SimpleDataResponse edit( |
|||
@RequestBody @Validated OptBuildingParams optBuildingParams, |
|||
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required = true) String LoginName, |
|||
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required = true) String AccessToken, |
|||
@Parameter(name="UserId",description="用户ID",required=true,schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) String UserId, |
|||
@Parameter(name="CompanyId",description="所属企业ID",required=false,schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) String CompanyId, |
|||
@Parameter(name = "LanguageType", description = "Language type", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required = true) Integer LanguageType) { |
|||
return buildingService.edit(optBuildingParams, UserId, CompanyId, LanguageType); |
|||
} |
|||
|
|||
/** |
|||
* Batch delete buildings. |
|||
* |
|||
* @param deleteBuildingParams parameters for deleting buildings |
|||
* @param LoginName login name |
|||
* @param AccessToken authentication token |
|||
* @param UserId user ID |
|||
* @param CompanyId user's company ID (optional) |
|||
* @param LanguageType language type (0: Chinese, 1: English, 2: Japanese) |
|||
* @return a SimpleDataResponse indicating the result of the batch delete operation |
|||
*/ |
|||
@Operation(summary = "Batch delete buildings") |
|||
@RequestMapping(value = "/batchDelete", method = RequestMethod.POST) |
|||
public SimpleDataResponse batchDelete( |
|||
@RequestBody @Validated DeleteBuildingParams deleteBuildingParams, |
|||
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required = true) String LoginName, |
|||
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required = true) String AccessToken, |
|||
@Parameter(name="UserId",description="用户ID",required=true,schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) String UserId, |
|||
@Parameter(name="CompanyId",description="所属企业ID",required=false,schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) String CompanyId, |
|||
@Parameter(name = "LanguageType", description = "Language type", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required = true) Integer LanguageType) { |
|||
return buildingService.batchDelete(deleteBuildingParams, UserId, CompanyId, LanguageType); |
|||
} |
|||
|
|||
/** |
|||
* Get a page of building list. |
|||
**/ |
|||
@Operation(summary = "Get a page of building list") |
|||
@RequestMapping(value = "/getListPage", method = RequestMethod.GET) |
|||
public PageResponse<IPage<BuildingPageVO>> getListPage( |
|||
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required = true) String LoginName, |
|||
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required = true) String AccessToken, |
|||
@Parameter(name="UserId",description="用户ID",required=true,schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) String UserId, |
|||
@Parameter(name="CompanyId",description="所属企业ID",required=false,schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) String CompanyId, |
|||
@Parameter(name = "LanguageType", description = "Language type", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required = true) Integer LanguageType, |
|||
@Parameter(name = "UTCOffset", description = "Difference between GMT and local time in minutes", required = true, schema = @Schema(defaultValue = "-480")) @RequestHeader(required = true) Integer UTCOffset, |
|||
BuildingSearchParams pageSearchParam) { |
|||
|
|||
pageSearchParam.setUserId(UserId); |
|||
|
|||
PageResponse<IPage<BuildingPageVO>> pageResponse = new PageResponse<>(); |
|||
try { |
|||
pageResponse.setData(buildingService.getListPage(pageSearchParam, CompanyId, UserId, LanguageType, UTCOffset)); |
|||
pageResponse.setCode(ResponseCode.SUCCESS); |
|||
pageResponse.setMsg("success"); |
|||
} catch (Exception e) { |
|||
logger.error("Error querying list", e); |
|||
pageResponse.setCode(ResponseCode.SERVER_ERROR); |
|||
pageResponse.setMsg("service error"); |
|||
} |
|||
return pageResponse; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
package com.model2d3d.viewer.back.dao.auto; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.model2d3d.viewer.back.model.BasicBuilding; |
|||
|
|||
/** |
|||
* <p> |
|||
* 楼宇表 Mapper 接口 |
|||
* </p> |
|||
* |
|||
* @author jwy |
|||
* @since |
|||
*/ |
|||
public interface BasicBuildingMapper extends BaseMapper<BasicBuilding> { |
|||
|
|||
} |
|||
|
@ -0,0 +1,27 @@ |
|||
package com.model2d3d.viewer.back.dao.ex; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.model2d3d.viewer.back.dao.auto.BasicBuildingMapper; |
|||
import com.model2d3d.viewer.back.dao.auto.BasicCompanyMapper; |
|||
import com.model2d3d.viewer.back.dto.building.BuildingSearchParams; |
|||
import com.model2d3d.viewer.back.dto.building.OptBuildingParams; |
|||
import com.model2d3d.viewer.back.dto.company.CompanySearchParams; |
|||
import com.model2d3d.viewer.back.dto.company.OptCompanyParams; |
|||
import com.model2d3d.viewer.back.model.BasicCompany; |
|||
import com.model2d3d.viewer.back.vo.TreeMenusDTO; |
|||
import com.model2d3d.viewer.back.vo.building.BuildingPageVO; |
|||
import com.model2d3d.viewer.back.vo.company.CompanyPageDTO; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Mapper |
|||
public interface BasicBuildingMapperExt extends BasicBuildingMapper { |
|||
|
|||
int checkExist(OptBuildingParams optBuildingParams); |
|||
|
|||
IPage<BuildingPageVO> getListPage(Page page, @Param("params") BuildingSearchParams pageSearchParam); |
|||
} |
@ -0,0 +1,26 @@ |
|||
<?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.model2d3d.viewer.back.dao.auto.BasicBuildingMapper"> |
|||
|
|||
<!-- 通用查询映射结果 --> |
|||
<resultMap id="BaseResultMap" type="com.model2d3d.viewer.back.model.BasicBuilding"> |
|||
<id column="building_id" property="buildingId" /> |
|||
<result column="company_id" property="companyId" /> |
|||
<result column="name" property="name" /> |
|||
<result column="address" property="address" /> |
|||
<result column="unique_identification" property="uniqueIdentification" /> |
|||
<result column="dimensional_url" property="dimensionalUrl" /> |
|||
<result column="flag" property="flag" /> |
|||
<result column="create_time" property="createTime" /> |
|||
<result column="creator_id" property="creatorId" /> |
|||
<result column="modify_time" property="modifyTime" /> |
|||
<result column="modifier_id" property="modifierId" /> |
|||
<result column="udf_building_id" property="udfBuildingId" /> |
|||
</resultMap> |
|||
|
|||
<!-- 通用查询结果列 --> |
|||
<sql id="Base_Column_List"> |
|||
building_id, company_id, name, address, unique_identification, dimensional_url, flag, create_time, creator_id, modify_time, modifier_id, udf_building_id |
|||
</sql> |
|||
|
|||
</mapper> |
@ -0,0 +1,45 @@ |
|||
<?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.model2d3d.viewer.back.dao.ex.BasicBuildingMapperExt"> |
|||
|
|||
|
|||
<select id="checkExist" resultType="java.lang.Integer"> |
|||
SELECT |
|||
COUNT(1) |
|||
FROM |
|||
basic_building |
|||
WHERE |
|||
flag != 1 AND (name = #{buildingName} OR unique_identification = #{uniqueIdentification}) |
|||
<if test="companyId != null"> |
|||
AND company_id = #{companyId} |
|||
</if> |
|||
<if test="buildingId != null"> |
|||
AND building_id != #{buildingId} |
|||
</if> |
|||
</select> |
|||
|
|||
|
|||
<select id="getListPage" resultType="com.model2d3d.viewer.back.vo.building.BuildingPageVO"> |
|||
SELECT |
|||
bbuilding.building_id buildingId, |
|||
bbuilding.company_id companyId, |
|||
bbuilding.name buildingName, |
|||
bbuilding.address, |
|||
bbuilding.unique_identification, |
|||
bbuilding.dimensional_url |
|||
FROM |
|||
basic_building bbuilding |
|||
INNER JOIN basic_company bcomp ON bcomp.id = bbuilding.company_id |
|||
WHERE |
|||
bbuilding.flag != 1 AND bcomp.flag != 1 |
|||
AND bbuilding.company_id IN <foreach collection="params.companyIdList" item="item" open="(" separator="," close=")">#{item}</foreach> |
|||
<if test="params.buildingIdList != null"> |
|||
AND bbuilding.building_id IN <foreach collection="params.buildingIdList" item="item" open="(" separator="," close=")">#{item}</foreach> |
|||
</if> |
|||
<if test="params.buildingName != null"> |
|||
AND bbuilding.name LIKE CONCAT('%',#{params.buildingName},'%') |
|||
</if> |
|||
</select> |
|||
|
|||
|
|||
</mapper> |
@ -0,0 +1,25 @@ |
|||
package com.model2d3d.viewer.back.dto.building; |
|||
|
|||
import java.util.List; |
|||
|
|||
import com.model2d3d.viewer.back.dto.BaseSearchParams; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @author Mr.Jiang |
|||
* @time 2022年7月21日 下午8:50:31 |
|||
*/ |
|||
@Data |
|||
public class BuildingSearchParams extends BaseSearchParams { |
|||
|
|||
@Schema(description ="Building name", example = "张三李四") |
|||
private String buildingName; |
|||
|
|||
@Schema(description ="Building IDs, comma-separated", example = "1,47") |
|||
private String buildingIds; |
|||
|
|||
@Schema(description ="Building IDs", hidden = true) |
|||
private List<String> buildingIdList; |
|||
|
|||
} |
@ -0,0 +1,18 @@ |
|||
package com.model2d3d.viewer.back.dto.building; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author Mr.Jiang |
|||
* @time 2022年7月21日 下午8:50:31 |
|||
*/ |
|||
@Data |
|||
public class DeleteBuildingParams{ |
|||
|
|||
@Schema(description ="Building IDs, array", example = "[\"acbdef2738967\",\"abcc556587\"]") |
|||
private List<String> buildingIds; |
|||
|
|||
} |
@ -0,0 +1,42 @@ |
|||
package com.model2d3d.viewer.back.dto.building; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import jakarta.validation.constraints.NotBlank; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
|
|||
/** |
|||
* @author Mr.Jiang |
|||
* @time 2022年7月21日 下午8:50:31 |
|||
*/ |
|||
@Data |
|||
public class OptBuildingParams{ |
|||
|
|||
@Schema(description ="Building unique identifier ID, not required for new additions", example = "2738967") |
|||
private String buildingId; |
|||
|
|||
@Schema(description ="Company ID", example = "2738967", hidden = true) |
|||
private String companyId; |
|||
|
|||
@NotBlank(message = "1001") |
|||
@Length(max = 100,message = "1002") |
|||
@Schema(description ="Building name", example = "testBuilding1", required = true) |
|||
private String buildingName; |
|||
|
|||
@Schema(description ="Address", example = "Abiko City, Japan", required = true) |
|||
private String address; |
|||
|
|||
// @Schema(description ="User-defined building ID", example = "123AAA6", required = true)
|
|||
// private String udfBuildingId;
|
|||
|
|||
@NotBlank(message = "1001") |
|||
@Length(max = 255,message = "1002") |
|||
@Schema(description ="unique identification", example = "123cbaede2aa6", required = true) |
|||
private String uniqueIdentification; |
|||
|
|||
@NotBlank(message = "1001") |
|||
@Length(max = 255,message = "1002") |
|||
@Schema(description ="3D redirect URL", example = "www.3d.com", required = true) |
|||
private String dimensionalUrl; |
|||
|
|||
} |
@ -0,0 +1,70 @@ |
|||
package com.model2d3d.viewer.back.model; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
@Getter |
|||
@Setter |
|||
@ToString |
|||
@Accessors(chain = true) |
|||
@TableName("basic_building") |
|||
@Schema(description = "楼宇表") |
|||
public class BasicBuilding implements Serializable { |
|||
|
|||
@TableId(value = "building_id", type = IdType.ASSIGN_UUID) |
|||
@Schema(description = "") |
|||
private String buildingId; |
|||
|
|||
|
|||
@TableField("company_id") |
|||
@Schema(description = "") |
|||
private String companyId; |
|||
|
|||
@TableField("name") |
|||
@Schema(description = "楼宇名称") |
|||
private String name; |
|||
|
|||
@TableField("address") |
|||
@Schema(description = "地址") |
|||
private String address; |
|||
|
|||
@TableField("unique_identification") |
|||
@Schema(description = "唯一标识") |
|||
private String uniqueIdentification; |
|||
|
|||
@TableField("dimensional_url") |
|||
@Schema(description = "立体画面跳转url") |
|||
private String dimensionalUrl; |
|||
|
|||
@TableField("flag") |
|||
@Schema(description = "0-正常,1-删除") |
|||
private Integer flag; |
|||
|
|||
@TableField("create_time") |
|||
@Schema(description = "") |
|||
private Long createTime; |
|||
|
|||
@TableField("creator_id") |
|||
@Schema(description = "") |
|||
private String creatorId; |
|||
|
|||
@TableField("modify_time") |
|||
@Schema(description = "") |
|||
private Long modifyTime; |
|||
|
|||
@TableField("modifier_id") |
|||
@Schema(description = "") |
|||
private String modifierId; |
|||
|
|||
@TableField("udf_building_id") |
|||
@Schema(description = "用户自定楼宇ID") |
|||
private String udfBuildingId; |
|||
|
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.model2d3d.viewer.back.vo.building; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import jakarta.validation.constraints.NotBlank; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
|
|||
/** |
|||
* @author Mr.Jiang |
|||
* @time 2022年7月21日 下午8:50:31 |
|||
*/ |
|||
@Data |
|||
public class BuildingPageVO{ |
|||
|
|||
@Schema(description ="Building unique identifier ID, not required for new additions", example = "2738967") |
|||
private String buildingId; |
|||
|
|||
@Schema(description ="Company ID", example = "2738967", hidden = true) |
|||
private String companyId; |
|||
|
|||
@Schema(description ="Building name", example = "testBuilding1", required = true) |
|||
private String buildingName; |
|||
|
|||
@Schema(description ="Address", example = "Abiko City, Japan", required = true) |
|||
private String address; |
|||
|
|||
// @Schema(description ="User-defined building ID", example = "123AAA6", required = true)
|
|||
// private String udfBuildingId;
|
|||
|
|||
@Schema(description ="unique identification", example = "123cbaede2aa6", required = true) |
|||
private String uniqueIdentification; |
|||
|
|||
@Schema(description ="3D redirect URL", example = "www.3d.com", required = true) |
|||
private String dimensionalUrl; |
|||
|
|||
} |
@ -0,0 +1,30 @@ |
|||
package com.model2d3d.viewer.back.service; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.model2d3d.viewer.back.common.response.SimpleDataResponse; |
|||
import com.model2d3d.viewer.back.dto.building.BuildingSearchParams; |
|||
import com.model2d3d.viewer.back.dto.building.DeleteBuildingParams; |
|||
import com.model2d3d.viewer.back.dto.building.OptBuildingParams; |
|||
import com.model2d3d.viewer.back.vo.building.BuildingPageVO; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* |
|||
* @author jwy-style |
|||
* |
|||
*/ |
|||
public interface BuildingService { |
|||
|
|||
SimpleDataResponse add(OptBuildingParams optBuildingParams, String userId, String companyId, Integer languageType); |
|||
|
|||
SimpleDataResponse edit(OptBuildingParams optBuildingParams, String userId, String companyId, Integer languageType); |
|||
|
|||
SimpleDataResponse batchDelete(DeleteBuildingParams deleteBuildingParams, String userId, String companyId, Integer languageType); |
|||
|
|||
IPage<BuildingPageVO> getListPage(BuildingSearchParams pageSearchParam, String companyId, String userId, |
|||
Integer languageType, Integer uTCOffset); |
|||
|
|||
} |
@ -0,0 +1,208 @@ |
|||
package com.model2d3d.viewer.back.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.model2d3d.viewer.back.common.exception.MsgCodeException; |
|||
import com.model2d3d.viewer.back.common.language.msg.MsgLanguageChange; |
|||
import com.model2d3d.viewer.back.common.response.ResponseCode; |
|||
import com.model2d3d.viewer.back.common.response.SimpleDataResponse; |
|||
import com.model2d3d.viewer.back.dao.ex.BasicBuildingMapperExt; |
|||
import com.model2d3d.viewer.back.dto.building.BuildingSearchParams; |
|||
import com.model2d3d.viewer.back.dto.building.DeleteBuildingParams; |
|||
import com.model2d3d.viewer.back.dto.building.OptBuildingParams; |
|||
import com.model2d3d.viewer.back.model.BasicBuilding; |
|||
import com.model2d3d.viewer.back.service.BuildingService; |
|||
import com.model2d3d.viewer.back.service.common.CommonOpt; |
|||
import com.model2d3d.viewer.back.util.CommonUtil; |
|||
import com.model2d3d.viewer.back.vo.building.BuildingPageVO; |
|||
import org.apache.commons.collections.CollectionUtils; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|||
import org.springframework.util.ObjectUtils; |
|||
|
|||
/** |
|||
* |
|||
* @author jwy-style |
|||
* |
|||
*/ |
|||
@Service |
|||
public class BuildingServiceImpl implements BuildingService { |
|||
|
|||
private static Logger logger = LoggerFactory.getLogger(BuildingServiceImpl.class); |
|||
|
|||
|
|||
@Autowired |
|||
private CommonOpt commonOpt; |
|||
|
|||
@Autowired |
|||
private MsgLanguageChange msgLanguageChange; |
|||
@Autowired |
|||
private BasicBuildingMapperExt basicBuildingMapperExt; |
|||
|
|||
|
|||
/** |
|||
* Adds a new building entity to the system. |
|||
* |
|||
* @param optBuildingParams The parameters for creating the building. |
|||
* @param userId The ID of the user performing the operation. |
|||
* @param companyId The ID of the company associated with the operation. |
|||
* @param languageType The language type for error messages. |
|||
* @return A SimpleDataResponse indicating the outcome of the operation. |
|||
*/ |
|||
@Override |
|||
@Transactional |
|||
public SimpleDataResponse add(OptBuildingParams optBuildingParams, String userId, String companyId, |
|||
Integer languageType) { |
|||
try { |
|||
optBuildingParams.setBuildingId(null); // Ensure buildingId is null for new entity creation
|
|||
|
|||
// Validate parameters and perform necessary checks
|
|||
try { |
|||
// Check company association to prevent unauthorized operations on other companies' data
|
|||
// if (ObjectUtils.isEmpty(optBuildingParams.getCompanyId())) {
|
|||
optBuildingParams.setCompanyId(companyId); |
|||
// } else {
|
|||
// checkCompany(optBuildingParams, languageType, companyId);
|
|||
// }
|
|||
|
|||
commonVerifyOpt(optBuildingParams, companyId, languageType); |
|||
|
|||
} catch (MsgCodeException e) { |
|||
return new SimpleDataResponse(ResponseCode.MSG_ERROR, e.getMessage()); |
|||
} |
|||
|
|||
long currentUnix = System.currentTimeMillis(); |
|||
BasicBuilding basicBuilding = new BasicBuilding(); |
|||
BeanUtils.copyProperties(optBuildingParams, basicBuilding); |
|||
basicBuilding.setCompanyId(companyId); |
|||
basicBuilding.setBuildingId(null); // Ensure buildingId is null for new entity creation
|
|||
basicBuilding.setName(optBuildingParams.getBuildingName()); |
|||
basicBuilding.setCreateTime(currentUnix); |
|||
basicBuilding.setCreatorId(userId); |
|||
|
|||
basicBuildingMapperExt.insert(basicBuilding); // Insert building entity
|
|||
|
|||
return SimpleDataResponse.success(); |
|||
} catch (Exception e) { |
|||
logger.error("Error occurred while adding a building", e); |
|||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // Rollback transaction on error
|
|||
return new SimpleDataResponse(ResponseCode.SERVER_ERROR, ResponseCode.SERVER_ERROR_MSG); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Performs common verification operations for adding a building. |
|||
* |
|||
* @param optBuildingParams The parameters for creating the building. |
|||
* @param companyId The ID of the company associated with the operation. |
|||
* @param languageType The language type for error messages. |
|||
*/ |
|||
private void commonVerifyOpt(OptBuildingParams optBuildingParams, String companyId, Integer languageType) { |
|||
// Check for existing building with the same name
|
|||
checkExist(optBuildingParams, languageType); |
|||
} |
|||
|
|||
/** |
|||
* Checks if a building with the same name already exists in the database. |
|||
* Throws a MsgCodeException if the building name is already taken. |
|||
* |
|||
* @param optBuildingParams The parameters for creating the building. |
|||
* @param languageType The language type for error messages. |
|||
*/ |
|||
private void checkExist(OptBuildingParams optBuildingParams, Integer languageType) { |
|||
if (basicBuildingMapperExt.checkExist(optBuildingParams) > 0) { |
|||
throw new MsgCodeException(msgLanguageChange.getParameterMapByCode(languageType, "buildingNameHasExisted")); |
|||
} |
|||
} |
|||
|
|||
|
|||
@Override |
|||
@Transactional |
|||
public SimpleDataResponse edit(OptBuildingParams optBuildingParams, String userId, String companyId, |
|||
Integer languageType) { |
|||
try { |
|||
BasicBuilding oldBP = basicBuildingMapperExt.selectById(optBuildingParams.getBuildingId()); |
|||
if (ObjectUtils.isEmpty(oldBP) || oldBP.getFlag() == 1) { |
|||
return new SimpleDataResponse(ResponseCode.MSG_ERROR, "Not found"); |
|||
} |
|||
|
|||
try { |
|||
|
|||
commonVerifyOpt(optBuildingParams, companyId, languageType); |
|||
|
|||
} catch (MsgCodeException e) { |
|||
return new SimpleDataResponse(ResponseCode.MSG_ERROR, e.getMessage()); |
|||
} |
|||
|
|||
LambdaUpdateWrapper<BasicBuilding> updateWrapper = new LambdaUpdateWrapper<>(); |
|||
updateWrapper.eq(BasicBuilding::getBuildingId, optBuildingParams.getBuildingId()) |
|||
.set(BasicBuilding::getName, optBuildingParams.getBuildingName()) |
|||
.set(BasicBuilding::getAddress, optBuildingParams.getAddress()) |
|||
.set(BasicBuilding::getUniqueIdentification, optBuildingParams.getUniqueIdentification()) |
|||
.set(BasicBuilding::getDimensionalUrl, optBuildingParams.getDimensionalUrl()) |
|||
.set(BasicBuilding::getModifierId, userId) |
|||
.set(BasicBuilding::getModifyTime, System.currentTimeMillis()); |
|||
|
|||
basicBuildingMapperExt.update(null, updateWrapper); |
|||
|
|||
return SimpleDataResponse.success(); |
|||
} catch (Exception e) { |
|||
logger.error("Error occurred while editing a building", e); |
|||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|||
return new SimpleDataResponse(ResponseCode.SERVER_ERROR, ResponseCode.SERVER_ERROR_MSG); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public SimpleDataResponse batchDelete(DeleteBuildingParams deleteBuildingParams, String userId, |
|||
String companyId, Integer languageType) { |
|||
if (CollectionUtils.isEmpty(deleteBuildingParams.getBuildingIds())) { |
|||
return SimpleDataResponse.success(); |
|||
} |
|||
|
|||
try { |
|||
LambdaUpdateWrapper<BasicBuilding> updateWrapper = new LambdaUpdateWrapper<>(); |
|||
updateWrapper.in(BasicBuilding::getBuildingId, deleteBuildingParams.getBuildingIds()) |
|||
.set(BasicBuilding::getFlag, 1); |
|||
|
|||
basicBuildingMapperExt.update(null, updateWrapper); |
|||
|
|||
return SimpleDataResponse.success(); |
|||
} catch (Exception e) { |
|||
logger.error("Error occurred while batch deleting buildings", e); |
|||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|||
return new SimpleDataResponse(ResponseCode.SERVER_ERROR, ResponseCode.SERVER_ERROR_MSG); |
|||
} |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public IPage<BuildingPageVO> getListPage(BuildingSearchParams pageSearchParam, String companyId, String userId, |
|||
Integer languageType, Integer uTCOffset) { |
|||
//list防${}注入
|
|||
if (StringUtils.isBlank(pageSearchParam.getCompanyIds())) { |
|||
pageSearchParam.setCompanyIdList(commonOpt.getSelfAndSubCompanyId(companyId)); |
|||
} else { |
|||
pageSearchParam.setCompanyIdList(commonOpt.filterCompanyIds(companyId, pageSearchParam.getCompanyIds())); |
|||
} |
|||
if (StringUtils.isNotBlank(pageSearchParam.getBuildingIds())) { |
|||
pageSearchParam.setBuildingIdList(CommonUtil.commaStr2LongList(pageSearchParam.getBuildingIds())); |
|||
} |
|||
// 使用 MyBatis-Plus 提供的分页对象 Page
|
|||
Page<BuildingPageVO> page = new Page<>( |
|||
pageSearchParam.getPageNum() == null ? 1 : pageSearchParam.getPageNum(), |
|||
pageSearchParam.getPageSize() == null ? 20 : pageSearchParam.getPageSize()); |
|||
|
|||
return basicBuildingMapperExt.getListPage(page, pageSearchParam); |
|||
} |
|||
|
|||
|
|||
} |
Loading…
Reference in new issue