SmartWarningServiceImpl.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.template.services.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.template.mapper.SmartWarningMapper;
  8. import com.template.model.pojo.SmartWarning;
  9. import com.template.model.pojo.SmartWarning;
  10. import com.template.mapper.SmartWarningMapper;
  11. import com.template.model.result.PageUtils;
  12. import com.template.services.SmartWarningService;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.util.StringUtils;
  17. import java.time.LocalDate;
  18. import java.time.format.DateTimeFormatter;
  19. import java.util.List;
  20. /**
  21. * <p>
  22. * 服务实现类
  23. * </p>
  24. *
  25. * @author ceshi
  26. * @since 2023-12-04
  27. */
  28. @Service
  29. public class SmartWarningServiceImpl extends ServiceImpl<SmartWarningMapper, SmartWarning> implements SmartWarningService {
  30. @Autowired
  31. private SmartWarningMapper smartWarningMapper;
  32. @Override
  33. public int insertSmartWarning(SmartWarning sa) {
  34. int result = smartWarningMapper.insert(sa);
  35. return result;
  36. }
  37. @Override
  38. public int updateSmartWarning(SmartWarning sa) {
  39. int result = smartWarningMapper.updateById(sa);
  40. return result;
  41. }
  42. @Override
  43. public PageUtils<SmartWarning> queryPageSmartWarnings(int currentPage, int pageCount, String name,String state) {
  44. Page<SmartWarning> page = new Page<>(currentPage, pageCount);
  45. LambdaQueryWrapper<SmartWarning> queryWrapper = new LambdaQueryWrapper<>();
  46. queryWrapper.like(ObjectUtils.isNotEmpty(name),SmartWarning::getLocation,name)
  47. .eq(ObjectUtils.isNotEmpty(state),SmartWarning::getStatu,state);
  48. IPage<SmartWarning> result = smartWarningMapper.selectPage(page, queryWrapper);
  49. return new PageUtils<>(result);
  50. }
  51. @Override
  52. public int deleteSmartWarningById(int id) {
  53. int result = smartWarningMapper.deleteById(id);
  54. return result;
  55. }
  56. @Override
  57. public SmartWarning getSmartById(int id) {
  58. SmartWarning result = smartWarningMapper.selectById(id);
  59. return result;
  60. }
  61. @Override
  62. public List<String> warningType() {
  63. return smartWarningMapper.warningType();
  64. }
  65. @Override
  66. public PageUtils<SmartWarning> pageWarning(int currentPage, int pageCount, String type, String dateTime) {
  67. DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  68. LocalDate state = LocalDate.parse(dateTime, dateTimeFormatter2);
  69. LocalDate end = state.plusDays(1);
  70. Page<SmartWarning> page = new Page<>(currentPage, pageCount);
  71. LambdaQueryWrapper<SmartWarning> queryWrapper = new LambdaQueryWrapper<>();
  72. if (!"全部".equals(type)) {
  73. queryWrapper.eq(SmartWarning::getType,type);
  74. }
  75. queryWrapper.between(SmartWarning::getDateTime,state,end)
  76. .eq(SmartWarning::getStatu,0)
  77. .orderByDesc(SmartWarning::getDateTime);
  78. IPage<SmartWarning> result = smartWarningMapper.selectPage(page, queryWrapper);
  79. return new PageUtils<>(result);
  80. }
  81. }