From c8fbeff3b07f96ffb4624dd64344ac00ec0c8ef8 Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期五, 18 七月 2025 11:03:47 +0800 Subject: [PATCH] 1.优化正式库 2.yml设置 --- main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentManagementServiceImpl.java | 17 +++ main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java | 12 ++ main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java | 2 main-business/src/main/java/com/ruoyi/business/controller/OfficialInventoryController.java | 3 main-business/src/main/java/com/ruoyi/business/entity/EquipmentUsageRecord.java | 2 main-business/src/main/resources/db/migration/postgresql/V20250701142700__create_table_equipment_management.sql | 2 main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentUsageRecordServiceImpl.java | 35 +++++- ruoyi-admin/src/main/resources/application-prod.yml.example | 76 +++++++++++++++ main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java | 4 ruoyi-admin/src/main/resources/application-druid.yml.example1 | 84 ++++++++++++++++ ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java | 1 pom.xml | 6 - 12 files changed, 223 insertions(+), 21 deletions(-) diff --git a/main-business/src/main/java/com/ruoyi/business/controller/OfficialInventoryController.java b/main-business/src/main/java/com/ruoyi/business/controller/OfficialInventoryController.java index a8b1667..bdddb30 100644 --- a/main-business/src/main/java/com/ruoyi/business/controller/OfficialInventoryController.java +++ b/main-business/src/main/java/com/ruoyi/business/controller/OfficialInventoryController.java @@ -8,6 +8,7 @@ import com.ruoyi.business.vo.OfficialInventoryVo; import com.ruoyi.common.core.domain.R; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -23,6 +24,7 @@ @RestController @AllArgsConstructor +@Slf4j @RequestMapping("/officialInventory") public class OfficialInventoryController { @@ -61,6 +63,7 @@ return R.ok(officialInventoryService.editOfficial(officialInventoryDto)); } + /** * 鍚堝苟 */ diff --git a/main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java b/main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java index fd90126..0d0e2c2 100644 --- a/main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java +++ b/main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java @@ -22,6 +22,6 @@ private String supplierCoal; //渚涘簲鍟� + 鐓ょ - private List<CoalValue> coalValues; //濯掕川鏂规瀛楁鍊� + private List<Map<String, String>> coalValues; //濯掕川鏂规瀛楁鍊� } diff --git a/main-business/src/main/java/com/ruoyi/business/entity/EquipmentUsageRecord.java b/main-business/src/main/java/com/ruoyi/business/entity/EquipmentUsageRecord.java index b4d0fc3..9337b33 100644 --- a/main-business/src/main/java/com/ruoyi/business/entity/EquipmentUsageRecord.java +++ b/main-business/src/main/java/com/ruoyi/business/entity/EquipmentUsageRecord.java @@ -44,7 +44,7 @@ @TableField(value = "department_id") private Long departmentId; /** - * 璁惧鐘舵�侊紙姝e父/鏁呴殰/缁翠慨涓級 + * 璁惧鐘舵�侊紙浣跨敤涓紝宸插綊杩橈級 */ @TableField(value = "equipment_status") private String equipmentStatus; diff --git a/main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java b/main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java index 6dd6ed6..d5fcc4e 100644 --- a/main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java +++ b/main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.common.core.domain.MyBaseEntity; import lombok.Data; @@ -19,8 +20,6 @@ @Data @TableName("official_inventory") public class OfficialInventory extends MyBaseEntity { - - private static final long serialVersionUID = 1L; /** * 涓婚敭ID @@ -88,6 +87,7 @@ * 鐧昏鏃ユ湡 */ @TableField(value = "registration_date") + @JsonFormat(pattern = "yyyy-MM-dd") private LocalDate registrationDate; /** diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentManagementServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentManagementServiceImpl.java index 863d663..ece6d7b 100644 --- a/main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentManagementServiceImpl.java +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentManagementServiceImpl.java @@ -11,11 +11,15 @@ import com.ruoyi.business.service.EquipmentManagementService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.business.vo.EquipmentManagementVo; +import com.ruoyi.common.exception.base.BaseException; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanUtils; import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import java.beans.Transient; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -109,7 +113,18 @@ } @Override + @Transactional(isolation = Isolation.REPEATABLE_READ) public int delByIds(Long[] ids) { - return equipmentManagementMapper.deleteByIds(Arrays.asList(ids)); + // 1. 妫�鏌ヨ澶囨槸鍚︽鍦ㄤ娇鐢紙娣诲姞琛岄攣 for update锛� + List<EquipmentUsageRecord> records = equipmentUsageRecordMapper.selectList( + new LambdaQueryWrapper<EquipmentUsageRecord>() + .in(EquipmentUsageRecord::getEquipmentId, Arrays.asList(ids)) + .last("FOR UPDATE") // 娣诲姞琛岄攣锛岄攣瀹氭煡璇㈢粨鏋� + ); + if (!records.isEmpty()) { + throw new BaseException("璁惧姝e湪浣跨敤涓紝璇锋牳瀵�!"); + } else { + return equipmentManagementMapper.deleteByIds(Arrays.asList(ids)); + } } } diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentUsageRecordServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentUsageRecordServiceImpl.java index 7b78a37..5c2366c 100644 --- a/main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentUsageRecordServiceImpl.java +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/EquipmentUsageRecordServiceImpl.java @@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -66,7 +67,7 @@ if (!userIds.isEmpty()) { List<SysUser> sysUsers = sysUserMapper.selectList(userIds); userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity())); - }else { + } else { userMap = new HashMap<>(); } //鍖归厤鏁版嵁 @@ -92,6 +93,12 @@ @Override @Transactional(rollbackFor = Exception.class) public int addOrEditUsageRecord(EquipmentUsageRecordDto equipmentUsageRecordDto) { + // 鍙傛暟鏍¢獙 + if (equipmentUsageRecordDto == null) { + throw new IllegalArgumentException("璁惧浣跨敤璁板綍鍙傛暟涓嶈兘涓虹┖"); + } + + // 澶嶅埗灞炴�у埌瀹炰綋瀵硅薄 EquipmentUsageRecord equipmentUsageRecord = new EquipmentUsageRecord(); BeanUtils.copyProperties(equipmentUsageRecordDto, equipmentUsageRecord); @@ -99,12 +106,13 @@ Long equipmentId = equipmentUsageRecordDto.getEquipmentId(); Integer newUsageQuantity = equipmentUsageRecordDto.getUsageQuantity(); - // 鏌ヨ璁惧淇℃伅锛堝甫涔愯閿佺増鏈彿锛� + // 鏌ヨ璁惧淇℃伅 EquipmentManagement equipment = equipmentManagementMapper.selectById(equipmentId); if (equipment == null) { throw new RuntimeException("璁惧涓嶅瓨鍦�"); } + // 鏂板璁板綍閫昏緫 if (Objects.isNull(equipmentUsageRecordDto.getId())) { // 妫�鏌ュ簱瀛樻槸鍚﹀厖瓒� if (equipment.getQuantity() < newUsageQuantity) { @@ -115,9 +123,18 @@ equipment.setQuantity(equipment.getQuantity() - newUsageQuantity); equipmentManagementMapper.updateById(equipment); - // 鍒涘缓棰嗙敤璁板綍 + // 璁剧疆浣跨敤寮�濮嬫椂闂翠负褰撳墠鏃堕棿 + equipmentUsageRecord.setUsageStartTime(LocalDate.now()); + + // 濡傛灉鐘舵�佷负1(宸插綊杩�)锛屽垯璁剧疆缁撴潫鏃堕棿 + if ("1".equals(equipmentUsageRecordDto.getEquipmentStatus())) { + equipmentUsageRecord.setUsageEndTime(LocalDate.now()); + } + return equipmentUsageRecordMapper.insert(equipmentUsageRecord); - } else { + } + // 鏇存柊璁板綍閫昏緫 + else { // 1. 鏌ヨ鍘熼鐢ㄨ褰� EquipmentUsageRecord originalRecord = equipmentUsageRecordMapper.selectById(equipmentUsageRecordDto.getId()); if (originalRecord == null) { @@ -128,7 +145,7 @@ int quantityDelta = newUsageQuantity - originalRecord.getUsageQuantity(); if (quantityDelta != 0) { - // 3. 妫�鏌ヨ皟鏁村悗搴撳瓨鏄惁鍏呰冻锛堣�冭檻澧炲姞鍜屽噺灏戜袱绉嶆儏鍐碉級 + // 3. 妫�鏌ヨ皟鏁村悗搴撳瓨鏄惁鍏呰冻 int newInventory = equipment.getQuantity() - quantityDelta; if (newInventory < 0) { throw new RuntimeException("搴撳瓨涓嶈冻锛岃皟鏁村悗搴撳瓨灏嗕负锛�" + newInventory); @@ -141,7 +158,13 @@ } } - // 5. 鏇存柊棰嗙敤璁板綍 + // 5. 濡傛灉鐘舵�佸彉涓�1(宸插綊杩�)锛屽垯璁剧疆缁撴潫鏃堕棿涓哄綋鍓嶆椂闂� + if ("1".equals(equipmentUsageRecordDto.getEquipmentStatus()) && + (originalRecord.getEquipmentStatus() == null || !"1".equals(originalRecord.getEquipmentStatus()))) { + equipmentUsageRecord.setUsageEndTime(LocalDate.now()); + } + + // 6. 鏇存柊棰嗙敤璁板綍 return equipmentUsageRecordMapper.updateById(equipmentUsageRecord); } } diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java index eba9e50..aa53535 100644 --- a/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java @@ -94,7 +94,7 @@ if (!registrantIds.isEmpty()) { List<SysUser> sysUsers = sysUserMapper.selectList(registrantIds); userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity())); - }else { + } else { userMap = new HashMap<>(); } @@ -391,7 +391,15 @@ dto.setSupplierCoal(supply.getSupplierName() + " - " + coalInfo.getCoal()); } // 璁剧疆鐓よ川鏁版嵁 - dto.setCoalValues(coalValuesMap.getOrDefault(inventory.getCoalPlanId(), Collections.emptyList())); + dto.setCoalValues(coalValuesMap.getOrDefault(inventory.getCoalPlanId(), Collections.emptyList()) + .stream() + .map(coalValue -> { + Map<String, String> map = new HashMap<>(); + map.put("fieldName", coalValue.getFieldName()); + map.put("coalValue", coalValue.getCoalValue()); + return map; + }) + .collect(Collectors.toList())); return dto; }) .collect(Collectors.toList()); diff --git a/main-business/src/main/resources/db/migration/postgresql/V20250701142700__create_table_equipment_management.sql b/main-business/src/main/resources/db/migration/postgresql/V20250701142700__create_table_equipment_management.sql index a682429..c599d4f 100644 --- a/main-business/src/main/resources/db/migration/postgresql/V20250701142700__create_table_equipment_management.sql +++ b/main-business/src/main/resources/db/migration/postgresql/V20250701142700__create_table_equipment_management.sql @@ -7,7 +7,7 @@ equipment_name VARCHAR(100) NOT NULL, -- 璁惧鍚嶇О quantity INT NOT NULL DEFAULT 0, -- 鏁伴噺 specification VARCHAR(50) NOT NULL, -- 瑙勬牸鍨嬪彿 - usage_status VARCHAR(20) NOT NULL, -- 浣跨敤鐘舵�� + usage_status VARCHAR(20), -- 浣跨敤鐘舵�� using_department VARCHAR(50) NOT NULL, -- 浣跨敤閮ㄩ棬 user_id BIGINT, -- 浣跨敤浜� storage_location VARCHAR(100) NOT NULL, -- 瀛樻斁浣嶇疆 diff --git a/pom.xml b/pom.xml index 9276600..de2ebda 100644 --- a/pom.xml +++ b/pom.xml @@ -272,12 +272,6 @@ <version>${freemarker.version}</version> </dependency> - <dependency> - <groupId>com.alibaba</groupId> - <artifactId>fastjson</artifactId> - <version>2.0.38</version> <!-- 閫夌敤鏈�鏂扮ǔ瀹氱増鏈� --> - </dependency> - </dependencies> <modules> diff --git a/ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java b/ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java index 064730b..e6b381b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/PlusCodeGenerator.java @@ -24,7 +24,6 @@ * 鍔熻兘锛氭牴鎹暟鎹簱琛ㄧ粨鏋勮嚜鍔ㄧ敓鎴怑ntity銆丮apper銆丼ervice銆丆ontroller绛変唬鐮� * 淇锛氳В鍐矲reemarker妯℃澘涓璯enerateService鍙橀噺缂哄け鐨勯棶棰� */ -@SpringBootApplication public class PlusCodeGenerator { // 鏁版嵁搴撻厤缃� diff --git a/ruoyi-admin/src/main/resources/application-druid.yml.example1 b/ruoyi-admin/src/main/resources/application-druid.yml.example1 new file mode 100644 index 0000000..810fbfa --- /dev/null +++ b/ruoyi-admin/src/main/resources/application-druid.yml.example1 @@ -0,0 +1,84 @@ +# 鏁版嵁婧愰厤缃� +spring: + datasource: + type: com.alibaba.druid.pool.DruidDataSource +# driverClassName: com.mysql.cj.jdbc.Driver # mysql椹卞姩 + driverClassName: org.postgresql.Driver + druid: + # 涓诲簱鏁版嵁婧� + master: +# mysql +# url: jdbc:mysql://124.220.0.228:3300/ruoyi-java?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 +# pg +# url: jdbc:postgresql://localhost:5433/ruoyi-zd + url: jdbc:postgresql://localhost:5433/zd-01 + username: postgres + password: 123456 + # 浠庡簱鏁版嵁婧� + slave: + # 浠庢暟鎹簮寮�鍏�/榛樿鍏抽棴 + enabled: false + url: + username: + password: + # 鍒濆杩炴帴鏁� + initialSize: 5 + # 鏈�灏忚繛鎺ユ睜鏁伴噺 + minIdle: 10 + # 鏈�澶ц繛鎺ユ睜鏁伴噺 + maxActive: 20 + # 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂� + maxWait: 60000 + # 閰嶇疆杩炴帴瓒呮椂鏃堕棿 + connectTimeout: 30000 + # 閰嶇疆缃戠粶瓒呮椂鏃堕棿 + socketTimeout: 60000 + # 閰嶇疆闂撮殧澶氫箙鎵嶈繘琛屼竴娆℃娴嬶紝妫�娴嬮渶瑕佸叧闂殑绌洪棽杩炴帴锛屽崟浣嶆槸姣 + timeBetweenEvictionRunsMillis: 60000 + # 閰嶇疆涓�涓繛鎺ュ湪姹犱腑鏈�灏忕敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 + minEvictableIdleTimeMillis: 300000 + # 閰嶇疆涓�涓繛鎺ュ湪姹犱腑鏈�澶х敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 + maxEvictableIdleTimeMillis: 900000 + # 閰嶇疆妫�娴嬭繛鎺ユ槸鍚︽湁鏁� + validationQuery: SELECT VERSION() + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + webStatFilter: + enabled: true + statViewServlet: + enabled: true + # 璁剧疆鐧藉悕鍗曪紝涓嶅~鍒欏厑璁告墍鏈夎闂� + allow: + url-pattern: /druid/* + # 鎺у埗鍙扮鐞嗙敤鎴峰悕鍜屽瘑鐮� + login-username: ruoyi + login-password: 123456 + filter: + stat: + enabled: true + # 鎱QL璁板綍 + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true + +# 鍏徃鏈嶅姟鍣� minio +minio: +# endpoint: http://114.132.189.42/ +# port: 7019 +# secure: false +# accessKey: admin +# secretKey: 12345678 +# preview-expiry: 24 # 棰勮鍦板潃榛樿24灏忔椂 +# default-bucket: ruoyi-zd # 榛樿瀛樺偍妗� + endpoint: 127.0.0.1 + port: 9002 + secure: false + accessKey: admin + secretKey: 12345678 + preview-expiry: 24 # 棰勮鍦板潃榛樿24灏忔椂 + default-bucket: ruoyi-zd # 榛樿瀛樺偍妗� + diff --git a/ruoyi-admin/src/main/resources/application-prod.yml.example b/ruoyi-admin/src/main/resources/application-prod.yml.example new file mode 100644 index 0000000..a158a6e --- /dev/null +++ b/ruoyi-admin/src/main/resources/application-prod.yml.example @@ -0,0 +1,76 @@ +# 鏁版嵁婧愰厤缃� +spring: + datasource: + type: com.alibaba.druid.pool.DruidDataSource +# driverClassName: com.mysql.cj.jdbc.Driver # mysql椹卞姩 + driverClassName: org.postgresql.Driver + druid: + # 涓诲簱鏁版嵁婧� + master: +# mysql +# url: jdbc:mysql://124.220.0.228:3300/ruoyi-java?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 +# pg + url: jdbc:postgresql://114.132.189.42:5432/zd-test + username: postgres + password: bYD#nM+-BiLb + # 浠庡簱鏁版嵁婧� + slave: + # 浠庢暟鎹簮寮�鍏�/榛樿鍏抽棴 + enabled: false + url: + username: + password: + # 鍒濆杩炴帴鏁� + initialSize: 5 + # 鏈�灏忚繛鎺ユ睜鏁伴噺 + minIdle: 10 + # 鏈�澶ц繛鎺ユ睜鏁伴噺 + maxActive: 20 + # 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂� + maxWait: 60000 + # 閰嶇疆杩炴帴瓒呮椂鏃堕棿 + connectTimeout: 30000 + # 閰嶇疆缃戠粶瓒呮椂鏃堕棿 + socketTimeout: 60000 + # 閰嶇疆闂撮殧澶氫箙鎵嶈繘琛屼竴娆℃娴嬶紝妫�娴嬮渶瑕佸叧闂殑绌洪棽杩炴帴锛屽崟浣嶆槸姣 + timeBetweenEvictionRunsMillis: 60000 + # 閰嶇疆涓�涓繛鎺ュ湪姹犱腑鏈�灏忕敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 + minEvictableIdleTimeMillis: 300000 + # 閰嶇疆涓�涓繛鎺ュ湪姹犱腑鏈�澶х敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 + maxEvictableIdleTimeMillis: 900000 + # 閰嶇疆妫�娴嬭繛鎺ユ槸鍚︽湁鏁� + validationQuery: SELECT VERSION() + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + webStatFilter: + enabled: true + statViewServlet: + enabled: true + # 璁剧疆鐧藉悕鍗曪紝涓嶅~鍒欏厑璁告墍鏈夎闂� + allow: + url-pattern: /druid/* + # 鎺у埗鍙扮鐞嗙敤鎴峰悕鍜屽瘑鐮� + login-username: ruoyi + login-password: 123456 + filter: + stat: + enabled: true + # 鎱QL璁板綍 + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true + +# 鍏徃鏈嶅姟鍣� minio +minio: + endpoint: http://114.132.189.42/ + port: 7019 + secure: false + accessKey: admin + secretKey: 12345678 + preview-expiry: 24 # 棰勮鍦板潃榛樿24灏忔椂 + default-bucket: ruoyi-zd # 榛樿瀛樺偍妗� + -- Gitblit v1.9.3