TestTableServiceImpl.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.zhaoliangsz.grainsearch.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.zhaoliangsz.grainsearch.domain.entity.TestTable;
  4. import com.zhaoliangsz.grainsearch.mapper.TestTableMapper;
  5. import com.zhaoliangsz.grainsearch.service.ITestTableService;
  6. import com.baomidou.mybatisplus.extension.service.IService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.scheduling.annotation.Scheduled;
  9. import org.springframework.stereotype.Service;
  10. import com.zhaoliangsz.grainsearch.basic.exception.ServiceException;
  11. import com.zhaoliangsz.grainsearch.basic.result.PageResult;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import lombok.extern.slf4j.Slf4j;
  14. import java.sql.Wrapper;
  15. import java.util.*;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import com.zhaoliangsz.grainsearch.basic.exception.ExceptionDefinition;
  18. /**
  19. * <p>
  20. * 服务实现类
  21. * </p>
  22. *
  23. * @author zyw
  24. * @since 2023-08-21 14:40:08
  25. */
  26. @Slf4j
  27. @Service
  28. public class TestTableServiceImpl extends ServiceImpl<TestTableMapper, TestTable> implements ITestTableService {
  29. @Autowired
  30. private TestTableMapper testTableMapper;
  31. @Override
  32. public PageResult<TestTable> queryTestTableList(TestTable queryTestTable) throws ServiceException{
  33. try{
  34. Map<String,Object>pageView=new HashMap<>();
  35. pageView.put("startRecord",(queryTestTable.getCurrentPage()-1)
  36. *queryTestTable.getPageSize());
  37. pageView.put("pageSize",queryTestTable.getPageSize());
  38. pageView.put("currentPage",queryTestTable.getCurrentPage());
  39. Integer dataCount=baseMapper.getCountByCondition(pageView);
  40. List<TestTable>dataList=baseMapper.getListByCondition(pageView);
  41. return new PageResult<>(dataList==null?new ArrayList<>():dataList,dataCount==null?0:dataCount);
  42. }
  43. catch(Exception ex){
  44. log.error("[TestTableServiceImpl.queryTestTableList]异常:{}",ex.toString());
  45. throw new ServiceException(ExceptionDefinition.QUERY_DATA_EXCEPTION);
  46. }
  47. }
  48. @Override
  49. @Transactional(rollbackFor = Exception.class)
  50. public String addTestTable(TestTable addTestTable) throws ServiceException {
  51. TestTable testTable=testTableMapper.selectOne(new QueryWrapper<TestTable>()
  52. .eq("type",addTestTable.getType())
  53. .eq("banci",addTestTable.getBanci())
  54. .eq("banzu",addTestTable.getBanzu())
  55. .eq("date",addTestTable.getDate()));
  56. boolean flag;
  57. if (testTable!=null){
  58. addTestTable.setUpdateTime(new Date());
  59. addTestTable.setId(testTable.getId());
  60. flag= this.updateById(addTestTable);
  61. }
  62. else {
  63. addTestTable.setCreateTime(new Date());
  64. addTestTable.setUpdateTime(new Date());
  65. flag= this.save(addTestTable);
  66. }
  67. if(flag){
  68. return "ok";
  69. }
  70. else{
  71. throw new ServiceException(ExceptionDefinition.ADD_DATA_EXCEPTION);
  72. }
  73. }
  74. @Override
  75. @Transactional(rollbackFor = Exception.class)
  76. public String editTestTable(TestTable editTestTable) throws ServiceException {
  77. boolean flag = this.updateById(editTestTable);
  78. if(flag){
  79. return "ok";
  80. }
  81. else{
  82. throw new ServiceException(ExceptionDefinition.EDIT_DATA_EXCEPTION);
  83. }
  84. }
  85. @Override
  86. @Transactional(rollbackFor = Exception.class)
  87. public String deleteTestTable(TestTable deleteTestTable) throws ServiceException {
  88. boolean flag = this.removeById(deleteTestTable);
  89. if(flag){
  90. return "ok";
  91. }
  92. else{
  93. throw new ServiceException(ExceptionDefinition.DELETE_DATA_EXCEPTION);
  94. }
  95. }
  96. /**
  97. * 每天23.55点更新(新)
  98. */
  99. // @Transactional(rollbackFor = Exception.class)
  100. // @Scheduled(cron = "0 55 23 * * ?")
  101. // public String addInfo() {
  102. // if ("3".equals(ENV)) {
  103. // }
  104. // return "OK";
  105. // }
  106. }