123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package com.zhaoliangsz.grainsearch.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.zhaoliangsz.grainsearch.domain.entity.TestTable;
- import com.zhaoliangsz.grainsearch.mapper.TestTableMapper;
- import com.zhaoliangsz.grainsearch.service.ITestTableService;
- import com.baomidou.mybatisplus.extension.service.IService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- import com.zhaoliangsz.grainsearch.basic.exception.ServiceException;
- import com.zhaoliangsz.grainsearch.basic.result.PageResult;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import lombok.extern.slf4j.Slf4j;
- import java.sql.Wrapper;
- import java.util.*;
- import org.springframework.transaction.annotation.Transactional;
- import com.zhaoliangsz.grainsearch.basic.exception.ExceptionDefinition;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author zyw
- * @since 2023-08-21 14:40:08
- */
- @Slf4j
- @Service
- public class TestTableServiceImpl extends ServiceImpl<TestTableMapper, TestTable> implements ITestTableService {
- @Autowired
- private TestTableMapper testTableMapper;
- @Override
- public PageResult<TestTable> queryTestTableList(TestTable queryTestTable) throws ServiceException{
- try{
- Map<String,Object>pageView=new HashMap<>();
- pageView.put("startRecord",(queryTestTable.getCurrentPage()-1)
- *queryTestTable.getPageSize());
- pageView.put("pageSize",queryTestTable.getPageSize());
- pageView.put("currentPage",queryTestTable.getCurrentPage());
- Integer dataCount=baseMapper.getCountByCondition(pageView);
- List<TestTable>dataList=baseMapper.getListByCondition(pageView);
- return new PageResult<>(dataList==null?new ArrayList<>():dataList,dataCount==null?0:dataCount);
- }
- catch(Exception ex){
- log.error("[TestTableServiceImpl.queryTestTableList]异常:{}",ex.toString());
- throw new ServiceException(ExceptionDefinition.QUERY_DATA_EXCEPTION);
- }
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public String addTestTable(TestTable addTestTable) throws ServiceException {
- TestTable testTable=testTableMapper.selectOne(new QueryWrapper<TestTable>()
- .eq("type",addTestTable.getType())
- .eq("banci",addTestTable.getBanci())
- .eq("banzu",addTestTable.getBanzu())
- .eq("date",addTestTable.getDate()));
- boolean flag;
- if (testTable!=null){
- addTestTable.setUpdateTime(new Date());
- addTestTable.setId(testTable.getId());
- flag= this.updateById(addTestTable);
- }
- else {
- addTestTable.setCreateTime(new Date());
- addTestTable.setUpdateTime(new Date());
- flag= this.save(addTestTable);
- }
- if(flag){
- return "ok";
- }
- else{
- throw new ServiceException(ExceptionDefinition.ADD_DATA_EXCEPTION);
- }
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public String editTestTable(TestTable editTestTable) throws ServiceException {
- boolean flag = this.updateById(editTestTable);
- if(flag){
- return "ok";
- }
- else{
- throw new ServiceException(ExceptionDefinition.EDIT_DATA_EXCEPTION);
- }
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public String deleteTestTable(TestTable deleteTestTable) throws ServiceException {
- boolean flag = this.removeById(deleteTestTable);
- if(flag){
- return "ok";
- }
- else{
- throw new ServiceException(ExceptionDefinition.DELETE_DATA_EXCEPTION);
- }
- }
- /**
- * 每天23.55点更新(新)
- */
- // @Transactional(rollbackFor = Exception.class)
- // @Scheduled(cron = "0 55 23 * * ?")
- // public String addInfo() {
- // if ("3".equals(ENV)) {
- // }
- // return "OK";
- // }
- }
|