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; /** *

* 服务实现类 *

* * @author zyw * @since 2023-08-21 14:40:08 */ @Slf4j @Service public class TestTableServiceImpl extends ServiceImpl implements ITestTableService { @Autowired private TestTableMapper testTableMapper; @Override public PageResult queryTestTableList(TestTable queryTestTable) throws ServiceException{ try{ MappageView=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); ListdataList=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() .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"; // } }