督导检查、执法车辆管理、执法装备管理等接口类
This commit is contained in:
parent
b6c5558beb
commit
146938b77f
|
|
@ -0,0 +1,453 @@
|
||||||
|
package com.aisino.iles.lawenforcement.service;
|
||||||
|
|
||||||
|
import com.aisino.iles.common.service.FtpService;
|
||||||
|
import com.aisino.iles.common.util.PageableHelper;
|
||||||
|
import com.aisino.iles.lawenforcement.model.*;
|
||||||
|
import com.aisino.iles.lawenforcement.model.dto.SupervisionCheckDto;
|
||||||
|
import com.aisino.iles.lawenforcement.model.dto.SupervisionCheckStatisticsDto;
|
||||||
|
import com.aisino.iles.lawenforcement.model.enums.FlowNode;
|
||||||
|
import com.aisino.iles.lawenforcement.model.query.SupervisionCheckQuery;
|
||||||
|
import com.aisino.iles.lawenforcement.repository.AgencyRepository;
|
||||||
|
import com.aisino.iles.lawenforcement.repository.EnforceCheckRepository;
|
||||||
|
import com.aisino.iles.lawenforcement.repository.EnforcementInfoRepository;
|
||||||
|
import com.aisino.iles.lawenforcement.repository.SupervisionCheckRepository;
|
||||||
|
import com.smartlx.sso.client.model.RemoteUserInfo;
|
||||||
|
import jakarta.persistence.criteria.Join;
|
||||||
|
import jakarta.persistence.criteria.JoinType;
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 督导检查服务类
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SupervisionCheckService {
|
||||||
|
|
||||||
|
private final SupervisionCheckRepository supervisionCheckRepository;
|
||||||
|
private final EnforcementInfoRepository enforcementInfoRepository;
|
||||||
|
private final EnforceCheckRepository enforceCheckRepository;
|
||||||
|
private final AgencyRepository agencyRepo;
|
||||||
|
private final FtpService ftpService;
|
||||||
|
|
||||||
|
public SupervisionCheckService(SupervisionCheckRepository supervisionCheckRepository,
|
||||||
|
EnforcementInfoRepository enforcementInfoRepository,
|
||||||
|
EnforceCheckRepository enforceCheckRepository,
|
||||||
|
AgencyRepository agencyRepo,FtpService ftpService) {
|
||||||
|
this.supervisionCheckRepository = supervisionCheckRepository;
|
||||||
|
this.enforcementInfoRepository = enforcementInfoRepository;
|
||||||
|
this.enforceCheckRepository = enforceCheckRepository;
|
||||||
|
this.agencyRepo = agencyRepo;
|
||||||
|
this.ftpService = ftpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存督导检查信息
|
||||||
|
*
|
||||||
|
* @param supervisionCheckDto 督导检查信息
|
||||||
|
* @return 保存后的督导检查信息
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void saveSupervisionChecks(SupervisionCheckDto supervisionCheckDto,RemoteUserInfo user) {
|
||||||
|
Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!"));
|
||||||
|
if("single".equals(supervisionCheckDto.getType())){
|
||||||
|
SupervisionCheck supervisionCheck = new SupervisionCheck();
|
||||||
|
supervisionCheck.setEnterpriseId(supervisionCheckDto.getEnterprise().getEnterpriseId());
|
||||||
|
supervisionCheck.setAgencyId(supervisionCheckDto.getAgency().getAgencyId());
|
||||||
|
supervisionCheck.setDeliverAgencyLevel(supervisionCheckDto.getAgency().getAgencyLevel());
|
||||||
|
supervisionCheck.setDescription(supervisionCheckDto.getDescription());
|
||||||
|
supervisionCheck.setDeliverAgencyId(currentAgency.getAgencyId());
|
||||||
|
supervisionCheck.setDeliverAgencyLevel(currentAgency.getAgencyLevel());
|
||||||
|
supervisionCheck.setDeliverPerson(user.getXm());
|
||||||
|
supervisionCheck.setCheckType(supervisionCheckDto.getCheckType());
|
||||||
|
|
||||||
|
// todo
|
||||||
|
if("交叉互查".equals(supervisionCheckDto.getCheckType())){
|
||||||
|
supervisionCheck.setCheckStatus(SupervisionCheck.CheckStatus.reviewing_done);
|
||||||
|
}else{
|
||||||
|
supervisionCheck.setCheckStatus(SupervisionCheck.CheckStatus.pending);
|
||||||
|
}
|
||||||
|
supervisionCheck.setDeliverTime(LocalDateTime.now());
|
||||||
|
supervisionCheck.setEvidence(supervisionCheckDto.getEvidence());
|
||||||
|
saveSupervisionCheck(supervisionCheck);
|
||||||
|
}else{
|
||||||
|
List<SupervisionCheck> supervisionChecks = new ArrayList<>();
|
||||||
|
supervisionCheckDto.getEnterprises().forEach(enterprise -> {
|
||||||
|
SupervisionCheck supervisionCheck = new SupervisionCheck();
|
||||||
|
supervisionCheck.setEnterpriseId(enterprise.getEnterpriseId());
|
||||||
|
supervisionCheck.setAgencyId(supervisionCheckDto.getAgency().getAgencyId());
|
||||||
|
supervisionCheck.setDescription(supervisionCheckDto.getDescription());
|
||||||
|
supervisionCheck.setDeliverAgencyId(currentAgency.getAgencyId());
|
||||||
|
supervisionCheck.setDeliverAgencyLevel(currentAgency.getAgencyLevel());
|
||||||
|
supervisionCheck.setDeliverPerson(user.getXm());
|
||||||
|
supervisionCheck.setCheckType(supervisionCheckDto.getCheckType());
|
||||||
|
if("交叉互查".equals(supervisionCheckDto.getCheckType())){
|
||||||
|
supervisionCheck.setCheckStatus(SupervisionCheck.CheckStatus.reviewing_done);
|
||||||
|
}else{
|
||||||
|
supervisionCheck.setCheckStatus(SupervisionCheck.CheckStatus.pending);
|
||||||
|
}
|
||||||
|
supervisionCheck.setDeliverTime(LocalDateTime.now());
|
||||||
|
supervisionCheck.setEvidence(supervisionCheckDto.getEvidence());
|
||||||
|
supervisionChecks.add(supervisionCheck);
|
||||||
|
});
|
||||||
|
saveSupervisionChecks(supervisionChecks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 保存单条督导检查信息
|
||||||
|
*
|
||||||
|
* @param supervisionCheck 督导检查信息
|
||||||
|
* @return 保存后的督导检查信息
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public SupervisionCheck saveSupervisionCheck(SupervisionCheck supervisionCheck) {
|
||||||
|
return supervisionCheckRepository.save(supervisionCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 督导检查审批
|
||||||
|
*
|
||||||
|
* @param supervisionCheck 督导检查信息
|
||||||
|
* @return 保存后的督导检查信息
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public SupervisionCheck reviewSupervisionCheck(SupervisionCheck supervisionCheck,RemoteUserInfo user) {
|
||||||
|
return supervisionCheckRepository.findById(supervisionCheck.getCheckId()).map(s ->{
|
||||||
|
s.setCheckStatus(supervisionCheck.getCheckStatus());
|
||||||
|
s.setVerifyDesc(supervisionCheck.getVerifyDesc());
|
||||||
|
s.setVerifyTime(LocalDateTime.now());
|
||||||
|
s.setVerifyUserName(user.getXm());
|
||||||
|
s.setVerifyUserId(user.getYhwybs());
|
||||||
|
return supervisionCheckRepository.save(s);
|
||||||
|
}).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存督导检查信息
|
||||||
|
*
|
||||||
|
* @param supervisionChecks 督导检查信息列表
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void saveSupervisionChecks(List<SupervisionCheck> supervisionChecks) {
|
||||||
|
supervisionCheckRepository.saveAll(supervisionChecks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询督导检查信息
|
||||||
|
*
|
||||||
|
* @param checkId 督导检查ID
|
||||||
|
* @return 督导检查信息
|
||||||
|
*/
|
||||||
|
public Optional<SupervisionCheck> findSupervisionCheckById(String checkId) {
|
||||||
|
return supervisionCheckRepository.findById(checkId).map(supervisionCheck -> {
|
||||||
|
supervisionCheck.getDeliverAgency().getAgencyName();
|
||||||
|
supervisionCheck.getEnterprise().getUnitName();
|
||||||
|
switch (supervisionCheck.getCheckStatus().getValue()){
|
||||||
|
case "pending" -> supervisionCheck.setCheckStatusName("待审批");
|
||||||
|
case "reviewing_done" -> supervisionCheck.setCheckStatusName("审批通过");
|
||||||
|
case "reviewing_failed" -> supervisionCheck.setCheckStatusName("审批不通过");
|
||||||
|
case "completed" -> supervisionCheck.setCheckStatusName("已处理");
|
||||||
|
}
|
||||||
|
String savePath = String.valueOf(supervisionCheck.getEvidence().get("savePathName"));
|
||||||
|
supervisionCheck.getEvidence().put("downloadUrl",ftpService.getFileUrl(savePath));
|
||||||
|
supervisionCheck.getEvidence().put("url",ftpService.getFileUrl(savePath));
|
||||||
|
return supervisionCheck;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 督导检查任务保存执法信息和检查项
|
||||||
|
*
|
||||||
|
* @param supervisionCheckDto 督导检查信息
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void addEnforcementInfoCheck(SupervisionCheckDto supervisionCheckDto,RemoteUserInfo user) {
|
||||||
|
Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!"));
|
||||||
|
if("single".equals(supervisionCheckDto.getType())){
|
||||||
|
SupervisionCheck supervisionCheck = supervisionCheckDto.getSupervisionCheck();
|
||||||
|
|
||||||
|
EnforcementInfo enforcementInfo = new EnforcementInfo();
|
||||||
|
String dataFrom = "";
|
||||||
|
if(supervisionCheck.getDeliverAgencyLevel()>currentAgency.getAgencyLevel()){
|
||||||
|
dataFrom="5";
|
||||||
|
}else if(supervisionCheck.getDeliverAgencyLevel().equals(currentAgency.getAgencyLevel())){
|
||||||
|
dataFrom="6";
|
||||||
|
}
|
||||||
|
enforcementInfo.setDataFrom(dataFrom);
|
||||||
|
enforcementInfo.setEnterpriseId(supervisionCheck.getEnterpriseId());
|
||||||
|
enforcementInfo.setAgencyId(supervisionCheck.getAgencyId());
|
||||||
|
enforcementInfo.setCurrentNodeCode(FlowNode.plan_approved);
|
||||||
|
enforcementInfo.setCurrentNode("方案审批通过");
|
||||||
|
enforcementInfo.setCreateTime(LocalDateTime.now());
|
||||||
|
enforcementInfoRepository.save(enforcementInfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EnforceCheck enforceCheck = new EnforceCheck();
|
||||||
|
Optional.ofNullable(supervisionCheckDto.getCheckItemIds()).ifPresent(ids -> enforceCheck.setCheckItemIds(String.join(",", ids)));
|
||||||
|
enforceCheck.setCheckType("5");
|
||||||
|
enforceCheck.setEnforcementId(enforcementInfo.getEnforcementId());
|
||||||
|
enforceCheck.setCreateTime(LocalDateTime.now());
|
||||||
|
enforceCheck.setCheckStatus("1");
|
||||||
|
enforceCheck.setCheckFlag("1");
|
||||||
|
if("督导检查".equals(supervisionCheck.getCheckType())){
|
||||||
|
enforceCheck.setCheckType("5");
|
||||||
|
}else if("交叉互查".equals(supervisionCheck.getCheckType())){
|
||||||
|
enforceCheck.setCheckType("6");
|
||||||
|
}
|
||||||
|
enforceCheck.setPlanId(supervisionCheck.getCheckId());
|
||||||
|
enforceCheck.setWriterId(user.getYhwybs());
|
||||||
|
enforceCheck.setCreatedBy(user.getXm());
|
||||||
|
enforceCheck.setCreatedAccountBy(user.getYhwybs());
|
||||||
|
enforceCheckRepository.save(enforceCheck);
|
||||||
|
|
||||||
|
supervisionCheckRepository.findById(supervisionCheck.getCheckId()).map(s->{
|
||||||
|
s.setEnforcementId(enforcementInfo.getEnforcementId());
|
||||||
|
s.setCheckStatus(SupervisionCheck.CheckStatus.completed);
|
||||||
|
return s;
|
||||||
|
});
|
||||||
|
|
||||||
|
}else{
|
||||||
|
supervisionCheckDto.getSupervisionChecks().forEach(supervisionCheck -> {
|
||||||
|
EnforcementInfo enforcementInfo = new EnforcementInfo();
|
||||||
|
String dataFrom = "";
|
||||||
|
if(supervisionCheck.getDeliverAgencyLevel()>currentAgency.getAgencyLevel()){
|
||||||
|
dataFrom="5";
|
||||||
|
}else if(supervisionCheck.getDeliverAgencyLevel().equals(currentAgency.getAgencyLevel())){
|
||||||
|
dataFrom="6";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enforcementInfo.setDataFrom(dataFrom);
|
||||||
|
enforcementInfo.setEnterpriseId(supervisionCheck.getEnterpriseId());
|
||||||
|
enforcementInfo.setAgencyId(supervisionCheck.getAgencyId());
|
||||||
|
enforcementInfo.setCurrentNodeCode(FlowNode.plan_approved);
|
||||||
|
enforcementInfo.setCurrentNode("方案审批通过");
|
||||||
|
enforcementInfo.setCreateTime(LocalDateTime.now());
|
||||||
|
enforcementInfoRepository.save(enforcementInfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EnforceCheck enforceCheck = new EnforceCheck();
|
||||||
|
Optional.ofNullable(supervisionCheckDto.getCheckItemIds()).ifPresent(ids -> enforceCheck.setCheckItemIds(String.join(",", ids)));
|
||||||
|
enforceCheck.setCheckType("5");
|
||||||
|
enforceCheck.setEnforcementId(enforcementInfo.getEnforcementId());
|
||||||
|
enforceCheck.setCreateTime(LocalDateTime.now());
|
||||||
|
enforceCheck.setCheckStatus("1");
|
||||||
|
enforceCheck.setCheckFlag("1");
|
||||||
|
enforceCheck.setPlanId(supervisionCheck.getCheckId());
|
||||||
|
if("督导检查".equals(supervisionCheck.getCheckType())){
|
||||||
|
enforceCheck.setCheckType("5");
|
||||||
|
}else if("交叉互查".equals(supervisionCheck.getCheckType())){
|
||||||
|
enforceCheck.setCheckType("6");
|
||||||
|
}
|
||||||
|
enforceCheck.setWriterId(user.getYhwybs());
|
||||||
|
enforceCheck.setCreatedBy(user.getXm());
|
||||||
|
enforceCheck.setCreatedAccountBy(user.getYhwybs());
|
||||||
|
enforceCheckRepository.save(enforceCheck);
|
||||||
|
|
||||||
|
supervisionCheckRepository.findById(supervisionCheck.getCheckId()).map(s->{
|
||||||
|
s.setEnforcementId(enforcementInfo.getEnforcementId());
|
||||||
|
s.setCheckStatus(SupervisionCheck.CheckStatus.completed);
|
||||||
|
return s;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据查询条件分页查询督导检查信息
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 分页督导检查信息
|
||||||
|
*/
|
||||||
|
public Page<SupervisionCheck> findSupervisionChecksPage(SupervisionCheckQuery query, RemoteUserInfo user) {
|
||||||
|
return supervisionCheckRepository.findAll(buildSpecification(query, user), PageableHelper.buildPageRequest(query.page(), query.pageSize(), query.sort(), query.dir())).map(this::getSupervisionCheckInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建查询条件
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 规格
|
||||||
|
*/
|
||||||
|
private Specification<SupervisionCheck> buildSpecification(SupervisionCheckQuery query, RemoteUserInfo user) {
|
||||||
|
Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!"));
|
||||||
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
||||||
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
|
||||||
|
if(query.getCheckStatus()!=null){
|
||||||
|
Optional.ofNullable(query.getCheckStatus()).ifPresent(o->predicates.add(criteriaBuilder.equal(root.get(SupervisionCheck_.checkStatus),o)));
|
||||||
|
}else{
|
||||||
|
Optional.ofNullable(query.getStatus()).filter(com.aisino.iles.common.util.StringUtils::isNotEmpty).ifPresent(o -> {
|
||||||
|
List<Predicate> orPredicates = Arrays.stream(o.split(","))
|
||||||
|
.map(code -> criteriaBuilder.equal(root.get(SupervisionCheck_.checkStatus), SupervisionCheck.CheckStatus.fromString(code)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
predicates.add(orPredicates.size() == 1 ? orPredicates.get(0) : criteriaBuilder.or(orPredicates.toArray(new Predicate[0])));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Optional.ofNullable(query.getCheckType()).ifPresent(o->predicates.add(criteriaBuilder.equal(root.get(SupervisionCheck_.checkType),o)));
|
||||||
|
Optional.ofNullable(query.getDeliverTime()).filter(f -> f.length == 2).map(f -> {
|
||||||
|
List<Predicate> timePredicates = new ArrayList<>();
|
||||||
|
Optional.ofNullable(f[0]).map(from -> criteriaBuilder.greaterThanOrEqualTo(root.get("deliverTime"), from)).ifPresent(timePredicates::add);
|
||||||
|
Optional.ofNullable(f[1]).map(to -> criteriaBuilder.lessThanOrEqualTo(root.get("deliverTime"), to)).ifPresent(timePredicates::add);
|
||||||
|
return timePredicates;
|
||||||
|
}).ifPresent(predicates::addAll);
|
||||||
|
if("sp".equals(query.getFlag())){
|
||||||
|
//审批查询转交的审批机构
|
||||||
|
Join<SupervisionCheck, Agency> supervisionCheckAgencyJoin = root.join("deliverAgency", JoinType.LEFT);
|
||||||
|
predicates.add(criteriaBuilder.equal((supervisionCheckAgencyJoin.get(Agency_.agencyCode)),currentAgency.getAgencyCode()));
|
||||||
|
}
|
||||||
|
if("cl".equals(query.getFlag())){
|
||||||
|
//被转交机构查任务
|
||||||
|
Join<SupervisionCheck, Agency> supervisionCheckAgencyJoin = root.join("agency", JoinType.LEFT);
|
||||||
|
predicates.add(criteriaBuilder.equal((supervisionCheckAgencyJoin.get(Agency_.agencyCode)),currentAgency.getAgencyCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (StringUtils.hasText(query.getUnitName())) {
|
||||||
|
Join<SupervisionCheck, Enterprise> supervisionCheckenterpriseJoin = root.join("enterprise", JoinType.LEFT);
|
||||||
|
predicates.add(criteriaBuilder.like((supervisionCheckenterpriseJoin.get(Enterprise_.unitName)), '%' + query.getUnitName() + '%'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
private SupervisionCheck getSupervisionCheckInfo(SupervisionCheck o) {
|
||||||
|
o.getDeliverAgency().getAgencyName();
|
||||||
|
o.getEnterprise().getUnitName();
|
||||||
|
switch (o.getCheckStatus().getValue()){
|
||||||
|
case "pending" -> o.setCheckStatusName("待审批");
|
||||||
|
case "reviewing_done" -> o.setCheckStatusName("审批通过");
|
||||||
|
case "reviewing_failed" -> o.setCheckStatusName("审批不通过");
|
||||||
|
case "completed" -> o.setCheckStatusName("已处理");
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional.ofNullable(o.getEvidence()).ifPresent(e->{
|
||||||
|
Optional.ofNullable(e.get("filesData")).ifPresent(list->{
|
||||||
|
List<Map<String,String>> files = (ArrayList)list;
|
||||||
|
files.forEach(f->{
|
||||||
|
String savePathName=f.get("savePathName");
|
||||||
|
String url = ftpService.getFileUrl(savePathName ) ;
|
||||||
|
String downloadUrl = ftpService.getFileUrl(savePathName);
|
||||||
|
f.put("url", url);
|
||||||
|
f.put("downloadUrl", downloadUrl);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 条件查询督导检查信息
|
||||||
|
*
|
||||||
|
* @param spec 查询条件
|
||||||
|
* @return 督导检查信息列表
|
||||||
|
*/
|
||||||
|
public List<SupervisionCheck> findSupervisionChecksBySpec(Specification<SupervisionCheck> spec) {
|
||||||
|
return supervisionCheckRepository.findAll(spec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件分页查询督导检查信息
|
||||||
|
*
|
||||||
|
* @param spec 查询条件
|
||||||
|
* @param pageRequest 分页请求
|
||||||
|
* @return 分页督导检查信息
|
||||||
|
*/
|
||||||
|
public Page<SupervisionCheck> findSupervisionChecksPageBySpec(Specification<SupervisionCheck> spec, PageRequest pageRequest) {
|
||||||
|
return supervisionCheckRepository.findAll(spec, pageRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID删除督导检查信息
|
||||||
|
*
|
||||||
|
* @param checkId 督导检查ID
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void deleteSupervisionCheckById(String checkId) {
|
||||||
|
supervisionCheckRepository.deleteById(checkId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除督导检查信息
|
||||||
|
*
|
||||||
|
* @param checkIds 督导检查ID列表
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void deleteSupervisionChecksByIds(List<String> checkIds) {
|
||||||
|
supervisionCheckRepository.deleteAllById(checkIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查督导检查是否存在
|
||||||
|
*
|
||||||
|
* @param checkId 督导检查ID
|
||||||
|
* @return 是否存在
|
||||||
|
*/
|
||||||
|
public boolean existsSupervisionCheckById(String checkId) {
|
||||||
|
return supervisionCheckRepository.existsById(checkId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取督导检查总数
|
||||||
|
*
|
||||||
|
* @return 督导检查总数
|
||||||
|
*/
|
||||||
|
public long countSupervisionChecks() {
|
||||||
|
return supervisionCheckRepository.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新督导检查状态
|
||||||
|
*
|
||||||
|
* @param checkId 督导检查ID
|
||||||
|
* @param checkStatus 检查状态
|
||||||
|
* @return 更新后的督导检查信息
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Optional<SupervisionCheck> updateSupervisionCheckStatus(String checkId, SupervisionCheck.CheckStatus checkStatus) {
|
||||||
|
Optional<SupervisionCheck> supervisionCheckOpt = supervisionCheckRepository.findById(checkId);
|
||||||
|
if (supervisionCheckOpt.isPresent()) {
|
||||||
|
SupervisionCheck supervisionCheck = supervisionCheckOpt.get();
|
||||||
|
supervisionCheck.setCheckStatus(checkStatus);
|
||||||
|
return Optional.of(supervisionCheckRepository.save(supervisionCheck));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执法检查统计
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 统计结果
|
||||||
|
*/
|
||||||
|
public List<SupervisionCheckStatisticsDto> checkStatistics(SupervisionCheckQuery query, RemoteUserInfo user) {
|
||||||
|
// Jurisdiction userJurisdiction = user.getJurisdictions().stream().findFirst().orElseThrow();
|
||||||
|
// String gxdwbm = com.aisino.iles.common.util.StringUtils.trimTrailingString((Optional.ofNullable(query.getGxdwbm()).filter(StringUtils::hasText).orElse(userJurisdiction.getJurisdictionCode())), "00") + "%";
|
||||||
|
// Integer ilevel = Optional.ofNullable(query.getIlevel()).orElse(userJurisdiction.getJurisdictionLevel());
|
||||||
|
return supervisionCheckRepository.checkStatistics(com.aisino.iles.common.util.StringUtils.trimEven0(query.getGxdwbm()) + "%", query.getIlevel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SupervisionCheckStatisticsDto> sdywStatistics(SupervisionCheckQuery query, RemoteUserInfo user) {
|
||||||
|
return null;
|
||||||
|
// String agencyCode = com.aisino.iles.common.util.StringUtils.trimEven0(query.getAgencyCode()) + "%";
|
||||||
|
// List<Agency> agencys = agencyRepo.findLikeAgencyCode(agencyCode, query.getAgencyLevel());
|
||||||
|
// return agencys.stream().map(agency -> {
|
||||||
|
// SupervisionCheckStatisticsDto statisticsDto = new SupervisionCheckStatisticsDto();
|
||||||
|
// statisticsDto.setJurisdictionCode(agency.getAgencyCode());
|
||||||
|
// statisticsDto.setJurisdictionName(agency.getAgencyName());
|
||||||
|
// statisticsDto.setHasChildren(agency.getLeaf() ? 0 : 1);
|
||||||
|
// statisticsDto.setJurisdictionLevel(agency.getAgencyLevel());
|
||||||
|
// statisticsDto.setChecks(0);
|
||||||
|
// return statisticsDto;
|
||||||
|
// }).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,195 @@
|
||||||
|
package com.aisino.iles.lawenforcement.service;
|
||||||
|
|
||||||
|
import com.aisino.iles.common.util.BeanUtils;
|
||||||
|
import com.aisino.iles.lawenforcement.model.Agency;
|
||||||
|
import com.aisino.iles.lawenforcement.model.Zfclgl;
|
||||||
|
import com.aisino.iles.lawenforcement.model.Zfclgl_;
|
||||||
|
import com.aisino.iles.lawenforcement.model.query.ZfclglQuery;
|
||||||
|
import com.aisino.iles.lawenforcement.repository.AgencyRepository;
|
||||||
|
import com.aisino.iles.lawenforcement.repository.ZfclglRepository;
|
||||||
|
import com.smartlx.sso.client.model.RemoteUserInfo;
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执法车辆管理
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ZfclglService {
|
||||||
|
|
||||||
|
private final ZfclglRepository zfclglRep;
|
||||||
|
private final AgencyRepository agencyRepo;
|
||||||
|
|
||||||
|
public ZfclglService(ZfclglRepository zfclglRep,
|
||||||
|
AgencyRepository agencyRepo) {
|
||||||
|
this.zfclglRep = zfclglRep;
|
||||||
|
this.agencyRepo = agencyRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Zfclgl> list(ZfclglQuery query) {
|
||||||
|
return zfclglRep.findAll(buildQueryCondition(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Page<Zfclgl> page(ZfclglQuery query, RemoteUserInfo user) {
|
||||||
|
Integer _psize = Optional.ofNullable(query.pageSize()).filter(f -> f > 0).orElse(20);
|
||||||
|
Integer _page = Optional.ofNullable(query.page()).filter(f -> f > 0).map(f -> f - 1).orElse(0);
|
||||||
|
String _sort = Optional.ofNullable(query.sort()).filter(com.aisino.iles.common.util.StringUtils::isNotEmpty).orElse(Zfclgl_.GZSJ);
|
||||||
|
String _dir = Optional.ofNullable(query.dir()).filter(d -> Sort.Direction.fromOptionalString(d).isPresent()).orElse("desc");
|
||||||
|
|
||||||
|
return zfclglRep.findAll(buildQueryCondition(query), PageRequest.of(_page, _psize, Sort.by(Sort.Direction.fromString(_dir), _sort))).map(this::getZfclglInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Zfclgl getZfclglInfo(Zfclgl zfclgl) {
|
||||||
|
return zfclgl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态查询条件构建
|
||||||
|
*/
|
||||||
|
private Specification<Zfclgl> buildQueryCondition(ZfclglQuery query) {
|
||||||
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
||||||
|
Set<Predicate> predicates = new LinkedHashSet<>();
|
||||||
|
// 车辆类型代码
|
||||||
|
Optional.ofNullable(query.getCllxdm()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(Zfclgl_.cllxdm), o)));
|
||||||
|
// 车牌号
|
||||||
|
Optional.ofNullable(query.getCph()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.like(root.get(Zfclgl_.cph), "%" + o + "%")));
|
||||||
|
// 属地代码
|
||||||
|
if (null != query.getAgency()) {
|
||||||
|
query.setSddm(query.getAgency().getAgencyCode());
|
||||||
|
Optional.ofNullable(query.getSddm()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(Zfclgl_.sddm), o)));
|
||||||
|
}
|
||||||
|
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Zfclgl save(Zfclgl zfclgl, RemoteUserInfo user) {
|
||||||
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(zfclgl.getCllxdm())) {
|
||||||
|
if ("1".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("轿车");
|
||||||
|
} else if ("2".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("SUV");
|
||||||
|
} else if ("3".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("MPV");
|
||||||
|
} else if ("4".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("载货汽车");
|
||||||
|
} else if ("5".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("挂车");
|
||||||
|
} else if ("6".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("摩托车");
|
||||||
|
} else if ("7".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("自卸汽车");
|
||||||
|
} else if ("8".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("牵引汽车");
|
||||||
|
} else if ("8".equals(zfclgl.getCllxdm())) {
|
||||||
|
zfclgl.setCllx("救护车");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != zfclgl.getAgency()) {
|
||||||
|
zfclgl.setSddm(zfclgl.getAgency().getAgencyCode()); // 属地代码
|
||||||
|
zfclgl.setSdmc(zfclgl.getAgency().getAgencyName()); // 属地名称
|
||||||
|
}
|
||||||
|
return zfclglRep.save(zfclgl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Zfclgl modify(String zfclglid, Zfclgl zfclgl, RemoteUserInfo user) {
|
||||||
|
zfclglRep.findById(zfclglid).ifPresent(z -> {
|
||||||
|
BeanUtils.copyProperties(zfclgl, z);
|
||||||
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(z.getCllxdm())) {
|
||||||
|
if ("1".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("轿车");
|
||||||
|
} else if ("2".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("SUV");
|
||||||
|
} else if ("3".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("MPV");
|
||||||
|
} else if ("4".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("载货汽车");
|
||||||
|
} else if ("5".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("挂车");
|
||||||
|
} else if ("6".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("摩托车");
|
||||||
|
} else if ("7".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("自卸汽车");
|
||||||
|
} else if ("8".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("牵引汽车");
|
||||||
|
} else if ("8".equals(z.getCllxdm())) {
|
||||||
|
z.setCllx("救护车");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != z.getAgency()) {
|
||||||
|
z.setSddm(z.getAgency().getAgencyCode()); // 属地代码
|
||||||
|
z.setSdmc(z.getAgency().getAgencyName()); // 属地名称
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return zfclgl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void remove(@Validated @NotNull String zfclglid, RemoteUserInfo user) {
|
||||||
|
zfclglRep.deleteById(zfclglid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条查询
|
||||||
|
*/
|
||||||
|
public Optional<Zfclgl> findOne(@Validated @NotNull String zfclglid) {
|
||||||
|
return zfclglRep.findById(zfclglid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long count() {
|
||||||
|
return zfclglRep.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Zfclgl> zfclList(ZfclglQuery query, RemoteUserInfo user) {
|
||||||
|
return zfclglRep.findAll(buildQueryCondition(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<Zfclgl> page2(ZfclglQuery query, RemoteUserInfo user) {
|
||||||
|
Integer _psize = Optional.ofNullable(query.pageSize()).filter(f -> f > 0).orElse(20);
|
||||||
|
Integer _page = Optional.ofNullable(query.page()).filter(f -> f > 0).map(f -> f - 1).orElse(0);
|
||||||
|
String _sort = Optional.ofNullable(query.sort()).filter(com.aisino.iles.common.util.StringUtils::isNotEmpty).orElse(Zfclgl_.GZSJ);
|
||||||
|
String _dir = Optional.ofNullable(query.dir()).filter(d -> Sort.Direction.fromOptionalString(d).isPresent()).orElse("desc");
|
||||||
|
return zfclglRep.findAll(buildQueryCondition2(query, user), PageRequest.of(_page, _psize, Sort.by(Sort.Direction.fromString(_dir), _sort))).map(this::getZfclglInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Specification<Zfclgl> buildQueryCondition2(ZfclglQuery query, RemoteUserInfo user) {
|
||||||
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
||||||
|
Set<Predicate> predicates = new LinkedHashSet<>();
|
||||||
|
// 车辆类型代码
|
||||||
|
Optional.ofNullable(query.getCllxdm()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(Zfclgl_.cllxdm), o)));
|
||||||
|
// 车牌号
|
||||||
|
Optional.ofNullable(query.getCph()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.like(root.get(Zfclgl_.cph), "%" + o + "%")));
|
||||||
|
// 属地代码
|
||||||
|
Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!"));
|
||||||
|
if (currentAgency.getAgencyLevel() == 3) {
|
||||||
|
predicates.add(criteriaBuilder.equal(root.get(Zfclgl_.sddm), currentAgency.getAgencyCode()));
|
||||||
|
}
|
||||||
|
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
package com.aisino.iles.lawenforcement.service;
|
||||||
|
|
||||||
|
import com.aisino.iles.common.util.BeanUtils;
|
||||||
|
import com.aisino.iles.core.model.UserType_;
|
||||||
|
import com.aisino.iles.lawenforcement.model.*;
|
||||||
|
import com.aisino.iles.lawenforcement.model.dto.ZfzbglStatisticsDto;
|
||||||
|
import com.aisino.iles.lawenforcement.model.query.ZfzbglQuery;
|
||||||
|
import com.aisino.iles.lawenforcement.repository.*;
|
||||||
|
import com.smartlx.sso.client.model.RemoteUserInfo;
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执法装备管理
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ZfzbglService {
|
||||||
|
|
||||||
|
private final ZfzbglRepository zfzbglRepository;
|
||||||
|
private final EquipmentHistoryVideoRepository equipmentHistoryVideoRepository;
|
||||||
|
|
||||||
|
public ZfzbglService(ZfzbglRepository zfzbglRepository,EquipmentHistoryVideoRepository equipmentHistoryVideoRepository) {
|
||||||
|
this.zfzbglRepository = zfzbglRepository;
|
||||||
|
this.equipmentHistoryVideoRepository = equipmentHistoryVideoRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Zfzbgl> list(ZfzbglQuery query) {
|
||||||
|
return zfzbglRepository.findAll(buildQueryCondition(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Page<Zfzbgl> page(ZfzbglQuery query, RemoteUserInfo user) {
|
||||||
|
Integer _psize = Optional.ofNullable(query.pageSize()).filter(f -> f > 0).orElse(20);
|
||||||
|
Integer _page = Optional.ofNullable(query.page()).filter(f -> f > 0).map(f -> f - 1).orElse(0);
|
||||||
|
String _sort = Optional.ofNullable(query.sort()).filter(com.aisino.iles.common.util.StringUtils::isNotEmpty).orElse(Zfzbgl_.GZSJ);
|
||||||
|
String _dir = Optional.ofNullable(query.dir()).filter(d -> Sort.Direction.fromOptionalString(d).isPresent()).orElse("desc");
|
||||||
|
|
||||||
|
return zfzbglRepository.findAll(buildQueryCondition(query), PageRequest.of(_page, _psize, Sort.by(Sort.Direction.fromString(_dir), _sort)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态查询条件构建
|
||||||
|
*/
|
||||||
|
private Specification<Zfzbgl> buildQueryCondition(ZfzbglQuery query) {
|
||||||
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
||||||
|
Set<Predicate> predicates = new LinkedHashSet<>();
|
||||||
|
// 装备类型代码
|
||||||
|
Optional.ofNullable(query.getZblxdm()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(Zfzbgl_.zblxdm), o)));
|
||||||
|
// 使用人
|
||||||
|
Optional.ofNullable(query.getSyr()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.like(root.get(Zfzbgl_.syr), "%" + o + "%")));
|
||||||
|
// 属地代码
|
||||||
|
if (null!=query.getAgency()) {
|
||||||
|
query.setSddm(query.getAgency().getAgencyCode());
|
||||||
|
Optional.ofNullable(query.getSddm()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(Zfzbgl_.sddm), o)));
|
||||||
|
}
|
||||||
|
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Zfzbgl save(Zfzbgl zfzbgl, RemoteUserInfo user) {
|
||||||
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(zfzbgl.getZblxdm())) {
|
||||||
|
if ("1".equals(zfzbgl.getZblxdm())) {
|
||||||
|
zfzbgl.setZblx("个体防护");
|
||||||
|
} else if ("2".equals(zfzbgl.getZblxdm())) {
|
||||||
|
zfzbgl.setZblx("执法保障");
|
||||||
|
} else if ("3".equals(zfzbgl.getZblxdm())) {
|
||||||
|
zfzbgl.setZblx("执法过程");
|
||||||
|
} else if ("4".equals(zfzbgl.getZblxdm())) {
|
||||||
|
zfzbgl.setZblx("测量侦检");
|
||||||
|
} else if ("5".equals(zfzbgl.getZblxdm())) {
|
||||||
|
zfzbgl.setZblx("矿山执法");
|
||||||
|
} else if ("6".equals(zfzbgl.getZblxdm())) {
|
||||||
|
zfzbgl.setZblx("危化品执法");
|
||||||
|
} else if ("7".equals(zfzbgl.getZblxdm())) {
|
||||||
|
zfzbgl.setZblx("执法记录仪");
|
||||||
|
} else if ("8".equals(zfzbgl.getZblxdm())) {
|
||||||
|
zfzbgl.setZblx("对讲机");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null!=zfzbgl.getAgency()) {
|
||||||
|
zfzbgl.setSddm(zfzbgl.getAgency().getAgencyCode()); // 属地代码
|
||||||
|
zfzbgl.setSdmc(zfzbgl.getAgency().getAgencyName()); // 属地名称
|
||||||
|
}
|
||||||
|
return zfzbglRepository.save(zfzbgl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Zfzbgl modify(Zfzbgl zfzbgl, RemoteUserInfo user) {
|
||||||
|
zfzbglRepository.findById(zfzbgl.getZfzbglid()).ifPresent(z -> {
|
||||||
|
BeanUtils.copyProperties(zfzbgl, z);
|
||||||
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(z.getZblxdm())) {
|
||||||
|
if ("1".equals(z.getZblxdm())) {
|
||||||
|
z.setZblx("个体防护");
|
||||||
|
} else if ("2".equals(z.getZblxdm())) {
|
||||||
|
z.setZblx("执法保障");
|
||||||
|
} else if ("3".equals(z.getZblxdm())) {
|
||||||
|
z.setZblx("执法过程");
|
||||||
|
} else if ("4".equals(z.getZblxdm())) {
|
||||||
|
z.setZblx("测量侦检");
|
||||||
|
} else if ("5".equals(z.getZblxdm())) {
|
||||||
|
z.setZblx("矿山执法");
|
||||||
|
} else if ("6".equals(z.getZblxdm())) {
|
||||||
|
z.setZblx("危化品执法");
|
||||||
|
} else if ("7".equals(z.getZblxdm())) {
|
||||||
|
z.setZblx("执法记录仪");
|
||||||
|
} else if ("8".equals(z.getZblxdm())) {
|
||||||
|
z.setZblx("对讲机");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null!=z.getAgency()) {
|
||||||
|
z.setSddm(z.getAgency().getAgencyCode()); // 属地代码
|
||||||
|
z.setSdmc(z.getAgency().getAgencyName()); // 属地名称
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return zfzbgl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void remove(@Validated @NotNull String zfzbglid, RemoteUserInfo user) {
|
||||||
|
zfzbglRepository.deleteById(zfzbglid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条查询
|
||||||
|
*/
|
||||||
|
public Optional<Zfzbgl> findOne(@Validated @NotNull String zfzbglid) {
|
||||||
|
Optional<Zfzbgl> zfzbgl = zfzbglRepository.findById(zfzbglid);
|
||||||
|
if (zfzbgl.get().getZblxdm().equals("7") || zfzbgl.get().getZblxdm().equals("8")) {
|
||||||
|
List<EquipmentHistoryVideo> videos = equipmentHistoryVideoRepository.findByZbdm(zfzbgl.get().getSbbm());
|
||||||
|
zfzbgl.get().setVideos(videos);
|
||||||
|
}
|
||||||
|
return zfzbgl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首页-执法装备分类统计
|
||||||
|
*/
|
||||||
|
public List<ZfzbglStatisticsDto> syStatistics(ZfzbglQuery query, RemoteUserInfo user) {
|
||||||
|
List<String> allCodes = List.of("1", "2", "3", "4", "5", "6", "7", "8");
|
||||||
|
List<ZfzbglStatisticsDto> list = zfzbglRepository.syStatistics();
|
||||||
|
// 创建结果列表,初始包含原始数据
|
||||||
|
List<ZfzbglStatisticsDto> result = new ArrayList<>(list);
|
||||||
|
// 检查每个代码是否存在
|
||||||
|
for (String code : allCodes) {
|
||||||
|
boolean exists = list.stream().anyMatch(dto -> dto.getZblxdm() != null && dto.getZblxdm().equals(code));
|
||||||
|
// 如果不存在,创建并添加一个数量为0的DTO
|
||||||
|
if (!exists) {
|
||||||
|
ZfzbglStatisticsDto newDto = new ZfzbglStatisticsDto();
|
||||||
|
newDto.setZblxdm(code);
|
||||||
|
newDto.setNums(0L);
|
||||||
|
result.add(newDto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
package com.aisino.iles.lawenforcement.service;
|
||||||
|
|
||||||
|
import com.aisino.iles.common.util.BeanUtils;
|
||||||
|
import com.aisino.iles.lawenforcement.model.Zsfzgl;
|
||||||
|
import com.aisino.iles.lawenforcement.model.Zsfzgl_;
|
||||||
|
import com.aisino.iles.lawenforcement.model.query.ZsfzglQuery;
|
||||||
|
import com.aisino.iles.lawenforcement.repository.ZsfzglRepository;
|
||||||
|
import com.smartlx.sso.client.model.RemoteUserInfo;
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执法装备管理
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ZsfzglService {
|
||||||
|
|
||||||
|
private final ZsfzglRepository zsfzglRepository;
|
||||||
|
|
||||||
|
public ZsfzglService(ZsfzglRepository zsfzglRepository) {
|
||||||
|
this.zsfzglRepository = zsfzglRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Zsfzgl> list(ZsfzglQuery query) {
|
||||||
|
return zsfzglRepository.findAll(buildQueryCondition(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Page<Zsfzgl> page(ZsfzglQuery query, RemoteUserInfo user) {
|
||||||
|
Integer _psize = Optional.ofNullable(query.pageSize()).filter(f -> f > 0).orElse(20);
|
||||||
|
Integer _page = Optional.ofNullable(query.page()).filter(f -> f > 0).map(f -> f - 1).orElse(0);
|
||||||
|
String _sort = Optional.ofNullable(query.sort()).filter(com.aisino.iles.common.util.StringUtils::isNotEmpty).orElse(Zsfzgl_.GZSJ);
|
||||||
|
String _dir = Optional.ofNullable(query.dir()).filter(d -> Sort.Direction.fromOptionalString(d).isPresent()).orElse("desc");
|
||||||
|
|
||||||
|
return zsfzglRepository.findAll(buildQueryCondition(query), PageRequest.of(_page, _psize, Sort.by(Sort.Direction.fromString(_dir), _sort)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态查询条件构建
|
||||||
|
*/
|
||||||
|
private Specification<Zsfzgl> buildQueryCondition(ZsfzglQuery query) {
|
||||||
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
||||||
|
Set<Predicate> predicates = new LinkedHashSet<>();
|
||||||
|
// 服装类型代码
|
||||||
|
Optional.ofNullable(query.getFzlxdm()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(Zsfzgl_.fzlxdm), o)));
|
||||||
|
// 姓名
|
||||||
|
Optional.ofNullable(query.getName()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.like(root.get(Zsfzgl_.name), "%" + o + "%")));
|
||||||
|
// 属地代码
|
||||||
|
if (null!=query.getAgency()) {
|
||||||
|
query.setSddm(query.getAgency().getAgencyCode());
|
||||||
|
Optional.ofNullable(query.getSddm()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(Zsfzgl_.sddm), o)));
|
||||||
|
}
|
||||||
|
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Zsfzgl save(Zsfzgl zsfzgl, RemoteUserInfo user) {
|
||||||
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(zsfzgl.getFzlxdm())) {
|
||||||
|
if ("1".equals(zsfzgl.getFzlxdm())) {
|
||||||
|
zsfzgl.setFzlx("常服");
|
||||||
|
} else if ("2".equals(zsfzgl.getFzlxdm())) {
|
||||||
|
zsfzgl.setFzlx("执勤服");
|
||||||
|
} else if ("3".equals(zsfzgl.getFzlxdm())) {
|
||||||
|
zsfzgl.setFzlx("夏装制式衬衣");
|
||||||
|
} else if ("4".equals(zsfzgl.getFzlxdm())) {
|
||||||
|
zsfzgl.setFzlx("单裤、裙子");
|
||||||
|
} else if ("5".equals(zsfzgl.getFzlxdm())) {
|
||||||
|
zsfzgl.setFzlx("防寒服");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null!=zsfzgl.getAgency()) {
|
||||||
|
zsfzgl.setSddm(zsfzgl.getAgency().getAgencyCode()); // 属地代码
|
||||||
|
zsfzgl.setSdmc(zsfzgl.getAgency().getAgencyName()); // 属地名称
|
||||||
|
}
|
||||||
|
return zsfzglRepository.save(zsfzgl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Zsfzgl modify(String zsfzglid, Zsfzgl zsfzgl, RemoteUserInfo user) {
|
||||||
|
zsfzglRepository.findById(zsfzglid).ifPresent(z -> {
|
||||||
|
BeanUtils.copyProperties(zsfzgl, z);
|
||||||
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(z.getFzlxdm())) {
|
||||||
|
if ("1".equals(z.getFzlxdm())) {
|
||||||
|
z.setFzlx("常服");
|
||||||
|
} else if ("2".equals(z.getFzlxdm())) {
|
||||||
|
z.setFzlx("执勤服");
|
||||||
|
} else if ("3".equals(z.getFzlxdm())) {
|
||||||
|
z.setFzlx("夏装制式衬衣");
|
||||||
|
} else if ("4".equals(z.getFzlxdm())) {
|
||||||
|
z.setFzlx("单裤、裙子");
|
||||||
|
} else if ("5".equals(z.getFzlxdm())) {
|
||||||
|
z.setFzlx("防寒服");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null!=z.getAgency()) {
|
||||||
|
z.setSddm(z.getAgency().getAgencyCode()); // 属地代码
|
||||||
|
z.setSdmc(z.getAgency().getAgencyName()); // 属地名称
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return zsfzgl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void remove(@Validated @NotNull String zsfzglid, RemoteUserInfo user) {
|
||||||
|
zsfzglRepository.deleteById(zsfzglid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单条查询
|
||||||
|
*/
|
||||||
|
public Optional<Zsfzgl> findOne(@Validated @NotNull String zsfzglid) {
|
||||||
|
return zsfzglRepository.findById(zsfzglid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long count() {
|
||||||
|
return zsfzglRepository.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue