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.EventsManage.ComplaintUserStateMapper; import com.newfiber.api.pc.model.EventsManage.ComplaintUserState; import com.newfiber.api.pc.service.ComplaintUserStateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; @Service("complaintUserStateService") public class ComplaintUserStateServiceImpl extends ServiceImpl<ComplaintUserStateMapper, ComplaintUserState> implements ComplaintUserStateService { @Autowired private ComplaintUserStateMapper complaintUserStateMapper; @Override public PageInfo<ComplaintUserState> listForPage(String searchStr, Integer pageNo, Integer pageSize) { PageHelper.startPage(pageNo, pageSize); EntityWrapper<ComplaintUserState> wapper = new EntityWrapper<>(); //name 模糊匹配的字段 wapper.like("name", searchStr); List<ComplaintUserState> list = complaintUserStateMapper.selectList(wapper); PageInfo<ComplaintUserState> result = new PageInfo<>(); if (!list.isEmpty()) { result = new PageInfo<ComplaintUserState>(list); } return result; } @Override public void addOrUpdateUserState(Long id,Integer complaintType, String userNo, int state) { Boolean flag = existData(id, complaintType, userNo); if(flag){//存在 ComplaintUserState problem = new ComplaintUserState(); problem.setState(state); EntityWrapper<ComplaintUserState> wrapper = new EntityWrapper<>(); wrapper.eq("complaint_task_id",id); wrapper.eq("complaint_type",complaintType); wrapper.eq("user_no",userNo); complaintUserStateMapper.update(problem,wrapper); } else {//更新 ComplaintUserState patrolUserState = new ComplaintUserState(); patrolUserState.setUserNo(userNo); patrolUserState.setComplaintTaskId(id); patrolUserState.setComplaintType(complaintType); patrolUserState.setState(state); patrolUserState.setCreateTime(new Date()); complaintUserStateMapper.insert(patrolUserState); } } private Boolean existData(Long id,Integer complaintType, String userNo) { EntityWrapper<ComplaintUserState> wrapper = new EntityWrapper<>(); wrapper.eq("complaint_type", complaintType); wrapper.eq("complaint_task_id", id); wrapper.eq("user_no", userNo); ComplaintUserState userState = this.selectOne(wrapper); if (userState != null) { return true; } return false; } }