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. 75
      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. 344
      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 userIdStr;
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:
**/
@Data
public class PageRequest<T> {
public class PageRequest<T> implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private int pageNum;
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 String regionPath;
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 = "导出作业记录")
public void exportJobs(@RequestBody(required = false) JobPageRequest jobPageRequest, HttpServletResponse response) {
jobService.exportJobs(jobPageRequest, response);
}
@PostMapping("/exportByFarmer")
@PostMapping(value = "/exportByFarmer",consumes = "application/json")
@Operation(summary = "导出作业记录")
public void exportByFarmer(@RequestBody(required = false) JobPageRequest jobPageRequest, HttpServletResponse 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;
@SaCheckRole(value = {"manager", "machinist"}, mode = SaMode.OR)
@Operation(summary = "获取下一级的所有区域列表")
@GetMapping("getChildren")
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;
import com.jiagutech.ams.event.JobFinishEvent;
import com.jiagutech.ams.mapper.JobMapper;
import com.jiagutech.ams.model.TrackItem;
import com.jiagutech.ams.model.dto.JobDTO;
import com.jiagutech.ams.service.JobService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
/**
@ -22,12 +26,21 @@ import java.util.List;
@RequiredArgsConstructor
public class JobFinishListener {
private final JobService jobService;
private final JobMapper jobMapper;
@EventListener(JobFinishEvent.class)
public void finishJob(JobFinishEvent event) {
log.info("JobFinishListener:{}", event.getJobId());
JobDTO jobDTO = jobMapper.selectById(event.getJobId());
Long startTime = jobDTO.getStartTime();
Long endTime = System.currentTimeMillis();
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());
jobMapper.updateById(jobDTO);
} catch (Exception 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 Float duration;
private Integer duration;
private Integer status;
@ -41,4 +41,5 @@ public class JobDTO {
private Long deptId;
}

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

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

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

@ -21,8 +21,10 @@ public class JobItem {
@ExcelIgnore
@JsonSerialize(using = ToStringSerializer.class)
private Long jobId;
@ExcelIgnore
@ExcelProperty(value = "机手")
private String operatorName;
@ExcelIgnore
@ExcelProperty(value = "机手手机号")
private String operatorPhone;
@ExcelIgnore
@ -59,5 +61,7 @@ public class JobItem {
@ExcelProperty(value = "作业地区")
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) {
queryWrapper.eq("j.farmer_id", requestParam.getFarmerId());
}
if (requestParam.getRegionCode() != 0l) {
queryWrapper.eq("j.region_code", requestParam.getRegionCode());
}
}

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

@ -3,59 +3,84 @@
<mapper namespace="com.jiagutech.ams.mapper.JobMapper">
<sql id="jobItem">
select j.id as job_id,
select j.id as job_id,
j.start_time,
j.end_time,
j.area,
j.status,
j.device_id,
j.operator_id,
FROM_UNIXTIME(j.start_time/1000,'%Y-%m-%d %H:%i:%s') as start_time_str,
u1.nick_name as operator_name,
u1.phone as operator_phone,
j.duration,
FROM_UNIXTIME(j.start_time / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str,
u1.nick_name as operator_name,
u1.phone as operator_phone,
j.farmer_id,
u2.nick_name as farmer_name,
u2.phone as farmer_phone,
u2.region_name ,
u2.nick_name as farmer_name,
u2.phone as farmer_phone,
u2.region_name,
j.job_type,
t.name as type_name,
d.id as dept_id,
d.name as dept_name
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_dept d on j.dept_id = d.id
left join ams_user u1 on j.operator_id = u1.id
left join ams_user u2 on j.farmer_id = u2.id
</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">
<include refid="jobItem"></include>
${ew.getCustomSqlSegment}
</select>
<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 id="jobListCountByFarmer" resultType="com.jiagutech.ams.model.response.JobItem">
select ROUND(sum(j.area),2) as area,j.farmer_id,
u2.nick_name as farmer_name,
j.job_type,t.name as type_name,
d.id as dept_id,
d.name as dept_name,
u2.phone as farmer_phone,
select ROUND(sum(j.area), 2) as area,
j.farmer_id,
u2.nick_name as farmer_name,
j.job_type,
t.name as type_name,
d.id as dept_id,
d.name as dept_name,
CONCAT(LEFT(u2.phone, 3), '****', RIGHT(u2.phone, 4)) as farmer_phone,
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
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_dept d on j.dept_id = d.id
left join ams_user u2 on j.farmer_id = u2.id
${ew.getCustomSqlSegment}
group by j.farmer_id,j.job_type,t.name,d.id,d.name,u2.nick_name
order by j.farmer_id,j.job_type
group by j.farmer_id, j.job_type, t.name, d.id, d.name, u2.nick_name
order by j.farmer_id, j.job_type
</select>
</mapper>

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

@ -85,7 +85,8 @@ public class UserController {
@Operation(summary = "根据区域码获取农户列表")
@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);
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
public List<UserDetail> getAllFarmersByRegionCode(Long regionCode) {
public List<UserDetail> getAllFarmersByRegionCode(Long regionCode, String nickName) {
QueryWrapper<UserDetail> query = Wrappers.query();
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("r.key", "farmer");

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

@ -93,7 +93,9 @@
u.phone,
u.create_time,
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
left join ams_user_role ur on u.id = ur.user_id
left join ams_role r on ur.role_id = r.id

344
web/pom.xml

@ -1,162 +1,202 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jiagutech</groupId>
<artifactId>ams-social</artifactId>
<version>${revision}</version>
</parent>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jiagutech</groupId>
<artifactId>ams-social</artifactId>
<version>${revision}</version>
</parent>
<artifactId>web</artifactId>
<artifactId>web</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<!-- 环境标识,需要与配置文件的名称相对应 -->
<profiles.active>dev</profiles.active>
<logging.level>info</logging.level>
</properties>
<activation>
<!-- 默认环境 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>zyg</id>
<properties>
<profiles.active>zyg</profiles.active>
<logging.level>info</logging.level>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
<logging.level>info</logging.level>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.jiagutech</groupId>
<artifactId>system</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.jiagutech</groupId>
<artifactId>social</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<profiles>
<profile>
<id>dev</id>
<properties>
<!-- 环境标识,需要与配置文件的名称相对应 -->
<profiles.active>dev</profiles.active>
<logging.level>info</logging.level>
</properties>
<activation>
<!-- 默认环境 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>zyg</id>
<properties>
<profiles.active>zyg</profiles.active>
<logging.level>info</logging.level>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
<logging.level>info</logging.level>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.jiagutech</groupId>
<artifactId>system</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.jiagutech</groupId>
<artifactId>social</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot3-starter</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot3-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId>
</dependency>
<!-- 添加 MapStruct 依赖 -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.3.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.yml</include>
<include>application-${profiles.active}.yml</include>
<include>*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 添加 MapStruct 插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.3.Final</version>
</path>
<!-- 添加 Lombok 注解处理器 -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</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>
<!-- <dependency>-->
<!-- <groupId>cn.dev33</groupId>-->
<!-- <artifactId>sa-token-redis</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId>
</dependency>
<!-- 添加 MapStruct 依赖 -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.3.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.yml</include>
<include>application-${profiles.active}.yml</include>
<include>*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 添加 MapStruct 插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.3.Final</version>
</path>
<!-- 添加 Lombok 注解处理器 -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</build>
</project>

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

@ -1,10 +1,6 @@
package com.jiagutech.ams.common;
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.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.info.Contact;
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.SecurityScheme;
import org.springframework.context.annotation.Bean;

Loading…
Cancel
Save