| | |
| | | maintainer_id int4 NOT NULL DEFAULT 0, -- ç»´æ¤äººï¼ä¸å
许为空 |
| | | maintenance_date DATE NOT NULL, -- ç»´æ¤æ¥æï¼ä¸å
许为空 |
| | | |
| | | -- æ°å¢å段 |
| | | deleted int4 NOT NULL DEFAULT 0, -- æ¯å¦å é¤ï¼è½¯å 餿 å¿ï¼ |
| | | create_by VARCHAR(255), -- å建人 |
| | | create_time TIMESTAMP WITHOUT TIME ZONE, -- å建æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | |
| | | -- å建ç
¤è´¨ä¿¡æ¯è¡¨ |
| | | CREATE TABLE coal_field |
| | | ( |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®IDï¼èªå¨éå¢ |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®IDï¼èªå¨éå¢ |
| | | fields VARCHAR(255) NOT NULL, --ç
¤è´¨å段 |
| | | field_name VARCHAR(255) NOT NULL, -- ç
¤è´¨æè¿° |
| | | field_description VARCHAR(255), -- ç
¤è´¨æè¿° |
| | | |
| | | fields VARCHAR(255) NOT NULL, --ç
¤è´¨å段 |
| | | field_name VARCHAR(255) NOT NULL, -- ç
¤è´¨æè¿° |
| | | field_description VARCHAR(255) NOT NULL, -- ç
¤è´¨æè¿° |
| | | |
| | | deleted INT NOT NULL DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- åå»ºäººç¨æ·å |
| | | create_time TIMESTAMP WITHOUT TIME ZONE, -- å建æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | update_by VARCHAR(255), -- æåæ´æ°äººç¨æ·å |
| | | update_time TIMESTAMP WITHOUT TIME ZONE -- æåæ´æ°æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | deleted INT NOT NULL DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- åå»ºäººç¨æ·å |
| | | create_time TIMESTAMP WITHOUT TIME ZONE, -- å建æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | update_by VARCHAR(255), -- æåæ´æ°äººç¨æ·å |
| | | update_time TIMESTAMP WITHOUT TIME ZONE -- æåæ´æ°æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | ); |
| | | |
| | | -- 表注é |
| | |
| | | -- å建ç
¤è´¨ä¿¡æ¯è¡¨ |
| | | CREATE TABLE coal_plan |
| | | ( |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®IDï¼èªå¨éå¢ |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®IDï¼èªå¨éå¢ |
| | | plan VARCHAR(255) NOT NULL, --ç
¤è´¨æ¹æ¡ |
| | | field_ids VARCHAR(255) NOT NULL, --ç
¤è´¨æ¹æ¡å段id |
| | | coal_fields VARCHAR(255) NOT NULL, -- ç
¤è´¨æ¹æ¡å段 |
| | | scheme_desc VARCHAR(255), -- åæ®µæè¿° |
| | | |
| | | plan VARCHAR(255) NOT NULL, --ç
¤è´¨æ¹æ¡ |
| | | field_ids VARCHAR(255) NOT NULL, --ç
¤è´¨æ¹æ¡å段id |
| | | coal_fields BIGINT NOT NULL, -- ç
¤è´¨æ¹æ¡å段 |
| | | |
| | | deleted INT NOT NULL DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- åå»ºäººç¨æ·å |
| | | create_time TIMESTAMP WITHOUT TIME ZONE, -- å建æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | update_by VARCHAR(255), -- æåæ´æ°äººç¨æ·å |
| | | update_time TIMESTAMP WITHOUT TIME ZONE -- æåæ´æ°æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | deleted INT NOT NULL DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- åå»ºäººç¨æ·å |
| | | create_time TIMESTAMP WITHOUT TIME ZONE, -- å建æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | update_by VARCHAR(255), -- æåæ´æ°äººç¨æ·å |
| | | update_time TIMESTAMP WITHOUT TIME ZONE -- æåæ´æ°æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | ); |
| | | |
| | | -- 表注é |
| | |
| | | COMMENT ON COLUMN coal_plan.plan IS 'ç
¤è´¨æ¹æ¡'; |
| | | COMMENT ON COLUMN coal_plan.coal_fields IS 'ç
¤è´¨æ¹æ¡å段'; |
| | | COMMENT ON COLUMN coal_plan.field_ids IS 'ç
¤è´¨æ¹æ¡å段id'; |
| | | COMMENT ON COLUMN coal_plan.scheme_desc IS 'åæ®µæè¿°'; |
| | | COMMENT ON COLUMN coal_plan.deleted IS '软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤'; |
| | | COMMENT ON COLUMN coal_plan.create_by IS 'å建该记å½çç¨æ·'; |
| | | COMMENT ON COLUMN coal_plan.create_time IS 'è®°å½å建æ¶é´'; |
| | |
| | | CREATE TABLE coal_value |
| | | ( |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®IDï¼èªå¨éå¢ |
| | | |
| | | plan_id VARCHAR(255) NOT NULL, --å
³èç
¤è´¨æ¹æ¡ä¸»é®ID |
| | | plan_id BIGINT NOT NULL, --å
³èç
¤è´¨æ¹æ¡ä¸»é®ID |
| | | coal_value VARCHAR(255) NOT NULL, -- åæ®µå¼ |
| | | fields VARCHAR(255) NOT NULL, -- åæ®µ |
| | | field_name VARCHAR(255) NOT NULL, -- åæ®µå |
| | |
| | | * åæ®µå |
| | | */ |
| | | private String fieldName; |
| | | |
| | | /** |
| | | * åæ®µå |
| | | */ |
| | | private Integer type; |
| | | } |
| | |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | /** |
| | | * |
| | | * ç产å å·¥id |
| | | */ |
| | | @TableField(value = "master_id") |
| | | private Long masterId; |
| | | /** |
| | | * ä¾è´§ååç§° |
| | | */ |
| | |
| | | */ |
| | | @TableField(value = "coal_id") |
| | | private Long coalId; |
| | | /** |
| | | * ç
¤ç§ |
| | | */ |
| | | @TableField(value = "coal") |
| | | private String coal; |
| | | /** |
| | | * åä½ |
| | | */ |
| | |
| | | */ |
| | | @TableField(value = "coal_id") |
| | | private Long coalId; |
| | | /** |
| | | * ç
¤ç§ |
| | | */ |
| | | @TableField(value = "coal") |
| | | private String coal; |
| | | |
| | | /** |
| | | * åºåæ°é |
| | | */ |
| | |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | /** |
| | | * ç
¤ç§ |
| | | */ |
| | | @TableField(value = "coal") |
| | | private String coal; |
| | | /** |
| | | * ç
¤ç§id |
| | | */ |
| | | @TableField(value = "coal_id") |
| | |
| | | package com.ruoyi.business.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.business.dto.OfficialInventoryDto; |
| | | import com.ruoyi.business.dto.PendingInventoryDto; |
| | | import com.ruoyi.business.entity.InventorySummary; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @param officialInventoryDto æ£å¼åºå |
| | | */ |
| | | int updateInventory(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto); |
| | | |
| | | /** |
| | | * æ¹éæ´æ°åºå |
| | | * @param ids åºåid |
| | | * @return |
| | | */ |
| | | int updateInventorySummary(List<Long> ids); |
| | | } |
| | |
| | | import com.ruoyi.business.mapper.InventorySummaryMapper; |
| | | import com.ruoyi.business.service.InputInventoryRecordService; |
| | | import com.ruoyi.business.service.InventorySummaryService; |
| | | import com.ruoyi.business.utils.InventoryUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.ruoyi.business.constant.InventoryRecordConstant.OFFICIAL_INVENTORY; |
| | | import static com.ruoyi.business.constant.InventoryRecordConstant.PENDING_INVENTORY; |
| | |
| | | private final InputInventoryRecordMapper inputInventoryRecordMapper; |
| | | private final InventorySummaryService inventorySummaryService; |
| | | private final InventorySummaryMapper inventorySummaryMapper; |
| | | private final InventoryUtils inventoryUtils; |
| | | |
| | | @Override |
| | | public int insertInputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity) { |
| | |
| | | |
| | | @Override |
| | | public int deleteInputInventoryRecord(List<Long> ids) { |
| | | if (CollectionUtils.isNotEmpty(ids)) { |
| | | List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectBatchIds(ids); |
| | | // æ ¹æ®idè¿è¡éåºæåº |
| | | List<InputInventoryRecord> inputInventoryRecordList = inputInventoryRecords.stream() |
| | | .sorted(Comparator.comparing(InputInventoryRecord::getId).reversed()) |
| | | .toList(); |
| | | |
| | | String InventoryType = inputInventoryRecords.get(0).getInventoryType(); |
| | | List<Long> inventoryIds = inputInventoryRecords.stream().map(InputInventoryRecord::getInventoryId).toList(); |
| | | List<InventorySummary> inventorySummaries = inventorySummaryMapper.selectList(new LambdaQueryWrapper<InventorySummary>() |
| | | .eq(InventorySummary::getInventoryType, InventoryType) |
| | | .in(InventorySummary::getInventoryId, inventoryIds)); |
| | | if (CollectionUtils.isNotEmpty(inventorySummaries)) { |
| | | List<InventorySummary> updates = new ArrayList<>(); |
| | | for (InventorySummary inventorySummary : inventorySummaries) { |
| | | for (InputInventoryRecord inputInventoryRecord : inputInventoryRecords) { |
| | | // 妿èç¹ä¸çå
¥åºè®°å½id大äºåæ´çidï¼è¯´ææ¤idåææå
¥åºè®°å½é½è¦éæ°è®¡ç® |
| | | if (Objects.equals(inventorySummary.getInventoryId(), inputInventoryRecord.getInventoryId()) && inventorySummary.getInputEndRecordId() > inputInventoryRecord.getId()) { |
| | | inventorySummary.setInputEndRecordId(inputInventoryRecord.getId()); |
| | | updates.add(inventorySummary); |
| | | } |
| | | } |
| | | |
| | | } |
| | | // éç½®ä»ä»¬çèç¹æç»id |
| | | inventorySummaryMapper.updateById(updates); |
| | | } |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | throw new RuntimeException("è¯·ä¼ å
¥è¦å é¤çidè®°å½"); |
| | | } |
| | | // todo éæ°è®¡ç®èç¹åºå |
| | | // todo æ´æ°åºå宿½æ°æ® |
| | | List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectBatchIds(ids); |
| | | // æ ¹æ®idè¿è¡éåºæåº |
| | | List<InputInventoryRecord> inputInventoryRecordList = inputInventoryRecords.stream() |
| | | .sorted(Comparator.comparing(InputInventoryRecord::getId).reversed()) |
| | | .toList(); |
| | | |
| | | String InventoryType = inputInventoryRecords.get(0).getInventoryType(); |
| | | List<Long> inventoryIds = inputInventoryRecords.stream().map(InputInventoryRecord::getInventoryId).toList().stream().distinct().collect(Collectors.toList()); |
| | | List<InventorySummary> inventorySummaries = inventorySummaryMapper.selectList(new LambdaQueryWrapper<InventorySummary>() |
| | | .eq(InventorySummary::getInventoryType, InventoryType) |
| | | .in(InventorySummary::getInventoryId, inventoryIds)); |
| | | if (CollectionUtils.isNotEmpty(inventorySummaries)) { |
| | | List<InventorySummary> updates = new ArrayList<>(); |
| | | for (InventorySummary inventorySummary : inventorySummaries) { |
| | | for (InputInventoryRecord inputInventoryRecord : inputInventoryRecordList) { |
| | | // 妿èç¹ä¸çå
¥åºè®°å½id大äºåæ´çidï¼è¯´ææ¤idåææå
¥åºè®°å½é½è¦éæ°è®¡ç® |
| | | if (Objects.equals(inventorySummary.getInventoryId(), inputInventoryRecord.getInventoryId()) && inventorySummary.getInputEndRecordId() > inputInventoryRecord.getId()) { |
| | | inventorySummary.setInputEndRecordId(inputInventoryRecord.getId()); |
| | | updates.add(inventorySummary); |
| | | } |
| | | } |
| | | |
| | | } |
| | | // éç½®èç¹æç»id |
| | | inventorySummaryMapper.updateById(updates); |
| | | } |
| | | |
| | | // éæ°è®¡ç®èç¹åºå |
| | | inventorySummaryService.updateInventorySummary(ids); |
| | | |
| | | // æ´æ°åºå宿¶æ°æ® |
| | | inventoryUtils.updateInventoryByIds(inventoryIds, inputInventoryRecords.get(0).getInventoryType()); |
| | | |
| | | |
| | | // å é¤å
¥åºè®°å½ |
| | |
| | | return officialInventoryMapper.updateById(officialInventory); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int updateInventorySummary(List<Long> ids) { |
| | | List<InventorySummary> inventorySummaries = inventorySummaryMapper.selectBatchIds(ids); |
| | | for (InventorySummary inventorySummary : inventorySummaries) { |
| | | // æ¥è¯¢èç¹ä¹åææå
¥åºè®°å½ |
| | | List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectList(new LambdaQueryWrapper<InputInventoryRecord>() |
| | | .eq(InputInventoryRecord::getInventoryId, inventorySummary.getInventoryId()) |
| | | .eq(InputInventoryRecord::getInventoryType, inventorySummary.getInventoryType()) |
| | | .lt(InputInventoryRecord::getId, inventorySummary.getInputEndRecordId())); |
| | | |
| | | // æ¥è¯¢èç¹ä¹åææåºåºè®°å½ |
| | | List<OutputInventoryRecord> outputInventoryRecords = outputInventoryRecordMapper.selectList(new LambdaQueryWrapper<OutputInventoryRecord>() |
| | | .eq(OutputInventoryRecord::getInventoryId, inventorySummary.getInventoryId()) |
| | | .eq(OutputInventoryRecord::getInventoryType, inventorySummary.getInventoryType()) |
| | | .lt(OutputInventoryRecord::getId, inventorySummary.getOutputEndRecordId())); |
| | | |
| | | // 计ç®åºåæ°é |
| | | BigDecimal inputQuantity = inputInventoryRecords.stream().map(InputInventoryRecord::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal outputQuantity = outputInventoryRecords.stream().map(OutputInventoryRecord::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | inventorySummary.setInventoryQuantity(inputQuantity.subtract(outputQuantity)); |
| | | } |
| | | |
| | | return inventorySummaryMapper.updateById(inventorySummaries).size(); |
| | | } |
| | | } |
| | |
| | | // 2. æå
¥æ°åºåè®°å½ |
| | | OfficialInventory officialInventory = new OfficialInventory(); |
| | | BeanUtils.copyProperties(officialInventoryDto, officialInventory); |
| | | officialInventory.setId(null); |
| | | officialInventory.setMergeId(ids.toString()); |
| | | officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserName()); |
| | | if (officialInventoryMapper.insert(officialInventory) <= 0) { |
| | |
| | | coalValue.setCoalValue(value); |
| | | coalValue.setFields(key); |
| | | coalValue.setFieldName(fieldName); |
| | | coalValue.setType(String.valueOf(1)); |
| | | i = coalValueMapper.insert(coalValue); |
| | | } |
| | | } |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public int addOrEditPM(ProductionMasterDto productionMasterDto) { |
| | | // 1. ç´æ¥è®¡ç®èåå¼ï¼é¿å
å建å¤ä½å表 |
| | | BigDecimal totalPurchasePrice = BigDecimal.ZERO; |
| | | BigDecimal totalLaborCost = BigDecimal.ZERO; |
| | | BigDecimal totalEnergyConsumptionCost = BigDecimal.ZERO; |
| | | BigDecimal totalTotalCost = BigDecimal.ZERO; |
| | | BigDecimal totalEquipmentDepreciation = BigDecimal.ZERO; |
| | | BigDecimal totalProductionQuantity = BigDecimal.ZERO; |
| | | public int addOrEditPM(ProductionMasterDto dto) { |
| | | Long masterId = dto.getId(); |
| | | |
| | | for (Production production : productionMasterDto.getProductionList()) { |
| | | totalPurchasePrice = totalPurchasePrice.add(production.getPurchasePrice()); |
| | | totalLaborCost = totalLaborCost.add(production.getLaborCost()); |
| | | totalEnergyConsumptionCost = totalEnergyConsumptionCost.add(production.getEnergyConsumptionCost()); |
| | | totalTotalCost = totalTotalCost.add(production.getTotalCost()); |
| | | totalEquipmentDepreciation = totalEquipmentDepreciation.add(production.getEquipmentDepreciation()); |
| | | totalProductionQuantity = production.getProductionQuantity().add(totalProductionQuantity); |
| | | // ç¼è¾åºæ¯ï¼åæ»æ§åºåå¹¶å 餿§è®°å½ |
| | | if (masterId != null) { |
| | | rollbackOldInventory(masterId); |
| | | deleteChildRecords(masterId); |
| | | } |
| | | //ç
¤ç§å段 |
| | | List<Long> coalIds = productionMasterDto.getProductionList().stream() |
| | | .map(Production::getCoalId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<CoalInfo> coalInfos = coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds)); |
| | | // æ ¡éªä½¿ç¨éå¹¶åå°åºå |
| | | validateAndReduceInventory(dto.getProductionInventoryList()); |
| | | |
| | | // 2. å建主表对象 |
| | | ProductionMaster productionMaster = new ProductionMaster(); |
| | | productionMaster.setProductionQuantity(totalProductionQuantity); |
| | | productionMaster.setTotalCost(totalTotalCost); |
| | | productionMaster.setEquipmentDepreciation(totalEquipmentDepreciation); |
| | | productionMaster.setEnergyConsumptionCost(totalEnergyConsumptionCost); |
| | | productionMaster.setLaborCost(totalLaborCost); |
| | | productionMaster.setCoal(coalInfos.stream().map(CoalInfo::getCoal).collect(Collectors.joining(","))); |
| | | productionMaster.setCoalId(coalIds.stream().map(String::valueOf).collect(Collectors.joining(","))); |
| | | // æé 主表å®ä½å¯¹è±¡ |
| | | ProductionMaster master = buildProductionMaster(dto); |
| | | |
| | | Long masterId = productionMasterDto.getId(); |
| | | productionMaster.setId(masterId); |
| | | |
| | | // 3. ç»ä¸å表å¤çé»è¾ |
| | | // æå
¥ææ´æ°ä¸»è¡¨ |
| | | if (masterId == null) { |
| | | productionMasterMapper.insert(productionMaster); |
| | | masterId = productionMaster.getId(); // è·åæ°çæçID |
| | | productionMasterMapper.insert(master); |
| | | masterId = master.getId(); |
| | | } else { |
| | | // å é¤å
³èåè¡¨æ°æ® |
| | | productionMapper.delete(new LambdaQueryWrapper<Production>() |
| | | .eq(Production::getProductionMasterId, masterId)); |
| | | |
| | | productionInventoryMapper.delete(new LambdaQueryWrapper<ProductionInventory>() |
| | | .eq(ProductionInventory::getProductionMasterId, masterId)); |
| | | |
| | | productionMasterMapper.updateById(productionMaster); |
| | | master.setId(masterId); |
| | | productionMasterMapper.updateById(master); |
| | | } |
| | | //åºåæ´æ° |
| | | for (ProductionInventory productionInventory : productionMasterDto.getProductionInventoryList()) { |
| | | OfficialInventory officialInventory = officialInventoryMapper.selectById(productionInventory.getOfficialId()); |
| | | BigDecimal subtract = officialInventory.getInventoryQuantity().subtract(new BigDecimal(productionInventory.getUsedQuantity())); |
| | | if (subtract.compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new BaseException("åºåä¸è¶³"); |
| | | } |
| | | officialInventory.setInventoryQuantity(subtract); |
| | | officialInventoryMapper.updateById(officialInventory); |
| | | } |
| | | |
| | | // 4. æ¹éæå
¥åè¡¨æ°æ® |
| | | batchInsertProductions(masterId, productionMasterDto.getProductionList()); |
| | | batchInsertInventories(masterId, productionMasterDto.getProductionInventoryList()); |
| | | |
| | | //5. æå
¥å°å¾
å
¥åº |
| | | for (Production production : productionMasterDto.getProductionList()) { |
| | | PendingInventory pendingInventory = new PendingInventory(); |
| | | pendingInventory.setCoalId(production.getCoalId()); |
| | | pendingInventory.setInventoryQuantity(production.getProductionQuantity()); |
| | | pendingInventory.setSupplierName("ç产å å·¥å
¥åº"); |
| | | pendingInventory.setTotalPriceIncludingTax(production.getTotalCost()); |
| | | pendingInventory.setPriceIncludingTax(production.getPurchasePrice()); |
| | | } |
| | | // æ¹éæå
¥ç产记å½ä¸åºåè®°å½ |
| | | batchInsertProductions(masterId, dto.getProductionList()); |
| | | batchInsertInventories(masterId, dto.getProductionInventoryList()); |
| | | |
| | | // æå
¥å¾
å
¥åºæ°æ® |
| | | insertPendingInventory(dto.getProductionList()); |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | // æ¹éæå
¥çäº§æ°æ® |
| | | private void batchInsertProductions(Long masterId, List<Production> productions) { |
| | | if (productions.isEmpty()) { |
| | | return; |
| | | } |
| | | // 1. æ¶éææéè¦æ¥è¯¢çcoalId |
| | | List<Long> coalIds = productions.stream() |
| | | .map(Production::getCoalId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | /** |
| | | * åæ»æ§çåºåæ°æ®ï¼å°åºåæ°éè¿åï¼ |
| | | */ |
| | | private void rollbackOldInventory(Long masterId) { |
| | | List<ProductionInventory> oldInventories = productionInventoryMapper.selectList( |
| | | new LambdaQueryWrapper<ProductionInventory>().eq(ProductionInventory::getProductionMasterId, masterId)); |
| | | |
| | | // 2. æ¹éæ¥è¯¢coalInfoæ°æ® |
| | | Map<Long, CoalInfo> coalInfoMap = coalIds.isEmpty() ? |
| | | Collections.emptyMap() : |
| | | coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds)) |
| | | .stream() |
| | | .collect(Collectors.toMap(CoalInfo::getId, Function.identity())); |
| | | if (coalInfoMap.isEmpty()){ |
| | | throw new BaseException("ç
¤ç§ä¿¡æ¯ä¸åå¨"); |
| | | } |
| | | |
| | | // 3. å夿¹éæå
¥æ°æ® |
| | | List<Production> batchInsertList = productions.stream() |
| | | .map(production -> { |
| | | Production p = new Production(); // å建æ°å¯¹è±¡é¿å
å¯ä½ç¨ |
| | | BeanUtils.copyProperties(production, p); |
| | | // å¤å¶å¿
è¦å段 |
| | | p.setProductionMasterId(masterId); |
| | | p.setCoalId(production.getCoalId()); |
| | | return p; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | if (!batchInsertList.isEmpty()) { |
| | | for (Production production : batchInsertList) { |
| | | production.setId(null); |
| | | productionMapper.insert(production); |
| | | for (ProductionInventory oldInv : oldInventories) { |
| | | OfficialInventory inv = officialInventoryMapper.selectById(oldInv.getOfficialId()); |
| | | if (inv != null) { |
| | | inv.setInventoryQuantity(inv.getInventoryQuantity().add(new BigDecimal(oldInv.getUsedQuantity()))); |
| | | officialInventoryMapper.updateById(inv); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // æ¹éæå
¥åºåæ°æ® |
| | | private void batchInsertInventories(Long masterId, List<ProductionInventory> inventories) { |
| | | List<ProductionInventory> insertList = inventories.stream() |
| | | .peek(inv -> { |
| | | inv.setId(null); |
| | | inv.setProductionMasterId(masterId); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | /** |
| | | * å 餿§çåè¡¨æ°æ®åå¾
å
¥åºæ°æ® |
| | | */ |
| | | private void deleteChildRecords(Long masterId) { |
| | | productionMapper.delete(new LambdaQueryWrapper<Production>().eq(Production::getProductionMasterId, masterId)); |
| | | productionInventoryMapper.delete(new LambdaQueryWrapper<ProductionInventory>().eq(ProductionInventory::getProductionMasterId, masterId)); |
| | | pendingInventoryMapper.delete(new LambdaQueryWrapper<PendingInventory>().eq(PendingInventory::getMasterId, masterId)); |
| | | } |
| | | |
| | | if (!insertList.isEmpty()) { |
| | | for (ProductionInventory inventory : inventories) { |
| | | inventory.setId(null); |
| | | inventory.setProductionMasterId(masterId); |
| | | productionInventoryMapper.insert(inventory); |
| | | /** |
| | | * æ ¡éªæ¯æ¡ä½¿ç¨éæ¯å¦è¶³å¤ï¼å¹¶åå°æ£å¼åºåæ°é |
| | | */ |
| | | private void validateAndReduceInventory(List<ProductionInventory> inventoryList) { |
| | | for (ProductionInventory inv : inventoryList) { |
| | | OfficialInventory official = officialInventoryMapper.selectById(inv.getOfficialId()); |
| | | BigDecimal used = new BigDecimal(inv.getUsedQuantity()); |
| | | if (official.getInventoryQuantity().compareTo(used) < 0) { |
| | | throw new BaseException("åºåä¸è¶³"); |
| | | } |
| | | official.setInventoryQuantity(official.getInventoryQuantity().subtract(used)); |
| | | officialInventoryMapper.updateById(official); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æé 主表对象并èååæ®µå¼ï¼å¦æ»ææ¬ãç
¤ç§çï¼ |
| | | */ |
| | | private ProductionMaster buildProductionMaster(ProductionMasterDto dto) { |
| | | BigDecimal totalPurchase = BigDecimal.ZERO; |
| | | BigDecimal totalLabor = BigDecimal.ZERO; |
| | | BigDecimal totalEnergy = BigDecimal.ZERO; |
| | | BigDecimal totalCost = BigDecimal.ZERO; |
| | | BigDecimal totalDepreciation = BigDecimal.ZERO; |
| | | BigDecimal totalQuantity = BigDecimal.ZERO; |
| | | |
| | | List<Long> coalIds = new ArrayList<>(); |
| | | |
| | | for (Production p : dto.getProductionList()) { |
| | | totalPurchase = totalPurchase.add(p.getPurchasePrice()); |
| | | totalLabor = totalLabor.add(p.getLaborCost()); |
| | | totalEnergy = totalEnergy.add(p.getEnergyConsumptionCost()); |
| | | totalCost = totalCost.add(p.getTotalCost()); |
| | | totalDepreciation = totalDepreciation.add(p.getEquipmentDepreciation()); |
| | | totalQuantity = totalQuantity.add(p.getProductionQuantity()); |
| | | coalIds.add(p.getCoalId()); |
| | | } |
| | | |
| | | List<CoalInfo> coalInfos = coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds)); |
| | | |
| | | ProductionMaster master = new ProductionMaster(); |
| | | master.setProductionQuantity(totalQuantity); |
| | | master.setTotalCost(totalCost); |
| | | master.setLaborCost(totalLabor); |
| | | master.setEnergyConsumptionCost(totalEnergy); |
| | | master.setEquipmentDepreciation(totalDepreciation); |
| | | master.setCoalId(coalIds.stream().map(String::valueOf).collect(Collectors.joining(","))); |
| | | |
| | | return master; |
| | | } |
| | | |
| | | /** |
| | | * æ¹éæå
¥ç产åè¡¨æ°æ® |
| | | */ |
| | | private void batchInsertProductions(Long masterId, List<Production> list) { |
| | | if (list.isEmpty()) return; |
| | | |
| | | for (Production p : list) { |
| | | Production copy = new Production(); |
| | | BeanUtils.copyProperties(p, copy); |
| | | copy.setId(null); |
| | | copy.setProductionMasterId(masterId); |
| | | productionMapper.insert(copy); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¹éæå
¥åºå使ç¨åè¡¨æ°æ® |
| | | */ |
| | | private void batchInsertInventories(Long masterId, List<ProductionInventory> list) { |
| | | if (list.isEmpty()) return; |
| | | |
| | | for (ProductionInventory p : list) { |
| | | p.setId(null); |
| | | p.setProductionMasterId(masterId); |
| | | productionInventoryMapper.insert(p); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°å 工产çç产åè®°å½å°å¾
å
¥åºè¡¨ |
| | | */ |
| | | private void insertPendingInventory(List<Production> list) { |
| | | for (Production p : list) { |
| | | PendingInventory pending = new PendingInventory(); |
| | | pending.setCoalId(p.getCoalId()); |
| | | pending.setInventoryQuantity(p.getProductionQuantity()); |
| | | pending.setSupplierName("ç产å å·¥å
¥åº"); |
| | | pending.setTotalPriceIncludingTax(p.getTotalCost()); |
| | | pending.setPriceIncludingTax(p.getPurchasePrice()); |
| | | pending.setPriceIncludingTax(p.getPurchasePrice()); |
| | | pendingInventoryMapper.insert(pending); |
| | | } |
| | | } |
| | | |
| | |
| | | // éè´ç»è®°æåï¼åæ¥å建å¾
å
¥åºè®°å½ |
| | | PendingInventory pendingInventory = createPendingInventory(purchaseRegistration); |
| | | pendingInventory.setSupplierName(supply.getSupplierName()); |
| | | pendingInventory.setCoal(coalInfo.getCoal()); |
| | | return pendingInventoryMapper.insert(pendingInventory); |
| | | } |
| | | return insertCount; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.business.utils; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.business.constant.InventoryRecordConstant; |
| | | import com.ruoyi.business.entity.*; |
| | | import com.ruoyi.business.mapper.*; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | public class InventoryUtils { |
| | | |
| | | @Autowired |
| | | private InventorySummaryMapper inventorySummaryMapper; |
| | | @Autowired |
| | | private InputInventoryRecordMapper inputInventoryRecordMapper; |
| | | @Autowired |
| | | private OutputInventoryRecordMapper outputInventoryRecordMapper; |
| | | @Autowired |
| | | private OfficialInventoryMapper officialInventoryMapper; |
| | | @Autowired |
| | | private PendingInventoryMapper pendingInventoryMapper; |
| | | |
| | | /** |
| | | * æ´æ°åºå |
| | | */ |
| | | public void updateInventoryByIds(List<Long> ids, String type) { |
| | | if (StringUtils.isEmpty(type)) { |
| | | throw new RuntimeException("请æå®åºåç±»å"); |
| | | } |
| | | |
| | | for (Long id : ids) { |
| | | // è·ååºåèç¹ |
| | | InventorySummary inventorySummary = inventorySummaryMapper.selectOne(new LambdaQueryWrapper<InventorySummary>() |
| | | .eq(InventorySummary::getInventoryId, id) |
| | | .eq(InventorySummary::getInventoryType, type)); |
| | | Long inputEndRecordId = inventorySummary != null ? inventorySummary.getInputEndRecordId() : 0L; |
| | | Long outputEndRecordId = inventorySummary != null ? inventorySummary.getOutputEndRecordId() : 0L; |
| | | List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectList(new LambdaQueryWrapper<InputInventoryRecord>() |
| | | .eq(InputInventoryRecord::getInventoryId, id) |
| | | .eq(InputInventoryRecord::getInventoryType, type) |
| | | .gt(InputInventoryRecord::getId, inputEndRecordId)); |
| | | |
| | | List<OutputInventoryRecord> outputInventoryRecords = outputInventoryRecordMapper.selectList(new LambdaQueryWrapper<OutputInventoryRecord>() |
| | | .eq(OutputInventoryRecord::getInventoryId, id) |
| | | .eq(OutputInventoryRecord::getInventoryType, type) |
| | | .gt(OutputInventoryRecord::getId, outputEndRecordId)); |
| | | |
| | | // è·ååºåæ°æ® |
| | | BigDecimal inputQuantity = inputInventoryRecords.stream().map(InputInventoryRecord::getQuantity).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); |
| | | BigDecimal outputQuantity = outputInventoryRecords.stream().map(OutputInventoryRecord::getQuantity).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); |
| | | // 计ç®è¿æ¬¡åºåæ°æ® |
| | | BigDecimal quantity = inventorySummary != null ? inventorySummary.getInventoryQuantity().add(inputQuantity.subtract(outputQuantity)) : inputQuantity.subtract(outputQuantity); |
| | | if (inventorySummary != null) { |
| | | if (type.equals(InventoryRecordConstant.OFFICIAL_INVENTORY)) { |
| | | OfficialInventory update = new OfficialInventory(); |
| | | update.setInventoryQuantity(quantity); |
| | | update.setId(id); |
| | | officialInventoryMapper.updateById(update); |
| | | } else { |
| | | PendingInventory update = new PendingInventory(); |
| | | update.setInventoryQuantity(quantity); |
| | | update.setId(id); |
| | | pendingInventoryMapper.updateById(update); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®ID |
| | | production_master_id BIGINT NOT NULL DEFAULT 0, -- ç产主表ID |
| | | coal_id BIGINT NOT NULL DEFAULT 0, -- ç
¤ç§ID |
| | | coal VARCHAR(50) NOT NULL, -- ç
¤ç§ |
| | | production_quantity INT NOT NULL, -- ç产æ°é |
| | | labor_cost DECIMAL(10, 2) NOT NULL, -- äººå·¥ææ¬ |
| | | energy_consumption_cost DECIMAL(10, 2) NOT NULL, -- è½èææ¬ |
| | |
| | | -- æ·»å åæ®µæ³¨é |
| | | COMMENT ON COLUMN production.id IS '主é®ID'; |
| | | COMMENT ON COLUMN production.coal_id IS 'ç
¤ç§ID'; |
| | | COMMENT ON COLUMN production.coal IS 'ç
¤ç§'; |
| | | COMMENT ON COLUMN production.production_quantity IS 'ç产æ°é'; |
| | | COMMENT ON COLUMN production.labor_cost IS 'äººå·¥ææ¬'; |
| | | COMMENT ON COLUMN production.energy_consumption_cost IS 'è½èææ¬'; |
| | |
| | | -- å建å¾
å
¥åºè¡¨ |
| | | CREATE TABLE pending_inventory |
| | | ( |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®ID |
| | | supplier_name VARCHAR(255) NOT NULL, -- ä¾è´§ååç§° |
| | | coal VARCHAR(50) NOT NULL, -- ç
¤ç§ |
| | | unit VARCHAR(50) NOT NULL, -- åä½ |
| | | inventory_quantity DECIMAL(10, 2) NOT NULL, -- åºåæ°é |
| | | price_including_tax DECIMAL(10, 2) NOT NULL, -- åä»·ï¼å«ç¨ï¼ |
| | | total_price_including_tax DECIMAL(10, 2) NOT NULL, -- æ»ä»·ï¼å«ç¨ï¼ |
| | | registrant VARCHAR(50) NOT NULL, -- ç»è®°äºº |
| | | registration_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- ç»è®°æ¶é´ |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®ID |
| | | supplier_name VARCHAR(255) NOT NULL, -- ä¾è´§ååç§° |
| | | coal VARCHAR(50) NOT NULL, -- ç
¤ç§ |
| | | unit VARCHAR(50) NOT NULL, -- åä½ |
| | | inventory_quantity NUMERIC(10,2) NOT NULL, -- åºåæ°é |
| | | price_including_tax NUMERIC(10,2) NOT NULL, -- åä»·ï¼å«ç¨ï¼ |
| | | total_price_including_tax NUMERIC(10,2) NOT NULL, -- æ»ä»·ï¼å«ç¨ï¼ |
| | | registrant VARCHAR(50), -- ç»è®°äºº |
| | | registration_time TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP, -- ç»è®°æ¶é´ |
| | | price_excluding_tax VARCHAR(255), -- åä»·ï¼ä¸å«ç¨ï¼ |
| | | total_price_excluding_tax VARCHAR(255), -- æ»ä»·ï¼ä¸å«ç¨ï¼ |
| | | registrant_id VARCHAR(32), -- ç»è®°äººID |
| | | registration_date DATE, -- ç»è®°æ¥æ |
| | | supplier_id BIGINT, -- ä¾è´§åID |
| | | coal_id BIGINT, -- ç
¤ç§ID |
| | | |
| | | deleted INT NOT NULL DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- åå»ºäººç¨æ·å |
| | | create_time TIMESTAMP WITHOUT TIME ZONE, -- å建æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | update_by VARCHAR(255), -- æåæ´æ°äººç¨æ·å |
| | | update_time TIMESTAMP WITHOUT TIME ZONE -- æåæ´æ°æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | deleted INTEGER DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- å建该记å½çç¨æ· |
| | | create_time TIMESTAMP(6), -- è®°å½å建æ¶é´ |
| | | update_by VARCHAR(255), -- æåä¿®æ¹è¯¥è®°å½çç¨æ· |
| | | update_time TIMESTAMP(6) -- è®°å½æåæ´æ°æ¶é´ |
| | | |
| | | ); |
| | | |
| | | -- æ·»å 表注é |
| | | COMMENT ON TABLE pending_inventory IS 'å¾
å
¥åºè¡¨'; |
| | | |
| | | -- æ·»å åæ®µæ³¨é |
| | | -- åæ®µæ³¨é |
| | | COMMENT ON COLUMN pending_inventory.id IS '主é®ID'; |
| | | COMMENT ON COLUMN pending_inventory.supplier_name IS 'ä¾è´§ååç§°'; |
| | | COMMENT ON COLUMN pending_inventory.coal IS 'ç
¤ç§'; |
| | |
| | | COMMENT ON COLUMN pending_inventory.total_price_including_tax IS 'æ»ä»·ï¼å«ç¨ï¼'; |
| | | COMMENT ON COLUMN pending_inventory.registrant IS 'ç»è®°äºº'; |
| | | COMMENT ON COLUMN pending_inventory.registration_time IS 'ç»è®°æ¶é´'; |
| | | COMMENT ON COLUMN pending_inventory.price_excluding_tax IS 'åä»·ï¼ä¸å«ç¨ï¼'; |
| | | COMMENT ON COLUMN pending_inventory.total_price_excluding_tax IS 'æ»ä»·ï¼ä¸å«ç¨ï¼'; |
| | | COMMENT ON COLUMN pending_inventory.registrant_id IS 'ç»è®°äººID'; |
| | | COMMENT ON COLUMN pending_inventory.registration_date IS 'ç»è®°æ¥æ'; |
| | | COMMENT ON COLUMN pending_inventory.supplier_id IS 'ä¾è´§åID'; |
| | | COMMENT ON COLUMN pending_inventory.coal_id IS 'ç
¤ç§ID'; |
| | | |
| | | COMMENT ON COLUMN pending_inventory.deleted IS '软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤'; |
| | | COMMENT ON COLUMN pending_inventory.create_by IS 'å建该记å½çç¨æ·'; |
| | | COMMENT ON COLUMN pending_inventory.create_time IS 'è®°å½å建æ¶é´'; |
| | | COMMENT ON COLUMN pending_inventory.update_by IS 'æåä¿®æ¹è¯¥è®°å½çç¨æ·'; |
| | | COMMENT ON COLUMN pending_inventory.update_time IS 'è®°å½æåæ´æ°æ¶é´'; |
| | | COMMENT ON COLUMN pending_inventory.update_time IS 'è®°å½æåæ´æ°æ¶é´'; |
| | | |
| | |
| | | supplier_name VARCHAR(255) NOT NULL, -- ä¾è´§ååç§° |
| | | coal VARCHAR(50) NOT NULL, -- ç
¤ç§ |
| | | unit VARCHAR(50) NOT NULL, -- åä½ |
| | | inventory_quantity DECIMAL(10, 2) NOT NULL, -- åºåæ°é |
| | | inventory_quantity DECIMAL(10, 0), -- åºåæ°é |
| | | price_including_tax DECIMAL(10, 2) NOT NULL, -- åä»·ï¼å«ç¨ï¼ |
| | | total_price_including_tax DECIMAL(10, 2) NOT NULL, -- æ»ä»·ï¼å«ç¨ï¼ |
| | | price_excluding_tax DECIMAL(10, 2) NOT NULL, -- ä¸å«ç¨åä»· |
| | | total_price_excluding_tax DECIMAL(10, 2) NOT NULL, -- ä¸å«ç¨æ»ä»· |
| | | pending_replenishment DECIMAL(10, 2) NOT NULL, -- å¾
è¡¥åº |
| | | pending_replenishment DECIMAL(10, 0), -- å¾
è¡¥åº |
| | | registrant_id VARCHAR(50) NOT NULL, -- ç»è®°äººid |
| | | type VARCHAR(50) NOT NULL, -- ç»è®°äººid |
| | | type VARCHAR(50), -- ç±»å 1 éè´/ 2 æ£å¼ å
¥åº |
| | | pending_id BIGINT, -- å¾
å
¥åºid |
| | | merge_id VARCHAR(255), -- åå¹¶id |
| | | registration_date TIMESTAMP WITHOUT TIME ZONE, |
| | | |
| | | deleted INT NOT NULL DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | |
| | | COMMENT ON COLUMN official_inventory.pending_replenishment IS 'å¾
è¡¥åº'; |
| | | COMMENT ON COLUMN official_inventory.registrant_id IS 'ç»è®°äººid'; |
| | | COMMENT ON COLUMN official_inventory.registration_date IS 'ç»è®°æ¥æ'; |
| | | COMMENT ON COLUMN official_inventory.merge_id IS 'åå¹¶id'; |
| | | |
| | | COMMENT ON COLUMN official_inventory.deleted IS '软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤'; |
| | | COMMENT ON COLUMN official_inventory.create_by IS 'å建该记å½çç¨æ·'; |
| | |
| | | CREATE TABLE tree |
| | | ( |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®IDï¼èªå¨éå¢ |
| | | |
| | | name VARCHAR(255) NOT NULL, -- åç§° |
| | | parent_id BIGINT, -- ç¶id |
| | | |
| | |
| | | -- å建档æ¡è¡¨ |
| | | CREATE TABLE archive |
| | | ( |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®IDï¼èªå¨éå¢ |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®ID |
| | | name VARCHAR(255) NOT NULL, -- æ¡£æ¡åç§° |
| | | type VARCHAR(255) NOT NULL, -- æ¡£æ¡ç±»åï¼ä¾å¦ï¼ååãæ¥åãè¯ä»¶ç |
| | | status VARCHAR(50) NOT NULL, -- æ¡£æ¡ç¶æï¼ä¾å¦ï¼ææãè¿æãä½åº |
| | | |
| | | name VARCHAR(255) NOT NULL, -- æ¡£æ¡åç§° |
| | | type VARCHAR(255) NOT NULL, -- æ¡£æ¡ç±»åï¼å¦ï¼ååãæ¥åãè¯ä»¶çï¼ |
| | | status VARCHAR(50) NOT NULL, -- ç¶æï¼å¦ï¼ææãè¿æãä½åºï¼ |
| | | |
| | | deleted INT NOT NULL DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- åå»ºäººç¨æ·å |
| | | create_time TIMESTAMP WITHOUT TIME ZONE, -- å建æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | update_by VARCHAR(255), -- æåæ´æ°äººç¨æ·å |
| | | update_time TIMESTAMP WITHOUT TIME ZONE -- æåæ´æ°æ¶é´ï¼é»è®¤å½åæ¶é´-- ç»è®°æ¥æ |
| | | deleted INTEGER DEFAULT 0 NOT NULL, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- å建该记å½çç¨æ· |
| | | create_time TIMESTAMP(6), -- è®°å½å建æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | update_by VARCHAR(255), -- æåä¿®æ¹è¯¥è®°å½çç¨æ· |
| | | update_time TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP, -- æåæ´æ°æ¶é´ï¼é»è®¤å½åæ¶é´ |
| | | tree_id BIGINT -- æ èç¹ID |
| | | ); |
| | | |
| | | -- 表注é |
| | | COMMENT ON TABLE archive IS 'æ¡£æ¡ä¿¡æ¯è¡¨ï¼è®°å½ç³»ç»ä¸å类档æ¡çåºæ¬ä¿¡æ¯'; |
| | | COMMENT ON TABLE archive IS 'æ¡£æ¡ä¿¡æ¯è¡¨'; |
| | | |
| | | -- åæ®µæ³¨é |
| | | COMMENT ON COLUMN archive.id IS '主é®ID'; |
| | |
| | | COMMENT ON COLUMN archive.create_by IS 'å建该记å½çç¨æ·'; |
| | | COMMENT ON COLUMN archive.create_time IS 'è®°å½å建æ¶é´'; |
| | | COMMENT ON COLUMN archive.update_by IS 'æåä¿®æ¹è¯¥è®°å½çç¨æ·'; |
| | | COMMENT ON COLUMN archive.update_time IS 'è®°å½æåæ´æ°æ¶é´'; |
| | | COMMENT ON COLUMN archive.update_time IS 'è®°å½æåæ´æ°æ¶é´'; |
| | | COMMENT ON COLUMN archive.tree_id IS 'æ èç¹ID'; |
| | |
| | | CREATE TABLE production_master |
| | | ( |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®ID |
| | | coal VARCHAR(50) NOT NULL, -- ç
¤ç§ |
| | | coal_id BIGINT, -- ç
¤ç§ID |
| | | production_quantity INT NOT NULL, -- ç产æ°é |
| | | labor_cost DECIMAL(10, 2) NOT NULL, -- äººå·¥ææ¬ |
| | | energy_consumption_cost DECIMAL(10, 2) NOT NULL, -- è½èææ¬ |
| | |
| | | |
| | | -- æ·»å åæ®µæ³¨é |
| | | COMMENT ON COLUMN production_master.id IS '主é®ID'; |
| | | COMMENT ON COLUMN production_master.coal IS 'ç
¤ç§'; |
| | | COMMENT ON COLUMN production_master.coal_id IS 'ç
¤ç§ID'; |
| | | COMMENT ON COLUMN production_master.production_quantity IS 'ç产æ°é'; |
| | | COMMENT ON COLUMN production_master.labor_cost IS 'äººå·¥ææ¬'; |
| | | COMMENT ON COLUMN production_master.energy_consumption_cost IS 'è½èææ¬'; |
| | |
| | | id BIGSERIAL PRIMARY KEY, -- 主é®ID |
| | | production_master_id BIGINT NOT NULL DEFAULT 0, -- ç产主表ID |
| | | coal_id BIGINT NOT NULL DEFAULT 0, -- ç
¤ç§ID |
| | | coal VARCHAR(50) NOT NULL, -- ç
¤ç§ |
| | | official_id BIGINT NOT NULL DEFAULT 0, -- åºåID |
| | | inventory_quantity INT NOT NULL, -- åºåæ°é |
| | | used_quantity INT NOT NULL, -- ä½¿ç¨æ°é |
| | | |
| | | |
| | | deleted INT NOT NULL DEFAULT 0, -- 软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤ |
| | | create_by VARCHAR(255), -- åå»ºäººç¨æ·å |
| | |
| | | COMMENT ON COLUMN production_inventory.id IS '主é®ID'; |
| | | COMMENT ON COLUMN production_inventory.production_master_id IS 'ç产主表ID'; |
| | | COMMENT ON COLUMN production_inventory.coal_id IS 'ç
¤ç§ID'; |
| | | COMMENT ON COLUMN production_inventory.coal IS 'ç
¤ç§'; |
| | | COMMENT ON COLUMN production_inventory.official_id IS 'åºåID'; |
| | | COMMENT ON COLUMN production_inventory.inventory_quantity IS 'åºåæ°é'; |
| | | COMMENT ON COLUMN production_inventory.used_quantity IS 'ä½¿ç¨æ°é'; |
| | | |
| | |
| | | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
| | | <java.version>17</java.version> |
| | | <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version> |
| | | <mybatis-spring-boot.version>3.0.3</mybatis-spring-boot.version> |
| | | <druid.version>1.2.23</druid.version> |
| | | <bitwalker.version>1.21</bitwalker.version> |
| | | <swagger.version>3.0.0</swagger.version> |
| | |
| | | <artifactId>jakarta.servlet-api</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.mybatis</groupId> |
| | | <artifactId>mybatis</artifactId> |
| | | <version>3.5.16</version> |
| | | </dependency> |
| | | |
| | | <!-- minio --> |
| | | <dependency> |
| | | <groupId>io.minio</groupId> |
| | |
| | | import com.ruoyi.basic.mapper.StorageBlobMapper; |
| | | import com.ruoyi.basic.service.StorageBlobService; |
| | | import com.ruoyi.common.core.domain.MinioResult; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.exception.file.InvalidExtensionException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.file.MinioUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | List<StorageBlobDTO> storageBlobDTOs = new ArrayList<>(); |
| | | for (MultipartFile file : files) { |
| | | try { |
| | | validateFileExtension(file); |
| | | |
| | | MinioResult res = minioUtils.upload(bucketName, file, false); |
| | | StorageBlobDTO dto = new StorageBlobDTO(); |
| | | dto.setContentType(file.getContentType()); |
| | | dto.setBucketFilename(res.getBucketFileName()); |
| | | dto.setOriginalFilename(res.getOriginalName()); |
| | | dto.setByteSize(file.getSize()); |
| | | dto.setKey(IdUtils.simpleUUID()); |
| | | dto.setBucketName(bucketName); |
| | | dto.setUrl(minioUtils.getPreviewUrl(res.getBucketFileName(), bucketName, false)); |
| | | dto.setDownloadUrl(minioUtils.getDownloadUrl(res.getBucketFileName(), bucketName)); |
| | | if (type != null){ |
| | | dto.setType(type); |
| | | } |
| | | // æå
¥æ°æ®åº |
| | | |
| | | StorageBlobDTO dto = buildStorageBlobDTO(file, res, bucketName, type); |
| | | |
| | | storageBlobMapper.insert(dto); |
| | | storageBlobDTOs.add(dto); |
| | | |
| | | } catch (InvalidExtensionException e) { |
| | | throw new RuntimeException("minioæä»¶ä¸ä¼ å¼å¸¸ï¼" + e); |
| | | throw new RuntimeException("䏿¯æçæä»¶ç±»åï¼" + file.getOriginalFilename(), e); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("ä¸ä¼ æä»¶å¤±è´¥ï¼" + file.getOriginalFilename(), e); |
| | | } |
| | | } |
| | | return storageBlobDTOs; |
| | | } |
| | | |
| | | private void validateFileExtension(MultipartFile file) throws InvalidExtensionException { |
| | | String filename = file.getOriginalFilename(); |
| | | String extension = FilenameUtils.getExtension(filename).toLowerCase(); |
| | | List<String> allowedExtensions = Arrays.asList( |
| | | // å¾ç |
| | | "jpg", "jpeg", "png", "gif", "bmp", "webp", "tiff", "ico", "svg", |
| | | |
| | | // ææ¡£ |
| | | "pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "rtf", "md", "csv", "odt", |
| | | |
| | | // è§é¢ |
| | | "mp4", "mov", "avi", "wmv", "flv", "mkv", "webm", "mpeg", "3gp","MOV", |
| | | |
| | | // é³é¢ |
| | | "mp3", "wav", "ogg", "aac", "flac", "m4a", "wma", "amr", |
| | | |
| | | // å缩å
|
| | | "zip", "rar", "7z", "tar", "gz", "bz2", "xz", |
| | | |
| | | // ç¼ç¨ä»£ç æä»¶ |
| | | "java", "py", "js", "ts", "html", "css", "cpp", "c", "cs", "json", "xml", "sql", "yaml", "yml", "sh", "bat", |
| | | |
| | | // å®è£
ç¨åº & äºè¿å¶ |
| | | "exe", "apk", "dmg", "msi", "bin", "iso", |
| | | |
| | | // 设计类 |
| | | "psd", "ai", "xd", "sketch", "fig" |
| | | ); |
| | | |
| | | if (!allowedExtensions.contains(extension)) { |
| | | throw new BaseException("æä»¶ç±»åä¸è¢«å
许ï¼" + extension); |
| | | } |
| | | } |
| | | |
| | | private StorageBlobDTO buildStorageBlobDTO(MultipartFile file, MinioResult res, String bucketName, Long type) { |
| | | StorageBlobDTO dto = new StorageBlobDTO(); |
| | | dto.setContentType(file.getContentType()); |
| | | dto.setBucketFilename(res.getBucketFileName()); |
| | | dto.setOriginalFilename(res.getOriginalName()); |
| | | dto.setByteSize(file.getSize()); |
| | | dto.setKey(IdUtils.simpleUUID()); |
| | | dto.setBucketName(bucketName); |
| | | dto.setUrl(minioUtils.getPreviewUrl(res.getBucketFileName(), bucketName, false)); |
| | | dto.setDownloadUrl(minioUtils.getDownloadUrl(res.getBucketFileName(), bucketName)); |
| | | |
| | | if (type != null) { |
| | | dto.setType(type); |
| | | } |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | public int deleteStorageBlobs(StorageAttachment attachment) { |
| | | List<StorageAttachment> attachments = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>() |
| | |
| | | package com.ruoyi.common.utils.file; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.nio.file.Paths; |
| | | import java.util.Objects; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException; |
| | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.uuid.Seq; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.nio.file.Paths; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ å·¥å
·ç±» |
| | |
| | | /** |
| | | * é»è®¤å¤§å° 50M |
| | | */ |
| | | public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024L; |
| | | public static final long DEFAULT_MAX_SIZE = 1000 * 1024 * 1024L; |
| | | |
| | | /** |
| | | * é»è®¤çæä»¶åæå¤§é¿åº¦ 100 |
| | |
| | | public static final String[] FLASH_EXTENSION = { "swf", "flv" }; |
| | | |
| | | public static final String[] MEDIA_EXTENSION = { "swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", |
| | | "asf", "rm", "rmvb" }; |
| | | "asf", "rm", "rmvb","mov","MOV" }; |
| | | |
| | | public static final String[] VIDEO_EXTENSION = { "mp4", "avi", "rmvb" }; |
| | | public static final String[] VIDEO_EXTENSION = { "mp4", "avi", "rmvb","mov","MOV" }; |
| | | |
| | | public static final String[] DEFAULT_ALLOWED_EXTENSION = { |
| | | // å¾ç |
| | |
| | | // å缩æä»¶ |
| | | "rar", "zip", "gz", "bz2", |
| | | // è§é¢æ ¼å¼ |
| | | "mp4", "avi", "rmvb", |
| | | "mp4", "avi", "rmvb","mov","MOV", |
| | | // pdf |
| | | "pdf" }; |
| | | |
| | |
| | | CREATE TABLE storage_blob |
| | | ( |
| | | id bigserial PRIMARY KEY, |
| | | create_time timestamp default now() NOT NULL, |
| | | create_time timestamp default now() NOT NULL, |
| | | key varchar(150) DEFAULT '' NOT NULL, |
| | | content_type varchar(100) DEFAULT '' NOT NULL, |
| | | original_filename varchar(255) DEFAULT '' NOT NULL, |
| | | bucket_filename varchar(255) DEFAULT '' NOT NULL, |
| | | bucket_name varchar(255) DEFAULT '' NOT NULL, |
| | | byte_size bigint DEFAULT 0 NOT NULL, |
| | | type varchar(150), |
| | | UNIQUE (key) |
| | | ); |
| | | |
| | | COMMENT ON TABLE storage_blob IS 'éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯'; |
| | | COMMENT |
| | | ON TABLE storage_blob IS 'éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯'; |
| | | |
| | | COMMENT ON COLUMN storage_blob.key IS 'èµæºid'; |
| | | COMMENT ON COLUMN storage_blob.content_type IS 'èµæºç±»åï¼ä¾å¦JPGå¾ççèµæºç±»å为image/jpg'; |
| | | COMMENT ON COLUMN storage_blob.original_filename IS 'åæä»¶åç§°'; |
| | | COMMENT ON COLUMN storage_blob.bucket_filename IS 'å卿¡¶ä¸æä»¶å'; |
| | | COMMENT ON COLUMN storage_blob.bucket_name IS 'å卿¡¶å'; |
| | | COMMENT ON COLUMN storage_blob.byte_size IS 'èµæºå°ºå¯¸(åè)'; |
| | | COMMENT |
| | | ON COLUMN storage_blob.key IS 'èµæºid'; |
| | | COMMENT |
| | | ON COLUMN storage_blob.content_type IS 'èµæºç±»åï¼ä¾å¦JPGå¾ççèµæºç±»å为image/jpg'; |
| | | COMMENT |
| | | ON COLUMN storage_blob.original_filename IS 'åæä»¶åç§°'; |
| | | COMMENT |
| | | ON COLUMN storage_blob.bucket_filename IS 'å卿¡¶ä¸æä»¶å'; |
| | | COMMENT |
| | | ON COLUMN storage_blob.bucket_name IS 'å卿¡¶å'; |
| | | COMMENT |
| | | ON COLUMN storage_blob.byte_size IS 'èµæºå°ºå¯¸(åè)'; |
| | | COMMENT |
| | | ON COLUMN storage_blob.type IS '0ç产å 1ç产å 2ç产é®é¢'; |
| | | |
| | |
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.exception.user.BlackListException; |
| | | import com.ruoyi.common.exception.user.CaptchaException; |
| | | import com.ruoyi.common.exception.user.CaptchaExpireException; |
| | | import com.ruoyi.common.exception.user.UserNotExistsException; |
| | | import com.ruoyi.common.exception.user.UserPasswordNotMatchException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.exception.user.*; |
| | | import com.ruoyi.common.utils.MessageUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | |
| | | import com.ruoyi.framework.security.context.AuthenticationContextHolder; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * ç»å½æ ¡éªæ¹æ³ |
| | |
| | | { |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setUserId(userId); |
| | | sysUser.setLoginIp(IpUtils.getIpAddr()); |
| | | sysUser.setLoginDate(DateUtils.getNowDate()); |
| | | // sysUser.setLoginIp(IpUtils.getIpAddr()); |
| | | // sysUser.setLoginDate(DateUtils.getNowDate()); |
| | | userService.updateUserProfile(sysUser); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.system.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | |
| | | |
| | | /** |
| | | * ç¨æ·è¡¨ æ°æ®å± |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public interface SysUserMapper |
| | | extends BaseMapper<SysUser> { |
| | | public interface SysUserMapper{ |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢ç¨æ·å表 |
| | | * |
| | | * |
| | | * @param sysUser ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢å·²é
ç¨æ·è§è²å表 |
| | | * |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * æ ¹æ®æ¡ä»¶å页æ¥è¯¢æªåé
ç¨æ·è§è²å表 |
| | | * |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç¨æ·ä¿¡æ¯éåä¿¡æ¯ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * éè¿ç¨æ·åæ¥è¯¢ç¨æ· |
| | | * |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * éè¿ç¨æ·IDæ¥è¯¢ç¨æ· |
| | | * |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç¨æ·å¯¹è±¡ä¿¡æ¯ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * æ°å¢ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * |
| | | * @param user ç¨æ·ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * ä¿®æ¹ç¨æ·å¤´å |
| | | * |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @param avatar 头åå°å |
| | | * @param avatar 头åå°å |
| | | * @return ç»æ |
| | | */ |
| | | public int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar); |
| | | |
| | | /** |
| | | * éç½®ç¨æ·å¯ç |
| | | * |
| | | * |
| | | * @param userName ç¨æ·å |
| | | * @param password å¯ç |
| | | * @return ç»æ |
| | |
| | | |
| | | /** |
| | | * éè¿ç¨æ·IDå é¤ç¨æ· |
| | | * |
| | | * |
| | | * @param userId ç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * æ¹éå é¤ç¨æ·ä¿¡æ¯ |
| | | * |
| | | * |
| | | * @param userIds éè¦å é¤çç¨æ·ID |
| | | * @return ç»æ |
| | | */ |
| | |
| | | |
| | | /** |
| | | * æ ¡éªç¨æ·åç§°æ¯å¦å¯ä¸ |
| | | * |
| | | * |
| | | * @param userName ç¨æ·åç§° |
| | | * @return ç»æ |
| | | */ |
| | |
| | | @Override |
| | | public int updateUserProfile(SysUser user) { |
| | | return userMapper.updateUser(user); |
| | | |
| | | // return userMapper.update(user,new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserId, user.getUserId())); |
| | | } |
| | | |
| | | /** |