diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 0a760c5..a5f438e 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -68,14 +68,15 @@ spring: data: # redis 配置 redis: - # host: ngtools.cn - host: 10.75.166.165 + host: ngtools.cn + #host: 10.75.166.165 # 端口,默认为6379 port: 6379 # 数据库索引 database: 0 # 密码 - password: Cxc@2024!1121 + #password: Cxc@2024!1121 + password: 4877017Ldy # 连接超时时间 timeout: 10s lettuce: diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUnitConvertController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUnitConvertController.java new file mode 100644 index 0000000..acf99c6 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUnitConvertController.java @@ -0,0 +1,104 @@ +package com.ruoyi.system.controller; + +import java.util.List; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.SysUnitConvert; +import com.ruoyi.system.service.ISysUnitConvertService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 【请填写功能名称】Controller + * + * @author ruoyi + * @date 2026-01-17 + */ +@RestController +@RequestMapping("/system/convert") +public class SysUnitConvertController extends BaseController +{ + @Autowired + private ISysUnitConvertService sysUnitConvertService; + + /** + * 查询【请填写功能名称】列表 + */ + @PreAuthorize("@ss.hasPermi('system:convert:list')") + @GetMapping("/list") + public TableDataInfo list(SysUnitConvert sysUnitConvert) + { + startPage(); + List list = sysUnitConvertService.selectSysUnitConvertList(sysUnitConvert); + return getDataTable(list); + } + + /** + * 导出【请填写功能名称】列表 + */ + @PreAuthorize("@ss.hasPermi('system:convert:export')") + @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SysUnitConvert sysUnitConvert) + { + List list = sysUnitConvertService.selectSysUnitConvertList(sysUnitConvert); + ExcelUtil util = new ExcelUtil(SysUnitConvert.class); + util.exportExcel(response, list, "【请填写功能名称】数据"); + } + + /** + * 获取【请填写功能名称】详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:convert:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(sysUnitConvertService.selectSysUnitConvertById(id)); + } + + /** + * 新增【请填写功能名称】 + */ + @PreAuthorize("@ss.hasPermi('system:convert:add')") + @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SysUnitConvert sysUnitConvert) + { + return toAjax(sysUnitConvertService.insertSysUnitConvert(sysUnitConvert)); + } + + /** + * 修改【请填写功能名称】 + */ + @PreAuthorize("@ss.hasPermi('system:convert:edit')") + @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SysUnitConvert sysUnitConvert) + { + return toAjax(sysUnitConvertService.updateSysUnitConvert(sysUnitConvert)); + } + + /** + * 删除【请填写功能名称】 + */ + @PreAuthorize("@ss.hasPermi('system:convert:remove')") + @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(sysUnitConvertService.deleteSysUnitConvertByIds(ids)); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UnitConvert.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UnitConvert.java new file mode 100644 index 0000000..06edf79 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UnitConvert.java @@ -0,0 +1,90 @@ +package com.ruoyi.system.controller; + + +import com.ruoyi.system.domain.SysUnitConvert; +import com.ruoyi.system.service.ISysUnitConvertService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +@Component +public class UnitConvert { + + @Autowired + private ISysUnitConvertService sysUnitConvertService; + + public double ConvertUniter(String unitType, double oldValue, int oldUnit, int newUnit) { + // 查询旧单位信息 + if ("temperature".equalsIgnoreCase(unitType)) { + return handleTemperatureConversion(BigDecimal.valueOf(oldValue), (long) oldUnit, (long) newUnit).doubleValue(); + } else { + + SysUnitConvert oldUnitInfo =sysUnitConvertService.selectSysUnitConvertUnitByTypeOrder(unitType, (long) oldUnit,null); + if (oldUnitInfo == null) { + throw new IllegalArgumentException("旧单位 '" + oldUnit + "' 不存在或不可用"); + } + + + SysUnitConvert baseUnitInfo = sysUnitConvertService.selectSysUnitConvertUnitByTypeOrder (unitType,null,"Y"); + if (baseUnitInfo == null) { + throw new IllegalArgumentException("基准单位 不存在或不可用"); + } + + // 查询新单位信息 + SysUnitConvert newUnitInfo = sysUnitConvertService.selectSysUnitConvertUnitByTypeOrder(unitType, (long) newUnit,null); + if (newUnitInfo == null) { + throw new IllegalArgumentException("新单位 '" + newUnit + "' 不存在或不可用"); + } + + BigDecimal oldFactor = oldUnitInfo.getConversionFactor(); + BigDecimal newFactor = newUnitInfo.getConversionFactor(); + + // 检查旧单位转换因子是否为零 + if (oldFactor.compareTo(BigDecimal.ZERO) == 0) { + throw new ArithmeticException("旧单位 '" + oldUnit + "' 的转换因子为零,无法进行转换"); + } + + // 计算基准值:oldValue / oldFactor + int scale = 20; // 设置足够大的精度以避免精度丢失 + BigDecimal baseValue = BigDecimal.valueOf(oldValue).divide(oldFactor, scale, RoundingMode.HALF_UP); + + // 计算新值:baseValue * newFactor + BigDecimal newValue = baseValue.multiply(newFactor); + + // 四舍五入到合理的小数位数(例如10位) + newValue = newValue.setScale(10, RoundingMode.HALF_UP); + + return newValue.doubleValue(); + } + } + + // 温度转换方法 + public static BigDecimal handleTemperatureConversion(BigDecimal oldValue, Long oldUnit, Long newUnit) { + final BigDecimal THIRTY_TWO = BigDecimal.valueOf(32); + final BigDecimal FIVE = BigDecimal.valueOf(5); + final BigDecimal NINE = BigDecimal.valueOf(9); + final BigDecimal TWO_HUNDRED_SEVENTY_THREE_POINT_ONE_FIVE = BigDecimal.valueOf(273.15); + // 使用原始值计算 + BigDecimal celsius; + if (oldUnit == 0) { + celsius = oldValue; + } else if (oldUnit == 1) { + celsius = oldValue.subtract(THIRTY_TWO).multiply(FIVE).divide(NINE, 10, RoundingMode.HALF_UP); + } else if (oldUnit == 2) { + celsius = oldValue.subtract(TWO_HUNDRED_SEVENTY_THREE_POINT_ONE_FIVE); + } else { + throw new IllegalArgumentException("无效温度单位"); + } + + if (newUnit == 0) { + return celsius; + } else if (newUnit == 1) { + return celsius.multiply(NINE).divide(FIVE, 10, RoundingMode.HALF_UP).add(THIRTY_TWO); + } else if (newUnit == 2) { + return celsius.add(TWO_HUNDRED_SEVENTY_THREE_POINT_ONE_FIVE); + } + throw new IllegalArgumentException("无效温度单位"); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUnitConvert.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUnitConvert.java new file mode 100644 index 0000000..dadac0f --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUnitConvert.java @@ -0,0 +1,143 @@ +package com.ruoyi.system.domain; + +import java.math.BigDecimal; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 【请填写功能名称】对象 sys_unit_convert + * + * @author ruoyi + * @date 2026-01-17 + */ +public class SysUnitConvert extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 单位类型 */ + @Excel(name = "单位类型") + private String unitType; + + /** 单位名称 */ + @Excel(name = "单位名称") + private String unitName; + + /** 是否基准 */ + @Excel(name = "是否基准") + private String baseUnit; + + /** 换算因子 */ + @Excel(name = "换算因子") + private BigDecimal conversionFactor; + + /** 类型名称 */ + @Excel(name = "类型名称") + private String unitTypeName; + + /** 状态 */ + @Excel(name = "状态") + private String status; + + /** 单位序号 */ + @Excel(name = "单位序号") + private Long unitOrder; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setUnitType(String unitType) + { + this.unitType = unitType; + } + + public String getUnitType() + { + return unitType; + } + + public void setUnitName(String unitName) + { + this.unitName = unitName; + } + + public String getUnitName() + { + return unitName; + } + + public void setBaseUnit(String baseUnit) + { + this.baseUnit = baseUnit; + } + + public String getBaseUnit() + { + return baseUnit; + } + + public void setConversionFactor(BigDecimal conversionFactor) + { + this.conversionFactor = conversionFactor; + } + + public BigDecimal getConversionFactor() + { + return conversionFactor; + } + + public void setUnitTypeName(String unitTypeName) + { + this.unitTypeName = unitTypeName; + } + + public String getUnitTypeName() + { + return unitTypeName; + } + + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + + public void setUnitOrder(Long unitOrder) + { + this.unitOrder = unitOrder; + } + + public Long getUnitOrder() + { + return unitOrder; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("unitType", getUnitType()) + .append("unitName", getUnitName()) + .append("baseUnit", getBaseUnit()) + .append("conversionFactor", getConversionFactor()) + .append("unitTypeName", getUnitTypeName()) + .append("status", getStatus()) + .append("unitOrder", getUnitOrder()) + .toString(); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUnitConvertMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUnitConvertMapper.java new file mode 100644 index 0000000..03b2c3b --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUnitConvertMapper.java @@ -0,0 +1,77 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.SysUnitConvert; +import org.apache.ibatis.annotations.Param; + +/** + * 【请填写功能名称】Mapper接口 + * + * @author ruoyi + * @date 2026-01-17 + */ +public interface SysUnitConvertMapper +{ + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public SysUnitConvert selectSysUnitConvertById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectSysUnitConvertList(SysUnitConvert sysUnitConvert); + + /** + * 新增【请填写功能名称】 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 结果 + */ + public int insertSysUnitConvert(SysUnitConvert sysUnitConvert); + + /** + * 修改【请填写功能名称】 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 结果 + */ + public int updateSysUnitConvert(SysUnitConvert sysUnitConvert); + + /** + * 删除【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteSysUnitConvertById(Long id); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSysUnitConvertByIds(Long[] ids); + + /** + * 查询单位换算 + * + * @param unitType 单位换算 + * @param unitOrder 单位换算 + * @param baseUnit 单位换算 + * @return 结果 + */ + public SysUnitConvert selectSysUnitConvertUnitByTypeOrder( + @Param("unitType") String unitType, + @Param("unitOrder") Long unitOrder, // 修正参数类型 + @Param("baseUnit") String baseUnit + ); + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUnitConvertService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUnitConvertService.java new file mode 100644 index 0000000..1a2f15e --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUnitConvertService.java @@ -0,0 +1,73 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.SysUnitConvert; + +/** + * 【请填写功能名称】Service接口 + * + * @author ruoyi + * @date 2026-01-17 + */ +public interface ISysUnitConvertService +{ + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public SysUnitConvert selectSysUnitConvertById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectSysUnitConvertList(SysUnitConvert sysUnitConvert); + + /** + * 新增【请填写功能名称】 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 结果 + */ + public int insertSysUnitConvert(SysUnitConvert sysUnitConvert); + + /** + * 修改【请填写功能名称】 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 结果 + */ + public int updateSysUnitConvert(SysUnitConvert sysUnitConvert); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键集合 + * @return 结果 + */ + public int deleteSysUnitConvertByIds(Long[] ids); + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteSysUnitConvertById(Long id); + + + /** + * 查询单位 + * + * @param unitType 单位换算 + * @param unitOrder 单位换算 + * @param baseUnit 单位换算 + * @return 单位换算集合 + */ + public SysUnitConvert selectSysUnitConvertUnitByTypeOrder(String unitType,Long unitOrder, String baseUnit); + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUnitConvertServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUnitConvertServiceImpl.java new file mode 100644 index 0000000..e3811aa --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUnitConvertServiceImpl.java @@ -0,0 +1,108 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.mapper.SysUnitConvertMapper; +import com.ruoyi.system.domain.SysUnitConvert; +import com.ruoyi.system.service.ISysUnitConvertService; + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author ruoyi + * @date 2026-01-17 + */ +@Service +public class SysUnitConvertServiceImpl implements ISysUnitConvertService +{ + @Autowired + private SysUnitConvertMapper sysUnitConvertMapper; + + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + @Override + public SysUnitConvert selectSysUnitConvertById(Long id) + { + return sysUnitConvertMapper.selectSysUnitConvertById(id); + } + + /** + * 查询【请填写功能名称】列表 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 【请填写功能名称】 + */ + @Override + public List selectSysUnitConvertList(SysUnitConvert sysUnitConvert) + { + return sysUnitConvertMapper.selectSysUnitConvertList(sysUnitConvert); + } + + /** + * 新增【请填写功能名称】 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 结果 + */ + @Override + public int insertSysUnitConvert(SysUnitConvert sysUnitConvert) + { + return sysUnitConvertMapper.insertSysUnitConvert(sysUnitConvert); + } + + /** + * 修改【请填写功能名称】 + * + * @param sysUnitConvert 【请填写功能名称】 + * @return 结果 + */ + @Override + public int updateSysUnitConvert(SysUnitConvert sysUnitConvert) + { + return sysUnitConvertMapper.updateSysUnitConvert(sysUnitConvert); + } + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键 + * @return 结果 + */ + @Override + public int deleteSysUnitConvertByIds(Long[] ids) + { + return sysUnitConvertMapper.deleteSysUnitConvertByIds(ids); + } + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + @Override + public int deleteSysUnitConvertById(Long id) + { + return sysUnitConvertMapper.deleteSysUnitConvertById(id); + } + + /** + * 查询单位换算 + * @param unitType 单位换算 + * @param unitOrder 单位换算 + * @param baseUnit 单位换算 + * @return 单位换算 + */ + + @Override + + public SysUnitConvert selectSysUnitConvertUnitByTypeOrder(String unitType,Long unitOrder, String baseUnit) { + return sysUnitConvertMapper.selectSysUnitConvertUnitByTypeOrder(unitType, unitOrder,baseUnit); + } + +} diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUnitConvertMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUnitConvertMapper.xml new file mode 100644 index 0000000..0943484 --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/system/SysUnitConvertMapper.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + select id, unit_type, unit_name, base_unit, conversion_factor, unit_type_name, status, unit_order from sys_unit_convert + + + + + + + + insert into sys_unit_convert + + unit_type, + unit_name, + base_unit, + conversion_factor, + unit_type_name, + status, + unit_order, + + + #{unitType}, + #{unitName}, + #{baseUnit}, + #{conversionFactor}, + #{unitTypeName}, + #{status}, + #{unitOrder}, + + + + + update sys_unit_convert + + unit_type = #{unitType}, + unit_name = #{unitName}, + base_unit = #{baseUnit}, + conversion_factor = #{conversionFactor}, + unit_type_name = #{unitTypeName}, + status = #{status}, + unit_order = #{unitOrder}, + + where id = #{id} + + + + delete from sys_unit_convert where id = #{id} + + + + delete from sys_unit_convert where id in + + #{id} + + + \ No newline at end of file