package com.newfiber.api.pc.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.newfiber.api.pc.dao.RiverManage.PatrolManageUserStateMapper; import com.newfiber.api.pc.model.River.PatrolManageProcess; import com.newfiber.api.pc.model.River.PatrolManageUserState; import com.newfiber.api.pc.service.PatrolManageUserStateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service("patrolManageUserService") public class PatrolManageUserStateServiceImpl extends ServiceImpl<PatrolManageUserStateMapper, PatrolManageUserState> implements PatrolManageUserStateService { @Autowired private PatrolManageUserStateMapper patrolManageUserStateMapper; @Override public PageInfo<PatrolManageUserState> listForPage(String searchStr, Integer pageNo, Integer pageSize) { PageHelper.startPage(pageNo, pageSize); EntityWrapper wapper = new EntityWrapper<>(); //name 模糊匹配的字段 wapper.like("name", searchStr); List<PatrolManageUserState> list = patrolManageUserStateMapper.selectList(wapper); PageInfo<PatrolManageUserState> result = new PageInfo<>(); if (!list.isEmpty()) { result = new PageInfo<>(list); } return result; } @Override public int insertOrupdateByName(PatrolManageProcess process, String userNo, Integer state) { if(userNo== null){ return 0; } //判断是否存在数据 if (existData(process, userNo)) { /*PatrolManageUserState problem = new PatrolManageUserState(); problem.setProblemState(state); problem.setPatrolType(problem.getPatrolType()); EntityWrapper<PatrolManageUserState> wrapper = new EntityWrapper<>(); wrapper.eq("problem_id",process.getProblemId()); //wrapper.eq("patrol_type",process.getPatrolType()); wrapper.eq("user_no",userNo);*/ return patrolManageUserStateMapper.updateTypeAndState(process.getProblemId(),process.getPatrolType(),userNo,state); } else { PatrolManageUserState patrolUserState = new PatrolManageUserState(); patrolUserState.setUserNo(userNo); patrolUserState.setProblemId(process.getProblemId()); patrolUserState.setPatrolType(process.getPatrolType()); patrolUserState.setProblemState(state); return patrolManageUserStateMapper.insert(patrolUserState); } } @Override public int deleteStateByName(Long id, Integer patrolType, String userNo) { return patrolManageUserStateMapper.deleteByProblemId(id,patrolType,userNo); } @Override public void addOrUpdateUserState(Long id, Integer patrolType, String operatorNo, int state) { if(operatorNo==null){ return; } Boolean flag = existData(id, patrolType, operatorNo); if(flag){//存在 PatrolManageUserState problem = new PatrolManageUserState(); problem.setProblemState(state); problem.setPatrolType(patrolType); EntityWrapper<PatrolManageUserState> wrapper = new EntityWrapper<>(); wrapper.eq("problem_id",id); //wrapper.eq("patrol_type",patrolType); wrapper.eq("user_no",operatorNo); patrolManageUserStateMapper.updateTypeAndState(id,patrolType,operatorNo,state); } else {//更新 PatrolManageUserState patrolUserState = new PatrolManageUserState(); patrolUserState.setUserNo(operatorNo); patrolUserState.setProblemId(id); patrolUserState.setPatrolType(patrolType); patrolUserState.setProblemState(state); patrolManageUserStateMapper.insert(patrolUserState); } } @Override public int updateByProblemId(Long id, Integer patrolType) { return patrolManageUserStateMapper.updateByProblemId(id,patrolType); } /** * 是否存在数据 * * @param process * @param userNo * @return */ private Boolean existData(PatrolManageProcess process, String userNo) { EntityWrapper<PatrolManageUserState> wrapper = new EntityWrapper<>(); //wrapper.eq("patrol_type", process.getPatrolType()); wrapper.eq("problem_id", process.getProblemId()); wrapper.eq("user_no", userNo); wrapper.last("limit 1"); PatrolManageUserState userState = this.selectOne(wrapper); if (userState != null) { return true; } return false; } private Boolean existData(Long problemId,Integer patrolType, String userNo) { EntityWrapper<PatrolManageUserState> wrapper = new EntityWrapper<>(); //wrapper.eq("patrol_type",patrolType); wrapper.eq("problem_id", problemId); wrapper.eq("user_no", userNo); wrapper.last("limit 1"); PatrolManageUserState userState = this.selectOne(wrapper); if (userState != null) { return true; } return false; } }