package com.newfiber.api.pc.service.impl; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.newfiber.api.core.exception.RRException; import com.newfiber.api.pc.dao.ManPumpstationMapper; import com.newfiber.api.pc.dao.SysOrgJurisdictionDao; import com.newfiber.api.pc.dao.Data_User_JurisdictionDao; import com.newfiber.api.pc.dao.Data_User_OrgDao; import com.newfiber.api.pc.model.entity.OrgJurisdiction; import com.newfiber.api.pc.model.entity.Data_User_Info; import com.newfiber.api.pc.model.entity.Data_User_Jurisdiction; import com.newfiber.api.pc.model.entity.Data_User_Org; import com.newfiber.api.pc.model.vo.OrgVo; import com.newfiber.api.pc.model.zhz.ManPumpstation; import com.newfiber.api.pc.service.Data_User_OrgService; import javax.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.Date; import java.util.List; @Service @Transactional(rollbackFor = Exception.class) public class DataUserOrgServiceImpl extends ServiceImpl<Data_User_OrgDao, Data_User_Org> implements Data_User_OrgService { @Autowired private Data_User_OrgDao UserOrgDao; @Autowired private SysOrgJurisdictionDao dataOrgDao; @Autowired private Data_User_JurisdictionDao userJurisdiction; @Resource private UserJurisdictionServiceImpl userJurisdictionService; @Override public Page<Data_User_Info> userOrgByList(String sort, String order, int pageNo, int pageSize, String Org_No) throws Exception { Page<Data_User_Info> result = new Page<>(); Data_User_Info info=new Data_User_Info(); info.setPageSize(pageSize); info.setPageNo(pageNo); info.setOrgNo(Org_No); info.setSort(sort); info.setOrder(order); List<Data_User_Info> uRoleList=UserOrgDao.orgList(info); result.setRecords(uRoleList); int total=UserOrgDao.orgUserCount(info); result.setTotal(total); return result; } //新增时查询未分配用户的机构 @Override public Page<Data_User_Info> userOrgByListOne(String sort, String order, int pageNo, int pageSize, String Org_No) throws Exception { Page<Data_User_Info> result = new Page<>(); Data_User_Info info=new Data_User_Info(); info.setPageSize(pageSize); info.setPageNo(pageNo); info.setOrgNo(Org_No); info.setSort(sort); info.setOrder(order); List<Data_User_Info> uRoleList=UserOrgDao.orgNotUserList(info); result.setRecords(uRoleList); int total=UserOrgDao.orgNotUserCount(info); result.setTotal(total); return result; } //添加机构用户 @Override @Transactional(rollbackFor = Exception.class) public int addUserOrg(String userNos, String orgNo){ String[] userNoArray = userNos.split(","); List<OrgJurisdiction> orgJurisdictionList = dataOrgDao.GetOrgJur(orgNo); List<OrgJurisdiction> orgRoleJurisdictionList = dataOrgDao.GetOrgRoleJur(orgNo); List<Data_User_Org> userOrgList = new ArrayList<>(); List<Data_User_Jurisdiction> userJurisdictionList = new ArrayList<>(); for (String userNo : userNoArray) { Data_User_Org userOrg = new Data_User_Org(); userOrg.setUserNo(userNo); userOrg.setOrgNo(orgNo); userOrgList.add(userOrg); for (OrgJurisdiction orgJurisdiction : orgJurisdictionList) { Data_User_Jurisdiction userJurisdiction = new Data_User_Jurisdiction(); userJurisdiction.setJurisdictionNo(orgJurisdiction.getJurisdictionNo()); userJurisdiction.setUserNo(userNo); userJurisdiction.setType(orgJurisdiction.getType()); userJurisdictionList.add(userJurisdiction); } for (OrgJurisdiction orgJurisdiction : orgRoleJurisdictionList) { Data_User_Jurisdiction userJurisdiction = new Data_User_Jurisdiction(); userJurisdiction.setJurisdictionNo(orgJurisdiction.getJurisdictionNo()); userJurisdiction.setUserNo(userNo); userJurisdiction.setType(orgJurisdiction.getType()); userJurisdictionList.add(userJurisdiction); } } this.insertBatch(userOrgList); if(CollectionUtils.isNotEmpty(userJurisdictionList)){ userJurisdictionService.insertBatch(userJurisdictionList); } return 0; } @Override public void deleteUserOrg(String User_No,String Org_No) throws Exception { List<OrgJurisdiction> list3=dataOrgDao.GetOrgRoleJur(Org_No); if(User_No!=null&&User_No!=""){ List<Data_User_Org> duoList = new ArrayList<>(); String []userNo=User_No.split(","); for(int i=0;i<userNo.length;i++){ Data_User_Org org=new Data_User_Org(); org.setOrgNo(Org_No); org.setUserNo(userNo[i]); duoList.add(org); } UserOrgDao.deleteOrg(duoList); if(list3.size()>0){ List<OrgJurisdiction> ojList = new ArrayList<>(); for(int j=0;j<list3.size();j++){ OrgJurisdiction orgjUr= new OrgJurisdiction(); orgjUr.setType(list3.get(j).getType()); orgjUr.setJurisdictionNo(list3.get(j).getJurisdictionNo()); ojList.add(orgjUr); } userJurisdiction.deleteUserOrgJur(ojList); } } } @Override public List<OrgVo> selectOrgNoByUserNo(String userNo) { if(StringUtils.isEmpty(userNo)){ throw new RRException("传入参数为空",505); } return UserOrgDao.selectOrgNoByUserNo(userNo); } }