From 7290d3fb0fdccaf0a29053926d9806d914c81287 Mon Sep 17 00:00:00 2001 From: itcast Date: Fri, 12 Dec 2025 17:37:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../material/devchange/domain/MaDevInfo.java | 5 + .../devchange/mapper/MaDevInfoMapper.java | 4 + .../service/MaDevInfoServiceImpl.java | 60 +++++ .../material/tool/domain/ToolEntity.java | 3 + .../controller/ToolLedgerController.java | 48 +++- .../domain/ToolLedgerAllEntity.java | 215 ++++++++++++++++++ .../toolLedger/domain/ToolLedgerEntity.java | 22 +- .../toolLedger/mapper/ToolLedgerMapper.java | 3 +- .../service/Impl/ToolLedgerServiceImpl.java | 3 +- .../toolLedger/service/ToolLedgerService.java | 3 +- .../material/devchange/MaDevInfoMapper.xml | 7 + .../material/toolLedger/ToolLedgerMapper.xml | 2 +- .../toolProcess/ToolProcessMapper.xml | 18 +- 13 files changed, 374 insertions(+), 19 deletions(-) create mode 100644 bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerAllEntity.java diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfo.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfo.java index 745f6b0..cb47f76 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfo.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfo.java @@ -229,6 +229,11 @@ public class MaDevInfo { */ private BigDecimal originalValue; + /** + * 资产净值(元) + * 说明:装备的当前采购价值,以元为单位 + */ + private BigDecimal value; /** * 最小资产原值(元) diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/mapper/MaDevInfoMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/mapper/MaDevInfoMapper.java index c8a6010..d629573 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/mapper/MaDevInfoMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/mapper/MaDevInfoMapper.java @@ -6,6 +6,7 @@ import io.swagger.models.auth.In; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.math.BigDecimal; import java.util.List; @Mapper @@ -52,5 +53,8 @@ public interface MaDevInfoMapper { List batchGetProperties( @Param("mainIds") List mainIds); List listXlsx(MaDevInfo o); + + void updatePrice(@Param("maId") Integer maId,@Param("value") BigDecimal value); + } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoServiceImpl.java index 108f8b8..c87cc1b 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoServiceImpl.java @@ -9,11 +9,17 @@ import com.bonus.material.device.domain.vo.DevMergeVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.Period; +import java.time.ZoneId; import java.util.*; import java.util.stream.Collectors; import static com.bonus.common.biz.constant.MaterialConstants.ADMIN_ID; import static com.bonus.common.biz.constant.MaterialConstants.PROVINCE_COMPANY_DEPT_ID; +import static org.apache.commons.math3.exception.util.LocalizedFormats.SCALE; @Service public class MaDevInfoServiceImpl implements MaDevInfoService { @@ -33,6 +39,11 @@ public class MaDevInfoServiceImpl implements MaDevInfoService { o.setCompanyId(deptId); } List list = mapper.list(o); + + // 折旧常量定义(年折旧10% → 剩余90%,保留2位小数) + BigDecimal DEPRECIATION_RATE = new BigDecimal("0.9"); + int SCALE = 2; + list.forEach(item -> { List propertiiesList = mapper.getProperties(item); if (propertiiesList != null && !propertiiesList.isEmpty()) { @@ -42,7 +53,56 @@ public class MaDevInfoServiceImpl implements MaDevInfoService { item.setCertificates(mapper.getFileList(item.getMaId(), 2)); item.setInspectionReports(mapper.getFileList(item.getMaId(), 3)); item.setPurchaseInvoices(mapper.getFileList(item.getMaId(), 4)); + + // 计算资产净值 + // 空值校验:出厂日期/原值为空 → 净值设为null + Date productionDate = item.getProductionDate(); + BigDecimal originalValue = item.getOriginalValue(); + if (productionDate == null || originalValue == null) { + item.setValue(null); // 净值字段设为null + return; // 跳过当前装备的净值计算 + } + + // Date转LocalDate(解决日期计算兼容问题) + LocalDate prodLocalDate = productionDate.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + LocalDate currentDate = LocalDate.now(); + + // 出厂日期晚于当前日期 → 净值=原值 + if (prodLocalDate.isAfter(currentDate)) { + item.setValue(originalValue.setScale(SCALE, RoundingMode.HALF_UP)); + return; + } + + // 计算使用年限(整年数,不足1年按0算) + Period period = Period.between(prodLocalDate, currentDate); + int useYears = period.getYears(); + // 校验:若「出厂日期+使用年限」仍晚于当前日期,说明不足1年,年份减1 + if (prodLocalDate.plusYears(useYears).isAfter(currentDate)) { + useYears--; + } + useYears = Math.max(useYears, 0); // 最低为0年 + + //计算净值:原值 × (0.9)^使用年限,保留2位小数 + BigDecimal depreciation = DEPRECIATION_RATE.pow(useYears); + BigDecimal netValue = originalValue.multiply(depreciation) + .setScale(SCALE, RoundingMode.HALF_UP); // 四舍五入 + // 兜底:净值最低为0(避免折旧后为负) + netValue = netValue.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : netValue; + + if(item.getValue() == null ||!item.getValue().equals(netValue) ){ + mapper.updatePrice(item.getMaId(),netValue); + } + + // 填充净值到实体字段 + item.setValue(netValue); + + }); + + + return list; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/tool/domain/ToolEntity.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/tool/domain/ToolEntity.java index 90bfe92..07f35a4 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/tool/domain/ToolEntity.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/tool/domain/ToolEntity.java @@ -106,4 +106,7 @@ public class ToolEntity implements Serializable { @ApiModelProperty(value = "关键字") private String keyWord; + + @ApiModelProperty(value = "单价") + private BigDecimal originCost; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/controller/ToolLedgerController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/controller/ToolLedgerController.java index 697d721..d26823a 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/controller/ToolLedgerController.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/controller/ToolLedgerController.java @@ -1,9 +1,16 @@ package com.bonus.material.toolLedger.controller; +import com.bonus.common.core.utils.poi.ExcelUtil; import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.page.TableDataInfo; +import com.bonus.common.log.annotation.SysLog; +import com.bonus.common.log.enums.OperaType; +import com.bonus.material.devchange.domain.MaDevInfo; +import com.bonus.material.devchange.domain.MaDevInfoXlsx; +import com.bonus.material.project.domain.Project; import com.bonus.material.tool.domain.ToolEntity; +import com.bonus.material.toolLedger.domain.ToolLedgerAllEntity; import com.bonus.material.toolLedger.domain.ToolLedgerEntity; import com.bonus.material.toolLedger.service.ToolLedgerService; import io.swagger.annotations.Api; @@ -11,6 +18,8 @@ import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -31,10 +40,10 @@ public class ToolLedgerController extends BaseController { */ @ApiOperation(value = "工具台账表格") @GetMapping("/list") - public TableDataInfo list(ToolLedgerEntity entity) { + public TableDataInfo list(ToolLedgerAllEntity entity) { try { startPage(); - List list = toolLedgerService.list(entity); + List list = toolLedgerService.list(entity); return getDataTable(list); } catch (Exception e) { logger.error(e.toString(), e); @@ -116,4 +125,39 @@ public class ToolLedgerController extends BaseController { } + /** + * 导出 + * @param response + * @param entity + */ + @PostMapping("/export") + @SysLog(title = "编码工具台账", businessType = OperaType.EXPORT, logType = 0, module = "编码工具台账", details = "编码工具台账") + public void export(HttpServletResponse response, ToolLedgerEntity entity) { + try { + List list = toolLedgerService.listCode(entity); + ExcelUtil util = new ExcelUtil(ToolLedgerEntity.class); + util.exportExcel(response,list,"编码工具台账"); + } catch (Exception e) { + logger.error(e.toString(), e); + } + } + + /** + * 导出 + * @param response + * @param entity + */ + @PostMapping("/exportAll") + @SysLog(title = "工具台账", businessType = OperaType.EXPORT, logType = 0, module = "工具台账", details = "工具台账") + public void export(HttpServletResponse response, ToolLedgerAllEntity entity) { + try { + List list = toolLedgerService.list(entity); + ExcelUtil util = new ExcelUtil(ToolLedgerAllEntity.class); + util.exportExcel(response,list,"工具台账"); + } catch (Exception e) { + logger.error(e.toString(), e); + } + } + + } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerAllEntity.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerAllEntity.java new file mode 100644 index 0000000..2751944 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerAllEntity.java @@ -0,0 +1,215 @@ +package com.bonus.material.toolLedger.domain; + +import com.bonus.common.core.annotation.Excel; +import com.bonus.material.device.domain.vo.DevInfoPropertyVo; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ToolLedgerAllEntity implements Serializable { + + //用于excel导出的序号一列,不需要业务逻辑处理 + @Excel(name = "序号", isSequence = true, type = Excel.Type.EXPORT , sort = 0) + int sequence; + + + /** + * 主键(自增) + */ + private Long id; + + /** + * 工具编码(编码管理使用) + */ + + private String toolCode; + + /** + * 工具类型ID(非空) + */ + private Long typeId; + + @Excel(name = "规格型号", sort = 5) + private String typeName; + + /** + * 管理方式:1-编码管理;2-数量管理(非空) + * 建议后续用枚举 + */ + @Excel(name = "管理模式", sort = 12) + private Integer manageMode; + + /** + * 装备原值(仅编码设备) + * 对应数据库 decimal(10,2),用 BigDecimal 保证精度 + */ + + private BigDecimal originCost; + + /** + * 总数量(非空,默认1.00) + */ + @Excel(name = "工具总数", sort = 11) + private BigDecimal totalNum; + + + private String unitName; + + /** + * 在库数量(非空,默认0.00) + */ + @Excel(name = "在库数量", sort = 6) + private BigDecimal availableNum; + + /** + * 在用数量(非空,默认0.00) + */ + @Excel(name = "自用数量", sort = 7) + private BigDecimal inNum; + + /** + * 维修数量(非空,默认0.00) + */ + @Excel(name = "在修数量", sort = 9) + private BigDecimal repairNum; + + /** + * 报废数量(非空,默认0.00) + */ + private BigDecimal scrapNum; + + /** + * 共享数量 + */ + @Excel(name = "共享数量", sort = 8) + private BigDecimal shareNum; + + /** + * 厂家id(非空,默认0) + */ + private Integer supplierId; + + + private String supplierName; + + /** + * 采购日期 + * 用 LocalDate 对应数据库 date 类型(Java 8+ 推荐) + */ + private LocalDate purchaseDate; + + /** + * 出厂日期 + */ + @Excel(name = "出厂日期", sort = 10) + private LocalDate productionDate; + + /** + * 最近检验日期 + */ + private LocalDate lastCheckDate; + + /** + * 下次检验日期 + */ + + private LocalDate nextCheckDate; + + /** + * 当前状态:0-在库 1-在用 2-在修 3-已报废(非空,默认0) + * 建议后续用枚举 + */ + private String status; + + /** + * 上下架状态:1-上架 0-下架(非空,默认0) + * 建议后续用枚举 + */ + private String upDownStatus; + + /** + * 所属公司ID(非空) + */ + private Long companyId; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间(默认当前时间) + * 对应数据库 DEFAULT CURRENT_TIMESTAMP + */ + private LocalDateTime createTime; + + /** + * 更新时间(默认当前时间,更新时自动刷新) + * 对应数据库 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + */ + private LocalDateTime updateTime; + /** + * 装备原值 + */ + + private String identifyCode; + + + /** + * 4级父节点id + */ + private String fourthParentId; + /** + * 4级父节点名称 + */ + @Excel(name = "工具专业", sort = 1) + private String fourthParentName; + + /** + * 3级父节点id + */ + private String greatGrandparentId; + /** + * 3级父节点名称 + */ + @Excel(name = "施工类型", sort = 2) + private String greatGrandparentName; + /** + * 2级父节点id + */ + + private String grandparentTypeId; + /** + * 2级父节点名称 + */ + @Excel(name = "工具类型", sort = 3) + private String grandparentTypeName; + + /** + * 1级父节点id + */ + private String parentTypeId; + /** + * 1级父节点名称 + */ + @Excel(name = "工具名称", sort = 4) + private String parentTypeName; + /** + * 文件地址 + */ + private String fileList; + + private List propertyVoList = new ArrayList<>(); + + private String proName; +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerEntity.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerEntity.java index 0542ff0..2e7c0af 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerEntity.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerEntity.java @@ -18,6 +18,10 @@ import java.util.List; @NoArgsConstructor public class ToolLedgerEntity implements Serializable { + //用于excel导出的序号一列,不需要业务逻辑处理 + @Excel(name = "序号", isSequence = true, type = Excel.Type.EXPORT , sort = 0) + int sequence; + /** * 主键(自增) @@ -27,6 +31,7 @@ public class ToolLedgerEntity implements Serializable { /** * 工具编码(编码管理使用) */ + @Excel(name = "工具编码", sort = 7) private String toolCode; /** @@ -34,6 +39,7 @@ public class ToolLedgerEntity implements Serializable { */ private Long typeId; + @Excel(name = "规格型号", sort = 5) private String typeName; /** @@ -46,6 +52,7 @@ public class ToolLedgerEntity implements Serializable { * 装备原值(仅编码设备) * 对应数据库 decimal(10,2),用 BigDecimal 保证精度 */ + @Excel(name = "资产原值", sort = 11) private BigDecimal originCost; /** @@ -53,6 +60,7 @@ public class ToolLedgerEntity implements Serializable { */ private BigDecimal totalNum; + @Excel(name = "计量单位", sort = 6) private String unitName; /** @@ -85,6 +93,7 @@ public class ToolLedgerEntity implements Serializable { */ private Integer supplierId; + @Excel(name = "生产厂家", sort = 9) private String supplierName; /** @@ -96,6 +105,7 @@ public class ToolLedgerEntity implements Serializable { /** * 出厂日期 */ + @Excel(name = "出厂日期", sort = 10) private LocalDate productionDate; /** @@ -106,6 +116,7 @@ public class ToolLedgerEntity implements Serializable { /** * 下次检验日期 */ + @Excel(name = "下次检验日期", sort = 8) private LocalDate nextCheckDate; /** @@ -144,6 +155,7 @@ public class ToolLedgerEntity implements Serializable { /** * 装备原值 */ + @Excel(name = "原始编码", sort = 12) private String identifyCode; @@ -154,7 +166,7 @@ public class ToolLedgerEntity implements Serializable { /** * 4级父节点名称 */ - @Excel(name = "工具专业") + @Excel(name = "工具专业", sort = 1) private String fourthParentName; /** @@ -164,17 +176,17 @@ public class ToolLedgerEntity implements Serializable { /** * 3级父节点名称 */ - @Excel(name = "施工类型") + @Excel(name = "施工类型", sort = 2) private String greatGrandparentName; /** * 2级父节点id */ - @Excel(name = "工具类型") + private String grandparentTypeId; /** * 2级父节点名称 */ - @Excel(name = "工具类型") + @Excel(name = "工具类型", sort = 3) private String grandparentTypeName; /** @@ -184,7 +196,7 @@ public class ToolLedgerEntity implements Serializable { /** * 1级父节点名称 */ - @Excel(name = "工具名称") + @Excel(name = "工具名称", sort = 4) private String parentTypeName; /** * 文件地址 diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/mapper/ToolLedgerMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/mapper/ToolLedgerMapper.java index 05e9cac..64e9f66 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/mapper/ToolLedgerMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/mapper/ToolLedgerMapper.java @@ -1,6 +1,7 @@ package com.bonus.material.toolLedger.mapper; import com.bonus.material.device.domain.vo.DevInfoPropertyVo; +import com.bonus.material.toolLedger.domain.ToolLedgerAllEntity; import com.bonus.material.toolLedger.domain.ToolLedgerEntity; import io.swagger.models.auth.In; import org.apache.ibatis.annotations.Param; @@ -14,7 +15,7 @@ public interface ToolLedgerMapper { * @param entity 实体 * @return 表格 */ - List list(ToolLedgerEntity entity); + List list(ToolLedgerAllEntity entity); /** diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/Impl/ToolLedgerServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/Impl/ToolLedgerServiceImpl.java index 4b80edf..3da045f 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/Impl/ToolLedgerServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/Impl/ToolLedgerServiceImpl.java @@ -3,6 +3,7 @@ package com.bonus.material.toolLedger.service.Impl; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.security.utils.SecurityUtils; import com.bonus.material.device.domain.vo.DevInfoPropertyVo; +import com.bonus.material.toolLedger.domain.ToolLedgerAllEntity; import com.bonus.material.toolLedger.domain.ToolLedgerEntity; import com.bonus.material.toolLedger.mapper.ToolLedgerMapper; import com.bonus.material.toolLedger.service.ToolLedgerService; @@ -29,7 +30,7 @@ public class ToolLedgerServiceImpl implements ToolLedgerService { * @return 表格 */ @Override - public List list(ToolLedgerEntity entity) { + public List list(ToolLedgerAllEntity entity) { Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId(); Long userId = SecurityUtils.getLoginUser().getUserid(); // 管理员和省公司可查看所有数据 diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/ToolLedgerService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/ToolLedgerService.java index 893726e..e086a23 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/ToolLedgerService.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/ToolLedgerService.java @@ -1,6 +1,7 @@ package com.bonus.material.toolLedger.service; import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.toolLedger.domain.ToolLedgerAllEntity; import com.bonus.material.toolLedger.domain.ToolLedgerEntity; import java.util.List; @@ -12,7 +13,7 @@ public interface ToolLedgerService { * @param entity 实体 * @return 表格 */ - List list(ToolLedgerEntity entity); + List list(ToolLedgerAllEntity entity); /** diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/MaDevInfoMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/MaDevInfoMapper.xml index 3a4f469..90f08b6 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/MaDevInfoMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/MaDevInfoMapper.xml @@ -234,6 +234,12 @@ + + UPDATE ma_dev_info + SET price = #{value} + WHERE ma_id = #{maId} + + +