package org.jeecg.modules.arj.service.impl; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.shiro.SecurityUtils; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.arj.entity.Bianxk; import org.jeecg.modules.arj.mapper.BianxkMapper; import org.jeecg.modules.arj.service.BianxkService; import org.jeecg.modules.arj.service.HeadService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; import org.jeecg.modules.arj.entity.Head; import org.jeecg.modules.arj.mapper.HeadMapper; import java.util.List; /** * ;(head)表服务实现类 * @author : http://www.chiner.pro * @date : 2022-11-22 */ @Service public class HeadServiceImpl extends ServiceImpl implements HeadService { @Autowired private HeadMapper headMapper; @Override public Head queryLast(String leixing) { QueryWrapper Q = new QueryWrapper(); // LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); // // // if (loginUser != null) { // if (loginUser.getUserIdentity() <= 1) // Q.eq("createdby", loginUser.getRealname()); // else { // // 0开头的工号是盖线 // if (loginUser.getWorkNo().indexOf("0") == 0) { // Q.like("shengcx", "盖"); // } // if (loginUser.getWorkNo().indexOf("2") == 0) { // Q.like("shengcx", "二"); // } // if (loginUser.getWorkNo().indexOf("5") == 0) { // Q.like("shengcx", "五"); // } // } // } Q.orderByDesc("reportTime"); Q.eq("leixing",leixing); Q.last("limit 1"); List h = headMapper.selectList(Q); if( h != null && h.size() > 0 ) return h.get(0) ; return null ; } @Override public Head queryLeixingChanxian(String leixing,String shengcx) { QueryWrapper Q = new QueryWrapper(); Q.orderByDesc("reportTime"); Q.eq("leixing",leixing); if( shengcx != null ) Q.like("shengcx",shengcx); Q.last("limit 1"); List h = headMapper.selectList(Q); if( h != null && h.size() > 0 ) return h.get(0) ; return null ; } /** * 通过ID查询单条数据 * * @param id 主键 * @return 实例对象 */ public Head queryById(String id){ return headMapper.selectById(id); } /** * 分页查询 * * @param head 筛选条件 * @param current 当前页码 * @param size 每页大小 * @return */ public Page paginQuery(Head head, long current, long size){ //1. 构建动态查询条件 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if(StrUtil.isNotBlank(head.getShengcx())){ queryWrapper.eq(Head::getShengcx, head.getShengcx()); } if(StrUtil.isNotBlank(head.getChanpin())){ queryWrapper.eq(Head::getChanpin, head.getChanpin()); } if(StrUtil.isNotBlank(head.getBanci())){ queryWrapper.eq(Head::getBanci, head.getBanci()); } if(StrUtil.isNotBlank(head.getJiluyuan())){ queryWrapper.eq(Head::getJiluyuan, head.getJiluyuan()); } //2. 执行分页查询 Page pagin = new Page<>(current , size , true); IPage selectResult = headMapper.selectPage(pagin , queryWrapper); pagin.setPages(selectResult.getPages()); pagin.setTotal(selectResult.getTotal()); pagin.setRecords(selectResult.getRecords()); //3. 返回结果 return pagin; } /** * 新增数据 * * @param head 实例对象 * @return 实例对象 */ public Head insert(Head head){ headMapper.insert(head); return head; } /** * 更新数据 * * @param head 实例对象 * @return 实例对象 */ public Head update(Head head){ //1. 根据条件动态更新 LambdaUpdateChainWrapper chainWrapper = new LambdaUpdateChainWrapper(headMapper); if(StrUtil.isNotBlank(head.getShengcx())){ chainWrapper.eq(Head::getShengcx, head.getShengcx()); } if(StrUtil.isNotBlank(head.getChanpin())){ chainWrapper.eq(Head::getChanpin, head.getChanpin()); } if(StrUtil.isNotBlank(head.getBanci())){ chainWrapper.eq(Head::getBanci, head.getBanci()); } if(StrUtil.isNotBlank(head.getJiluyuan())){ chainWrapper.eq(Head::getJiluyuan, head.getJiluyuan()); } //2. 设置主键,并更新 chainWrapper.set(Head::getId, head.getId()); boolean ret = chainWrapper.update(); //3. 更新成功了,查询最最对象返回 if(ret){ return queryById(head.getId()); }else{ return head; } } /** * 通过主键删除数据 * * @param id 主键 * @return 是否成功 */ public boolean deleteById(String id){ int total = headMapper.deleteById(id); return total > 0; } }