代码提交

This commit is contained in:
itcast 2025-12-12 17:37:54 +08:00
parent 1f8ff23fcb
commit 7290d3fb0f
13 changed files with 374 additions and 19 deletions

View File

@ -229,6 +229,11 @@ public class MaDevInfo {
*/ */
private BigDecimal originalValue; private BigDecimal originalValue;
/**
* 资产净值
* 说明装备的当前采购价值以元为单位
*/
private BigDecimal value;
/** /**
* 最小资产原值 * 最小资产原值

View File

@ -6,6 +6,7 @@ import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
@Mapper @Mapper
@ -52,5 +53,8 @@ public interface MaDevInfoMapper {
List<DevInfoPropertyVo> batchGetProperties( @Param("mainIds") List<Integer> mainIds); List<DevInfoPropertyVo> batchGetProperties( @Param("mainIds") List<Integer> mainIds);
List<MaDevInfoXlsx> listXlsx(MaDevInfo o); List<MaDevInfoXlsx> listXlsx(MaDevInfo o);
void updatePrice(@Param("maId") Integer maId,@Param("value") BigDecimal value);
} }

View File

@ -9,11 +9,17 @@ import com.bonus.material.device.domain.vo.DevMergeVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.bonus.common.biz.constant.MaterialConstants.ADMIN_ID; import static com.bonus.common.biz.constant.MaterialConstants.ADMIN_ID;
import static com.bonus.common.biz.constant.MaterialConstants.PROVINCE_COMPANY_DEPT_ID; import static com.bonus.common.biz.constant.MaterialConstants.PROVINCE_COMPANY_DEPT_ID;
import static org.apache.commons.math3.exception.util.LocalizedFormats.SCALE;
@Service @Service
public class MaDevInfoServiceImpl implements MaDevInfoService { public class MaDevInfoServiceImpl implements MaDevInfoService {
@ -33,6 +39,11 @@ public class MaDevInfoServiceImpl implements MaDevInfoService {
o.setCompanyId(deptId); o.setCompanyId(deptId);
} }
List<MaDevInfo> list = mapper.list(o); List<MaDevInfo> list = mapper.list(o);
// 折旧常量定义年折旧10% 剩余90%保留2位小数
BigDecimal DEPRECIATION_RATE = new BigDecimal("0.9");
int SCALE = 2;
list.forEach(item -> { list.forEach(item -> {
List<DevInfoPropertyVo> propertiiesList = mapper.getProperties(item); List<DevInfoPropertyVo> propertiiesList = mapper.getProperties(item);
if (propertiiesList != null && !propertiiesList.isEmpty()) { if (propertiiesList != null && !propertiiesList.isEmpty()) {
@ -42,7 +53,56 @@ public class MaDevInfoServiceImpl implements MaDevInfoService {
item.setCertificates(mapper.getFileList(item.getMaId(), 2)); item.setCertificates(mapper.getFileList(item.getMaId(), 2));
item.setInspectionReports(mapper.getFileList(item.getMaId(), 3)); item.setInspectionReports(mapper.getFileList(item.getMaId(), 3));
item.setPurchaseInvoices(mapper.getFileList(item.getMaId(), 4)); 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; return list;
} }

View File

@ -106,4 +106,7 @@ public class ToolEntity implements Serializable {
@ApiModelProperty(value = "关键字") @ApiModelProperty(value = "关键字")
private String keyWord; private String keyWord;
@ApiModelProperty(value = "单价")
private BigDecimal originCost;
} }

View File

@ -1,9 +1,16 @@
package com.bonus.material.toolLedger.controller; 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.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo; 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.tool.domain.ToolEntity;
import com.bonus.material.toolLedger.domain.ToolLedgerAllEntity;
import com.bonus.material.toolLedger.domain.ToolLedgerEntity; import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
import com.bonus.material.toolLedger.service.ToolLedgerService; import com.bonus.material.toolLedger.service.ToolLedgerService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -11,6 +18,8 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -31,10 +40,10 @@ public class ToolLedgerController extends BaseController {
*/ */
@ApiOperation(value = "工具台账表格") @ApiOperation(value = "工具台账表格")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(ToolLedgerEntity entity) { public TableDataInfo list(ToolLedgerAllEntity entity) {
try { try {
startPage(); startPage();
List<ToolLedgerEntity> list = toolLedgerService.list(entity); List<ToolLedgerAllEntity> list = toolLedgerService.list(entity);
return getDataTable(list); return getDataTable(list);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString(), 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<ToolLedgerEntity> list = toolLedgerService.listCode(entity);
ExcelUtil<ToolLedgerEntity> util = new ExcelUtil<ToolLedgerEntity>(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<ToolLedgerAllEntity> list = toolLedgerService.list(entity);
ExcelUtil<ToolLedgerAllEntity> util = new ExcelUtil<ToolLedgerAllEntity>(ToolLedgerAllEntity.class);
util.exportExcel(response,list,"工具台账");
} catch (Exception e) {
logger.error(e.toString(), e);
}
}
} }

View File

@ -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<DevInfoPropertyVo> propertyVoList = new ArrayList<>();
private String proName;
}

View File

@ -18,6 +18,10 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class ToolLedgerEntity implements Serializable { 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; private String toolCode;
/** /**
@ -34,6 +39,7 @@ public class ToolLedgerEntity implements Serializable {
*/ */
private Long typeId; private Long typeId;
@Excel(name = "规格型号", sort = 5)
private String typeName; private String typeName;
/** /**
@ -46,6 +52,7 @@ public class ToolLedgerEntity implements Serializable {
* 装备原值仅编码设备 * 装备原值仅编码设备
* 对应数据库 decimal(10,2) BigDecimal 保证精度 * 对应数据库 decimal(10,2) BigDecimal 保证精度
*/ */
@Excel(name = "资产原值", sort = 11)
private BigDecimal originCost; private BigDecimal originCost;
/** /**
@ -53,6 +60,7 @@ public class ToolLedgerEntity implements Serializable {
*/ */
private BigDecimal totalNum; private BigDecimal totalNum;
@Excel(name = "计量单位", sort = 6)
private String unitName; private String unitName;
/** /**
@ -85,6 +93,7 @@ public class ToolLedgerEntity implements Serializable {
*/ */
private Integer supplierId; private Integer supplierId;
@Excel(name = "生产厂家", sort = 9)
private String supplierName; private String supplierName;
/** /**
@ -96,6 +105,7 @@ public class ToolLedgerEntity implements Serializable {
/** /**
* 出厂日期 * 出厂日期
*/ */
@Excel(name = "出厂日期", sort = 10)
private LocalDate productionDate; private LocalDate productionDate;
/** /**
@ -106,6 +116,7 @@ public class ToolLedgerEntity implements Serializable {
/** /**
* 下次检验日期 * 下次检验日期
*/ */
@Excel(name = "下次检验日期", sort = 8)
private LocalDate nextCheckDate; private LocalDate nextCheckDate;
/** /**
@ -144,6 +155,7 @@ public class ToolLedgerEntity implements Serializable {
/** /**
* 装备原值 * 装备原值
*/ */
@Excel(name = "原始编码", sort = 12)
private String identifyCode; private String identifyCode;
@ -154,7 +166,7 @@ public class ToolLedgerEntity implements Serializable {
/** /**
* 4级父节点名称 * 4级父节点名称
*/ */
@Excel(name = "工具专业") @Excel(name = "工具专业", sort = 1)
private String fourthParentName; private String fourthParentName;
/** /**
@ -164,17 +176,17 @@ public class ToolLedgerEntity implements Serializable {
/** /**
* 3级父节点名称 * 3级父节点名称
*/ */
@Excel(name = "施工类型") @Excel(name = "施工类型", sort = 2)
private String greatGrandparentName; private String greatGrandparentName;
/** /**
* 2级父节点id * 2级父节点id
*/ */
@Excel(name = "工具类型")
private String grandparentTypeId; private String grandparentTypeId;
/** /**
* 2级父节点名称 * 2级父节点名称
*/ */
@Excel(name = "工具类型") @Excel(name = "工具类型", sort = 3)
private String grandparentTypeName; private String grandparentTypeName;
/** /**
@ -184,7 +196,7 @@ public class ToolLedgerEntity implements Serializable {
/** /**
* 1级父节点名称 * 1级父节点名称
*/ */
@Excel(name = "工具名称") @Excel(name = "工具名称", sort = 4)
private String parentTypeName; private String parentTypeName;
/** /**
* 文件地址 * 文件地址

View File

@ -1,6 +1,7 @@
package com.bonus.material.toolLedger.mapper; package com.bonus.material.toolLedger.mapper;
import com.bonus.material.device.domain.vo.DevInfoPropertyVo; 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.domain.ToolLedgerEntity;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -14,7 +15,7 @@ public interface ToolLedgerMapper {
* @param entity 实体 * @param entity 实体
* @return 表格 * @return 表格
*/ */
List<ToolLedgerEntity> list(ToolLedgerEntity entity); List<ToolLedgerAllEntity> list(ToolLedgerAllEntity entity);
/** /**

View File

@ -3,6 +3,7 @@ package com.bonus.material.toolLedger.service.Impl;
import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils; import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.device.domain.vo.DevInfoPropertyVo; 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.domain.ToolLedgerEntity;
import com.bonus.material.toolLedger.mapper.ToolLedgerMapper; import com.bonus.material.toolLedger.mapper.ToolLedgerMapper;
import com.bonus.material.toolLedger.service.ToolLedgerService; import com.bonus.material.toolLedger.service.ToolLedgerService;
@ -29,7 +30,7 @@ public class ToolLedgerServiceImpl implements ToolLedgerService {
* @return 表格 * @return 表格
*/ */
@Override @Override
public List<ToolLedgerEntity> list(ToolLedgerEntity entity) { public List<ToolLedgerAllEntity> list(ToolLedgerAllEntity entity) {
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId(); Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
Long userId = SecurityUtils.getLoginUser().getUserid(); Long userId = SecurityUtils.getLoginUser().getUserid();
// 管理员和省公司可查看所有数据 // 管理员和省公司可查看所有数据

View File

@ -1,6 +1,7 @@
package com.bonus.material.toolLedger.service; package com.bonus.material.toolLedger.service;
import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.toolLedger.domain.ToolLedgerAllEntity;
import com.bonus.material.toolLedger.domain.ToolLedgerEntity; import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
import java.util.List; import java.util.List;
@ -12,7 +13,7 @@ public interface ToolLedgerService {
* @param entity 实体 * @param entity 实体
* @return 表格 * @return 表格
*/ */
List<ToolLedgerEntity> list(ToolLedgerEntity entity); List<ToolLedgerAllEntity> list(ToolLedgerAllEntity entity);
/** /**

View File

@ -234,6 +234,12 @@
</foreach> </foreach>
</update> </update>
<update id="updatePrice">
UPDATE ma_dev_info
SET price = #{value}
WHERE ma_id = #{maId}
</update>
<select id="deviceTree" resultType="com.bonus.material.devchange.domain.DeviceTreeBean"> <select id="deviceTree" resultType="com.bonus.material.devchange.domain.DeviceTreeBean">
SELECT mt.type_id as id, SELECT mt.type_id as id,
mt.type_name as name, mt.type_name as name,
@ -463,6 +469,7 @@
sd.dept_id AS propertyUnitId, sd.dept_id AS propertyUnitId,
sd.dept_name AS propertyUnit, sd.dept_name AS propertyUnit,
mdi.buy_price AS originalValue, mdi.buy_price AS originalValue,
mdi.price AS value,
mdi.unit AS unit, mdi.unit AS unit,
mdq.next_check_time AS nextMaintenanceDate, mdq.next_check_time AS nextMaintenanceDate,
mdi.max_working_hours AS maxServiceLifeYears mdi.max_working_hours AS maxServiceLifeYears

View File

@ -60,7 +60,7 @@
</trim> </trim>
</insert> </insert>
<select id="list" resultType="com.bonus.material.toolLedger.domain.ToolLedgerEntity"> <select id="list" resultType="com.bonus.material.toolLedger.domain.ToolLedgerAllEntity">
SELECT SELECT
tt.type_id AS typeId, tt.type_id AS typeId,

View File

@ -36,7 +36,7 @@
#{item.typeId}, #{item.typeId},
#{item.supplierId}, #{item.supplierId},
#{item.applyNum}, #{item.applyNum},
#{item.toolPrice}, #{item.originCost},
#{item.productionDate}, #{item.productionDate},
#{item.code}, #{item.code},
#{item.identifyCode} #{item.identifyCode}
@ -130,13 +130,15 @@
</select> </select>
<select id="getTreeSelect" resultType="com.bonus.material.tool.domain.ToolEntity"> <select id="getTreeSelect" resultType="com.bonus.material.tool.domain.ToolEntity">
SELECT type_id AS typeId, SELECT tt.type_id AS typeId,
type_name AS typeName, tt.type_name AS typeName,
parent_id AS parentId, tt.parent_id AS parentId,
unit_name AS unitName, tt.unit_name AS unitName,
manage_type AS manageType, tt.manage_type AS manageType,
level AS level tt.level AS level,
FROM tool_type tl.origin_cost as origin_cost
FROM tool_type tt
left join tool_ledger tl on tt.type_id=tl.type_id
WHERE del_flag = '0' WHERE del_flag = '0'
and (manage_type = #{manageType} OR manage_type is null) and (manage_type = #{manageType} OR manage_type is null)
</select> </select>