zhangnaisong
2024-07-20 55811ddff81bc142eac3c27e44f30c55e84311f1
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankWallLockServiceImpl.java
@@ -6,11 +6,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Map;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.sy.mapper.ArdTankWallLockMapper;
import com.ruoyi.sy.domain.ArdTankWallLock;
import com.ruoyi.sy.service.IArdTankWallLockService;
import javax.annotation.Resource;
/**
 * 电子围栏电磁锁Service业务层处理
@@ -20,7 +24,7 @@
 */
@Service
public class ArdTankWallLockServiceImpl implements IArdTankWallLockService {
    @Autowired
    @Resource
    private ArdTankWallLockMapper ardTankWallLockMapper;
    /**
@@ -89,4 +93,49 @@
    public int deleteArdTankWallLockByProcessType(String processType) {
        return ardTankWallLockMapper.deleteArdTankWallLockByProcessType(processType);
    }
    @Override
    public int insertWallLock(Map<String, Object> para) {
        String id = (String) para.get("id");//锁主键
        List<Map<String,String>> tankWallLockList = (List<Map<String, String>>) para.get("tankWallLockList");
        if(tankWallLockList.size() == 0){//数组为空,做删除操作
            List<ArdTankWallLock> ardTankWallLockList = ardTankWallLockMapper.selectArdTankWallLockByLockId(id);//查询之前挂接的电子围栏
            if(ardTankWallLockList.size() == 0){//若没有挂接,不做操作
                return 1;
            }
            int result = ardTankWallLockMapper.deleteArdTankWallLockByLockId(id);
            return result;
        }
        //List<ArdTankWallLock> tankWallLocks = new ArrayList();
        List<String> idList = new ArrayList();//存放新增和修改的中间表主键
        int result = 0;
        for(Map<String,String> map : tankWallLockList){
            ArdTankWallLock ardTankWallLock = new ArdTankWallLock();
            ardTankWallLock.setWallId(map.get("wallId"));
            ardTankWallLock.setLockId(id);
            List<ArdTankWallLock> ardTankWallLockList = ardTankWallLockMapper.selectArdTankWallLockList(ardTankWallLock);
            if(ardTankWallLockList.size() != 0){
                ardTankWallLock.setProcessType(map.get("processType"));
                result = result + ardTankWallLockMapper.updateArdTankWallLockByWallIdAndLockId(ardTankWallLock);
                for(ArdTankWallLock ardTankWallLockOld : ardTankWallLockList){//需要修改的主键
                    idList.add(ardTankWallLockOld.getId());
                }
            }else{
                ardTankWallLock.setProcessType(map.get("processType"));
                ardTankWallLock.setId(IdUtils.simpleUUID());
                result = result + ardTankWallLockMapper.insertArdTankWallLock(ardTankWallLock);
                idList.add(ardTankWallLock.getId());//新增的主键
            }
        }
        if(!idList.isEmpty()){//判断是否有需要删除的数据主键
            result = result + ardTankWallLockMapper.deleteArdTankWallLockByLockIdAndOtherIds(id,idList);
        }
        return result;
    }
    @Override
    public int deleteArdTankWallLockByLockId(String id) {
        int result = ardTankWallLockMapper.deleteArdTankWallLockByLockId(id);
        return result;
    }
}