Commit ded7f8a2 authored by 付培阳's avatar 付培阳

消防专家接口修改

parent ba9bef83
...@@ -9,6 +9,7 @@ import com.yeejoin.amos.boot.biz.common.utils.NameUtils; ...@@ -9,6 +9,7 @@ import com.yeejoin.amos.boot.biz.common.utils.NameUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.biz.common.utils.TreeParser; import com.yeejoin.amos.boot.biz.common.utils.TreeParser;
import com.yeejoin.amos.boot.module.common.api.dto.ExcelDto; import com.yeejoin.amos.boot.module.common.api.dto.ExcelDto;
import com.yeejoin.amos.boot.module.common.api.dto.FireChemicalDto;
import com.yeejoin.amos.boot.module.common.api.dto.FireExpertsDto; import com.yeejoin.amos.boot.module.common.api.dto.FireExpertsDto;
import com.yeejoin.amos.boot.module.common.api.entity.DataDictionary; import com.yeejoin.amos.boot.module.common.api.entity.DataDictionary;
import com.yeejoin.amos.boot.module.common.api.entity.FireExperts; import com.yeejoin.amos.boot.module.common.api.entity.FireExperts;
...@@ -126,45 +127,17 @@ public class FireExpertsController extends BaseController { ...@@ -126,45 +127,17 @@ public class FireExpertsController extends BaseController {
public ResponseModel<IPage<FireExpertsDto>> queryForPage(@RequestParam(value = "current") int current, public ResponseModel<IPage<FireExpertsDto>> queryForPage(@RequestParam(value = "current") int current,
@RequestParam(value = "size") int size, @RequestParam(value = "size") int size,
FireExpertsDto fireExpertsDto) { FireExpertsDto fireExpertsDto) {
FireExperts fireExperts = BeanDtoVoUtils.convert(fireExpertsDto, FireExperts.class); Page<FireExpertsDto> page = new Page<>();
Page<FireExperts> pageBean; page.setCurrent(current);
QueryWrapper<FireExperts> fireExpertsQueryWrapper = new QueryWrapper<>(); page.setSize(size);
fireExpertsQueryWrapper.eq("is_delete", false); Page<FireExpertsDto> fireExpertsDtoPage = fireExpertsServiceImpl.queryForFireExpertsPage(page, false,
Class<? extends FireExperts> aClass = fireExperts.getClass(); fireExpertsDto.getName(), fireExpertsDto.getExpertCode());
Arrays.stream(aClass.getDeclaredFields()).forEach(field -> { List<FireExpertsDto> fireExpertsDtoList = fireExpertsDtoPage.getRecords().stream().map(item -> {
try { item.setAge(BeanDtoVoUtils.getAge(item.getBirthdayTime()));
field.setAccessible(true); return item;
Class<?> type = field.getType(); }).collect(Collectors.toList());
Object o = field.get(fireExperts); fireExpertsDtoPage.setRecords(fireExpertsDtoList);
if (o != null) { return ResponseHelper.buildResponse(fireExpertsDtoPage);
String name = NameUtils.camel2Underline(field.getName());
if ("name".equalsIgnoreCase(name)) {
String fileValue = (String) o;
fireExpertsQueryWrapper.like(name, fileValue);
} else if ("expert_code".equalsIgnoreCase(name)) {
String fileValue = (String) o;
fireExpertsQueryWrapper.eq(name, fileValue);
} else if (type.equals(Integer.class)) {
Integer fileValue = (Integer) o;
fireExpertsQueryWrapper.eq(name, fileValue);
} else if (type.equals(Long.class)) {
Long fileValue = (Long) o;
fireExpertsQueryWrapper.eq(name, fileValue);
} else {
String fileValue = (String) o;
fireExpertsQueryWrapper.like(name, fileValue);
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("系统异常");
}
});
IPage<FireExperts> page;
pageBean = new Page<>(current, size);
page = fireExpertsServiceImpl.page(pageBean, fireExpertsQueryWrapper);
IPage<FireExpertsDto> fireExpertsDtoIPage = BeanDtoVoUtils.iPageDtoStreamFireExperts(page);
return ResponseHelper.buildResponse(fireExpertsDtoIPage);
} }
/** /**
......
...@@ -25,8 +25,11 @@ public class FireExpertsServiceImpl extends BaseService<FireExpertsDto, FireExpe ...@@ -25,8 +25,11 @@ public class FireExpertsServiceImpl extends BaseService<FireExpertsDto, FireExpe
/** /**
* 分页查询 * 分页查询
*/ */
public Page<FireExpertsDto> queryForFireExpertsPage(Page<FireExpertsDto> page) { public Page<FireExpertsDto> queryForFireExpertsPage(Page<FireExpertsDto> page,
return this.queryForPage(page, null, false); @Condition(Operator.eq) Boolean isDelete,
@Condition(Operator.like) String name,
@Condition(Operator.eq) String expertCode) {
return this.queryForPage(page, null, false, isDelete, name, expertCode);
} }
/** /**
......
...@@ -6,6 +6,7 @@ import com.yeejoin.amos.boot.module.common.api.entity.FireExperts; ...@@ -6,6 +6,7 @@ import com.yeejoin.amos.boot.module.common.api.entity.FireExperts;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
...@@ -111,29 +112,21 @@ public class BeanDtoVoUtils { ...@@ -111,29 +112,21 @@ public class BeanDtoVoUtils {
//由出生日期获得年龄 //由出生日期获得年龄
public static int getAge(Date birthDay) { public static int getAge(Date birthDay) {
Calendar cal = Calendar.getInstance(); if (birthDay == null) {
return 0;
if (cal.before(birthDay)) {
throw new IllegalArgumentException("出生日期小于当前时间,无效的日期!");
} }
int yearNow = cal.get(Calendar.YEAR); LocalDate now = LocalDate.now();
int monthNow = cal.get(Calendar.MONTH); Calendar cal = Calendar.getInstance();
int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
cal.setTime(birthDay); cal.setTime(birthDay);
int yearBirth = cal.get(Calendar.YEAR); int yearBirth = cal.get(Calendar.YEAR);
int monthBirth = cal.get(Calendar.MONTH); int monthBirth = cal.get(Calendar.MONTH) + 1;
int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH); int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
int age = yearNow - yearBirth; LocalDate birth = LocalDate.of(yearBirth, monthBirth, dayOfMonthBirth);
if (birth.isAfter(now)) {
if (monthNow <= monthBirth) { return 0;
if (monthNow == monthBirth) {
if (dayOfMonthNow < dayOfMonthBirth) age--;
} else {
age--;
}
} }
int age = birth.until(now).getYears();
return age; return age;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment