Browse Source

优化

master
zhangyeguang 3 months ago
parent
commit
19f7f86f0e
  1. 2
      common/src/main/java/com/jiagutech/ams/model/UserDetail.java
  2. 3
      common/src/main/java/com/jiagutech/ams/model/common/PageRequest.java
  3. 2
      common/src/main/java/com/jiagutech/ams/model/dto/UserDTO.java
  4. 4
      social/src/main/java/com/jiagutech/ams/controller/JobController.java
  5. 1
      social/src/main/java/com/jiagutech/ams/controller/RegionController.java
  6. 13
      social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java
  7. 3
      social/src/main/java/com/jiagutech/ams/model/dto/JobDTO.java
  8. 5
      social/src/main/java/com/jiagutech/ams/model/request/JobPageRequest.java
  9. 4
      social/src/main/java/com/jiagutech/ams/model/response/JobItem.java
  10. 3
      social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java
  11. 39
      social/src/main/resources/mapper/JobMapper.xml
  12. 5
      system/src/main/java/com/jiagutech/ams/controller/UserController.java
  13. 2
      system/src/main/java/com/jiagutech/ams/service/UserService.java
  14. 5
      system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java
  15. 4
      system/src/main/resources/mapper/UserMapper.xml
  16. 50
      web/pom.xml
  17. 4
      web/src/main/java/com/jiagutech/ams/common/RabbitConfig.java
  18. 1
      web/src/main/java/com/jiagutech/ams/config/SpringDocConfig.java

2
common/src/main/java/com/jiagutech/ams/model/UserDetail.java

@ -30,4 +30,6 @@ public class UserDetail {
private String regionName; private String regionName;
private String userIdStr; private String userIdStr;
private String contactPhone; private String contactPhone;
private String identityCardNum;
} }

3
common/src/main/java/com/jiagutech/ams/model/common/PageRequest.java

@ -10,7 +10,8 @@ import lombok.Data;
* @description: * @description:
**/ **/
@Data @Data
public class PageRequest<T> {
public class PageRequest<T> implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private int pageNum; private int pageNum;
private int pageSize; private int pageSize;

2
common/src/main/java/com/jiagutech/ams/model/dto/UserDTO.java

@ -25,5 +25,7 @@ public class UserDTO {
private Long regionCode; private Long regionCode;
private String regionPath; private String regionPath;
private String regionName; private String regionName;
private String contactPhone;
} }

4
social/src/main/java/com/jiagutech/ams/controller/JobController.java

@ -75,13 +75,13 @@ public class JobController {
} }
@PostMapping("/export")
@PostMapping(value = "/export",consumes = "application/json")
@Operation(summary = "导出作业记录") @Operation(summary = "导出作业记录")
public void exportJobs(@RequestBody(required = false) JobPageRequest jobPageRequest, HttpServletResponse response) { public void exportJobs(@RequestBody(required = false) JobPageRequest jobPageRequest, HttpServletResponse response) {
jobService.exportJobs(jobPageRequest, response); jobService.exportJobs(jobPageRequest, response);
} }
@PostMapping("/exportByFarmer")
@PostMapping(value = "/exportByFarmer",consumes = "application/json")
@Operation(summary = "导出作业记录") @Operation(summary = "导出作业记录")
public void exportByFarmer(@RequestBody(required = false) JobPageRequest jobPageRequest, HttpServletResponse response) { public void exportByFarmer(@RequestBody(required = false) JobPageRequest jobPageRequest, HttpServletResponse response) {
jobService.exportByFarmer(jobPageRequest, response); jobService.exportByFarmer(jobPageRequest, response);

1
social/src/main/java/com/jiagutech/ams/controller/RegionController.java

@ -31,7 +31,6 @@ public class RegionController {
private final RegionService regionService; private final RegionService regionService;
@SaCheckRole(value = {"manager", "machinist"}, mode = SaMode.OR)
@Operation(summary = "获取下一级的所有区域列表") @Operation(summary = "获取下一级的所有区域列表")
@GetMapping("getChildren") @GetMapping("getChildren")
public R<List<RegionDTO>> getChildren(Long regionCode) { public R<List<RegionDTO>> getChildren(Long regionCode) {

13
social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java

@ -1,13 +1,17 @@
package com.jiagutech.ams.listener; package com.jiagutech.ams.listener;
import com.jiagutech.ams.event.JobFinishEvent; import com.jiagutech.ams.event.JobFinishEvent;
import com.jiagutech.ams.mapper.JobMapper;
import com.jiagutech.ams.model.TrackItem; import com.jiagutech.ams.model.TrackItem;
import com.jiagutech.ams.model.dto.JobDTO;
import com.jiagutech.ams.service.JobService; import com.jiagutech.ams.service.JobService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.Duration;
import java.time.Instant;
import java.util.List; import java.util.List;
/** /**
@ -22,12 +26,21 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class JobFinishListener { public class JobFinishListener {
private final JobService jobService; private final JobService jobService;
private final JobMapper jobMapper;
@EventListener(JobFinishEvent.class) @EventListener(JobFinishEvent.class)
public void finishJob(JobFinishEvent event) { public void finishJob(JobFinishEvent event) {
log.info("JobFinishListener:{}", event.getJobId()); log.info("JobFinishListener:{}", event.getJobId());
JobDTO jobDTO = jobMapper.selectById(event.getJobId());
Long startTime = jobDTO.getStartTime();
Long endTime = System.currentTimeMillis();
try { try {
Instant instant1 = Instant.ofEpochMilli(startTime);
Instant instant2 = Instant.ofEpochMilli(endTime);
Duration duration = Duration.between(instant1, instant2);
jobDTO.setDuration((int) duration.toSeconds());
List<TrackItem> trackList = jobService.getTrackList(event.getJobId()); List<TrackItem> trackList = jobService.getTrackList(event.getJobId());
jobMapper.updateById(jobDTO);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

3
social/src/main/java/com/jiagutech/ams/model/dto/JobDTO.java

@ -33,7 +33,7 @@ public class JobDTO {
private Long regionCode; private Long regionCode;
private Float duration;
private Integer duration;
private Integer status; private Integer status;
@ -41,4 +41,5 @@ public class JobDTO {
private Long deptId; private Long deptId;
} }

5
social/src/main/java/com/jiagutech/ams/model/request/JobPageRequest.java

@ -13,7 +13,10 @@ import lombok.Data;
* @description: * @description:
**/ **/
@Data @Data
public class JobPageRequest {
public class JobPageRequest implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private long startTimeBegin; private long startTimeBegin;
private long startTimeEnd; private long startTimeEnd;

4
social/src/main/java/com/jiagutech/ams/model/response/JobItem.java

@ -21,8 +21,10 @@ public class JobItem {
@ExcelIgnore @ExcelIgnore
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long jobId; private Long jobId;
@ExcelIgnore
@ExcelProperty(value = "机手") @ExcelProperty(value = "机手")
private String operatorName; private String operatorName;
@ExcelIgnore
@ExcelProperty(value = "机手手机号") @ExcelProperty(value = "机手手机号")
private String operatorPhone; private String operatorPhone;
@ExcelIgnore @ExcelIgnore
@ -59,5 +61,7 @@ public class JobItem {
@ExcelProperty(value = "作业地区") @ExcelProperty(value = "作业地区")
private String regionName; private String regionName;
private int duration;
} }

3
social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java

@ -196,6 +196,9 @@ public class JobServiceImpl implements JobService {
if (requestParam.getFarmerId() != 0l) { if (requestParam.getFarmerId() != 0l) {
queryWrapper.eq("j.farmer_id", requestParam.getFarmerId()); queryWrapper.eq("j.farmer_id", requestParam.getFarmerId());
} }
if (requestParam.getRegionCode() != 0l) {
queryWrapper.eq("j.region_code", requestParam.getRegionCode());
}
} }

39
social/src/main/resources/mapper/JobMapper.xml

@ -10,6 +10,7 @@
j.status, j.status,
j.device_id, j.device_id,
j.operator_id, j.operator_id,
j.duration,
FROM_UNIXTIME(j.start_time / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str, FROM_UNIXTIME(j.start_time / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str,
u1.nick_name as operator_name, u1.nick_name as operator_name,
u1.phone as operator_phone, u1.phone as operator_phone,
@ -28,23 +29,48 @@
left join ams_user u2 on j.farmer_id = u2.id left join ams_user u2 on j.farmer_id = u2.id
</sql> </sql>
<sql id="jobItem2">
select j.id as job_id,
j.start_time,
j.end_time,
j.area,
j.status,
j.device_id,
j.operator_id,
j.duration,
FROM_UNIXTIME(j.start_time / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str,
j.farmer_id,
u2.nick_name as farmer_name,
CONCAT(LEFT(u2.phone, 3), '****', RIGHT(u2.phone, 4)) as farmer_phone,
u2.region_name,
j.job_type,
t.name as type_name,
d.id as dept_id,
d.name as dept_name
from ams_job_info j
left join ams_job_type t on j.job_type = t.id
left join ams_dept d on j.dept_id = d.id
left join ams_user u2 on j.farmer_id = u2.id
</sql>
<select id="jobPage" resultType="com.jiagutech.ams.model.response.JobItem"> <select id="jobPage" resultType="com.jiagutech.ams.model.response.JobItem">
<include refid="jobItem"></include> <include refid="jobItem"></include>
${ew.getCustomSqlSegment} ${ew.getCustomSqlSegment}
</select> </select>
<select id="jobList" resultType="com.jiagutech.ams.model.response.JobItem"> <select id="jobList" resultType="com.jiagutech.ams.model.response.JobItem">
<include refid="jobItem"></include>
${ew.getCustomSqlSegment}
order by j.farmer_id,j.start_time
<include refid="jobItem2"></include>
${ew.getCustomSqlSegment} order by j.farmer_id,j.start_time
</select> </select>
<select id="jobListCountByFarmer" resultType="com.jiagutech.ams.model.response.JobItem"> <select id="jobListCountByFarmer" resultType="com.jiagutech.ams.model.response.JobItem">
select ROUND(sum(j.area),2) as area,j.farmer_id,
select ROUND(sum(j.area), 2) as area,
j.farmer_id,
u2.nick_name as farmer_name, u2.nick_name as farmer_name,
j.job_type,t.name as type_name,
j.job_type,
t.name as type_name,
d.id as dept_id, d.id as dept_id,
d.name as dept_name, d.name as dept_name,
u2.phone as farmer_phone,
CONCAT(LEFT(u2.phone, 3), '****', RIGHT(u2.phone, 4)) as farmer_phone,
u2.region_name, u2.region_name,
FROM_UNIXTIME(MIN(start_time) / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str FROM_UNIXTIME(MIN(start_time) / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str
from ams_job_info j from ams_job_info j
@ -57,5 +83,4 @@
</select> </select>
</mapper> </mapper>

5
system/src/main/java/com/jiagutech/ams/controller/UserController.java

@ -85,7 +85,8 @@ public class UserController {
@Operation(summary = "根据区域码获取农户列表") @Operation(summary = "根据区域码获取农户列表")
@GetMapping("/listFarmerByRegionCode") @GetMapping("/listFarmerByRegionCode")
public R<List<UserDetail>> getAllFarmersByRegionCode(Long regionCode) {
return R.ok(userService.getAllFarmersByRegionCode(regionCode));
public R<List<UserDetail>> getAllFarmersByRegionCode(@RequestParam(value = "regionCode") Long regionCode,
@RequestParam(value = "nickName", required = false) String nickName) {
return R.ok(userService.getAllFarmersByRegionCode(regionCode,nickName));
} }
} }

2
system/src/main/java/com/jiagutech/ams/service/UserService.java

@ -28,5 +28,5 @@ public interface UserService {
PageResult<UserDetail> getUserPage(PageRequest<PageUserRequest> pageRequest); PageResult<UserDetail> getUserPage(PageRequest<PageUserRequest> pageRequest);
List<UserDetail> getAllFarmersByRegionCode(Long regionCode);
List<UserDetail> getAllFarmersByRegionCode(Long regionCode,String nickName);
} }

5
system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java

@ -177,10 +177,13 @@ public class UserServiceImpl implements UserService {
@Override @Override
public List<UserDetail> getAllFarmersByRegionCode(Long regionCode) {
public List<UserDetail> getAllFarmersByRegionCode(Long regionCode, String nickName) {
QueryWrapper<UserDetail> query = Wrappers.query(); QueryWrapper<UserDetail> query = Wrappers.query();
query.eq("u.region_code", regionCode); query.eq("u.region_code", regionCode);
if (nickName != null && !nickName.isEmpty()) {
query.eq("u.nick_name", nickName);
}
query.eq("u.del_flag", 0); query.eq("u.del_flag", 0);
query.eq("r.key", "farmer"); query.eq("r.key", "farmer");

4
system/src/main/resources/mapper/UserMapper.xml

@ -93,7 +93,9 @@
u.phone, u.phone,
u.create_time, u.create_time,
u.avatar, u.avatar,
u.region_code
u.region_code,
u.contact_phone,
right(u.identity_card_num,4) as identity_card_num
from ams_user u from ams_user u
left join ams_user_role ur on u.id = ur.user_id left join ams_user_role ur on u.id = ur.user_id
left join ams_role r on ur.role_id = r.id left join ams_role r on ur.role_id = r.id

50
web/pom.xml

@ -83,11 +83,6 @@
<artifactId>sa-token-spring-boot3-starter</artifactId> <artifactId>sa-token-spring-boot3-starter</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>cn.dev33</groupId>-->
<!-- <artifactId>sa-token-redis</artifactId>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>cn.dev33</groupId> <groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId> <artifactId>sa-token-redis-jackson</artifactId>
@ -155,6 +150,51 @@
</annotationProcessorPaths> </annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
<!-- 添加 maven-pmd-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.15.0</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>6.38.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>6.38.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.2</version>
</dependency>
</dependencies>
<configuration>
<linkXRef>false</linkXRef>
<sourceEncoding>UTF-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>17</targetJdk>
<analysisCache>true</analysisCache>
<analysisCacheLocation>${project.build.directory}/pmd/pmd.cache</analysisCacheLocation>
<outputDirectory>${project.build.directory}/pmd</outputDirectory>
<format>html</format>
<failOnViolation>false</failOnViolation>
</configuration>
<executions>
<execution>
<id>pmd-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
<goal>pmd</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

4
web/src/main/java/com/jiagutech/ams/common/RabbitConfig.java

@ -1,10 +1,6 @@
package com.jiagutech.ams.common; package com.jiagutech.ams.common;
import org.springframework.amqp.core.*; import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.SimpleMessageConverter;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

1
web/src/main/java/com/jiagutech/ams/config/SpringDocConfig.java

@ -3,7 +3,6 @@ package com.jiagutech.ams.config;
import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;

Loading…
Cancel
Save