火点重构

This commit is contained in:
liuchengqian 2023-03-29 17:19:12 +08:00
parent 266f2d4ab0
commit 6d4e284d01

View File

@ -16,14 +16,19 @@ import com.xkrs.model.qo.UpdateFirePointQo;
import com.xkrs.service.DispatchFirePointService;
import com.xkrs.utilsnew.DateTimeUtils;
import com.xkrs.utilsnew.FirePointFilterUtils;
import org.apache.hc.core5.util.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@ -160,15 +165,42 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
@Override
public String updateFirePoint(UpdateFirePointQo updateFirePointQo) {
List<UpdateFirePointQo.DataDTO> list = updateFirePointQo.getData();
for (UpdateFirePointQo.DataDTO item : list) {
String fireCode = item.getFireCode();
String status = item.getStatus();
if ((!TextUtils.isEmpty(fireCode)) && (!TextUtils.isEmpty(status)) && (("0".equals(status)) || ("1".equals(status)))) {
System.out.println("参数正常fireCode = " + fireCode + "status = " + fireCode);
} else {
System.out.println("参数异常fireCode = " + fireCode + "status = " + fireCode);
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "更新失败", locale);
}
}
for (UpdateFirePointQo.DataDTO item : list) {
try {
String fireCode = item.getFireCode();
String status = item.getStatus();
Specification<FirePointOrdinaryEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
//查询条件集合
List<Predicate> predicateList = new ArrayList<>();
predicateList.add(criteriaBuilder.equal(root.get("fireCode").as(String.class), fireCode));
Predicate[] predicateArray = new Predicate[predicateList.size()];
return criteriaBuilder.and(predicateList.toArray(predicateArray));
};
List<FirePointOrdinaryEntity> firePointList = firePointOrdinaryDao.findAll(specification, Sort.by(Sort.Direction.DESC, "satelliteTime"));
if (firePointList.isEmpty()) {
System.out.println("操作异常审核系统发送的fireCode在秸秆系统已有的火点中找不到fireCode = " + fireCode + "status = " + fireCode);
} else {
for (FirePointOrdinaryEntity firePoint : firePointList) {
firePoint.setFireStatus(status);
firePointOrdinaryDao.save(firePoint);
}
}
} catch (Exception e) {
e.printStackTrace();
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "更新失败", locale);
}
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "更新成功", locale);
}
}