# RowController.java

    package cloud.wconnect.finance.controller.pl;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.cons.CommonFieldI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.commonlib.util.UploadUtils;
    import cloud.wconnect.finance.entity.pl.M3Row;
    import cloud.wconnect.finance.pojo.dto.pl.RowFormulaDTO;
    import cloud.wconnect.finance.pojo.dto.pl.UploadResult;
    import cloud.wconnect.finance.pojo.query.pl.RowQuery;
    import cloud.wconnect.finance.service.pl.IM3RowService;
    import com.google.common.collect.Lists;
    import jakarta.validation.Valid;
    import org.apache.commons.io.FileUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.*;
    import org.springframework.web.multipart.MultipartFile;

    import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.util.Objects;

    /**
     * <p>
     * 前端控制器
     * </p>
     *
     * @author lichen
     * @since 2025-09-25
     */
    @RestController
    @RequestMapping("/pl/row")
    public class RowController {

        @Autowired
        private I18nMessageUtils i18nMessageUtils;
        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private IM3RowService m3RowService;
        @Value("${file-max-size.pl}")
        private Long fileMaxSize;

        /**
         * 分页查询Row信息
         *
         * @param property 资产
         * @param query    查询参数
         * @return cloud.wconnect.commonlib.pojo.dto.ListPagedDTO<cloud.wconnect.finance.entity.pl.M3Row>
         * @author lichen
         * @date 2025/9/29
         */
        @ApiId(1601)
        @GetMapping
        private ListPagedDTO<M3Row> pageList(String property, @Valid RowQuery query) {
            int propertyId = sessionContext.getPropertyId(property);
            return m3RowService.pageList(propertyId, query);
        }

        /**
         * 上传Layout.xls
         *
         * @param property 资产
         * @param file     文件
         * @return cloud.wconnect.finance.pojo.dto.pl.UploadResult
         * @author lichen
         * @date 2025/9/29
         */
        @ApiId(1602)
        @PostMapping("/upload")
        public UploadResult upload(String property, MultipartFile file) {
            //校验文件不能为空
            if (Objects.isNull(file)) {
                throw new BadRequestException(CommonErrorI18nConstant.CANNOT_EMPTY,
                        i18nMessageUtils.getErrorParamMapNeedTranslate(CommonFieldI18nConstant.FILE),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the file cannot be null");
            }
            //校验文件后缀
            UploadUtils.checkFileFormat(file, Lists.newArrayList("xls", "xlsx"));

            //校验文件大小
            if (file.getSize() > fileMaxSize) {
                BigDecimal limitSize = BigDecimal.valueOf(fileMaxSize).divide(BigDecimal.valueOf(FileUtils.ONE_MB), 2, RoundingMode.HALF_UP);
                BigDecimal fileSizeBigDecimal = BigDecimal.valueOf(file.getSize()).divide(BigDecimal.valueOf(FileUtils.ONE_MB), 2, RoundingMode.HALF_UP);
                throw new BadRequestException(CommonErrorI18nConstant.FILE_SIZE_ERROR,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "Upload file exceeded limit;fileSize:" + fileSizeBigDecimal.stripTrailingZeros().toPlainString() +
                                "MB, maxSize:" + limitSize.stripTrailingZeros().toPlainString() + "MB");
            }

            int propertyId = sessionContext.getPropertyId(property);
            Integer tenantId = sessionContext.getTenantSymbolBO().getId();
            return m3RowService.upload(tenantId, propertyId, file);
        }

        /**
         * 获取Row公式
         *
         * @param property 资产
         * @param rowNumber Row编号
         * @return cloud.wconnect.finance.pojo.dto.pl.RowFormulaDTO
         * @author lichen
         * @date 2025/9/29
         */
        @ApiId(1603)
        @GetMapping("/formula")
        public RowFormulaDTO getRowFormula(String property, @RequestParam String rowNumber) {
            int propertyId = sessionContext.getPropertyId(property);
            return m3RowService.getRowFormula(propertyId, rowNumber);
        }

    }